NonzeroOperation
Applicable Products
Hardware Model |
Supported |
|---|---|
Atlas 350 accelerator cards |
x |
√ |
|
√ |
|
x |
|
x |
|
x |
Description
Outputs a non-zero index.
Definition
1 2 3 | struct NonzeroParam { uint8_t rsv[8] = {0}; }; |
Parameters
Member |
Type |
Default Value |
Description |
|---|---|---|---|
rsv[8] |
uint8_t |
{0} |
Reserved |
Input
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
x |
[dim_0, dim_1, ..., dim_n] |
int64 |
ND |
Input tensor. |
Output
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
output1 |
[inputDimNum, inputNumel] |
int64 |
ND |
Subscript of a non-zero element. inputDimNum is the number of dimensions (n+1) of the input tensor x. inputNumel is the product of all dimensions (dim_0 * dim_1 *... * dim_n) of the input tensor x. |
output2 |
[1] |
int64 |
ND |
Number of non-zero elements. |
API Calling Example
- One-dimensional scenario
Input
intensor = {[0, 1, 1, 0, 1]}Output
outtensor1 = {1, 2, 4, 0, 0} outtensor2 = [3] - Two-dimensional scenario
Input
intensor = {[[0, 1, 1, 0, 1], [0, 1, 1, 0, 1]]}Output
outtensor1 = {[[0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [1, 2, 4, 1, 2, 4, 0, 0, 0, 0]]} outtensor2 = [6]