Skip to content

Commit 4067511

Browse files
authored
Support Adjoint/Transpose -> COO (#2649)
1 parent 5461475 commit 4067511

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/cusparse/array.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ CuSparseMatrixCSR{T}(Mat::SparseMatrixCSC) where {T} = CuSparseMatrixCSR(CuSpars
464464
CuSparseMatrixBSR{T}(Mat::SparseMatrixCSC, blockdim) where {T} = CuSparseMatrixBSR(CuSparseMatrixCSR{T}(Mat), blockdim)
465465
CuSparseMatrixCOO{T}(Mat::SparseMatrixCSC) where {T} = CuSparseMatrixCOO(CuSparseMatrixCSR{T}(Mat))
466466

467+
CuSparseMatrixCOO{T}(Mat::Transpose{Tv, <:SparseMatrixCSC}) where {T, Tv} = CuSparseMatrixCOO{T}(CuSparseMatrixCSR{T}(Mat))
468+
CuSparseMatrixCOO{T}(Mat::Adjoint{Tv, <:SparseMatrixCSC}) where {T, Tv} = CuSparseMatrixCOO{T}(CuSparseMatrixCSR{T}(Mat))
469+
467470
# untyped variants
468471
CuSparseVector(x::AbstractSparseArray{T}) where {T} = CuSparseVector{T}(x)
469472
CuSparseMatrixCSC(x::AbstractSparseArray{T}) where {T} = CuSparseMatrixCSC{T}(x)

test/libraries/cusparse/conversions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ end
5353
end
5454
end
5555

56+
@testset "CuSparseMatrix(::Adjoint/::Transpose)" begin
57+
A = sprand(5, 5, 0.2)
58+
for T in (CuSparseMatrixCSC, CuSparseMatrixCSR, CuSparseMatrixCOO), f in (transpose, adjoint)
59+
dA = T(f(A))
60+
@test Array(dA) == f(A)
61+
end
62+
end
63+
5664
@testset "CuSparseMatrix(::Diagonal)" begin
5765
X = Diagonal(rand(10))
5866
dX = cu(X)

0 commit comments

Comments
 (0)