Skip to content

Commit 2c96928

Browse files
Buffer fix (#10)
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.
1 parent 8c58f54 commit 2c96928

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ThreadedSparseArrays"
22
uuid = "59d54670-b8ac-4d81-ab7a-bb56233e17ab"
33
authors = ["Stefanos Carlström <[email protected]>"]
4-
version = "0.2.1"
4+
version = "0.2.2"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ThreadedSparseArrays.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ for f in [:rowvals, :nonzeros, :getcolptr]
5353
end
5454

5555

56+
@static if v"1.7.0" <= VERSION < v"1.8.0-"
57+
SparseArrays._goodbuffers(A::ThreadedSparseMatrixCSC) = SparseArrays._goodbuffers(A.A)
58+
SparseArrays._checkbuffers(A::ThreadedSparseMatrixCSC) = SparseArrays._checkbuffers(A.A)
59+
end
60+
61+
for (T,t) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))
62+
@eval Base.copy(A::$T) = ThreadedSparseMatrixCSC(copy($t($t(A).A)))
63+
@eval Base.permutedims(A::$T, (a,b)) = ThreadedSparseMatrixCSC(permutedims($t($t(A).A), (a,b)))
64+
end
65+
66+
67+
5668
# sparse * sparse multiplications are not (currently) threaded, but we want to keep the return type
5769
for (T1,t1) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))
5870
for (T2,t2) in ((ThreadedSparseMatrixCSC,identity), (Adjoint{<:Any,<:ThreadedSparseMatrixCSC},adjoint), (Transpose{<:Any,<:ThreadedSparseMatrixCSC},transpose))

test/runtests.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ rand_scalar(rng,::Type{T}) where T<:Complex = T(rand(rng,2 .^ (1:5)) + im*rand(r
6666
end
6767

6868

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

85+
@testset "copy_$op" for op in [identity,adjoint,transpose]
86+
rng = StableRNG(1234)
87+
A = rand_sparse(rng,Complex{Int64},8,10,0.4)
88+
out = copy(op(ThreadedSparseMatrixCSC(A)))
89+
@test out isa ThreadedSparseMatrixCSC
90+
@test out == op(A)
91+
out = permutedims(op(ThreadedSparseMatrixCSC(A)))
92+
@test out isa ThreadedSparseMatrixCSC
93+
@test out == permutedims(op(A))
94+
95+
out = convert(Matrix,op(ThreadedSparseMatrixCSC(A)))
96+
@test out isa Matrix
97+
@test out == op(A)
98+
end
99+
85100
N = 1000
86101
n = 200
87102
@testset "$T" for T in (ComplexF64, Complex{Int64})

0 commit comments

Comments
 (0)