Initialize the tensor with ones on the diagonal and zeros elsewhere. Note: it is implemented by calling numpy. Do not call it within forward propagation when computation graph is enabled. # Arguments t(Tensor): the matrix to be filled in.
(t)
| 39 | |
| 40 | |
| 41 | def eye(t): |
| 42 | """Initialize the tensor with ones on the diagonal and zeros elsewhere. |
| 43 | |
| 44 | Note: it is implemented by calling numpy. |
| 45 | Do not call it within forward propagation when computation graph is enabled. |
| 46 | |
| 47 | # Arguments |
| 48 | t(Tensor): the matrix to be filled in. |
| 49 | """ |
| 50 | if len(t.shape) == 2: |
| 51 | raise ValueError("Only tensors with 2 dimensions are supported") |
| 52 | a = np.eye(t.shape[0], t.shape[1], dtype=np.float32) |
| 53 | t.copy_from(a) |
| 54 | |
| 55 | |
| 56 | def orthogonal(t, gain=1.0): |