@@ -14,14 +14,14 @@ function TruncationStrategy(; atol=nothing, rtol=nothing, maxrank=nothing)
1414 elseif isnothing (maxrank)
1515 atol = @something atol 0
1616 rtol = @something rtol 0
17- return TruncationKeepAbove ( atol, rtol)
17+ return trunctol (; atol, rtol)
1818 else
1919 if isnothing (atol) && isnothing (rtol)
2020 return truncrank (maxrank)
2121 else
2222 atol = @something atol 0
2323 rtol = @something rtol 0
24- return truncrank (maxrank) & TruncationKeepAbove ( atol, rtol)
24+ return truncrank (maxrank) & trunctol (; atol, rtol)
2525 end
2626 end
2727end
@@ -42,87 +42,102 @@ Truncation strategy that does nothing, and keeps all the values.
4242notrunc () = NoTruncation ()
4343
4444"""
45- TruncationKeepSorted (howmany::Int, by::Function, rev::Bool)
45+ TruncationByOrder (howmany::Int, by::Function, rev::Bool)
4646
4747Truncation strategy to keep the first `howmany` values when sorted according to `by` in increasing (decreasing) order if `rev` is false (true).
48+
4849See also [`truncrank`](@ref).
4950"""
50- struct TruncationKeepSorted {F} <: TruncationStrategy
51+ struct TruncationByOrder {F} <: TruncationStrategy
5152 howmany:: Int
5253 by:: F
5354 rev:: Bool
5455end
5556
5657"""
57- truncrank(howmany::Int ; by=abs, rev=true)
58+ truncrank(howmany::Integer ; by=abs, rev::Bool =true)
5859
5960Truncation strategy to keep the first `howmany` values when sorted according to `by` or the last `howmany` if `rev` is true.
6061"""
61- truncrank (howmany:: Int ; by= abs, rev= true ) = TruncationKeepSorted (howmany, by, rev)
62+ truncrank (howmany:: Integer ; by= abs, rev:: Bool = true ) = TruncationByOrder (howmany, by, rev)
6263
6364"""
64- TruncationKeepFiltered (filter::Function)
65+ TruncationByFilter (filter::Function)
6566
6667Truncation strategy to keep the values for which `filter` returns true.
68+
69+ See also [`truncfilter`](@ref).
6770"""
68- struct TruncationKeepFiltered {F} <: TruncationStrategy
71+ struct TruncationByFilter {F} <: TruncationStrategy
6972 filter:: F
7073end
7174
7275"""
73- truncabove(val::Real; by=abs)
76+ truncfilter(filter)
77+
78+ Truncation strategy to keep the values for which `filter` returns true.
79+ """
80+ truncfilter (f) = TruncationByFilter (f)
7481
75- Truncation strategy to discard the values that are larger than `val` according to `by`.
7682"""
77- truncabove (val :: Real ; by = abs) = TruncationKeepFiltered ( ≤ (val) ∘ by )
83+ TruncationByValue(atol ::Real, rtol::Real, p::Real, by, rev::Bool=true )
7884
79- struct TruncationKeepAbove{T<: Real ,P<: Real ,F} <: TruncationStrategy
85+ Truncation strategy to keep the values that satisfy `by(val) < max(atol, rtol * norm(values, p)`
86+ if `rev = true`, or discard them when `rev = false`.
87+ See also [`trunctol`](@ref)
88+ """
89+ struct TruncationByValue{T<: Real ,P<: Real ,F} <: TruncationStrategy
8090 atol:: T
8191 rtol:: T
8292 p:: P
8393 by:: F
94+ rev:: Bool
8495end
85- function TruncationKeepAbove (; atol:: Real , rtol:: Real , p:: Real = 2 , by= abs)
86- return TruncationKeepAbove ( atol, rtol, p, by)
96+ function TruncationByValue ( atol:: Real , rtol:: Real , p:: Real = 2 , by= abs, rev :: Bool = true )
97+ return TruncationByValue ( promote ( atol, rtol) ... , p, by, rev )
8798end
88- function TruncationKeepAbove (atol:: Real , rtol:: Real , p:: Real = 2 , by= abs)
89- return TruncationKeepAbove (promote (atol, rtol)... , p, by)
99+
100+ """
101+ trunctol(; atol::Real=0, rtol::Real=0, p::Real=2, by=abs, )
102+
103+ Truncation strategy to keep the values that satisfy `by(val) < max(atol, rtol * norm(values, p)`
104+ if `rev = true`, or discard them when `rev = false`.
105+ """
106+ function trunctol (; atol:: Real = 0 , rtol:: Real = 0 , p:: Real = 2 , by= abs, rev:: Bool = true )
107+ return TruncationByValue (atol, rtol, p, by, rev)
90108end
91109
92110"""
93- TruncationKeepBelow (; atol::Real, rtol::Real, p=2, by=abs )
111+ TruncationByError (; atol::Real, rtol::Real, p::Real )
94112
95- Truncation strategy to discard the values that are smaller than the norm of the values.
113+ Truncation strategy to discard values until the error caused by the discarded values exceeds some tolerances.
114+ See also [`truncerror`](@ref).
96115"""
97- struct TruncationKeepBelow {T<: Real ,P<: Real ,F } <: TruncationStrategy
116+ struct TruncationByError {T<: Real ,P<: Real } <: TruncationStrategy
98117 atol:: T
99118 rtol:: T
100119 p:: P
101- by:: F
102- end
103- function TruncationKeepBelow (; atol:: Real , rtol:: Real , p:: Real = 2 , by= abs)
104- return TruncationKeepBelow (atol, rtol, p, by)
105120end
106- function TruncationKeepBelow (atol:: Real , rtol:: Real , p:: Real = 2 , by = abs )
107- return TruncationKeepBelow (promote (atol, rtol)... , p, by )
121+ function TruncationError (atol:: Real , rtol:: Real , p:: Real = 2 )
122+ return TruncationError (promote (atol, rtol)... , p)
108123end
109124
110125"""
111- trunctol (; atol::Real, rtol::Real, p::Real=2, by=abs )
126+ truncerror (; atol::Real=0 , rtol::Real=0 , p::Real=2)
112127
113- Truncation strategy to discard all values that satisfy `by(val) < max(atol, rtol * norm(values))`.
128+ Create a truncation strategy for truncating such that the error in the factorization
129+ is smaller than `max(atol, rtol * norm)`, where the error is determined using the `p`-norm.
114130"""
115- function trunctol (; atol:: Real = 0 , rtol:: Real = 0 , p:: Real = 2 , by = abs )
116- return TruncationKeepBelow (; atol, rtol, p, by )
131+ function truncerror (; atol:: Real = 0 , rtol:: Real = 0 , p:: Real = 2 )
132+ return TruncationByError ( promote ( atol, rtol) ... , p)
117133end
118134
119135"""
120136 TruncationIntersection(trunc::TruncationStrategy, truncs::TruncationStrategy...)
121137
122138Composition of multiple truncation strategies, keeping values common between them.
123139"""
124- struct TruncationIntersection{T<: Tuple{Vararg{TruncationStrategy}} } < :
125- TruncationStrategy
140+ struct TruncationIntersection{T<: Tuple{Vararg{TruncationStrategy}} } <: TruncationStrategy
126141 components:: T
127142end
128143function TruncationIntersection (trunc:: TruncationStrategy , truncs:: TruncationStrategy... )
141156function Base.:& (trunc1:: TruncationStrategy , trunc2:: TruncationIntersection )
142157 return TruncationIntersection ((trunc1, trunc2. components... ))
143158end
144-
145- """
146- TruncationError(; atol::Real, rtol::Real, p::Real)
147-
148- Truncation strategy to discard values until the error caused by the discarded values exceeds some tolerances.
149- See also [`truncerror`](@ref).
150- """
151- struct TruncationError{T<: Real ,P<: Real } <: TruncationStrategy
152- atol:: T
153- rtol:: T
154- p:: P
155- end
156- function TruncationError (; atol:: Real , rtol:: Real , p:: Real = 2 )
157- return TruncationError (atol, rtol, p)
158- end
159- function TruncationError (atol:: Real , rtol:: Real , p:: Real = 2 )
160- return TruncationError (promote (atol, rtol)... , p)
161- end
162-
163- """
164- truncerror(; atol::Real=0, rtol::Real=0, p::Real=2)
165-
166- Create a truncation strategy for truncating such that the error in the factorization
167- is smaller than `max(atol, rtol * norm)`, where the error is determined using the `p`-norm.
168- """
169- function truncerror (; atol:: Real = 0 , rtol:: Real = 0 , p:: Real = 2 )
170- return TruncationError (promote (atol, rtol)... , p)
171- end
0 commit comments