Skip to content

Commit

Permalink
Merge pull request #95 from tkoolen/tk/scale-svector
Browse files Browse the repository at this point in the history
 Fix SVector * number optimization
  • Loading branch information
tkoolen authored Jan 22, 2019
2 parents e7ef2f7 + 316b7db commit 96f03a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lazyexpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ function optimize(expr::LazyExpression{typeof(convert)}, ::Type, ::Type{<:Abstra
LazyExpression(copyto!, deepcopy(expr()), expr.args[2])
end

function optimize(expr::LazyExpression{typeof(*)}, ::Type{<:Number}, ::Type{<:AbstractVector{<:Union{Number, Variable, AffineFunction}}})
function optimize(expr::LazyExpression{typeof(*)}, ::Type{<:Number}, ::Type{<:Vector{<:Union{Number, Variable, AffineFunction}}})
LazyExpression(Functions.scale!, deepcopy(expr()), expr.args...)
end

function optimize(expr::LazyExpression{typeof(*)}, ::Type{<:AbstractVector{<:Union{Number, Variable, AffineFunction}}}, ::Type{<:Number})
function optimize(expr::LazyExpression{typeof(*)}, ::Type{<:Vector{<:Union{Number, Variable, AffineFunction}}}, ::Type{<:Number})
LazyExpression(Functions.scale!, deepcopy(expr()), expr.args...)
end

Expand Down
9 changes: 9 additions & 0 deletions test/lazyexpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,13 @@ end
@test(@expression(reshape(A, (2, 2))) == reshape(A, (2, 2)))
end

@testset "scale SVector" begin
model = mock_model()
x = Parameter(model, val=SVector(Variable(1), Variable(2)))
expr = @expression x * 3
@test expr() == SVector(3 * x.val[][1], 3 * x.val[][2])
expr = @expression 3 * x
@test expr() == SVector(x.val[][1] * 3, x.val[][2] * 3)
end

end # module

0 comments on commit 96f03a2

Please sign in to comment.