FilesLast commitLast update
4 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
5 days ago
README

SparseReshape

English | 简体中文

Contribution Description

Contributor Contributed Operator Contribution Date Contribution Content

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products ×
Atlas inference products ×
Atlas training products ×

Function Description

  • Operator function: reshapes the indices of a sparse tensor (SparseTensor) from the input shape to the target shape. A sparse tensor consists of indices (coordinates of non-zero elements), values (values of non-zero elements), and shape (dense shape). SparseReshape reshapes only the indices and shape, and does not modify the values.

  • Computation formula:

flat_id=∑j=0input_rank−1indices[i,j]×input_strides[j]\text{flat\_id} = \sum_{j=0}^{\text{input\_rank}-1} \text{indices}[i, j] \times \text{input\_strides}[j]

y_indices[i,j]=⌊flat_id/output_strides[j]⌋,flat_id=flat_id mod output_strides[j]\text{y\_indices}[i, j] = \lfloor \text{flat\_id} / \text{output\_strides}[j] \rfloor, \quad \text{flat\_id} = \text{flat\_id} \bmod \text{output\_strides}[j]

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
indices Input Multi-dimensional coordinate matrix of non-zero elements. This parameter is a 2D tensor with the shape (nnz, input_rank). INT32, INT64 ND
shape Input Original dense shape. This parameter is a 1D tensor with the shape (input_rank,). INT32, INT64 ND
new_shape Input Target dense shape. This parameter is a 1D tensor with the shape (output_rank,). One value can be -1 and is inferred automatically. INT32, INT64 ND
y_indices Output Reshaped multi-dimensional coordinate matrix of non-zero elements. This parameter is a 2D tensor with the shape (nnz, output_rank). INT32, INT64 ND
y_shape Output Reshaped dense shape. This parameter is a 1D tensor with the shape (output_rank,). INT32, INT64 ND

Constraint Description

  • The input indices must be a 2D matrix, and shape and new_shape must be 1D vectors.
  • Each row of the input indices contains the multi-dimensional coordinates of a non-zero element. The value of each element must be greater than or equal to 0 and less than the size of the corresponding dimension in shape.
  • Both input_rank and output_rank do not exceed 8 dimensions (MAX_RANK=8).
  • At most one value in new_shape can be -1. This value is inferred automatically by dividing the product of the values of the shape parameter by the product of the other non--1 values of the new_shape parameter.
  • The product of the values of the input shape must be the same as the product of the values of the input new_shape.
  • The dtypes of all inputs and outputs must be the same (all int32 or all int64).

Invocation Description

Invocation Method Invocation Sample Description
Graph-mode invocation test_geir_sparse_reshape For operator compilation and verification, refer to Operator Invocation.