Skip to content

Commit 8f411fb

Browse files
committed
Merge branch 'fatteneder:fa/fix-scalar' into v4
2 parents 5833faa + 6098d35 commit 8f411fb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/indexnotation/analyzers.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ function decomposegeneraltensor(ex)
4242
elseif isa(ex, Expr) && ex.head == :call && ex.args[1] == :conj && length(ex.args) == 2 # conjugation: flip conjugation flag and conjugate scalar factor
4343
(object, leftind, rightind, α, conj) = decomposegeneraltensor(ex.args[2])
4444
return (object, leftind, rightind, Expr(:call, :conj, α), !conj)
45-
elseif ex.head == :call && ex.args[1] == :* && length(ex.args) == 3 # scalar multiplication: multiply scalar factors
46-
if isscalarexpr(ex.args[2]) && isgeneraltensor(ex.args[3])
47-
(object, leftind, rightind, α, conj) = decomposegeneraltensor(ex.args[3])
48-
return (object, leftind, rightind, Expr(:call, :*, ex.args[2], α), conj)
49-
elseif isscalarexpr(ex.args[3]) && isgeneraltensor(ex.args[2])
50-
(object, leftind, rightind, α, conj) = decomposegeneraltensor(ex.args[2])
51-
return (object, leftind, rightind, Expr(:call, :*, α, ex.args[3]), conj)
52-
end
45+
elseif ex.head == :call && ex.args[1] == :* && length(ex.args) >= 3 && count(a -> isgeneraltensor(a), ex.args) == 1 # scalar multiplication: multiply scalar factors
46+
idx = findfirst(a -> isgeneraltensor(a), ex.args)
47+
(object, leftind, rightind, α, conj) = decomposegeneraltensor(ex.args[idx])
48+
scalars = Expr(:call)
49+
append!(scalars.args, deepcopy(ex.args))
50+
scalars.args[idx] = α
51+
return (object, leftind, rightind, scalars, conj)
5352
elseif ex.head == :call && ex.args[1] == :/ && length(ex.args) == 3 # scalar multiplication: muliply scalar factors
5453
if isscalarexpr(ex.args[3]) && isgeneraltensor(ex.args[2])
5554
(object, leftind, rightind, α, conj) = decomposegeneraltensor(ex.args[2])

test/auxiliary.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@
6767
@test decomposegeneraltensor(:(conj(a[1,2,3]))) == (:a, [1,2,3], [], instantiate_scalar(:(conj(1))), true)
6868
@test isgeneraltensor(:(x*a[5][a b c]))
6969
@test decomposegeneraltensor(:(x*a[5][a b c])) == (:(a[5]), [:a,:b,:c], [], instantiate_scalar(:(x*1)), false)
70+
@test isgeneraltensor(:(x*x*a[5][a,b,c]))
71+
@test decomposegeneraltensor(:(x*x*a[5][a,b,c])) == (:(a[5]), [:a,:b,:c], [], instantiate_scalar(:(x*x*1)), false)
72+
@test isgeneraltensor(:(x*a[5][a,b,c]*x))
73+
@test decomposegeneraltensor(:(x*a[5][a,b,c]*x)) == (:(a[5]), [:a,:b,:c], [], instantiate_scalar(:(x*1*x)), false)
74+
@test isgeneraltensor(:(a[5][a,b,c]*x/y))
75+
@test decomposegeneraltensor(:(a[5][a,b,c]/y*x)) == (:(a[5]), [:a,:b,:c], [], instantiate_scalar(:((1/y)*x)), false)
76+
@test isgeneraltensor(:(x/y*a[5][a,b,c]*y/x))
77+
@test decomposegeneraltensor(:(x/y*a[5][a,b,c]/y*x)) == (:(a[5]), [:a,:b,:c], [], instantiate_scalar(:(((((x/y)*1)/y)*x))), false)
7078
@test isgeneraltensor(:(3*conj(a*cos(y)[a b c; 1 2 3])))
7179
@test decomposegeneraltensor(:(3*conj(a*cos(y)[a b c; 1 2 3]))) == (:(cos(y)), Any[:a,:b,:c], Any[1,2,3], instantiate_scalar(:(3*conj(a*1))), true)
7280
@test !isgeneraltensor(:(1/a[1,2,3]))
7381
@test !isgeneraltensor(:(a[1 2 3; 4 5 6]\x))
7482
@test !isgeneraltensor(:(cos(y)[a b c; 1 2 3]*b[4,5]))
83+
@test !isgeneraltensor(:(x*y*cos(y)[a b c; 1 2 3]*b[4,5]))
84+
@test !isgeneraltensor(:(x/y*cos(y)[a b c; 1 2 3]*b[4,5]/z*v))
7585
@test !isgeneraltensor(:(3+5))
7686

7787
@test hastraceindices(:(a[x,y,z,1,x]))

0 commit comments

Comments
 (0)