(x_gpu, y_gpu, transa='N', transb='N', handle=None, out=None)
Dot product of two arrays.

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

    Parameters
    ----------
    x_gpu : pycuda.gpuarray.GPUArray
        Input array.
    y_gpu : pycuda.gpuarray.GPUArray
        Input array.
    transa : char
        If 'T', compute the product of the transpose of `x_gpu`.
        If 'C', compute the product of the Hermitian of `x_gpu`.
    transb : char
        If 'T', compute the product of the transpose of `y_gpu`.
        If 'C', compute the product of the Hermitian of `y_gpu`.
    handle : int
        CUBLAS context. If no context is specified, the default handle from
        `skcuda.misc._global_cublas_handle` is used.
    out : pycuda.gpuarray.GPUArray, optional
        Output argument. Will be used to store the result.

    Returns
    -------
    c_gpu : pycuda.gpuarray.GPUArray, float{32,64}, or complex{64,128}
        Inner product of `x_gpu` and `y_gpu`. When the inputs are 1D
        arrays, the result will be returned as a scalar.

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

    Examples
    --------
    >>> import pycuda.autoinit
    >>> import pycuda.gpuarray as gpuarray
    >>> import numpy as np
    >>> import skcuda.linalg as linalg
    >>> import skcuda.misc as misc
    >>> linalg.init()
    >>> a = np.asarray(np.random.rand(4, 2), np.float32)
    >>> b = np.asarray(np.random.rand(2, 2), np.float32)
    >>> a_gpu = gpuarray.to_gpu(a)
    >>> b_gpu = gpuarray.to_gpu(b)
    >>> c_gpu = linalg.dot(a_gpu, b_gpu)
    >>> np.allclose(np.dot(a, b), c_gpu.get())
    True
    >>> d = np.asarray(np.random.rand(5), np.float32)
    >>> e = np.asarray(np.random.rand(5), np.float32)
    >>> d_gpu = gpuarray.to_gpu(d)
    >>> e_gpu = gpuarray.to_gpu(e)
    >>> f = linalg.dot(d_gpu, e_gpu)
    >>> np.allclose(np.dot(d, e), f)
    True
Dot product of two arrays.
Dot product of two arrays .
def dot(x_gpu, y_gpu, transa='N', transb='N', handle=None, out=None):
    """
    Dot product of two arrays.

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

    Parameters
    ----------
    x_gpu : pycuda.gpuarray.GPUArray
        Input array.
    y_gpu : pycuda.gpuarray.GPUArray
        Input array.
    transa : char
        If 'T', compute the product of the transpose of `x_gpu`.
        If 'C', compute the product of the Hermitian of `x_gpu`.
    transb : char
        If 'T', compute the product of the transpose of `y_gpu`.
        If 'C', compute the product of the Hermitian of `y_gpu`.
    handle : int
        CUBLAS context. If no context is specified, the default handle from
        `skcuda.misc._global_cublas_handle` is used.
    out : pycuda.gpuarray.GPUArray, optional
        Output argument. Will be used to store the result.

    Returns
    -------
    c_gpu : pycuda.gpuarray.GPUArray, float{32,64}, or complex{64,128}
        Inner product of `x_gpu` and `y_gpu`. When the inputs are 1D
        arrays, the result will be returned as a scalar.

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

    Examples
    --------
    >>> import pycuda.autoinit
    >>> import pycuda.gpuarray as gpuarray
    >>> import numpy as np
    >>> import skcuda.linalg as linalg
    >>> import skcuda.misc as misc
    >>> linalg.init()
    >>> a = np.asarray(np.random.rand(4, 2), np.float32)
    >>> b = np.asarray(np.random.rand(2, 2), np.float32)
    >>> a_gpu = gpuarray.to_gpu(a)
    >>> b_gpu = gpuarray.to_gpu(b)
    >>> c_gpu = linalg.dot(a_gpu, b_gpu)
    >>> np.allclose(np.dot(a, b), c_gpu.get())
    True
    >>> d = np.asarray(np.random.rand(5), np.float32)
    >>> e = np.asarray(np.random.rand(5), np.float32)
    >>> d_gpu = gpuarray.to_gpu(d)
    >>> e_gpu = gpuarray.to_gpu(e)
    >>> f = linalg.dot(d_gpu, e_gpu)
    >>> np.allclose(np.dot(d, e), f)
    True

    """
    if handle is None:
        handle = misc._global_cublas_handle

    x_shape = x_gpu.shape
    y_shape = y_gpu.shape

    # When one argument is a vector and the other a matrix, increase the number
    # of dimensions of the vector to 2 so that they can be multiplied using
    # GEMM, but also set the shape of the output to 1 dimension to conform with
    # the behavior of numpy.dot:
    if len(x_shape) == 1 and len(y_shape) > 1:
        out_shape = (y_shape[1],)
        x_shape = (1, x_shape[0])
        x_gpu = x_gpu.reshape(x_shape)
    elif len(x_shape) > 1 and len(y_shape) == 1:
        out_shape = (x_shape[0],)
        y_shape = (y_shape[0], 1)
        y_gpu = y_gpu.reshape(y_shape)

    if len(x_gpu.shape) == 1 and len(y_gpu.shape) == 1:
        if x_gpu.size != y_gpu.size:
            raise ValueError('arrays must be of same length')

        # Compute inner product for 1D arrays:
        if (x_gpu.dtype == np.complex64 and y_gpu.dtype == np.complex64):
            cublas_func = cublas.cublasCdotu
        elif (x_gpu.dtype == np.float32 and y_gpu.dtype == np.float32):
            cublas_func = cublas.cublasSdot
        elif (x_gpu.dtype == np.complex128 and y_gpu.dtype == np.complex128):
            cublas_func = cublas.cublasZdotu
        elif (x_gpu.dtype == np.float64 and y_gpu.dtype == np.float64):
            cublas_func = cublas.cublasDdot
        else:
            raise ValueError('unsupported combination of input types')

        return cublas_func(handle, x_gpu.size, x_gpu.gpudata, 1,
                           y_gpu.gpudata, 1)
    else:
        transa = transa.lower()
        transb = transb.lower()
        if out is None:
            if transa in ['t', 'c']:
                k, m = x_shape
            else:
                m, k = x_shape

            if transb in ['t', 'c']:
                n, l = y_shape
            else:
                l, n = y_shape

            alloc = misc._global_cublas_allocator
            if x_gpu.strides[1] > x_gpu.strides[0]: # F order
                out = gpuarray.empty((m, n), x_gpu.dtype, order="F", allocator=alloc)
            else:
                out = gpuarray.empty((m, n), x_gpu.dtype, order="C", allocator=alloc)

    add_dot(x_gpu, y_gpu, out, transa, transb, 1.0, 0.0, handle)
    if 'out_shape' in locals():
        return out.reshape(out_shape)
    else:
        return out
