Skip to content

Commit 039d72d

Browse files
committed
some unification of scaltype determination
1 parent 4864971 commit 039d72d

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/indexnotation/instantiators.jl

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,9 @@ function instantiate_generaltensor(
124124
if alloc (NewTensor, TemporaryTensor)
125125
TC = gensym("T_" * string(dst))
126126
istemporary = Val(alloc === TemporaryTensor)
127-
if scaltype === nothing
128-
TCval = α === One() ? instantiate_scalartype(src) :
129-
instantiate_scalartype(Expr(:call, :*, α, src))
130-
else
131-
TCval = scaltype
132-
end
127+
TCval = @something(
128+
scaltype, instantiate_scalartype=== One() ? src : Expr(:call, :*, α, src))
129+
)
133130
push!(out.args, Expr(:(=), TC, TCval))
134131
push!(
135132
out.args,
@@ -275,18 +272,15 @@ function instantiate_contraction(
275272
end
276273
if alloc (NewTensor, TemporaryTensor)
277274
TCsym = gensym("T_" * string(dst))
278-
if scaltype === nothing
279-
Atype = instantiate_scalartype(A)
280-
Btype = instantiate_scalartype(B)
281-
TCval = Expr(:call, :promote_contract, Atype, Btype)
282-
if α !== One()
283-
TCval = Expr(
284-
:call, :(Base.promote_op), :*, instantiate_scalartype(α), TCval
285-
)
275+
TCval = @something(
276+
scaltype,
277+
begin
278+
TA = instantiate_scalartype(A)
279+
TB = instantiate_scalartype(B)
280+
TAB = :(promote_contract($TA, $TB))
281+
α === One() ? TAB : :(Base.promote_op(*, $(instantiate_scalartype(α)), $TAB))
286282
end
287-
else
288-
TCval = scaltype
289-
end
283+
)
290284
istemporary = Val(alloc === TemporaryTensor)
291285
initC = Expr(
292286
:block, Expr(:(=), TCsym, TCval),

0 commit comments

Comments
 (0)