Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ParallelMergeCSR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using SparseArrays: AbstractSparseMatrixCSC,
getcolptr


export mul!

include("parallel_csr_mv.jl")
include("parallel_csc_mv.jl")

Expand Down
2 changes: 1 addition & 1 deletion src/parallel_csc_mv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function atomic_add!(a::AbstractVector{T},b::T) where T <: Complex
end
end

function SparseArrays.mul!(C::StridedVecOrMat, A::AbstractSparseMatrixCSC, B::DenseInputVecOrMat, α::Number, β::Number)
function mul!(C::StridedVecOrMat, A::AbstractSparseMatrixCSC, B::DenseInputVecOrMat, α::Number, β::Number)
size(A, 2) == size(B, 1) || throw(DimensionMismatch())
size(A, 1) == size(C, 1) || throw(DimensionMismatch())
size(B, 2) == size(C, 2) || throw(DimensionMismatch())
Expand Down
2 changes: 1 addition & 1 deletion src/parallel_csr_mv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end
# C = transpose(A)B + Cβ
# C = xABα + Cβ
for (T, t) in ((Adjoint, adjoint), (Transpose, transpose))
@eval function SparseArrays.mul!(C::StridedVecOrMat, xA::$T{<:Any,<:AbstractSparseMatrixCSC}, B::DenseInputVecOrMat, α::Number, β::Number)
@eval function mul!(C::StridedVecOrMat, xA::$T{<:Any,<:AbstractSparseMatrixCSC}, B::DenseInputVecOrMat, α::Number, β::Number)
# obtains the original matrix underneath the "lazy wrapper"
A = xA.parent
size(A, 2) == size(C, 1) || throw(DimensionMismatch())
Expand Down
36 changes: 18 additions & 18 deletions test/merge_csr_mv!.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using ParallelMergeCSR: merge_csr_mv!, Range
using SparseArrays
using SparseArrays: sprand, sparse


@testset "Range" begin
Expand Down Expand Up @@ -32,7 +32,7 @@ end

merge_csr_mv!(0.3, A, x, y, transpose)

@test Matrix(A) * x * 0.3 == y
@test A * x * 0.3 == y
end

@testset "Singleton (Complex)" begin
Expand All @@ -50,7 +50,7 @@ end
@testset "Single row (Real)" begin

# 10 x 1 converted to 1 x 10
A = 10.0 * SparseArrays.sprand(10, 1, 0.3)
A = 10.0 * sprand(10, 1, 0.3)

# x needs to be 10 x 1
x = rand(size(A, 1))
Expand All @@ -59,21 +59,21 @@ end

merge_csr_mv!(1.1, A, x, y, transpose)

@test (transpose(Matrix(A)) * x) * 1.1 ≈ y
@test (transpose(A) * x) * 1.1 ≈ y
end

@testset "Single row (Complex)" begin

# 10 x 1 is treated as 1 x 10 inside merge_csr_mv!
A = SparseArrays.sprand(Complex{Float64}, 10, 1, 0.3)
A = sprand(Complex{Float64}, 10, 1, 0.3)

x = rand(eltype(A), size(A, 1))

y = zeros(eltype(A), 1)

merge_csr_mv!(1.1, A, x, y, transpose)

@test (transpose(Matrix(A)) * x) * 1.1 ≈ y
@test (transpose(A) * x) * 1.1 ≈ y
end


Expand All @@ -92,7 +92,7 @@ end

# test fails, y seems to have lots of zero-entries
@testset "Square (Real)" begin
A = SparseArrays.sprand(10,10,0.3)
A = sprand(10,10,0.3)

# 10 x 1
x = rand(10)
Expand All @@ -102,20 +102,20 @@ end

merge_csr_mv!(1.1, A, x, y, adjoint)

@test (adjoint(Matrix(A)) * x) * 1.1 ≈ y
@test (adjoint(A) * x) * 1.1 ≈ y

end

@testset "Square (Complex)" begin
A = SparseArrays.sprand(Complex{Float64}, 10, 10, 0.3)
A = sprand(Complex{Float64}, 10, 10, 0.3)

x = 10 * rand(Complex{Float64}, 10)

