Unary

为输入张量的每个元素计算一元运算。

属性

operation 一元运算可以是以下之一

  • 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 是高斯误差函数}\)

  • NOT \(output=~input\)

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

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

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

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

输入

input: T 类型的张量

输出

output: T 类型的张量。 ISINFISNAN 仅输出 bool 类型。

数据类型

运算

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

形状信息

输出与输入具有相同的形状。

DLA 支持

DLA 支持以下 operation 类型

  • ABS

  • SIN

  • COS

  • ATAN

示例

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

有关 C++ IUnaryLayer 算子的更多信息,请参阅 C++ IUnaryLayer 文档

Python API

有关 Python IUnaryLayer 算子的更多信息,请参阅 Python IUnaryLayer 文档