Skip to content

Commit b8e6bb7

Browse files
committed
change meaning of rev
1 parent cb0b0ed commit b8e6bb7

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/implementations/orthnull.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function null_truncation_strategy(; atol=nothing, rtol=nothing, maxnullity=nothi
207207
end
208208
atol = @something atol 0
209209
rtol = @something rtol 0
210-
trunc = trunctol(; atol, rtol, rev=false)
210+
trunc = trunctol(; atol, rtol, rev=true)
211211
return !isnothing(maxnullity) ? trunc & truncrank(maxnullity; rev=false) : trunc
212212
end
213213

src/implementations/truncation.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ end
5252

5353
function findtruncated(values::AbstractVector, strategy::TruncationByValue)
5454
atol = max(strategy.atol, strategy.rtol * norm(values, strategy.p))
55-
filter = (strategy.rev ? (atol) : (atol)) strategy.by
55+
filter = (strategy.rev ? (atol) : (atol)) strategy.by
5656
return findall(filter, values)
5757
end
5858
function findtruncated_sorted(values::AbstractVector, strategy::TruncationByValue)
5959
atol = max(strategy.atol, strategy.rtol * norm(values, strategy.p))
6060
@assert strategy.by === abs || strategy.by === real "sorting strategy incompatible with implementation"
6161
if strategy.rev
62-
i = searchsortedlast(values, atol; by=strategy.by, rev=true)
63-
return 1:i
64-
else
6562
i = searchsortedfirst(values, atol; by=strategy.by, rev=true)
6663
return i:length(values)
64+
else
65+
i = searchsortedlast(values, atol; by=strategy.by, rev=true)
66+
return 1:i
6767
end
6868
end
6969

src/interface/truncation.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ Truncation strategy to keep the values for which `filter` returns true.
8080
truncfilter(f) = TruncationByFilter(f)
8181

8282
"""
83-
TruncationByValue(atol::Real, rtol::Real, p::Real, by, rev::Bool=true)
83+
TruncationByValue(atol::Real, rtol::Real, p::Real, by, rev::Bool=false)
8484
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`.
85+
Truncation strategy to keep the values that satisfy `by(val) > max(atol, rtol * norm(values, p)`
86+
if `rev = false`, or discard them when `rev = true`.
8787
See also [`trunctol`](@ref)
8888
"""
8989
struct TruncationByValue{T<:Real,P<:Real,F} <: TruncationStrategy
@@ -98,12 +98,12 @@ function TruncationByValue(atol::Real, rtol::Real, p::Real=2, by=abs, rev::Bool=
9898
end
9999

100100
"""
101-
trunctol(; atol::Real=0, rtol::Real=0, p::Real=2, by=abs, )
101+
trunctol(; atol::Real=0, rtol::Real=0, p::Real=2, by=abs, rev::Bool=false)
102102
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`.
103+
Truncation strategy to keep the values that satisfy `by(val) > max(atol, rtol * norm(values, p)`
104+
if `rev = false`, or discard them when `rev = true`.
105105
"""
106-
function trunctol(; atol::Real=0, rtol::Real=0, p::Real=2, by=abs, rev::Bool=true)
106+
function trunctol(; atol::Real=0, rtol::Real=0, p::Real=2, by=abs, rev::Bool=false)
107107
return TruncationByValue(atol, rtol, p, by, rev)
108108
end
109109

test/algorithms.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
notrunc())
5151
end
5252

53-
alg = TruncatedAlgorithm(LAPACK_Simple(), trunctol(; atol=0.1, rev=false))
53+
alg = TruncatedAlgorithm(LAPACK_Simple(), trunctol(; atol=0.1, rev=true))
5454
for f in (eig_trunc!, eigh_trunc!, svd_trunc!)
5555
@test @constinferred(select_algorithm(eig_trunc!, A, alg)) === alg
5656
@test_throws ArgumentError select_algorithm(eig_trunc!, A, alg; trunc=(; maxrank=2))

test/orthnull.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ end
125125

126126
rtol = eps(real(T))
127127
for (trunc_orth, trunc_null) in (((; rtol=rtol), (; rtol=rtol)),
128-
(trunctol(; rtol), trunctol(; rtol, rev=false)))
128+
(trunctol(; rtol), trunctol(; rtol, rev=true)))
129129
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); trunc=trunc_orth)
130130
N2 = @constinferred left_null!(copy!(Ac, A), N; trunc=trunc_null)
131131
@test V2 !== V

test/truncate.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using MatrixAlgebraKit: NoTruncation, TruncationIntersection, TruncationByOrder,
1818
@test trunc == trunctol(; atol, rtol)
1919
@test trunc.atol == atol
2020
@test trunc.rtol == rtol
21-
@test trunc.rev
21+
@test !trunc.rev
2222

2323
trunc = @constinferred TruncationStrategy(; maxrank)
2424
@test trunc isa TruncationByOrder
@@ -41,7 +41,7 @@ using MatrixAlgebraKit: NoTruncation, TruncationIntersection, TruncationByOrder,
4141
strategy = trunctol(; atol=0.4)
4242
@test @constinferred(findtruncated(values, strategy)) == 1:3
4343
@test @constinferred(findtruncated_sorted(values, strategy)) === 1:3
44-
strategy = trunctol(; atol=0.4, rev=false)
44+
strategy = trunctol(; atol=0.4, rev=true)
4545
@test @constinferred(findtruncated(values, strategy)) == 4:5
4646
@test @constinferred(findtruncated_sorted(values, strategy)) === 4:5
4747

@@ -53,10 +53,10 @@ using MatrixAlgebraKit: NoTruncation, TruncationIntersection, TruncationByOrder,
5353
@test @constinferred(findtruncated(values, strategy)) == [2, 3, 4, 5]
5454

5555
for strategy in
56-
(trunctol(; atol=0.4, rev=false), trunctol(; atol=0.2, by=identity, rev=false))
56+
(trunctol(; atol=0.4, rev=true), trunctol(; atol=0.2, by=identity, rev=true))
5757
@test @constinferred(findtruncated(values, strategy)) == [1, 4]
5858
end
59-
strategy = trunctol(; atol=0.2, rev=false)
59+
strategy = trunctol(; atol=0.2, rev=true)
6060
@test @constinferred(findtruncated(values, strategy)) == [1]
6161

6262
strategy = truncfilter(x -> 0.1 < x < 1)

0 commit comments

Comments
 (0)