y = zeros(eltype(A), size(x))

merge_csr_mv!(1.1, A, x, y, adjoint)

@test (adjoint(Matrix(A)) * x) * 1.1 ≈ y
@test (adjoint(A) * x) * 1.1 ≈ y
end

@testset "4x6 (Real)" begin
Expand All @@ -138,7 +138,7 @@ end
merge_csr_mv!(2.0, A, x, y, adjoint)


@test Matrix(adjoint(m)) * x * 2.0 == y
@test adjoint(m) * x * 2.0 == y
end

@testset "4 x 6 (Complex)" begin
Expand All @@ -160,13 +160,13 @@ end
# multiply
merge_csr_mv!(2.0, A, x, y, adjoint)

@test Matrix(adjoint(m)) * x * 2.0 == y
@test adjoint(m) * x * 2.0 == y

end

@testset "100x100 (Real)" begin
# create matrix
A = SparseArrays.sprand(100, 100, 0.3)
A = sprand(100, 100, 0.3)

# create vector
x = rand(100)
Expand All @@ -176,12 +176,12 @@ end

merge_csr_mv!(3.0, A, x, y, transpose)

@test transpose(Matrix(A)) * x * 3 ≈ y
@test transpose(A) * x * 3 ≈ y
end

@testset "100x100 (Complex)" begin
# create matrix
A = SparseArrays.sprand(Complex{Float64}, 100, 100, 0.3)
A = sprand(Complex{Float64}, 100, 100, 0.3)

# create vector
x = rand(Complex{Float64}, 100)
Expand All @@ -191,7 +191,7 @@ end

merge_csr_mv!(3.0, A, x, y, transpose)

@test transpose(Matrix(A)) * x * 3 ≈ y
@test transpose(A) * x * 3 ≈ y
end

#=
Expand All @@ -215,7 +215,7 @@ end
merge_csr_mv!(α, A, col, Y_view, transpose)
end

@test transpose(Matrix(A)) * X * 9.2 ≈ Y
@test transpose(A) * X * 9.2 ≈ Y

end

Expand All @@ -236,6 +236,6 @@ end
merge_csr_mv!(α, A, col, Y_view, adjoint)
end

@test adjoint(Matrix(A)) * X * 9.2 ≈ Y
@test adjoint(A) * X * 9.2 ≈ Y

end
41 changes: 11 additions & 30 deletions test/mul!.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ using SparseArrays
C_copy = deepcopy(C)
β = 3.9

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -31,9 +29,7 @@ end
C_copy = deepcopy(C)
β = 1.2

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end
# trigger merge_csr_mv!
Expand All @@ -49,10 +45,8 @@ end
C_copy = deepcopy(C)
β = 1.0

SparseArrays.mul!(C, A, B, α, β)

# right hand side is correct, left hand side is problematic
@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -67,9 +61,8 @@ end
C_copy = deepcopy(C)
β = 6.11 + 9.2im

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)
end

@testset "Transpose Rectangular Real" begin
Expand All @@ -83,9 +76,7 @@ end
C_copy = deepcopy(C)
β = 1.0

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -100,9 +91,7 @@ end
C_copy = deepcopy(C)
β = 1.0

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -117,8 +106,7 @@ end
C_copy = deepcopy(C)
β = 0.3

SparseArrays.mul!(C, A, B, α, β)
@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -133,8 +121,7 @@ end
C_copy = deepcopy(C)
β = 0.3

SparseArrays.mul!(C, A, B, α, β)
@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -148,9 +135,7 @@ end
C_copy = deepcopy(C)
β = 5.2

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)
end

@testset "Matrix x Vector (Real)" begin
Expand All @@ -163,9 +148,7 @@ end
C_copy = deepcopy(C)
β = 5.2

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end

Expand All @@ -179,8 +162,6 @@ end
C_copy = deepcopy(C)
β = 2.1+0.1im

SparseArrays.mul!(C, A, B, α, β)

@test C ≈ Matrix(A) * B * α + C_copy * β
@test ParallelMergeCSR.mul!(C, A, B, α, β) ≈ SparseArrays.mul!(C_copy, A, B, α, β)

end