Unary#

Computes a unary operation for each element of the input tensor.

Attributes#

operation Unary operation can be one of:

  • EXP \(output=e^{input}\)

  • LOG \(output=log_e(input)\)

  • SQRT \(output=\sqrt{input}\)

  • RECIP \(output=\frac{1}{input}\)

  • ABS \(output=|input|\)

  • NEG \(output=-input\)

  • SIN \(output=sin(input)\)

  • COS \(output=cos(input)\)

  • TAN \(output=tan(input)\)

  • SINH \(output=sinh(input)\)

  • COSH \(output=cosh(input)\)

  • ASIN \(output=asin(input)\)

  • ACOS \(output=acos(input)\)

  • ATAN \(output=atan(input)\)

  • ASINH \(output=asinh(input)\)

  • ACOSH \(output=acosh(input)\)

  • ATANH \(output=atanh(input)\)

  • CEIL \(output=\lceil input \rceil\)

  • FLOOR \(output=\lfloor input \rfloor\)

  • ERF \(output=gef(input) \, \text{, gef is a Gaussian Error Function}\)

  • NOT \(output=~input\)

  • SIGN \(output=sign(input)\)

  • ROUND \(output=round(input)\)

  • ISINF \(output=isinf(input)\)

  • ISNAN \(output=isnan(input)\)

Inputs#

input: tensor of type T

Outputs#

output: tensor of type T. ISINF and ISNAN only outputs bool type.

Data Types#

Operation

T

ABS

int8, int32, int64, float16, float32, bfloat16

ACOS

int8, float16, float32

ACOSH

int8, float16, float32

ASIN

int8, float16, float32

ASINH

int8, float16, float32

ATAN

int8, float16, float32

ATANH

int8, float16, float32,

CEIL

int8, float16, float32, bfloat16

COS

int8, float16, float32, bfloat16

COSH

int8, float16, float32

ERF

int8, float16, float32, bfloat16

EXP

int8, float16, float32, bfloat16

FLOOR

int8, float16, float32, bfloat16

LOG

int8, float16, float32, bfloat16

NEG

int8, int32, int64, float16, float32, bfloat16

RECIP

int8, float16, float32, bfloat16

ROUND

int8, float16, float32, bfloat16

SIN

int8, float16, float32, bfloat16

SINH

int8, float16, float32

SQRT

int8, float16, float32, bfloat16

TAN

int8, float16, float32

NOT

bool

SIGN

int8, int32, int64, float16, float32, bfloat16

ISINF

float16, float32, bfloat16

ISNAN

float16, float32, bfloat16

Shape Information#

The output has the same shape as the input.

DLA Support#

DLA supports the following operation types:

  • ABS

  • SIN

  • COS

  • ATAN

Examples#

Unary
in1 = network.add_input("input1", dtype=trt.float32, shape=(2, 3))
layer = network.add_unary(in1, op=trt.UnaryOperation.ABS)
network.mark_output(layer.get_output(0))

inputs[in1.name] = np.array([[-3.0, -2.0, -1.0], [0.0, 1.0, 2.0]])

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

expected[layer.get_output(0).name] = np.array([[3.0, 2.0, 1.0], [0.0, 1.0, 2.0]])

C++ API#

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

Python API#

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