@@ -199,7 +199,7 @@ function sort_coo(A::CuSparseMatrixCOO{Tv,Ti}, type::SparseChar='R') where {Tv,T
199199 # and we have the following error in the tests:
200200 # "Out of GPU memory trying to allocate 127.781 TiB".
201201 # We set 0 as default value to avoid it.
202- out = Ref {Csize_t} (0 )
202+ out = Ref {Csize_t} (1 )
203203 cusparseXcoosort_bufferSizeExt (handle (), m, n, nnz (A), A. rowInd, A. colInd, out)
204204 return out[]
205205 end
626626# need both typevars for compatibility with GPUArrays
627627function CuSparseMatrixCSR {Tv, Ti} (coo:: CuSparseMatrixCOO{Tv, Ti} ; index:: SparseChar = ' O' ) where {Tv, Ti}
628628 m, n = size (coo)
629- csrRowPtr = (index == ' O' ) ? CUDA. ones (Cint, m + 1 ) : CUDA. zeros (Cint, m + 1 )
630- nnz (coo) == 0 && return CuSparseMatrixCSR {Tv} (csrRowPtr, coo. colInd, nonzeros (coo), size (coo))
629+ csrRowPtr = CuArray {Ti} (undef, m + 1 )
630+ if iszero (m)
631+ csrRowPtr .= (index == ' O' ) ? 1 : 0 # cusparseXcoo2csr does not initialize csrRowPtr correctly if m == 0
632+ end
631633 coo = sort_coo (coo, ' R' )
632634 cusparseXcoo2csr (handle (), coo. rowInd, nnz (coo), m, csrRowPtr, index)
633635 CuSparseMatrixCSR {Tv,Cint} (csrRowPtr, coo. colInd, nonzeros (coo), size (coo))
@@ -637,7 +639,6 @@ CuSparseMatrixCSR(coo::CuSparseMatrixCOO{Tv, Ti}; index::SparseChar='O') where {
637639
638640function CuSparseMatrixCOO {Tv, Ti} (csr:: CuSparseMatrixCSR{Tv} ; index:: SparseChar = ' O' ) where {Tv, Ti}
639641 m,n = size (csr)
640- nnz (csr) == 0 && return CuSparseMatrixCOO {Tv,Cint} (CUDA. zeros (Cint, 0 ), CUDA. zeros (Cint, 0 ), nonzeros (csr), size (csr))
641642 cooRowInd = CuVector {Cint} (undef, nnz (csr))
642643 cusparseXcsr2coo (handle (), csr. rowPtr, nnz (csr), m, cooRowInd, index)
643644 CuSparseMatrixCOO {Tv,Cint} (cooRowInd, csr. colVal, nonzeros (csr), size (csr))
@@ -649,8 +650,10 @@ CuSparseMatrixCOO(csr::CuSparseMatrixCSR{Tv, Ti}; index::SparseChar='O') where {
649650
650651function CuSparseMatrixCSC {Tv, Ti} (coo:: CuSparseMatrixCOO{Tv, Ti} ; index:: SparseChar = ' O' ) where {Tv, Ti}
651652 m, n = size (coo)
652- cscColPtr = (index == ' O' ) ? CUDA. ones (Cint, n + 1 ) : CUDA. zeros (Cint, n + 1 )
653- nnz (coo) == 0 && return CuSparseMatrixCSC {Tv} (cscColPtr, coo. rowInd, nonzeros (coo), size (coo))
653+ cscColPtr = CuArray {Ti} (undef, n + 1 )
654+ if iszero (n)
655+ cscColPtr .= (index == ' O' ) ? 1 : 0 # cusparseXcoo2csr does not initialize cscColPtr correctly if n == 0
656+ end
654657 coo = sort_coo (coo, ' C' )
655658 cusparseXcoo2csr (handle (), coo. colInd, nnz (coo), n, cscColPtr, index)
656659 CuSparseMatrixCSC {Tv,Cint} (cscColPtr, coo. rowInd, nonzeros (coo), size (coo))
@@ -660,7 +663,6 @@ CuSparseMatrixCSC(coo::CuSparseMatrixCOO{Tv, Ti}; index::SparseChar='O') where {
660663
661664function CuSparseMatrixCOO {Tv, Ti} (csc:: CuSparseMatrixCSC{Tv, Ti} ; index:: SparseChar = ' O' ) where {Tv, Ti}
662665 m,n = size (csc)
663- nnz (csc) == 0 && return CuSparseMatrixCOO {Tv,Cint} (CUDA. zeros (Cint, 0 ), CUDA. zeros (Cint, 0 ), nonzeros (csc), size (csc))
664666 cooColInd = CuVector {Cint} (undef, nnz (csc))
665667 cusparseXcsr2coo (handle (), csc. colPtr, nnz (csc), n, cooColInd, index)
666668 coo = CuSparseMatrixCOO {Tv,Cint} (csc. rowVal, cooColInd, nonzeros (csc), size (csc))
0 commit comments