skcuda.linalg.scale

skcuda.linalg.scale(alpha, x_gpu, alpha_real=False, handle=None)[source]

Scale a vector by a factor alpha.

Parameters:
  • alpha (scalar) – Scale parameter
  • x_gpu (pycuda.gpuarray.GPUArray) – Input array.
  • alpha_real (bool) – If True and x_gpu is complex, then one of the specialized versions cublasCsscal or cublasZdscal is used which might improve performance for large arrays. (By default, alpha is coerced to the corresponding complex type.)
  • handle (int) – CUBLAS context. If no context is specified, the default handle from skcuda.misc._global_cublas_handle is used.

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> import skcuda.linalg as linalg
>>> linalg.init()
>>> x = np.asarray(np.random.rand(4, 4), np.float32)
>>> x_gpu = gpuarray.to_gpu(x)
>>> alpha = 2.4
>>> linalg.scale(alpha, x_gpu)
>>> np.allclose(x_gpu.get(), alpha*x)
True