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: Returns: e_gpu – Diagonal matrix of dimensions [N, N] with diagonal values set to 1.
Return type: 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