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
y_gpu : pycuda.gpuarray.GPUArray
transa : char
transb : char
handle : int
out : pycuda.gpuarray.GPUArray, optional
|
---|---|
Returns: | c_gpu : 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.gpuarray as gpuarray
>>> import pycuda.autoinit
>>> import numpy as np
>>> import linalg
>>> import 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