Skip to content

Commit

Permalink
Buffer fix (#10)
Browse files Browse the repository at this point in the history
Julia 1.7.x introduced _goodbuffers and _checkbuffers but use them
incorrectly for AbstractSparseArrays. This is fixed on 1.8, but we need
a workaround in 1.7.x.

Also fixed bug where copy(X'), copy(transpose(X)) and permutedims(X)
didn't return ThreadedSparseMatrixCSC.
  • Loading branch information
rasmushenningsson authored Jun 10, 2022
1 parent 8c58f54 commit 2c96928
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ThreadedSparseArrays"
uuid = "59d54670-b8ac-4d81-ab7a-bb56233e17ab"
authors = ["Stefanos Carlström <[email protected]>"]
version = "0.2.1"
version = "0.2.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
12 changes: 12 additions & 0 deletions src/ThreadedSparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ for f in [:rowvals, :nonzeros, :getcolptr]
end


@static if v"1.7.0" <= VERSION < v"1.8.0-"
SparseArrays._goodbuffers(A::ThreadedSparseMatrixCSC) = SparseArrays._goodbuffers(A.A)
SparseArrays._checkbuffers(A::ThreadedSparseMatrixCSC) = SparseArrays._checkbuffers(A.A)
end

for (T,t) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))
@eval Base.copy(A::$T) = ThreadedSparseMatrixCSC(copy($t($t(A).A)))
@eval Base.permutedims(A::$T, (a,b)) = ThreadedSparseMatrixCSC(permutedims($t($t(A).A), (a,b)))
end



# sparse * sparse multiplications are not (currently) threaded, but we want to keep the return type
for (T1,t1) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))
for (T2,t2) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))
Expand Down
17 changes: 16 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ rand_scalar(rng,::Type{T}) where T<:Complex = T(rand(rng,2 .^ (1:5)) + im*rand(r
end


@testset "ReturnType" for op1 in [identity,adjoint,transpose], op2 in [identity,adjoint,transpose]
@testset "ReturnType_$(op1)_$(op2)" for op1 in [identity,adjoint,transpose], op2 in [identity,adjoint,transpose]
rng = StableRNG(1234)
A = rand_sparse(rng,Complex{Int64},10,10,0.4)
B = rand_sparse(rng,Complex{Int64},10,10,0.4)
Expand All @@ -82,6 +82,21 @@ rand_scalar(rng,::Type{T}) where T<:Complex = T(rand(rng,2 .^ (1:5)) + im*rand(r
@test out == ref
end

@testset "copy_$op" for op in [identity,adjoint,transpose]
rng = StableRNG(1234)
A = rand_sparse(rng,Complex{Int64},8,10,0.4)
out = copy(op(ThreadedSparseMatrixCSC(A)))
@test out isa ThreadedSparseMatrixCSC
@test out == op(A)
out = permutedims(op(ThreadedSparseMatrixCSC(A)))
@test out isa ThreadedSparseMatrixCSC
@test out == permutedims(op(A))

out = convert(Matrix,op(ThreadedSparseMatrixCSC(A)))
@test out isa Matrix
@test out == op(A)
end

N = 1000
n = 200
@testset "$T" for T in (ComplexF64, Complex{Int64})
Expand Down

2 comments on commit 2c96928

@rasmushenningsson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Patch notes:

Fix issue with SparseArrays._checkbuffers in Julia 1.7.x.
copy of adjoint/transposed ThreadedSparseMatrixCSC now returns ThreadedSparseMatrixCSC
permutedims of ThreadedSparseMatrixCSC now returns ThreadedSparseMatrixCSC

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/62103

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" 2c96928094a03acda49d419b1146d0dcef59c546
git push origin v0.2.2

Please sign in to comment.