check_shape

Description

Verifies shape of a tensor.

shape must be a list or tuple of ints. The dimension, rank, and total size of shape are verified. If the verification fails, the message "RuntimeError" is thrown.

Prototype

def check_shape(shape, min_dim=0, max_dim=DIM_LIMIT, min_rank=0, max_rank=RANK_LIMIT, min_size=0, max_size=SHAPE_SIZE_LIMIT, param_name=PARAM_NAME)

Parameters

Parameter

Description

shape

Shape to be verified. It is a list or tuple.

min_dim

Minimum dim value. It is an int and defaults to 0.

max_dim

Maximum dim value. It is an int and defaults to DIM_LIMIT.

DIM_LIMIT = 2 ** 31

min_rank

Minimum rank value. It is an int and defaults to 0.

max_rank

Maximum rank value. It is an int and defaults to RANK_LIMIT.

RANK_LIMIT = 8

min_size

Minimum shape size. It is an int and defaults to 0.

max_size

Maximum shape size. It is an int and defaults to SHAPE_SIZE_LIMIT.

SHAPE_SIZE_LIMIT = 2 ** 31

param_name

Parameter name, used as an additional prompt during message printing. Defaults to NULL.

Returns

None. If the verification fails, a verification failure message is thrown.

Restrictions

None

Example

from tbe.common.utils import para_check
para_check.check_shape([2,3,4]) # Verify the shape using the default verification rule.
para_check.check_shape([2,3,4], min_dim=5) # Verify the shape using the default verification rule, in addition to fixing the minimum dim at 5. An exception is thrown on verification failure.