cuda_cffi/cusparse.py
def to_CSR(cls, A, handle=None):
        """ convert dense numpy or gpuarray matrices as well as any
        scipy.sparse matrix formats to cuSPARSE CSR.
        """
        alloc = misc._global_cusparse_allocator
        if alloc is None:
            raise ValueError("no allocator found.  Run cusparse.init() first.")

        if has_scipy and isinstance(A, scipy.sparse.spmatrix):
            """Convert scipy.sparse CSR, COO, BSR, etc to cuSPARSE CSR"""
            # converting BSR, COO, etc to CSR
            if A.dtype.char not in ['f', 'd', 'F', 'D']:
                raise ValueError("unsupported numpy dtype {}".format(A.dtype))

            if not isinstance(A, scipy.sparse.csr_matrix):
                A = A.tocsr()

            # avoid .astype() calls if possible for speed
            if A.indptr.dtype != np.int32:
                csrRowPtr = gpuarray.to_gpu(A.indptr.astype(np.int32),
                                            allocator=alloc)
            else:
                csrRowPtr = gpuarray.to_gpu(A.indptr, allocator=alloc)

            if A.indices.dtype != np.int32:
                csrColInd = gpuarray.to_gpu(A.indices.astype(np.int32),
                                            allocator=alloc)
            else:
                csrColInd = gpuarray.to_gpu(A.indices, allocator=alloc)

            csrVal = gpuarray.to_gpu(A.data, allocator=alloc)
            descr = cusparseCreateMatDescr()
            cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL)
            cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO)
        else:
            """Take dense numpy array or pyCUDA gpuarray and convert to CSR """
            if not isinstance(A, pycuda.gpuarray.GPUArray):
                A = np.asfortranarray(np.atleast_2d(A))
                A = gpuarray.to_gpu(A, allocator=alloc)
            else:
                # dense matrix must be column-major
                if not A.flags.f_contiguous:
                    # TODO :an change to Fortran ordering be done directly on
                    # the gpuarray without going back to numpy?
                    A = A.get()
                    A = np.asfortranarray(A)
                    A = gpuarray.to_gpu(A, allocator=alloc)

            (descr, csrVal, csrRowPtr, csrColInd) = dense2csr(A, handle=handle)
        return cls(descr, csrVal, csrRowPtr, csrColInd, A.shape)
 convert dense numpy or gpuarray matrices as well as any
        scipy.sparse matrix formats to cuSPARSE CSR.
        
convert dense numpy or gpuarray matrices as well as any
scipy.sparse matrix formats to cuSPARSE CSR.
convert dense numpy or gpuarray matrices as well as any scipy . sparse matrix formats to cuSPARSE CSR .
def to_CSR(cls, A, handle=None):
        alloc = misc._global_cusparse_allocator
        if alloc is None:
            raise ValueError("no allocator found.  Run cusparse.init() first.")
        if has_scipy and isinstance(A, scipy.sparse.spmatrix):
            if A.dtype.char not in ['f', 'd', 'F', 'D']:
                raise ValueError("unsupported numpy dtype {}".format(A.dtype))
            if not isinstance(A, scipy.sparse.csr_matrix):
                A = A.tocsr()
            if A.indptr.dtype != np.int32:
                csrRowPtr = gpuarray.to_gpu(A.indptr.astype(np.int32),
                                            allocator=alloc)
            else:
                csrRowPtr = gpuarray.to_gpu(A.indptr, allocator=alloc)
            if A.indices.dtype != np.int32:
                csrColInd = gpuarray.to_gpu(A.indices.astype(np.int32),
                                            allocator=alloc)
            else:
                csrColInd = gpuarray.to_gpu(A.indices, allocator=alloc)
            csrVal = gpuarray.to_gpu(A.data, allocator=alloc)
            descr = cusparseCreateMatDescr()
            cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL)
            cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO)
        else:
            if not isinstance(A, pycuda.gpuarray.GPUArray):
                A = np.asfortranarray(np.atleast_2d(A))
                A = gpuarray.to_gpu(A, allocator=alloc)
            else:
                if not A.flags.f_contiguous:
                    A = A.get()
                    A = np.asfortranarray(A)
                    A = gpuarray.to_gpu(A, allocator=alloc)
            (descr, csrVal, csrRowPtr, csrColInd) = dense2csr(A, handle=handle)
        return cls(descr, csrVal, csrRowPtr, csrColInd, A.shape)
def to_CSR ( cls , A , handle = None ) : alloc = misc . _global_cusparse_allocator if alloc is None : raise ValueError ( "no allocator found.  Run cusparse.init() first." ) if has_scipy and isinstance ( A , scipy . sparse . spmatrix ) : """Convert scipy.sparse CSR, COO, BSR, etc to cuSPARSE CSR""" if A . dtype . char not in [ 'f' , 'd' , 'F' , 'D' ] : raise ValueError ( "unsupported numpy dtype {}" . format ( A . dtype ) ) if not isinstance ( A , scipy . sparse . csr_matrix ) : A = A . tocsr ( ) if A . indptr . dtype != np . int32 : csrRowPtr = gpuarray . to_gpu ( A . indptr . astype ( np . int32 ) , allocator = alloc ) else : csrRowPtr = gpuarray . to_gpu ( A . indptr , allocator = alloc ) if A . indices . dtype != np . int32 : csrColInd = gpuarray . to_gpu ( A . indices . astype ( np . int32 ) , allocator = alloc ) else : csrColInd = gpuarray . to_gpu ( A . indices , allocator = alloc ) csrVal = gpuarray . to_gpu ( A . data , allocator = alloc ) descr = cusparseCreateMatDescr ( ) cusparseSetMatType ( descr , CUSPARSE_MATRIX_TYPE_GENERAL ) cusparseSetMatIndexBase ( descr , CUSPARSE_INDEX_BASE_ZERO ) else : """Take dense numpy array or pyCUDA gpuarray and convert to CSR """ if not isinstance ( A , pycuda . gpuarray . GPUArray ) : A = np . asfortranarray ( np . atleast_2d ( A ) ) A = gpuarray . to_gpu ( A , allocator = alloc ) else : if not A . flags . f_contiguous : A = A . get ( ) A = np . asfortranarray ( A ) A = gpuarray . to_gpu ( A , allocator = alloc ) ( descr , csrVal , csrRowPtr , csrColInd ) = dense2csr ( A , handle = handle ) return cls ( descr , csrVal , csrRowPtr , csrColInd , A . shape )
convert dense numpy or gpuarray matrices as well as any
scipy.sparse matrix formats to cuSPARSE CSR.
convert dense numpy or gpuarray matrices as well as any scipy . sparse matrix formats to cuSPARSE CSR .
""" convert dense numpy or gpuarray matrices as well as any
        scipy.sparse matrix formats to cuSPARSE CSR.
        """ """Convert scipy.sparse CSR, COO, BSR, etc to cuSPARSE CSR""" # converting BSR, COO, etc to CSR # avoid .astype() calls if possible for speed """Take dense numpy array or pyCUDA gpuarray and convert to CSR """ # dense matrix must be column-major # TODO :an change to Fortran ordering be done directly on # the gpuarray without going back to numpy?
cls
A
handle