Tanh#

  • Domain: ai.onnx

  • Since version: 13

Calculates the hyperbolic tangent of the given input tensor element-wise.

Inputs

  • input (T): Input tensor

Outputs

  • output (T): The hyperbolic tangent values of the input tensor computed element-wise

Type Constraints

  • T: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

Examples#

test_cc_tanh

Node:
  Tanh(input) -> (output)
Inputs:
  input: shape=(2, 3), dtype=float32
    [[-4., -1.,  0.],
     [ 1.,  2.,  4.]]

Outputs:
  output: shape=(2, 3), dtype=float32
    [[-0.9993293, -0.7615942,  0.       ],
     [ 0.7615942,  0.9640276,  0.9993293]]

test_cc_tanh_bfloat16

Node:
  Tanh(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=bfloat16
    [[-2, -1, 0],
     [0.5, 1, 2]]

Outputs:
  y: shape=(2, 3), dtype=bfloat16
    [[-0.964844, -0.761719, 0],
     [0.462891, 0.761719, 0.964844]]

test_cc_tanh_double

Node:
  Tanh(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=float64
    [[-2. , -1. ,  0. ],
     [ 0.5,  1. ,  2. ]]

Outputs:
  y: shape=(2, 3), dtype=float64
    [[-0.96402758, -0.76159416,  0.        ],
     [ 0.46211716,  0.76159416,  0.96402758]]

test_cc_tanh_float16

Node:
  Tanh(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=float16
    [[-2. , -1. ,  0. ],
     [ 0.5,  1. ,  2. ]]

Outputs:
  y: shape=(2, 3), dtype=float16
    [[-0.964 , -0.7617,  0.    ],
     [ 0.4622,  0.7617,  0.964 ]]

test_tanh

Node:
  Tanh(x) -> (y)
Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[ 1.4243481 , -0.61890423, -0.5907667 ,  1.4329695 ,  0.5837956 ],
      [-1.3854368 ,  1.2791865 ,  0.32735094,  0.6038593 ,  0.24222691],
      [-0.89236253, -1.1303798 , -0.09180629, -0.12591071, -1.2615176 ],
      [-0.55638343, -0.747256  , -0.59118223, -0.9279915 , -0.73401135]],

     [[ 1.1054384 , -0.69560546, -2.1534553 ,  0.11396561, -0.8268097 ],
      [ 1.2137318 , -0.22223468,  0.32949635, -0.21049212,  1.3518724 ],
      [ 0.01262847,  0.6841954 , -1.2623075 ,  0.20052178, -1.1255072 ],
      [-0.6395738 ,  1.5355366 , -1.1466801 , -0.42676184, -0.74427605]],

     [[-1.5989435 ,  2.3646672 , -1.0641551 ,  0.90345967, -0.24993172],
      [-1.784248  , -0.47239977,  0.09873669, -0.36464727,  0.6651279 ],
      [-1.01641   , -0.39525023,  0.45574856, -0.3439513 , -0.5487247 ],
      [ 0.06280329, -0.14411083, -1.1603392 ,  0.49200374, -0.16951095]]]

Outputs:
  y: shape=(3, 4, 5), dtype=float32
    [[[ 0.8905025 , -0.5503647 , -0.5304468 ,  0.89227355,  0.52541864],
      [-0.88216287,  0.85626805,  0.31613848,  0.53979003,  0.23759806],
      [-0.7125586 , -0.81114924, -0.09154923, -0.12524953, -0.851482  ],
      [-0.5052892 , -0.63350904, -0.5307454 , -0.7296561 , -0.6255134 ]],

     [[ 0.802444  , -0.601571  , -0.9734081 ,  0.11347475, -0.6787592 ],
      [ 0.8377954 , -0.21864694,  0.31806815, -0.2074375 ,  0.87449455],
      [ 0.0126278 ,  0.5942401 , -0.851699  ,  0.19787674, -0.809476  ],
      [-0.5646093 ,  0.9113673 , -0.8166513 , -0.40261155, -0.63172174]],

     [[-0.9215094 ,  0.98248994, -0.78724897,  0.7179783 , -0.24485448],
      [-0.9451502 , -0.44013628,  0.09841708, -0.3493009 ,  0.58176583],
      [-0.76840025, -0.3758776 ,  0.42661285, -0.3310004 , -0.4995638 ],
      [ 0.06272084, -0.14312144, -0.8211504 ,  0.45580533, -0.16790582]]]

test_tanh_example

Node:
  Tanh(x) -> (y)
Inputs:
  x: shape=(3,), dtype=float32
    [-1.,  0.,  1.]

Outputs:
  y: shape=(3,), dtype=float32
    [-0.7615942,  0.       ,  0.7615942]

Differences with previous version (6)#

SchemaDiff: Tanh (domain 'ai.onnx')

  • old version: 6

  • new version: 13

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(bfloat16)’]

Version History#