skcuda.linalg.eye

skcuda.linalg.eye(N, dtype=<Mock object>)[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 – Diagonal matrix of dimensions [N, N] with diagonal values set to 1.

Return type:

pycuda.gpuarray.GPUArray

Examples

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