skcuda.linalg.dot_diag

skcuda.linalg.dot_diag(d_gpu, a_gpu, trans='N', overwrite=False, handle=None)[source]

Dot product of diagonal and non-diagonal arrays.

Computes the matrix product of a diagonal array represented as a vector and a non-diagonal array.

Parameters:
  • d_gpu (pycuda.gpuarray.GPUArray) – Array of length N corresponding to the diagonal of the multiplier.
  • a_gpu (pycuda.gpuarray.GPUArray) – Multiplicand array with shape (N, M). Must have same data type as d_gpu.
  • trans (char) – If ‘T’, compute the product of the transpose of a_gpu.
  • overwrite (bool (default: False)) – If true, save the result in a_gpu.
  • handle (int) – CUBLAS context. If no context is specified, the default handle from skcuda.misc._global_cublas_handle is used.
Returns:

r_gpu – The computed matrix product.

Return type:

pycuda.gpuarray.GPUArray

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> import skcuda.linalg as linalg
>>> linalg.init()
>>> d = np.random.rand(4)
>>> a = np.random.rand(4, 4)
>>> d_gpu = gpuarray.to_gpu(d)
>>> a_gpu = gpuarray.to_gpu(a)
>>> r_gpu = linalg.dot_diag(d_gpu, a_gpu)
>>> np.allclose(np.dot(np.diag(d), a), r_gpu.get())
True