Skip to content
fn

eye_op

→TensorImplPtr
int eye_op(int N, int M, int k, Dtype dt, Device device, bool requires_grad)

Python wrappers

Public Python APIs implemented by this engine symbols.

Create an N×MN \times M identity-like matrix with ones on diagonal kk.

Math

out[i,j]={1j−i=k0otherwise \text{out}[i, j] = \begin{cases} 1 & j - i = k \\ 0 & \text{otherwise} \end{cases}

Parameters

Nint64_t
Number of rows (must be ≥0\ge 0).
Mint64_t
Number of columns (must be ≥0\ge 0).
kint64_t
Diagonal index. k = 0 is the main diagonal; positive k is above, negative k is below.
dtDtype
Element dtype.
deviceDevice
Target device.
requires_gradbool
Attach a fresh autograd leaf when true.

Returns

TensorImplPtr

2-D tensor of shape (N,M)(N, M).