@@ -337,6 +337,34 @@ function MAK.findtruncated_svd(values::SectorVector, strategy::TruncationUnion)
337337 return SectorDict {eltype(sectors), eltype(vals)} (sectors, vals)
338338end
339339
340+ # Degenerate values can occur in different blocks, for example when the sectors are related by
341+ # a symmetry, so groups of degenerate values are determined across all blocks simultaneously.
342+ function MAK. findtruncated (values:: SectorVector , strategy:: TruncationMultiplets )
343+ return _findtruncated_multiplets (values, MAK. findtruncated (values, strategy. trunc), strategy)
344+ end
345+ function MAK. findtruncated_svd (values:: SectorVector , strategy:: TruncationMultiplets )
346+ return _findtruncated_multiplets (values, MAK. findtruncated_svd (values, strategy. trunc), strategy)
347+ end
348+
349+ function _findtruncated_multiplets (values:: SectorVector , inds, strategy:: TruncationMultiplets )
350+ keep = similar (values, Bool)
351+ to_keep = collect (parent (_ind_to_mask! (keep, inds)))
352+ kept_values = collect (parent (values))
353+ perm = sortperm (kept_values; by = abs, rev = true )
354+ MAK. _keep_multiplets! (to_keep, kept_values, perm, strategy)
355+ copyto! (parent (keep), to_keep)
356+ return keep
357+ end
358+
359+ _ind_to_mask! (keep:: SectorVector{Bool} , inds:: SectorVector{Bool} ) = copyto! (keep, inds)
360+ function _ind_to_mask! (keep:: SectorVector{Bool} , inds:: SectorDict )
361+ fill! (parent (keep), false )
362+ for (c, ind) in pairs (inds)
363+ keep[c][ind] .= true
364+ end
365+ return keep
366+ end
367+
340368# Truncation error
341369# ----------------
342370MAK. truncation_error (values:: SectorVector , ind) = MAK. truncation_error! (copy (values), ind)
0 commit comments