forward of NonZero Args: x (CTensor): input tensor. Returns: the output CTensor.
(self, x)
| 4636 | super(NonZero, self).__init__() |
| 4637 | |
| 4638 | def forward(self, x): |
| 4639 | """ |
| 4640 | forward of NonZero |
| 4641 | Args: |
| 4642 | x (CTensor): input tensor. |
| 4643 | Returns: |
| 4644 | the output CTensor. |
| 4645 | """ |
| 4646 | y = tensor.to_numpy(tensor.from_raw_tensor(x)) |
| 4647 | y = np.array((np.nonzero(y))).astype(np.int32) |
| 4648 | y = tensor.from_numpy(y) |
| 4649 | y.to_device(x.device()) |
| 4650 | return y.data |
| 4651 | |
| 4652 | def backward(self, dy): |
| 4653 | """ |