Skip to content

Commit 4320dcd

Browse files
lkdvosclaude
andcommitted
Add minrank keyword argument to TruncationStrategy
`minrank` provides a lower bound on the number of kept values, composing with other constraints via `TruncationUnion`. When no upper-bound constraints are active, `minrank` alone returns `truncrank(minrank)` directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e2d59d7 commit 4320dcd

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/interface/truncation.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const docs_truncation_kwargs = """
2-
* `atol::Real` : Absolute tolerance for the truncation
3-
* `rtol::Real` : Relative tolerance for the truncation
4-
* `maxrank::Real` : Maximal rank for the truncation
5-
* `maxerror::Real` : Maximal truncation error.
6-
* `filter` : Custom filter to select truncated values.
2+
* `atol::Real` : Absolute tolerance for the truncation
3+
* `rtol::Real` : Relative tolerance for the truncation
4+
* `maxrank::Integer` : Maximal rank for the truncation
5+
* `minrank::Integer` : Minimal rank for the truncation
6+
* `maxerror::Real` : Maximal truncation error.
7+
* `filter` : Custom filter to select truncated values.
78
"""
89

910
const docs_truncation_strategies = """
@@ -28,16 +29,18 @@ Select a truncation strategy based on the provided keyword arguments.
2829
## Keyword arguments
2930
The following keyword arguments are all optional, and their default value (`nothing`)
3031
will be ignored. It is also allowed to combine multiple of these, in which case the kept
31-
values will consist of the intersection of the different truncated strategies.
32+
values will consist of the intersection of the different truncated strategies (except
33+
`minrank`, which uses union semantics to guarantee a lower bound on the number of kept values).
3234
3335
$docs_truncation_kwargs
3436
"""
3537
function TruncationStrategy(;
3638
atol::Union{Real, Nothing} = nothing,
3739
rtol::Union{Real, Nothing} = nothing,
38-
maxrank::Union{Real, Nothing} = nothing,
40+
maxrank::Union{Integer, Nothing} = nothing,
41+
minrank::Union{Integer, Nothing} = nothing,
3942
maxerror::Union{Real, Nothing} = nothing,
40-
filter = nothing
43+
filter = nothing,
4144
)
4245
strategy = notrunc()
4346

@@ -51,6 +54,14 @@ function TruncationStrategy(;
5154
isnothing(maxerror) || (strategy &= truncerror(; atol = maxerror))
5255
isnothing(filter) || (strategy &= truncfilter(filter))
5356

57+
# union constraint: guarantee a lower bound on number of kept values
58+
# special-case NoTruncation: keeping everything already satisfies any minrank
59+
if !isnothing(minrank) && !(strategy isa NoTruncation)
60+
strategy |= truncrank(minrank)
61+
elseif !isnothing(minrank)
62+
strategy = truncrank(minrank)
63+
end
64+
5465
return strategy
5566
end
5667

0 commit comments

Comments
 (0)