FilesLast commitLast update
4 months ago
2 months ago
6 months ago
25 days ago
18 days ago
29 days ago
25 days ago
1 month ago
5 days ago
README

BatchToSpaceND

English | 简体中文

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: rearranges data from the batch dimension into spatial dimensions and crops the spatial dimensions.

  • Function description: This operator is the inverse operation of SpaceToBatchND. It first rearranges the batch dimension of the input tensor into spatial dimensions according to the specified block shape (block_shape), and then crops the spatial dimensions according to the cropping parameter (crops). Specifically, it scatters data in the batch dimension into the spatial dimensions, increasing the size of the spatial dimensions while reducing the size of the batch dimension.

  • Computation formula: Assume that the input tensor x is an N-dimensional tensor with shape [x0,x1,…,xN−1][x_0, x_1, \ldots, x_{N-1}], block_shape is an M-dimensional 1D tensor [b0,b1,…,bM−1][b_0, b_1, \ldots, b_{M-1}], and crops is an M×2M \times 2 2D tensor [[c00,c01],[c10,c11],…,[cM−1,0,cM−1,1]][[c_{00}, c_{01}], [c_{10}, c_{11}], \ldots, [c_{M-1,0}, c_{M-1,1}]], satisfying 1≤M<N≤81 \leq M < N \leq 8.

    The output tensor y has the shape [y0,y1,…,yN−1][y_0, y_1, \ldots, y_{N-1}], computed as follows:

    yi={x0∏j=0M−1bj,i=0xi×bi−1−ci−1,0−ci−1,1,1≤i≤Mxi,M+1≤i≤N−1y_i = \begin{cases} \frac{x_0}{\prod_{j=0}^{M-1} b_j}, & i = 0 \\ x_i \times b_{i-1} - c_{i-1,0} - c_{i-1,1}, & 1 \leq i \leq M \\ x_i, & M+1 \leq i \leq N-1 \end{cases}

    Here, x0x_0 must be integer-divisible by ∏j=0M−1bj\prod_{j=0}^{M-1} b_j.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input Input tensor, supporting multiple data types INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BF16, FLOAT16, FLOAT, DOUBLE, BOOL, COMPLEX32, COMPLEX64 ND
block_shape Input Shape of spatial blocks, a 1D tensor with shape [M], specifying the block size of each spatial dimension INT32, INT64 -
crops Input Cropping amounts, a 2D tensor with shape [M, 2], specifying the number of elements cropped from the top and bottom (or left and right) of each spatial dimension INT32, INT64 -
y Output Output tensor, with the same data type as the input x. The output shape is computed based on block_shape and crops Same as x ND
  • For Atlas training products, Atlas inference products, Atlas 200I/500 A2 inference products, Atlas A2 products, and Atlas A3 products: BOOL is not supported.

Constraint Description

  • The dimension N of the input tensor x must satisfy 2 ≤ N ≤ 8.
  • The dimension M of block_shape must satisfy 1 ≤ M < N.
  • The length of block_shape must be equal to the length of the first dimension of crops.
  • crops must have the shape [M, 2].
  • Dimension 0 (batch dimension) of the input tensor must be integer-divisible by the product of all elements in block_shape.
  • Each element in block_shape must be greater than 0.
  • Each element in crops must be a non-negative integer.
  • For each spatial dimension i (i = 1, 2, ..., M), the size of the dimension after cropping must be greater than or equal to 0, that is, x.shape[i] × block_shape[i-1] - crops[i-1][0] - crops[i-1][1] ≥ 0.

Invocation Description

Invocation Method Sample Code Description
Graph-mode invocation test_geir_batch_to_space_nd Invokes the BatchToSpaceND operator by building a graph through the operator IR.