From 7ebe0dc178e673ab13fdb1619721caf91a271a84 Mon Sep 17 00:00:00 2001 From: John Long Date: Thu, 12 Jan 2023 15:17:13 -0500 Subject: [PATCH 1/2] Make tests take advantage of ability to add to existing vector contents --- test/merge_csr_mv!.jl | 57 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/test/merge_csr_mv!.jl b/test/merge_csr_mv!.jl index 3f4ef08..c7ffb86 100644 --- a/test/merge_csr_mv!.jl +++ b/test/merge_csr_mv!.jl @@ -25,11 +25,12 @@ end x = rand(1) - y = zeros(size(A, 1)) + y = rand(size(A, 1)) + y_original = deepcopy(y) merge_csr_mv!(0.3, A, x, y, transpose) - @test A * x * 0.3 == y + @test (A * x * 0.3) + y_original == y end @testset "Singleton (Complex)" begin @@ -37,11 +38,12 @@ end x = rand(1) - y = zeros(eltype(A), size(A, 1)) + y = rand(eltype(A), size(A, 1)) + y_original = deepcopy(y) merge_csr_mv!(10.1, A, x, y, adjoint) - @test adjoint(Matrix(A)) * x * 10.1 == y + @test (adjoint(Matrix(A)) * x * 10.1) + y_original == y end @testset "Single row (Real)" begin @@ -52,11 +54,12 @@ end # x needs to be 10 x 1 x = rand(size(A, 1)) - y = zeros(eltype(A), 1) + y = rand(eltype(A), 1) + y_original = deepcopy(y) merge_csr_mv!(1.1, A, x, y, transpose) - @test (transpose(A) * x) * 1.1 ≈ y + @test ((transpose(A) * x) * 1.1) + y_original ≈ y end @testset "Single row (Complex)" begin @@ -67,10 +70,11 @@ end x = rand(eltype(A), size(A, 1)) y = zeros(eltype(A), 1) + y_original = deepcopy(y) merge_csr_mv!(1.1, A, x, y, transpose) - @test (transpose(A) * x) * 1.1 ≈ y + @test ((transpose(A) * x) * 1.1) + y_original ≈ y end @@ -94,11 +98,12 @@ end x = rand(10) # 10 x 1 - y = zeros(size(x)) + y = rand(size(x)...) + y_original = deepcopy(y) merge_csr_mv!(1.1, A, x, y, adjoint) - @test (adjoint(A) * x) * 1.1 ≈ y + @test ((adjoint(A) * x) * 1.1) + y_original ≈ y end @@ -107,11 +112,12 @@ end x = 10 * rand(Complex{Float64}, 10) - y = zeros(eltype(A), size(x)) + y = rand(eltype(A), size(x)...) + y_original = deepcopy(y) merge_csr_mv!(1.1, A, x, y, adjoint) - @test (adjoint(A) * x) * 1.1 ≈ y + @test ((adjoint(A) * x) * 1.1) + y_original ≈ y end @testset "4x6 (Real)" begin @@ -128,13 +134,13 @@ end x = [5,2,3,1] # create empty solution - y = zeros(Int64, size(A, 2)) + y = rand(1:20, size(A, 2)) + y_original = deepcopy(y) # multiply merge_csr_mv!(2.0, A, x, y, adjoint) - - @test adjoint(m) * x * 2.0 == y + @test (adjoint(m) * x * 2.0) + y_original == y end @testset "4 x 6 (Complex)" begin @@ -151,12 +157,13 @@ end x = 22.1 * rand(Complex{Float64}, 4) # create empty solution - y = zeros(eltype(x), size(A, 2)) + y = rand(eltype(x), size(A, 2)) + y_original = deepcopy(y) # multiply merge_csr_mv!(2.0, A, x, y, adjoint) - @test adjoint(m) * x * 2.0 == y + @test (adjoint(m) * x * 2.0) + y_original == y end @@ -168,11 +175,12 @@ end x = rand(100) # create empty solution - y = zeros(size(A, 1)) + y = rand(size(A, 1)) + y_original = deepcopy(y) merge_csr_mv!(3.0, A, x, y, transpose) - @test transpose(A) * x * 3 ≈ y + @test (transpose(A) * x * 3) + y_original ≈ y end @testset "100x100 (Complex)" begin @@ -183,11 +191,12 @@ end x = rand(Complex{Float64}, 100) # create empty solution - y = zeros(eltype(x), size(A, 1)) + y = rand(eltype(x), size(A, 1)) + y_original = deepcopy(y) merge_csr_mv!(3.0, A, x, y, transpose) - @test transpose(A) * x * 3 ≈ y + @test (transpose(A) * x * 3) + y_original ≈ y end #= @@ -204,14 +213,15 @@ end α = 9.2 - Y = zeros(2, 4) + Y = rand(2, 4) + Y_original = deepcopy(Y) for (idx, col) in enumerate(eachcol(X)) Y_view = @view Y[:, idx] merge_csr_mv!(α, A, col, Y_view, transpose) end - @test transpose(A) * X * 9.2 ≈ Y + @test (transpose(A) * X * 9.2) + Y_original ≈ Y end @@ -226,12 +236,13 @@ end α = 9.2 Y = zeros(eltype(A), 2, 4) + Y_original = deepcopy(Y) for (idx, col) in enumerate(eachcol(X)) Y_view = @view Y[:, idx] merge_csr_mv!(α, A, col, Y_view, adjoint) end - @test adjoint(A) * X * 9.2 ≈ Y + @test (adjoint(A) * X * 9.2) + Y_original ≈ Y end \ No newline at end of file From b3bf48df00f55e81a66640aaf318d51ba6f0f053 Mon Sep 17 00:00:00 2001 From: John Long Date: Thu, 12 Jan 2023 16:35:10 -0500 Subject: [PATCH 2/2] Made spacing consistent, use \approx for floating point comparison --- test/merge_csr_mv!.jl | 21 +++++++++++++++++---- test/mul!.jl | 7 ++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/test/merge_csr_mv!.jl b/test/merge_csr_mv!.jl index c7ffb86..a378e65 100644 --- a/test/merge_csr_mv!.jl +++ b/test/merge_csr_mv!.jl @@ -20,7 +20,9 @@ using SparseArrays: sprand, sparse end @testset "Extreme Cases" begin + @testset "Singleton (Real)" begin + A = sparse(reshape([1], 1, 1)) x = rand(1) @@ -30,10 +32,12 @@ end merge_csr_mv!(0.3, A, x, y, transpose) - @test (A * x * 0.3) + y_original == y + @test (A * x * 0.3) + y_original ≈ y + end @testset "Singleton (Complex)" begin + A = sparse(reshape([1.0+2.5im], 1, 1)) x = rand(1) @@ -43,7 +47,8 @@ end merge_csr_mv!(10.1, A, x, y, adjoint) - @test (adjoint(Matrix(A)) * x * 10.1) + y_original == y + @test (adjoint(Matrix(A)) * x * 10.1) + y_original ≈ y + end @testset "Single row (Real)" begin @@ -60,6 +65,7 @@ end merge_csr_mv!(1.1, A, x, y, transpose) @test ((transpose(A) * x) * 1.1) + y_original ≈ y + end @testset "Single row (Complex)" begin @@ -75,6 +81,7 @@ end merge_csr_mv!(1.1, A, x, y, transpose) @test ((transpose(A) * x) * 1.1) + y_original ≈ y + end @@ -92,6 +99,7 @@ end end @testset "Square (Real)" begin + A = sprand(10,10,0.3) # 10 x 1 @@ -108,6 +116,7 @@ end end @testset "Square (Complex)" begin + A = sprand(Complex{Float64}, 10, 10, 0.3) x = 10 * rand(Complex{Float64}, 10) @@ -118,6 +127,7 @@ end merge_csr_mv!(1.1, A, x, y, adjoint) @test ((adjoint(A) * x) * 1.1) + y_original ≈ y + end @testset "4x6 (Real)" begin @@ -140,7 +150,8 @@ end # multiply merge_csr_mv!(2.0, A, x, y, adjoint) - @test (adjoint(m) * x * 2.0) + y_original == y + @test (adjoint(m) * x * 2.0) + y_original ≈ y + end @testset "4 x 6 (Complex)" begin @@ -163,7 +174,7 @@ end # multiply merge_csr_mv!(2.0, A, x, y, adjoint) - @test (adjoint(m) * x * 2.0) + y_original == y + @test (adjoint(m) * x * 2.0) + y_original ≈ y end @@ -181,6 +192,7 @@ end merge_csr_mv!(3.0, A, x, y, transpose) @test (transpose(A) * x * 3) + y_original ≈ y + end @testset "100x100 (Complex)" begin @@ -197,6 +209,7 @@ end merge_csr_mv!(3.0, A, x, y, transpose) @test (transpose(A) * x * 3) + y_original ≈ y + end #= diff --git a/test/mul!.jl b/test/mul!.jl index ef2cc58..b29129a 100644 --- a/test/mul!.jl +++ b/test/mul!.jl @@ -18,6 +18,7 @@ using SparseArrays ParallelMergeCSR.mul!(C, A, B, α, β) SparseArrays.mul!(C_copy, A, B, α, β) @test C ≈ C_copy + end @testset "Adjoint Complex Matrix" begin @@ -51,6 +52,7 @@ using SparseArrays ParallelMergeCSR.mul!(C, A, B, α, β) SparseArrays.mul!(C_copy, A, B, α, β) @test C ≈ C_copy + end @testset "Transpose Complex Matrix" begin @@ -66,7 +68,9 @@ using SparseArrays ParallelMergeCSR.mul!(C, A, B, α, β) SparseArrays.mul!(C_copy, A, B, α, β) @test C ≈ C_copy + end + end # trigger merge_csr_mv! in this repo, does not default to mul! somewhere else @@ -121,7 +125,6 @@ end SparseArrays.mul!(C_copy, A, B, α, β) @test C ≈ C_copy - end @testset "Transpose Square Complex" begin @@ -137,6 +140,7 @@ end ParallelMergeCSR.mul!(C, A, B, α, β) SparseArrays.mul!(C_copy, A, B, α, β) @test C ≈ C_copy + end @testset "Transpose Rectangular Real" begin @@ -172,4 +176,5 @@ end @test C ≈ C_copy end + end \ No newline at end of file