(a_gpu, b_gpu, c_gpu, transa='N', transb='N', alpha=1.0, beta=1.0, handle=None)
return c_gpu
Calculates the dot product of two arrays and adds it to a third matrix.

    In essence, this computes

    C =  alpha * (A B) + beta * C

    For 2D arrays of shapes `(m, k)` and `(k, n)`, it computes the matrix
    product; the result has shape `(m, n)`.

    Parameters
    ----------
    a_gpu : pycuda.gpuarray.GPUArray
        Input array.
    b_gpu : pycuda.gpuarray.GPUArray
        Input array.
    c_gpu : pycuda.gpuarray.GPUArray
        Cumulative array.
    transa : char
        If 'T', compute the product of the transpose of `a_gpu`.
        If 'C', compute the product of the Hermitian of `a_gpu`.
    transb : char
        If 'T', compute the product of the transpose of `b_gpu`.
        If 'C', compute the product of the Hermitian of `b_gpu`.
    handle : int (optional)
        CUBLAS context. If no context is specified, the default handle from
        `skcuda.misc._global_cublas_handle` is used.

    Returns
    -------
    c_gpu : pycuda.gpuarray.GPUArray

    Notes
    -----
    The matrices must all contain elements of the same data type.
Calculates the dot product of two arrays and adds it to a third matrix.
Calculates the dot product of two arrays and adds it to a third matrix .
def add_dot(a_gpu, b_gpu, c_gpu, transa='N', transb='N', alpha=1.0, beta=1.0, handle=None):
    """
    Calculates the dot product of two arrays and adds it to a third matrix.

    In essence, this computes

    C =  alpha * (A B) + beta * C

    For 2D arrays of shapes `(m, k)` and `(k, n)`, it computes the matrix
    product; the result has shape `(m, n)`.

    Parameters
    ----------
    a_gpu : pycuda.gpuarray.GPUArray
        Input array.
    b_gpu : pycuda.gpuarray.GPUArray
        Input array.
    c_gpu : pycuda.gpuarray.GPUArray
        Cumulative array.
    transa : char
        If 'T', compute the product of the transpose of `a_gpu`.
        If 'C', compute the product of the Hermitian of `a_gpu`.
    transb : char
        If 'T', compute the product of the transpose of `b_gpu`.
        If 'C', compute the product of the Hermitian of `b_gpu`.
    handle : int (optional)
        CUBLAS context. If no context is specified, the default handle from
        `skcuda.misc._global_cublas_handle` is used.

    Returns
    -------
    c_gpu : pycuda.gpuarray.GPUArray

    Notes
    -----
    The matrices must all contain elements of the same data type.
    """

    if handle is None:
        handle = misc._global_cublas_handle

    # Get the shapes of the arguments (accounting for the
    # possibility that one of them may only have one dimension):
    a_shape = a_gpu.shape
    b_shape = b_gpu.shape
    if len(a_shape) == 1:
        a_shape = (1, a_shape[0])
    if len(b_shape) == 1:
        b_shape = (1, b_shape[0])

    # Perform matrix multiplication for 2D arrays:
    if (a_gpu.dtype == np.complex64 and b_gpu.dtype == np.complex64):
        cublas_func = cublas.cublasCgemm
        alpha = np.complex64(alpha)
        beta = np.complex64(beta)
    elif (a_gpu.dtype == np.float32 and b_gpu.dtype == np.float32):
        cublas_func = cublas.cublasSgemm
        alpha = np.float32(alpha)
        beta = np.float32(beta)
    elif (a_gpu.dtype == np.complex128 and b_gpu.dtype == np.complex128):
        cublas_func = cublas.cublasZgemm
        alpha = np.complex128(alpha)
        beta = np.complex128(beta)
    elif (a_gpu.dtype == np.float64 and b_gpu.dtype == np.float64):
        cublas_func = cublas.cublasDgemm
        alpha = np.float64(alpha)
        beta = np.float64(beta)
    else:
        raise ValueError('unsupported combination of input types')

    transa = transa.lower()
    transb = transb.lower()

    a_f_order = a_gpu.strides[1] > a_gpu.strides[0]
    b_f_order = b_gpu.strides[1] > b_gpu.strides[0]
    c_f_order = c_gpu.strides[1] > c_gpu.strides[0]

    if a_f_order != b_f_order:
        raise ValueError('unsupported combination of input order')
    if a_f_order != c_f_order:
        raise ValueError('invalid order for c_gpu')

    if a_f_order:  # F order array
        if transa in ['t', 'c']:
            k, m = a_shape
        elif transa in ['n']:
            m, k = a_shape
        else:
            raise ValueError('invalid value for transa')

        if transb in ['t', 'c']:
            n, l = b_shape
        elif transb in ['n']:
            l, n = b_shape
        else:
            raise ValueError('invalid value for transb')

        if l != k:
            raise ValueError('objects are not aligned')

        lda = max(1, a_gpu.strides[1] // a_gpu.dtype.itemsize)
        ldb = max(1, b_gpu.strides[1] // b_gpu.dtype.itemsize)
        ldc = max(1, c_gpu.strides[1] // c_gpu.dtype.itemsize)

        if c_gpu.shape != (m, n) or c_gpu.dtype != a_gpu.dtype:
            raise ValueError('invalid value for c_gpu')
        cublas_func(handle, transa, transb, m, n, k, alpha, a_gpu.gpudata,
                lda, b_gpu.gpudata, ldb, beta, c_gpu.gpudata, ldc)
    else:
        if transb in ['t', 'c']:
            m, k = b_shape
        elif transb in ['n']:
            k, m = b_shape
        else:
            raise ValueError('invalid value for transb')

        if transa in ['t', 'c']:
            l, n = a_shape
        elif transa in ['n']:
            n, l = a_shape
        else:
            raise ValueError('invalid value for transa')

        if l != k:
            raise ValueError('objects are not aligned')

        lda = max(1, a_gpu.strides[0] // a_gpu.dtype.itemsize)
        ldb = max(1, b_gpu.strides[0] // b_gpu.dtype.itemsize)
        ldc = max(1, c_gpu.strides[0] // c_gpu.dtype.itemsize)

        # Note that the desired shape of the output matrix is the transpose
        # of what CUBLAS assumes:
        if c_gpu.shape != (n, m) or c_gpu.dtype != a_gpu.dtype:
            raise ValueError('invalid value for c_gpu')
        cublas_func(handle, transb, transa, m, n, k, alpha, b_gpu.gpudata,
                ldb, a_gpu.gpudata, lda, beta, c_gpu.gpudata, ldc)
    return c_gpu
def add_dot ( a_gpu , b_gpu , c_gpu , transa = 'N' , transb = 'N' , alpha = 1.0 , beta = 1.0 , handle = None ) : if handle is None : handle = misc . _global_cublas_handle # Get the shapes of the arguments (accounting for the # possibility that one of them may only have one dimension): a_shape = a_gpu . shape b_shape = b_gpu . shape if len ( a_shape ) == 1 : a_shape = ( 1 , a_shape [ 0 ] ) if len ( b_shape ) == 1 : b_shape = ( 1 , b_shape [ 0 ] ) # Perform matrix multiplication for 2D arrays: if ( a_gpu . dtype == np . complex64 and b_gpu . dtype == np . complex64 ) : cublas_func = cublas . cublasCgemm alpha = np . complex64 ( alpha ) beta = np . complex64 ( beta ) elif ( a_gpu . dtype == np . float32 and b_gpu . dtype == np . float32 ) : cublas_func = cublas . cublasSgemm alpha = np . float32 ( alpha ) beta = np . float32 ( beta ) elif ( a_gpu . dtype == np . complex128 and b_gpu . dtype == np . complex128 ) : cublas_func = cublas . cublasZgemm alpha = np . complex128 ( alpha ) beta = np . complex128 ( beta ) elif ( a_gpu . dtype == np . float64 and b_gpu . dtype == np . float64 ) : cublas_func = cublas . cublasDgemm alpha = np . float64 ( alpha ) beta = np . float64 ( beta ) else : raise ValueError ( 'unsupported combination of input types' ) transa = transa . lower ( ) transb = transb . lower ( ) a_f_order = a_gpu . strides [ 1 ] > a_gpu . strides [ 0 ] b_f_order = b_gpu . strides [ 1 ] > b_gpu . strides [ 0 ] c_f_order = c_gpu . strides [ 1 ] > c_gpu . strides [ 0 ] if a_f_order != b_f_order : raise ValueError ( 'unsupported combination of input order' ) if a_f_order != c_f_order : raise ValueError ( 'invalid order for c_gpu' ) if a_f_order : # F order array if transa in [ 't' , 'c' ] : k , m = a_shape elif transa in [ 'n' ] : m , k = a_shape else : raise ValueError ( 'invalid value for transa' ) if transb in [ 't' , 'c' ] : n , l = b_shape elif transb in [ 'n' ] : l , n = b_shape else : raise ValueError ( 'invalid value for transb' ) if l != k : raise ValueError ( 'objects are not aligned' ) lda = max ( 1 , a_gpu . strides [ 1 ] // a_gpu . dtype . itemsize ) ldb = max ( 1 , b_gpu . strides [ 1 ] // b_gpu . dtype . itemsize ) ldc = max ( 1 , c_gpu . strides [ 1 ] // c_gpu . dtype . itemsize ) if c_gpu . shape != ( m , n ) or c_gpu . dtype != a_gpu . dtype : raise ValueError ( 'invalid value for c_gpu' ) cublas_func ( handle , transa , transb , m , n , k , alpha , a_gpu . gpudata , lda , b_gpu . gpudata , ldb , beta , c_gpu . gpudata , ldc ) else : if transb in [ 't' , 'c' ] : m , k = b_shape elif transb in [ 'n' ] : k , m = b_shape else : raise ValueError ( 'invalid value for transb' ) if transa in [ 't' , 'c' ] : l , n = a_shape elif transa in [ 'n' ] : n , l = a_shape else : raise ValueError ( 'invalid value for transa' ) if l != k : raise ValueError ( 'objects are not aligned' ) lda = max ( 1 , a_gpu . strides [ 0 ] // a_gpu . dtype . itemsize ) ldb = max ( 1 , b_gpu . strides [ 0 ] // b_gpu . dtype . itemsize ) ldc = max ( 1 , c_gpu . strides [ 0 ] // c_gpu . dtype . itemsize ) # Note that the desired shape of the output matrix is the transpose # of what CUBLAS assumes: if c_gpu . shape != ( n , m ) or c_gpu . dtype != a_gpu . dtype : raise ValueError ( 'invalid value for c_gpu' ) cublas_func ( handle , transb , transa , m , n , k , alpha , b_gpu . gpudata , ldb , a_gpu . gpudata , lda , beta , c_gpu . gpudata , ldc ) return c_gpu