Skip to content

Commit

Permalink
Merge pull request #31 from JuliaML/josh
Browse files Browse the repository at this point in the history
allow * to construct scaled
  • Loading branch information
joshday authored Oct 30, 2017
2 parents 6da0c35 + 913c131 commit c2e9c7c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/elementpenalty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ end
scaled(p::ElementPenalty, λ::Number) = (_scale_check(λ); ScaledElementPenalty(p, λ))
Base.show(io::IO, sp::ScaledElementPenalty) = print(io, "$(sp.λ) * ($(sp.penalty))")

Base.:(*)(λ::Number, p::ElementPenalty) = scaled(p, λ)

value(p::ScaledElementPenalty{<:Number}, θ::Number) = p.λ * value(p.penalty, θ)
deriv(p::ScaledElementPenalty{<:Number}, θ::Number) = p.λ * deriv(p.penalty, θ)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ end
# FIXME: @inference broken during tests (not in REPL though)
# only for ElasticNetPenalty{Float64} for some reason
@test value(s, x) value(p, x, .1)
@test value(s, x) == value(.1 * p, x)
@test @inferred(deriv(s, x[1])) deriv(p, x[1], .1)
@test @inferred(grad(s, x)) grad(p, x, .1)
if typeof(p) <: ConvexElementPenalty
Expand Down

0 comments on commit c2e9c7c

Please sign in to comment.