Skip to content

Commit acfed8a

Browse files
sanderdemeyerJutholkdvos
authored
Add == for TruncationStrategys (#211)
* Add `isequal` for `TruncationStrategy`s * update to `isequal` * fix formatting * Update src/algorithms.jl Co-authored-by: Jutho <Jutho@users.noreply.github.com> * Update src/algorithms.jl Co-authored-by: Lukas Devos <ldevos98@gmail.com> * Update algorithms.jl --------- Co-authored-by: Jutho <Jutho@users.noreply.github.com> Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent b76c7bb commit acfed8a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/algorithms.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,7 @@ macro check_size(x, sz, size = :size)
539539
end
540540
)
541541
end
542+
543+
# Check equality of two `TruncationStrategy`s
544+
Base.:(==)(t1::T, t2::T) where {T <: TruncationStrategy} = all(getfield(t1, f) == getfield(t2, f) for f in fieldnames(T))
545+
Base.:(==)(t1::T1, t2::T2) where {T1 <: TruncationStrategy, T2 <: TruncationStrategy} = false

test/algorithms.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,23 @@ end
6060
@test @constinferred(select_algorithm(svd_compact!, A, $alg)) === QRIteration()
6161
end
6262
end
63+
64+
@testset "Truncation equivalencies" begin
65+
truncs = [
66+
notrunc(),
67+
truncrank(4),
68+
truncrank(5),
69+
truncfilter(x -> x > 0),
70+
truncfilter(x -> x > 1.0e-4),
71+
trunctol(; atol = 0),
72+
trunctol(; atol = 1.0e-4),
73+
truncerror(; atol = 0),
74+
truncerror(; atol = 1.0e-4),
75+
truncrank(4) & truncfilter(x -> x > 0),
76+
truncrank(4) & truncrank(5),
77+
]
78+
79+
for (i1, t1) in enumerate(truncs), (i2, t2) in enumerate(truncs)
80+
@test (i1 == i2) ? t1 == t2 : t1 != t2
81+
end
82+
end

0 commit comments

Comments
 (0)