check_input_type

Description

Verifies the argument types in an operator definition function.

Prototype

def check_input_type(*type_args, **type_kwargs)

Parameters

Parameter

Description

type_args

List of argument types to check. The argument types correspond to the parameters of the operator definition function.
  • The operator inputs and outputs are dictionaries.

    If the dictionaries contain the key value shape, shape must be a group or list of elements.

    If the dictionaries contain the key value dtype, dtype must be a string.

  • Set other parameters based on the actual format.

Assume that the operator definition function is as follows:

def add(input_x, input_y, output_z, kernel_name="add"):

If this wrapper function is used for verification, it is defined as follows:

@para_check.check_input_type(dict,dict,dict,str)

def add(input_x, input_y, output_z, kernel_name="add"):

type_kwargs

Reserved.

Returns

None

"RuntimeError" is thrown if the verification fails.

Restrictions

None

Example

from tbe.common.utils import para_check 

@para_check.check_input_type(dict, int, str)
def sample_op(x, i, kernel_name):
    ...
sample_op({"shape":(32, 64, 64, 3),"dtype":"float16"}, "index", "sample_op") 

Checks whether the sample_op argument is valid. If i is not an int, the message "RuntimeError" is thrown.