skcuda.linalg.norm

skcuda.linalg.norm(x_gpu, handle=None)[source]

Euclidean norm (2-norm) of real vector.

Computes the Euclidean norm of an array.

Parameters:
  • x_gpu (pycuda.gpuarray.GPUArray) – Input array.
  • handle (int) – CUBLAS context. If no context is specified, the default handle from skcuda.misc._global_cublas_handle is used.
Returns:

nrm – Euclidean norm of x.

Return type:

real

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)
>>> nrm = linalg.norm(x_gpu)
>>> np.allclose(nrm, np.linalg.norm(x))
True
>>> x_gpu = gpuarray.to_gpu(np.array([3+4j, 12-84j]))
>>> linalg.norm(x_gpu)
85.0