def dot ( x_gpu , y_gpu , transa = 'N' , transb = 'N' , handle = None , out = None ) : if handle is None : handle = misc . _global_cublas_handle x_shape = x_gpu . shape y_shape = y_gpu . shape # When one argument is a vector and the other a matrix, increase the number # of dimensions of the vector to 2 so that they can be multiplied using # GEMM, but also set the shape of the output to 1 dimension to conform with # the behavior of numpy.dot: if len ( x_shape ) == 1 and len ( y_shape ) > 1 : out_shape = ( y_shape [ 1 ] , ) x_shape = ( 1 , x_shape [ 0 ] ) x_gpu = x_gpu . reshape ( x_shape ) elif len ( x_shape ) > 1 and len ( y_shape ) == 1 : out_shape = ( x_shape [ 0 ] , ) y_shape = ( y_shape [ 0 ] , 1 ) y_gpu = y_gpu . reshape ( y_shape ) if len ( x_gpu . shape ) == 1 and len ( y_gpu . shape ) == 1 : if x_gpu . size != y_gpu . size : raise ValueError ( 'arrays must be of same length' ) # Compute inner product for 1D arrays: if ( x_gpu . dtype == np . complex64 and y_gpu . dtype == np . complex64 ) : cublas_func = cublas . cublasCdotu elif ( x_gpu . dtype == np . float32 and y_gpu . dtype == np . float32 ) : cublas_func = cublas . cublasSdot elif ( x_gpu . dtype == np . complex128 and y_gpu . dtype == np . complex128 ) : cublas_func = cublas . cublasZdotu elif ( x_gpu . dtype == np . float64 and y_gpu . dtype == np . float64 ) : cublas_func = cublas . cublasDdot else : raise ValueError ( 'unsupported combination of input types' ) return cublas_func ( handle , x_gpu . size , x_gpu . gpudata , 1 , y_gpu . gpudata , 1 ) else : transa = transa . lower ( ) transb = transb . lower ( ) if out is None : if transa in [ 't' , 'c' ] : k , m = x_shape else : m , k = x_shape if transb in [ 't' , 'c' ] : n , l = y_shape else : l , n = y_shape alloc = misc . _global_cublas_allocator if x_gpu . strides [ 1 ] > x_gpu . strides [ 0 ] : # F order out = gpuarray . empty ( ( m , n ) , x_gpu . dtype , order = "F" , allocator = alloc ) else : out = gpuarray . empty ( ( m , n ) , x_gpu . dtype , order = "C" , allocator = alloc ) add_dot ( x_gpu , y_gpu , out , transa , transb , 1.0 , 0.0 , handle ) if 'out_shape' in locals ( ) : return out . reshape ( out_shape ) else : return out