Skip to content

Commit f1f842f

Browse files
committed
fix type instability in trace
1 parent a3307f7 commit f1f842f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/tensors/linalg.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ end
276276
function LinearAlgebra.tr(t::AbstractTensorMap)
277277
domain(t) == codomain(t) ||
278278
throw(SpaceMismatch("Trace of a tensor only exist when domain == codomain"))
279-
return sum(dim(c) * tr(b) for (c, b) in blocks(t))
279+
s = zero(scalartype(t))
280+
for (c, b) in blocks(t)
281+
s += dim(c) * tr(b)
282+
end
283+
return s
280284
end
281285

282286
# TensorMap multiplication

0 commit comments

Comments
 (0)