Cast#

Outputs the given input tensor to the output tensor. The input is transformed from one precision to another.

All conversions between supported data types are allowed.

Attributes#

toType The DataType of the output tensor.

Inputs#

input: tensor of type T1.

Outputs#

output: tensor of type T2.

Data Types#

T1: bool, uint8, int8, int32, int64, float16, bfloat16, float32

T2: bool, uint8, int8, int32, int64, float16, bfloat16, float32

Shape Information#

input and output are tensors with a shape of \([a_0,...,a_n]\)

Examples#

Cast
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_cast(in1, trt.int32)
network.mark_output(layer.get_output(0))

inputs[in1.name] = np.array(
    [
        [
            [
                [1.2, 2.3, 3.4],
                [4.5, 5.6, 6.7],
                [7.8, 8.9, 9.1],
            ]
        ]
    ]
)

outputs[layer.get_output(0).name] = layer.get_output(0).shape

expected[layer.get_output(0).name] = np.array(
    [
        [
            [
                [1.0, 2.0, 3.0],
                [4.0, 5.0, 6.0],
                [7.0, 8.0, 9.0],
            ]
        ]
    ]
)

C++ API#

For more information about the C++ ICastLayer operator, refer to the C++ ICastLayer documentation.

Python API#

For more information about the Python ICastLayer operator, refer to the Python ICastLayer documentation.