@@ -56,6 +56,8 @@ all(>(2.9), diagview(Dtrunc))
5656true
5757```
5858
59+ Use ` maxrank ` together with a tolerance to keep at most ` maxrank ` values above the tolerance (intersection):
60+
5961``` jldoctest truncations; output=false
6062Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = (maxrank = 2, atol = 2.9));
6163size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
@@ -64,6 +66,16 @@ size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
6466true
6567```
6668
69+ Use ` minrank ` together with a tolerance to guarantee at least ` minrank ` values are kept (union):
70+
71+ ``` jldoctest truncations; output=false
72+ Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = (atol = 3.5, minrank = 2));
73+ size(Dtrunc, 1) >= 2
74+
75+ # output
76+ true
77+ ```
78+
6779In general, the keyword arguments that are supported can be found in the ` TruncationStrategy ` docstring:
6880
6981``` @docs; canonical = false
@@ -84,6 +96,8 @@ size(Dtrunc, 1) <= 2
8496true
8597```
8698
99+ Strategies can be combined with ` & ` (intersection: keep values satisfying ** all** conditions):
100+
87101``` jldoctest truncations; output=false
88102Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = truncrank(2) & trunctol(; atol = 2.9))
89103size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
@@ -92,6 +106,17 @@ size(Dtrunc, 1) <= 2 && all(>(2.9), diagview(Dtrunc))
92106true
93107```
94108
109+ Strategies can also be combined with ` | ` (union: keep values satisfying ** any** condition).
110+ This is useful to set a lower bound on the number of kept values with ` minrank ` :
111+
112+ ``` jldoctest truncations; output=false
113+ Dtrunc, Vtrunc, ϵ = eigh_trunc(A; trunc = trunctol(; atol = 3.5) | truncrank(2))
114+ size(Dtrunc, 1) >= 2
115+
116+ # output
117+ true
118+ ```
119+
95120## Truncation Strategies
96121
97122MatrixAlgebraKit provides several built-in truncation strategies:
@@ -104,11 +129,20 @@ truncfilter
104129truncerror
105130```
106131
107- Truncation strategies can be combined using the ` & ` operator to create intersection-based truncation.
108- When strategies are combined, only the values that satisfy all conditions are kept.
132+ Strategies can be composed using the ` & ` operator ([ ` TruncationIntersection ` ] ( @ref ) ) to keep only values
133+ satisfying all conditions, or the ` | ` operator ([ ` TruncationUnion ` ] ( @ref ) ) to keep values satisfying any condition.
134+
135+ ``` @docs; canonical=false
136+ TruncationIntersection
137+ TruncationUnion
138+ ```
109139
110140``` julia
141+ # Keep at most 10 values, all above tolerance (intersection)
111142combined_trunc = truncrank (10 ) & trunctol (; atol = 1e-6 );
143+
144+ # Keep values above tolerance, but always at least 3 (union)
145+ combined_trunc = trunctol (; atol = 1e-6 ) | truncrank (3 );
112146```
113147
114148## Truncation Error
0 commit comments