Assertion

Asserts when an input tensor contains false values. If the builder can prove that any of the input tensor values are false at build time, a build-time error is reported. Otherwise, the input tensor values are evaluated during runtime, and if any element is false, a runtime error is reported.

Attributes

message The message to print when the assertion fails.

Inputs

condition: tensor of type T

Data Types

T: bool

Shape Information

condition is a tensor with rank \(0 \leq n \leq 1\).

Examples

Assertion Not Firing
in1 = network.add_input("input1", dtype=trt.float32, shape=(3, 4, 4))
shape = network.add_shape(in1)
identity = network.add_identity(in1)
cond = network.add_elementwise(shape.get_output(0), shape.get_output(0), op=trt.ElementWiseOperation.EQUAL)
assertion = network.add_assertion(cond.get_output(0), message="Shouldn't fail")
network.mark_output(identity.get_output(0))

inputs[in1.name] = np.zeros(shape=(2, 4))
outputs[identity.get_output(0).name] = identity.get_output(0).shape
Assertion Fired At Build Time
# This test should fail during build stage
in1 = network.add_input("input1", dtype=trt.float32, shape=(3, 4, 4))
shape1 = network.add_shape(in1)
in2 = network.add_input("input2", dtype=trt.float32, shape=(3, 3, 4))
shape2 = network.add_shape(in2)
identity = network.add_identity(in1)
cond = network.add_elementwise(shape1.get_output(0), shape2.get_output(0), op=trt.ElementWiseOperation.EQUAL)
assertion = network.add_assertion(cond.get_output(0), message="Should fail")
network.mark_output(identity.get_output(0))

inputs[in1.name] = np.zeros(shape=(2, 4))
outputs[identity.get_output(0).name] = identity.get_output(0).shape

C++ API

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

Python API

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