simplify_axis_shape

Description

Given the input shape and input axis list, fuses the adjacent reduced axes into one axis and adjacent unreduced axes into one axis in input shape.

Also fuses the adjacent axes of the input axis list into one axis.

A 2-tuple that contains the fused shape and axis list is returned.

Prototype

def simplify_axis_shape(shape, axis)

Parameters

Parameter

Description

shape

Input shape.

axis

List of axes to be reduced.

Returns

2-tuple, including the fused shape and axis list

Restrictions

None

Example

from tbe.common.utils import shape_util 
shape_util.simplify_axis_shape((32, 64, 64, 1,4, 5), [1,2]) 

Given input shape (32, 64, 64, 1, 4, 5), as the axis list is [1,2], the adjacent reduced axes of shape are axis 1 and axis 2 while the adjacent unreduced axes of shape are axes 3, 4, and 5, resulting in shape (32, 4096, 20).

The adjacent axes (1 and 2) in the input axis list are fused to [1].

As a result, the final 2-tuple return is (32, 4096, 20),[1].