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)\)

Inputs

input: tensor of type T

Outputs

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

Data Types

Operation

T

ABS

int8, int32, float16, float32

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

ABS

int8, float16, float32

COS

int8, float16, float32

COSH

int8, float16, float32

ERF

int8, float16, float32

EXP

int8, float16, float32

FLOOR

int8, float16, float32

LOG

int8, float16, float32

NEG

int8, int32, float16, float32

RECIP

int8, float16, float32

ROUND

int8, float16, float32

SIN

int8, float16, float32

SINH

int8, float16, float32

SQRT

int8, float16, float32

ATAN

int8, float16, float32

NOT

bool

SIGN

int8, int32, float16, float32

ISINF

float16, float32

Shape Information

The output has the same shape as the input.

DLA Restrictions

When using DLA, only operation of type ABS is supported.

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.