Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Try out scalar parameters #537

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/transform/scaletransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@
```
"""
struct ScaleTransform{T<:Real} <: Transform
s::Vector{T}
s::T
end

function ScaleTransform(s::T=1.0) where {T<:Real}
return ScaleTransform{T}([s])
return ScaleTransform{T}(s)
end

@functor ScaleTransform
(t::ScaleTransform)(x) = t.s * x

Check warning on line 23 in src/transform/scaletransform.jl

View check run for this annotation

Codecov / codecov/patch

src/transform/scaletransform.jl#L23

Added line #L23 was not covered by tests

set!(t::ScaleTransform, ρ::Real) = t.s .= [ρ]
_map(t::ScaleTransform, x::AbstractVector{<:Real}) = t.s .* x
_map(t::ScaleTransform, x::ColVecs) = ColVecs(t.s .* x.X)
_map(t::ScaleTransform, x::RowVecs) = RowVecs(t.s .* x.X)

(t::ScaleTransform)(x) = only(t.s) * x
Base.isequal(t::ScaleTransform, t2::ScaleTransform) = isequal(t.s, only(t2.s))

Check warning on line 29 in src/transform/scaletransform.jl

View check run for this annotation

Codecov / codecov/patch

src/transform/scaletransform.jl#L29

Added line #L29 was not covered by tests

_map(t::ScaleTransform, x::AbstractVector{<:Real}) = only(t.s) .* x
_map(t::ScaleTransform, x::ColVecs) = ColVecs(only(t.s) .* x.X)
_map(t::ScaleTransform, x::RowVecs) = RowVecs(only(t.s) .* x.X)

Base.isequal(t::ScaleTransform, t2::ScaleTransform) = isequal(only(t.s), only(t2.s))

Base.show(io::IO, t::ScaleTransform) = print(io, "Scale Transform (s = ", only(t.s), ")")
Base.show(io::IO, t::ScaleTransform) = print(io, "Scale Transform (s = ", t.s, ")")

Check warning on line 31 in src/transform/scaletransform.jl

View check run for this annotation

Codecov / codecov/patch

src/transform/scaletransform.jl#L31

Added line #L31 was not covered by tests

# Helpers

Expand Down
Loading