scikits.cuda.linalg.dot_diag

scikits.cuda.linalg.dot_diag(d_gpu, a_gpu, trans='N', overwrite=True, 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).

trans : char

If ‘T’, compute the product of the transpose of a_gpu.

overwrite : bool

If true (default), save the result in a_gpu.

handle : int

CUBLAS context. If no context is specified, the default handle from scikits.cuda.misc._global_cublas_handle is used.

Returns:

r_gpu : pycuda.gpuarray.GPUArray

The computed matrix product.

Notes

d_gpu and a_gpu must have the same precision data type. d_gpu may be real and a_gpu may be complex, but not vice-versa.

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> import 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