Elu

Elu - 22

Version

  • name: Elu (GitHub)

  • domain: main

  • since_version: 22

  • function: True

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 22.

Summary

Elu takes one input data (Tensor<T>) and produces one output data (Tensor<T>) where the function f(x) = alpha * (exp(x) - 1.) for x &lt; 0, f(x) = x for x &gt;= 0., is applied to the tensor elementwise.

Function Body

The function definition for this operator.

&lt;
  domain: &#34;&#34;,
  opset_import: [&#34;&#34; : 18]
&gt;
Elu &lt;alpha&gt;(X) =&gt; (Y)
{
   Alpha = Constant &lt;value_float: float = @alpha&gt; ()
   AlphaCast = CastLike (Alpha, X)
   Zero = Constant &lt;value: tensor = float {0}&gt; ()
   ZeroCast = CastLike (Zero, X)
   One = Constant &lt;value: tensor = float {1}&gt; ()
   OneCast = CastLike (One, X)
   XLessThanZero = Less (X, ZeroCast)
   ExpX = Exp (X)
   ExpXSubOne = Sub (ExpX, OneCast)
   AlphaMulExpXSubOne = Mul (AlphaCast, ExpXSubOne)
   Y = Where (XLessThanZero, AlphaMulExpXSubOne, X)
}

Attributes

  • alpha - FLOAT (default is 1.0):

    Coefficient of ELU.

Inputs

  • X (heterogeneous) - T:

    Input tensor

Outputs

  • Y (heterogeneous) - T:

    Output tensor

Type Constraints

  • T in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ):

    Constrain input and output types to float tensors.

Examples

default

import numpy as np
import onnx

node = onnx.helper.make_node("Elu", inputs=["x"], outputs=["y"], alpha=2.0)

x = np.array([-1, 0, 1]).astype(np.float32)
# expected output [-1.2642411, 0., 1.]
y = np.clip(x, 0, np.inf) + np.expm1(np.clip(x, -np.inf, 0)) * 2.0
expect(node, inputs=[x], outputs=[y], name="test_elu_example")

x = np.random.randn(3, 4, 5).astype(np.float32)
y = np.clip(x, 0, np.inf) + np.expm1(np.clip(x, -np.inf, 0)) * 2.0
expect(node, inputs=[x], outputs=[y], name="test_elu")

_elu_default

import numpy as np
import onnx

default_alpha = 1.0
node = onnx.helper.make_node(
    "Elu",
    inputs=["x"],
    outputs=["y"],
)
x = np.random.randn(3, 4, 5).astype(np.float32)
y = np.clip(x, 0, np.inf) + np.expm1(np.clip(x, -np.inf, 0)) * default_alpha
expect(node, inputs=[x], outputs=[y], name="test_elu_default")

Elu - 6

Version

  • name: Elu (GitHub)

  • domain: main

  • since_version: 6

  • function: True

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 6.

Summary

Elu takes one input data (Tensor<T>) and produces one output data (Tensor<T>) where the function f(x) = alpha * (exp(x) - 1.) for x &lt; 0, f(x) = x for x &gt;= 0., is applied to the tensor elementwise.

Function Body

The function definition for this operator.

&lt;
  domain: &#34;&#34;,
  opset_import: [&#34;&#34; : 18]
&gt;
Elu &lt;alpha&gt;(X) =&gt; (Y)
{
   Alpha = Constant &lt;value_float: float = @alpha&gt; ()
   AlphaCast = CastLike (Alpha, X)
   Zero = Constant &lt;value: tensor = float {0}&gt; ()
   ZeroCast = CastLike (Zero, X)
   One = Constant &lt;value: tensor = float {1}&gt; ()
   OneCast = CastLike (One, X)
   XLessThanZero = Less (X, ZeroCast)
   ExpX = Exp (X)
   ExpXSubOne = Sub (ExpX, OneCast)
   AlphaMulExpXSubOne = Mul (AlphaCast, ExpXSubOne)
   Y = Where (XLessThanZero, AlphaMulExpXSubOne, X)
}

Attributes

  • alpha - FLOAT (default is 1.0):

    Coefficient of ELU.

Inputs

  • X (heterogeneous) - T:

    Input tensor

Outputs

  • Y (heterogeneous) - T:

    Output tensor

Type Constraints

  • T in ( tensor(double), tensor(float), tensor(float16) ):

    Constrain input and output types to float tensors.

Elu - 1

Version

  • name: Elu (GitHub)

  • domain: main

  • since_version: 1

  • function: False

  • support_level: SupportType.COMMON

  • shape inference: False

This version of the operator has been available since version 1.

Summary

Elu takes one input data (Tensor<T>) and produces one output data (Tensor<T>) where the function f(x) = alpha * (exp(x) - 1.) for x &lt; 0, f(x) = x for x &gt;= 0., is applied to the tensor elementwise.

Attributes

  • alpha - FLOAT (default is 1.0):

    Coefficient of ELU default to 1.0.

  • consumed_inputs - INTS :

    legacy optimization attribute.

Inputs

  • X (heterogeneous) - T:

    Input tensor

Outputs

  • Y (heterogeneous) - T:

    Output tensor

Type Constraints

  • T in ( tensor(double), tensor(float), tensor(float16) ):

    Constrain input and output types to float tensors.