Skip to content

Commit 314a563

Browse files
committed
Add tests
1 parent 9fa3235 commit 314a563

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

src/order.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ function DegreeBuckets(::Type{T}, degrees::Vector{T}, dmax::Integer) where {T}
146146
# bucket limits
147147
bucket_high = accumulate(+, deg_count)
148148
bucket_low = similar(bucket_high)
149-
bucket_low[1] = 0
150-
bucket_low[2:end] .= bucket_high[1:(end - 1)]
151-
bucket_low .+= 1
149+
bucket_low[1] = 1
150+
bucket_low[2:end] .= @view(bucket_high[1:(end - 1)]) .+ 1
152151
# assign each vertex to the correct position inside its degree class
153152
bucket_storage = similar(degrees, T)
154153
positions = similar(degrees, T)
@@ -380,3 +379,14 @@ The `elimination_algorithm` must be an instance of `CliqueTrees.EliminationAlgor
380379
struct PerfectEliminationOrder{E} <: AbstractOrder
381380
elimination_algorithm::E
382381
end
382+
383+
function all_orders()
384+
return [
385+
NaturalOrder(),
386+
RandomOrder(),
387+
LargestFirst(),
388+
SmallestLast(),
389+
IncidenceDegree(),
390+
DynamicLargestFirst(),
391+
]
392+
end

test/allocations.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,33 @@ end
132132
test_noallocs_structured_decompression(1000; structure, partition, decompression)
133133
end
134134
end
135+
136+
@testset "Single precision" begin
137+
n, p = 10_000, 0.001
138+
A64 = sparse(Symmetric(sprand(rng, Float32, 100, 100, 0.1)))
139+
A32 = convert(SparseMatrixCSC{Float32,Int32}, A64)
140+
@testset "$structure - $partition - $decompression" for (
141+
structure, partition, decompression
142+
) in [
143+
(:nonsymmetric, :column, :direct),
144+
(:nonsymmetric, :row, :direct),
145+
(:symmetric, :column, :direct),
146+
(:symmetric, :column, :substitution),
147+
(:nonsymmetric, :bidirectional, :direct),
148+
(:nonsymmetric, :bidirectional, :substitution),
149+
]
150+
@testset for order in
151+
(NaturalOrder(), RandomOrder(), LargestFirst(), DynamicLargestFirst())
152+
problem = ColoringProblem(; structure, partition)
153+
algo = GreedyColoringAlgorithm(order; decompression)
154+
b64 = @b fast_coloring(A64, problem, algo)
155+
b32 = @b fast_coloring(A32, problem, algo)
156+
# check that we allocate no more than 50% + epsilon with Int32
157+
if decompression == :direct
158+
@test b32.bytes < 0.6 * b64.bytes
159+
else
160+
@test_broken b32.bytes < 0.6 * b64.bytes
161+
end
162+
end
163+
end
164+
end;

test/type_stability.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using JET
33
using LinearAlgebra
44
using SparseArrays
55
using SparseMatrixColorings
6-
using SparseMatrixColorings: matrix_versions, respectful_similar
6+
using SparseMatrixColorings: matrix_versions, respectful_similar, all_orders
77
using StableRNGs
88
using Test
99

@@ -178,7 +178,7 @@ end;
178178
(:nonsymmetric, :bidirectional, :direct),
179179
(:nonsymmetric, :bidirectional, :substitution),
180180
]
181-
for order in (NaturalOrder(), RandomOrder(), LargestFirst(), DynamicLargestFirst())
181+
@testset for order in all_orders()
182182
result = coloring(
183183
A,
184184
ColoringProblem(; structure, partition),

0 commit comments

Comments
 (0)