diff --git a/src/factorizations/truncation.jl b/src/factorizations/truncation.jl index e8e113ec1..ff9c8a2e6 100644 --- a/src/factorizations/truncation.jl +++ b/src/factorizations/truncation.jl @@ -171,7 +171,8 @@ function MAK.findtruncated(values::SectorVector, strategy::TruncationByOrder) # dimensions are all 1 so no need to account for weight if FusionStyle(I) isa UniqueFusion - perm = partialsortperm(parent(values), 1:strategy.howmany; strategy.by, strategy.rev) + howmany = min(length(parent(values)), strategy.howmany) + perm = partialsortperm(parent(values), 1:howmany; strategy.by, strategy.rev) result = similar(values, Bool) fill!(parent(result), false) parent(result)[perm] .= true diff --git a/test/tensors/factorizations.jl b/test/tensors/factorizations.jl index 7e6510b6c..48dfaf6f1 100644 --- a/test/tensors/factorizations.jl +++ b/test/tensors/factorizations.jl @@ -254,6 +254,14 @@ for V in spacelist @test isisometric(U) @test isisometric(Vᴴ; side = :right) + # when rank of t is already smaller than truncrank + t_rank = ceil(Int, min(dim(codomain(t)), dim(domain(t)))) + U, S, Vᴴ, ϵ = @constinferred svd_trunc(t; trunc = truncrank(t_rank + 1)) + @test U * S * Vᴴ ≈ t + @test ϵ ≈ 0 + @test isisometric(U) + @test isisometric(Vᴴ; side = :right) + # dimension of S is a float for IsingBimodule nvals = round(Int, dim(domain(S)) / 2) trunc = truncrank(nvals)