Reciprocal#

  • Domain: ai.onnx

  • Since version: 13

Reciprocal takes one input data (Tensor ) and produces one output data (Tensor ) where the reciprocal is, y = 1/x, is applied to the tensor elementwise.

Inputs

  • X (T): Input tensor

Outputs

  • Y (T): Output tensor

Type Constraints

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

Examples#

test_cc_reciprocal

Node:
  Reciprocal(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=float32
    [[-2.  , -0.5 ,  0.25],
     [ 1.  ,  2.  ,  4.  ]]

Outputs:
  y: shape=(2, 3), dtype=float32
    [[-0.5 , -2.  ,  4.  ],
     [ 1.  ,  0.5 ,  0.25]]

test_cc_reciprocal_bfloat16

Node:
  Reciprocal(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=bfloat16
    [[0.5, 1, 2],
     [4, 0.25, 8]]

Outputs:
  y: shape=(2, 3), dtype=bfloat16
    [[2, 1, 0.5],
     [0.25, 4, 0.125]]

test_cc_reciprocal_float16

Node:
  Reciprocal(x) -> (y)
Inputs:
  x: shape=(2, 3), dtype=float16
    [[0.5 , 1.  , 2.  ],
     [4.  , 0.25, 8.  ]]

Outputs:
  y: shape=(2, 3), dtype=float16
    [[2.   , 1.   , 0.5  ],
     [0.25 , 4.   , 0.125]]

test_reciprocal

Node:
  Reciprocal(x) -> (y)
Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[1.0665616 , 1.2457818 , 1.4710028 , 0.9443592 , 0.9442647 ],
      [1.2628944 , 1.3773487 , 1.0230672 , 0.7855087 , 1.2939966 ],
      [0.90414214, 1.1054204 , 0.95493793, 1.030079  , 0.9359654 ],
      [0.667035  , 1.1453347 , 1.3153505 , 1.181705  , 1.3843246 ]],

     [[0.56596017, 0.58141464, 0.99587995, 0.62310886, 0.78691137],
      [0.54790115, 1.0155199 , 1.2137709 , 0.54374826, 1.4977479 ],
      [1.0978522 , 1.086595  , 0.89716923, 0.9389867 , 0.7532731 ],
      [1.0297574 , 1.0436708 , 1.2482353 , 1.3180335 , 1.1685734 ]],

     [[1.3618283 , 1.2081792 , 0.73636055, 1.1562355 , 1.3689089 ],
      [1.3393314 , 0.8244332 , 0.65917933, 1.393939  , 1.4126902 ],
      [0.8018563 , 0.63158494, 0.82568365, 1.4401739 , 0.89366215],
      [0.5877308 , 1.1070497 , 0.6554775 , 1.4583321 , 1.3756154 ]]]

Outputs:
  y: shape=(3, 4, 5), dtype=float32
    [[[0.9375924 , 0.8027088 , 0.6798084 , 1.0589191 , 1.059025  ],
      [0.79183185, 0.72603256, 0.9774529 , 1.2730604 , 0.77279955],
      [1.1060208 , 0.9046332 , 1.0471885 , 0.9707993 , 1.0684155 ],
      [1.4991717 , 0.8731072 , 0.7602536 , 0.8462349 , 0.72237396]],

     [[1.7669088 , 1.7199429 , 1.004137  , 1.604856  , 1.2707912 ],
      [1.8251467 , 0.9847173 , 0.8238787 , 1.8390863 , 0.6676691 ],
      [0.9108694 , 0.920306  , 1.1146169 , 1.0649778 , 1.3275397 ],
      [0.97110254, 0.9581566 , 0.80113095, 0.7587061 , 0.8557443 ]],

     [[0.73430693, 0.82769173, 1.3580304 , 0.86487573, 0.7305088 ],
      [0.7466412 , 1.2129545 , 1.5170379 , 0.7173915 , 0.7078693 ],
      [1.2471063 , 1.5833184 , 1.2111176 , 0.6943606 , 1.1189911 ],
      [1.7014592 , 0.90330184, 1.5256053 , 0.6857149 , 0.72694737]]]

test_reciprocal_example

Node:
  Reciprocal(x) -> (y)
Inputs:
  x: shape=(2,), dtype=float32
    [-4.,  2.]

Outputs:
  y: shape=(2,), dtype=float32
    [-0.25,  0.5 ]

Differences with previous version (6)#

SchemaDiff: Reciprocal (domain 'ai.onnx')

  • old version: 6

  • new version: 13

  • breaking: no

Type constraints:

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

Version History#