scikits.cuda.cublas.cublasSasum

scikits.cuda.cublas.cublasSasum(handle, n, x, incx)[source]

Sum of absolute values of single-precision real vector.

Computes the sum of the absolute values of the elements of a single-precision real vector.

Note: if the vector is complex, then this computes the sum sum(abs(x.real)) + sum(abs(x.imag))

Parameters:

handle : int

CUBLAS context.

n : int

Number of elements in input vector.

x : ctypes.c_void_p

Pointer to single-precision real input vector.

incx : int

Storage spacing between elements of x.

Returns:

s : numpy.float32

Sum of absolute values.

Examples

>>> import pycuda.autoinit
>>> import pycuda.gpuarray as gpuarray
>>> import numpy as np
>>> x = np.random.rand(5).astype(np.float32)
>>> x_gpu = gpuarray.to_gpu(x)
>>> h = cublasCreate()
>>> s = cublasSasum(h, x_gpu.size, x_gpu.gpudata, 1)
>>> cublasDestroy(h)
>>> np.allclose(s, abs(x.real).sum() + abs(x.imag).sum())
True