produce_shapes

Description

Returns the broadcast target shape based on input shape1 and shape2.

If the shape1 and shape2 have unequal dimension pairs, and neither of them is 1, the broadcast rules are not met. If shape1 and shape2 have uncompatible ranks, leading dimensions sized 1 will be added to the shorter shape before the broadcast operation.

Prototype

def produce_shapes(shape1, shape2)

Parameters

Parameter

Description

shape1

Shape 1.

shape2

Shape 2.

Returns

A tuple of shapes including shape1, shape2, and the broadcast target shape

Restrictions

None

Example

from tbe.common.utils import shape_util 
shape1 = (1,32,32, 3)
shape2 = (32, 32, 32, 1)
shape_util.produce_shapes(shape1, shape2) 

Result shape tuples:

shape1= (1, 32, 32, 3)

shape2= (32, 32, 32, 1)

shape3= (32, 32, 32,3)