clip

Description

Rounds data towards the range of [min_value, max_value] by comparing data's elements with min_value and max_value element-wise. If an element value is within the range, the element is retained. If an element value is not within the range, the element is round to the nearest extreme value.

Restrictions

Atlas 200/300/500 Inference Product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas Training Series Product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

In case of data type inconsistency, the data type of max_value and min_value will be cast into the same data type as data during computation.

Prototype

clip(data, max_value, min_value)

Parameters

  • data: a tvm.tensor for the input tensor.
  • max_value: a scalar for the maximum value of the target range.
  • min_value: a scalar for the minimum value of the target range.

Returns

res_tensor: a tvm.tensor for the result tensor

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Example

from tbe import tvm
from tbe import dsl
shape = (1024,1024)
input_dtype = "float16"
data = tvm.placeholder(shape, name="data", dtype=input_dtype)
max_value = tvm.const(2, dtype =input_dtype)
min_value = tvm.const(3, dtype =input_dtype)
res = dsl.clip(data, max_value, min_value)