skcuda.linalg.dot

skcuda.linalg.dot(x_gpu, y_gpu, transa='N', transb='N', handle=None, out=None)[source]

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 – Inner product of x_gpu and y_gpu. When the inputs are 1D arrays, the result will be returned as a scalar.

Return type:

pycuda.gpuarray.GPUArray, float{32,64}, or complex{64,128}

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