Skip to content

Commit 7dc00ae

Browse files
committed
Recursively evaluate combined factors
1 parent b38a06f commit 7dc00ae

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/forward.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ function evaluate(::Mult, arg1::BinaryOperation{Mult}, arg2::BinaryOperation{Mul
269269

270270
if isnothing(new_arg)
271271
new_arg = BinaryOperation{Mult}(args[1], args[2])
272+
if can_contract(args[1], args[2])
273+
new_arg = evaluate(new_arg)
274+
end
272275
else
273276
new_arg = BinaryOperation{Mult}(
274277
new_arg,

test/StdTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ end
255255
@test to_std(mul(mul(mul(x, y), z), v)) == "x ⊙ y ⊙ z ⊙ v"
256256
@test to_std(mul(v, mul(mul(x, y), z))) == "x ⊙ y ⊙ z ⊙ v"
257257
@test to_std(mul(v, mul(z, mul(x, y)))) == "x ⊙ y ⊙ z ⊙ v"
258-
@test to_std(mul(mul(z, v), mul(x, y))) == "z ⊙ vx ⊙ y"
258+
@test to_std(mul(mul(z, v), mul(x, y))) == "z ⊙ xv ⊙ y" # The order changes in 'evaluate'
259259
end
260260

261261
@testset "to_std output is correct with vector and trace of identity" begin

0 commit comments

Comments
 (0)