cuda_cffi/cusparse.py
def dense_nnz(descrA, A, handle=None, dirA=CUSPARSE_DIRECTION_ROW, lda=None,
              nnzPerRowCol=None, nnzTotalDevHostPtr=None):
    """ higher level wrapper to cusparse<t>nnz routines """
    if not isinstance(A, pycuda.gpuarray.GPUArray):
        raise ValueError("A must be a pyCUDA gpuarray")
    if len(A.shape) != 2:
        raise ValueError("A must be 2D")
    if lda is None:
        lda = A.shape[0]

    if handle is None:
        handle = misc._global_cusparse_handle

    m, n = A.shape
    assert lda >= m
    dtype = A.dtype

    alloc = misc._global_cusparse_allocator

    if nnzPerRowCol is None:
        if dirA == CUSPARSE_DIRECTION_ROW:
            nnzPerRowCol = gpuarray.zeros((m, ), dtype=np.int32,
                                          allocator=alloc)
        elif dirA == CUSPARSE_DIRECTION_COLUMN:
            nnzPerRowCol = gpuarray.zeros((n, ), dtype=np.int32,
                                          allocator=alloc)
        else:
            raise ValueError("Invalid dirA")
    if nnzTotalDevHostPtr is None:
        nnzTotalDevHostPtr = ffi.new('int *', 0)
    if dtype == np.float32:
        fn = cusparseSnnz
    elif dtype == np.float64:
        fn = cusparseDnnz
    elif dtype == np.complex64:
        fn = cusparseCnnz
    elif dtype == np.complex128:
        fn = cusparseZnnz
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)
    fn(handle, dirA, m, n, descrA, A, lda, nnzPerRowCol,
       nnzTotalDevHostPtr)
    return nnzPerRowCol, nnzTotalDevHostPtr[0]
 higher level wrapper to cusparse<t>nnz routines 
higher level wrapper to cusparsennz routines
higher level wrapper to cusparsennz routines
def dense_nnz(descrA, A, handle=None, dirA=CUSPARSE_DIRECTION_ROW, lda=None,
              nnzPerRowCol=None, nnzTotalDevHostPtr=None):
    if not isinstance(A, pycuda.gpuarray.GPUArray):
        raise ValueError("A must be a pyCUDA gpuarray")
    if len(A.shape) != 2:
        raise ValueError("A must be 2D")
    if lda is None:
        lda = A.shape[0]
    if handle is None:
        handle = misc._global_cusparse_handle
    m, n = A.shape
    assert lda >= m
    dtype = A.dtype
    alloc = misc._global_cusparse_allocator
    if nnzPerRowCol is None:
        if dirA == CUSPARSE_DIRECTION_ROW:
            nnzPerRowCol = gpuarray.zeros((m, ), dtype=np.int32,
                                          allocator=alloc)
        elif dirA == CUSPARSE_DIRECTION_COLUMN:
            nnzPerRowCol = gpuarray.zeros((n, ), dtype=np.int32,
                                          allocator=alloc)
        else:
            raise ValueError("Invalid dirA")
    if nnzTotalDevHostPtr is None:
        nnzTotalDevHostPtr = ffi.new('int *', 0)
    if dtype == np.float32:
        fn = cusparseSnnz
    elif dtype == np.float64:
        fn = cusparseDnnz
    elif dtype == np.complex64:
        fn = cusparseCnnz
    elif dtype == np.complex128:
        fn = cusparseZnnz
    else:
        raise ValueError("unsupported sparse matrix dtype: %s" % dtype)
    fn(handle, dirA, m, n, descrA, A, lda, nnzPerRowCol,
       nnzTotalDevHostPtr)
    return nnzPerRowCol, nnzTotalDevHostPtr[0]
def dense_nnz ( descrA , A , handle = None , dirA = CUSPARSE_DIRECTION_ROW , lda = None , nnzPerRowCol = None , nnzTotalDevHostPtr = None ) : if not isinstance ( A , pycuda . gpuarray . GPUArray ) : raise ValueError ( "A must be a pyCUDA gpuarray" ) if len ( A . shape ) != 2 : raise ValueError ( "A must be 2D" ) if lda is None : lda = A . shape [ 0 ] if handle is None : handle = misc . _global_cusparse_handle m , n = A . shape assert lda >= m dtype = A . dtype alloc = misc . _global_cusparse_allocator if nnzPerRowCol is None : if dirA == CUSPARSE_DIRECTION_ROW : nnzPerRowCol = gpuarray . zeros ( ( m , ) , dtype = np . int32 , allocator = alloc ) elif dirA == CUSPARSE_DIRECTION_COLUMN : nnzPerRowCol = gpuarray . zeros ( ( n , ) , dtype = np . int32 , allocator = alloc ) else : raise ValueError ( "Invalid dirA" ) if nnzTotalDevHostPtr is None : nnzTotalDevHostPtr = ffi . new ( 'int *' , 0 ) if dtype == np . float32 : fn = cusparseSnnz elif dtype == np . float64 : fn = cusparseDnnz elif dtype == np . complex64 : fn = cusparseCnnz elif dtype == np . complex128 : fn = cusparseZnnz else : raise ValueError ( "unsupported sparse matrix dtype: %s" % dtype ) fn ( handle , dirA , m , n , descrA , A , lda , nnzPerRowCol , nnzTotalDevHostPtr ) return nnzPerRowCol , nnzTotalDevHostPtr [ 0 ]
higher level wrapper to cusparse<t>nnz routines
higher level wrapper to cusparse<t > nnz routines
""" higher level wrapper to cusparse<t>nnz routines """
descrA
A
handle
dirA
lda
nnzPerRowCol
nnzTotalDevHostPtr