scikits.cuda.linalg.eye

scikits.cuda.linalg.eye(N, dtype=<Mock object at 0x2aade38bfa10>)[source]

Construct a 2D matrix with ones on the diagonal and zeros elsewhere.

Constructs a matrix in device memory whose diagonal elements are set to 1 and non-diagonal elements are set to 0.

Parameters:

N : int

Number of rows or columns in the output matrix.

dtype : type

Matrix data type.

Returns:

e_gpu : pycuda.gpuarray.GPUArray

Diagonal matrix of dimensions [N, N] with diagonal values set to 1.

Examples

>>> import pycuda.driver as drv
>>> import pycuda.gpuarray as gpuarray
>>> import pycuda.autoinit
>>> import numpy as np
>>> import linalg
>>> linalg.init()
>>> N = 5
>>> e_gpu = linalg.eye(N)
>>> np.all(e_gpu.get() == np.eye(N))
True
>>> e_gpu = linalg.eye(N, np.complex64)
>>> np.all(e_gpu.get() == np.eye(N, dtype=np.complex64))
True