Skip to content

Commit 96630e5

Browse files
committed
type stability of rank
1 parent 20b15a7 commit 96630e5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tensors/linalg.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,17 @@ _default_rtol(t) = eps(real(float(scalartype(t)))) * min(dim(domain(t)), dim(cod
289289

290290
function LinearAlgebra.rank(t::AbstractTensorMap;
291291
atol::Real=0, rtol::Real=atol > 0 ? 0 : _default_rtol(t))
292-
init = dim(one(sectortype(t))) * 0
293-
dim(t) == 0 && return init
292+
r = dim(one(sectortype(t))) * 0
293+
dim(t) == 0 && return r
294294
S = LinearAlgebra.svdvals(t)
295295
tol = max(atol, rtol * maximum(first, values(S)))
296-
return sum(((c, b),) -> dim(c) * count(>(tol), b), S; init)
296+
for (c, b) in S
297+
if !isempty(b)
298+
r += dim(c) * count(>(tol), b)
299+
end
300+
end
301+
return r
302+
# return sum(((c, b),) -> dim(c) * count(>(tol), b), S; init)
297303
end
298304

299305
function LinearAlgebra.cond(t::AbstractTensorMap, p::Real=2)

0 commit comments

Comments
 (0)