Skip to content

Commit fb18de6

Browse files
committed
Add isequal for TruncationStrategys
1 parent b76c7bb commit fb18de6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/algorithms.jl

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

test/algorithms.jl

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

0 commit comments

Comments
 (0)