Sub#

  • Domain: ai.onnx

  • Since version: 14

Performs element-wise binary subtraction (with Numpy-style broadcasting support).

This operator supports multidirectional (i.e., Numpy-style) broadcasting; for more details please check the broadcasting behavior in ONNX.

Inputs

  • A (T): First operand.

  • B (T): Second operand.

Outputs

  • C (T): Result, has same element type as two inputs

Type Constraints

  • T: Constrain input and output types to all numeric tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Examples#

test_cc_sub

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(2, 3), dtype=float32
    [[1., 2., 3.],
     [4., 5., 6.]]
  y: shape=(2, 3), dtype=float32
    [[10., 20., 30.],
     [40., 50., 60.]]

Outputs:
  z: shape=(2, 3), dtype=float32
    [[ -9., -18., -27.],
     [-36., -45., -54.]]

test_cc_sub_bcast

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

Outputs:
  z: shape=(2, 2), dtype=float32
    [[0.5, 1.5],
     [2.5, 3.5]]

test_cc_sub_bfloat16

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(4,), dtype=bfloat16
    [1, 2, 3, 4]
  y: shape=(4,), dtype=bfloat16
    [0.5, 1.5, 2.5, 3.5]

Outputs:
  z: shape=(4,), dtype=bfloat16
    [0.5, 0.5, 0.5, 0.5]

test_cc_sub_double

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(2, 3), dtype=float64
    [[1., 2., 3.],
     [4., 5., 6.]]
  y: shape=(2, 3), dtype=float64
    [[10., 20., 30.],
     [40., 50., 60.]]

Outputs:
  z: shape=(2, 3), dtype=float64
    [[ -9., -18., -27.],
     [-36., -45., -54.]]

test_cc_sub_empty_shape_scalars

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(), dtype=float32
    2.5
  y: shape=(), dtype=float32
    3.5

Outputs:
  z: shape=(), dtype=float32
    -1.

test_cc_sub_empty_shape_zero_dim

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(0,), dtype=float32
    []
  y: shape=(0,), dtype=float32
    []

Outputs:
  z: shape=(0,), dtype=float32
    []

test_cc_sub_empty_shape_zero_dim_2d

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(0, 3), dtype=float32
    []
  y: shape=(0, 3), dtype=float32
    []

Outputs:
  z: shape=(0, 3), dtype=float32
    []

test_cc_sub_float16

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(2, 3), dtype=float16
    [[1., 2., 3.],
     [4., 5., 6.]]
  y: shape=(2, 3), dtype=float16
    [[10., 20., 30.],
     [40., 50., 60.]]

Outputs:
  z: shape=(2, 3), dtype=float16
    [[ -9., -18., -27.],
     [-36., -45., -54.]]

test_cc_sub_nan_inf

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(6,), dtype=float32
    [ nan,  inf, -inf,  inf,   1.,   0.]
  y: shape=(6,), dtype=float32
    [  1.,   2.,  -2., -inf,  nan,  inf]

Outputs:
  z: shape=(6,), dtype=float32
    [ nan,  inf, -inf,  inf,  nan, -inf]

test_cc_sub_nan_inf_bcast_inf_scalar

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(4,), dtype=float32
    [ 1., -1.,  2., -2.]
  y: shape=(), dtype=float32
    inf

Outputs:
  z: shape=(4,), dtype=float32
    [-inf, -inf, -inf, -inf]

test_cc_sub_nan_inf_bcast_nan_scalar

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(4,), dtype=float32
    [ 1., -1.,  2., -2.]
  y: shape=(), dtype=float32
    nan

Outputs:
  z: shape=(4,), dtype=float32
    [nan, nan, nan, nan]

test_sub

Node:
  Sub(x, y) -> (z)
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]]]
  y: shape=(3, 4, 5), dtype=float32
    [[[ 0.5802847 , -1.4953256 ,  0.42665341,  0.16854794, -0.7854995 ],
      [-0.3418555 , -0.1149836 ,  0.95487213,  1.3025413 ,  0.5168173 ],
      [-0.6690302 ,  0.806894  , -0.2736855 , -0.47230572,  1.3611885 ],
      [-1.6060044 , -1.2981083 ,  0.58045334, -0.13972436, -0.35279942]],

     [[ 0.63143295, -0.770354  ,  0.3310645 ,  0.32500747, -0.91997206],
      [-0.51626676, -0.31889752, -1.4302723 ,  0.6759698 , -0.7796309 ],
      [-0.5247361 , -0.12912966, -0.40980053, -0.36663505,  0.8133978 ],
      [-0.12241841,  1.2133354 ,  1.0200249 ,  1.4152457 ,  0.62612057]],

     [[ 2.0329802 , -0.90274274,  1.2706685 , -0.04628804, -1.3271873 ],
      [ 0.2806637 , -0.9965783 , -0.57684577,  1.7659245 , -0.6384131 ],
      [ 0.14784828,  0.08228748,  0.4838705 ,  0.6750839 , -1.2548709 ],
      [ 0.79701257, -0.5844758 ,  0.3095379 ,  1.2291852 ,  2.0687242 ]]]

Outputs:
  z: shape=(3, 4, 5), dtype=float32
    [[[ 0.8440634 ,  0.87642133, -1.0174202 ,  1.2644215 ,  1.3692951 ],
      [-1.0435812 ,  1.39417   , -0.62752116, -0.69868195, -0.27459037],
      [-0.22333235, -1.9372737 ,  0.1818792 ,  0.34639502, -2.6227062 ],
      [ 1.0496209 ,  0.55085236, -1.1716356 , -0.78826714, -0.38121194]],

     [[ 0.4740054 ,  0.07474852, -2.4845197 , -0.21104187,  0.09316236],
      [ 1.7299986 ,  0.09666283,  1.7597687 , -0.8864619 ,  2.1315033 ],
      [ 0.5373646 ,  0.81332505, -0.852507  ,  0.56715685, -1.938905  ],
      [-0.5171554 ,  0.32220125, -2.1667051 , -1.8420075 , -1.3703966 ]],

     [[-3.6319237 ,  3.2674098 , -2.3348236 ,  0.9497477 ,  1.0772556 ],
      [-2.0649116 ,  0.5241785 ,  0.67558247, -2.1305718 ,  1.303541  ],
      [-1.1642582 , -0.47753772, -0.02812195, -1.0190352 ,  0.7061462 ],
      [-0.7342093 ,  0.440365  , -1.4698771 , -0.7371815 , -2.238235  ]]]

test_sub_bcast

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[ 0.16602525,  0.11929144,  0.5103543 , -0.07833039, -0.2179262 ],
      [-0.35897505, -0.9920161 ,  1.1369699 ,  0.15822072, -0.66695   ],
      [ 0.1640578 ,  0.5148549 ,  0.692694  ,  1.2886952 , -2.3116457 ],
      [-0.3991889 , -1.763249  , -0.46325874,  1.1941477 ,  0.1423654 ]],

     [[-0.7589299 ,  1.5638951 , -1.3538998 , -0.78615636, -0.7008719 ],
      [-0.49739143,  1.2461402 , -0.824719  , -1.2749853 , -0.44074798],
      [ 1.8726983 , -1.2862704 ,  0.38438547,  1.782237  , -0.76287836],
      [-0.53627247, -2.1623473 ,  0.3568203 ,  0.67731917, -0.40523142]],

     [[ 2.2794771 , -1.7118682 ,  0.17869362, -0.12453986,  0.51542616],
      [-0.34672984, -0.04749961, -1.1327435 ,  0.7626039 , -0.18739803],
      [-0.31375307, -1.0803736 ,  0.05428931,  0.53482765, -0.33528003],
      [-1.5306095 , -0.61205   , -1.8999155 ,  1.1543474 , -0.30809247]]]
  y: shape=(5,), dtype=float32
    [ 1.2357849 , -0.33475664,  1.0486782 ,  0.70084286,  0.7489813 ]

Outputs:
  z: shape=(3, 4, 5), dtype=float32
    [[[-1.0697596 ,  0.4540481 , -0.5383239 , -0.77917325, -0.9669075 ],
      [-1.59476   , -0.65725946,  0.08829176, -0.54262215, -1.4159312 ],
      [-1.071727  ,  0.8496115 , -0.35598415,  0.58785236, -3.060627  ],
      [-1.6349738 , -1.4284924 , -1.5119369 ,  0.49330485, -0.6066159 ]],

     [[-1.9947147 ,  1.8986517 , -2.4025779 , -1.4869993 , -1.4498532 ],
      [-1.7331764 ,  1.5808969 , -1.8733971 , -1.9758282 , -1.1897292 ],
      [ 0.6369134 , -0.95151377, -0.6642927 ,  1.0813942 , -1.5118597 ],
      [-1.7720573 , -1.8275907 , -0.6918579 , -0.02352369, -1.1542127 ]],

     [[ 1.0436922 , -1.3771116 , -0.8699845 , -0.8253827 , -0.23355514],
      [-1.5825148 ,  0.28725702, -2.1814218 ,  0.06176102, -0.9363793 ],
      [-1.5495379 , -0.74561703, -0.9943888 , -0.16601521, -1.0842613 ],
      [-2.7663944 , -0.27729335, -2.9485936 ,  0.45350456, -1.0570738 ]]]

test_sub_example

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3,), dtype=float32
    [1., 2., 3.]
  y: shape=(3,), dtype=float32
    [3., 2., 1.]

Outputs:
  z: shape=(3,), dtype=float32
    [-2.,  0.,  2.]

test_sub_int16

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=int16
    [[[ 0,  1, -2,  1,  0],
      [ 0,  0,  1,  0,  0],
      [ 0,  0, -1,  0,  2],
      [ 0, -1,  1,  0,  0]],

     [[ 0,  0, -1,  1,  1],
      [ 0,  0,  2,  1,  0],
      [ 1,  0,  0,  0,  1],
      [ 0,  1,  0,  0,  0]],

     [[ 0,  0,  0,  0,  1],
      [ 0,  1,  0,  1,  0],
      [ 0,  0, -1, -1,  0],
      [ 0,  1,  0,  0, -1]]]
  y: shape=(3, 4, 5), dtype=int16
    [[[ 0,  1,  0, -1, -2],
      [-1,  0,  0,  0,  0],
      [ 1,  0,  0,  0,  1],
      [ 0,  1,  0,  0, -1]],

     [[-1,  1, -1,  0,  1],
      [ 0,  1,  0,  1,  0],
      [ 0, -1,  0,  0,  0],
      [ 0,  0,  0,  0,  0]],

     [[-1,  0,  0, -1,  0],
      [ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0,  0],
      [ 0, -1,  0,  0,  0]]]

Outputs:
  z: shape=(3, 4, 5), dtype=int16
    [[[ 0,  0, -2,  2,  2],
      [ 1,  0,  1,  0,  0],
      [-1,  0, -1,  0,  1],
      [ 0, -2,  1,  0,  1]],

     [[ 1, -1,  0,  1,  0],
      [ 0, -1,  2,  0,  0],
      [ 1,  1,  0,  0,  1],
      [ 0,  1,  0,  0,  0]],

     [[ 1,  0,  0,  1,  1],
      [ 0,  1,  0,  1,  0],
      [ 0,  0, -1, -1,  0],
      [ 0,  2,  0,  0, -1]]]

test_sub_int32

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=int32
    [[[ 0,  0,  0,  0, -1],
      [ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0,  1],
      [-1,  0,  1,  0,  0]],

     [[ 0, -1,  1,  0, -1],
      [ 0,  0,  0,  0,  0],
      [-2,  0,  0,  0,  0],
      [ 0,  0,  0,  1,  0]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0,  0],
      [ 0,  0,  0, -1,  0],
      [-1,  0,  0,  0, -1]]]
  y: shape=(3, 4, 5), dtype=int32
    [[[ 0,  1,  0,  0,  0],
      [ 0, -1,  0,  0,  0],
      [ 0, -1,  0, -1,  1],
      [ 0,  0,  0,  1,  0]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0, -1],
      [ 0,  0,  0,  1,  0],
      [ 1,  0,  0,  0,  0]],

     [[-1,  0,  0,  0,  1],
      [ 0,  0,  0,  1,  0],
      [-1,  1,  3,  1,  0],
      [ 0, -1, -1, -1,  2]]]

Outputs:
  z: shape=(3, 4, 5), dtype=int32
    [[[ 0, -1,  0,  0, -1],
      [ 0,  1,  0,  0,  0],
      [ 0,  1,  0,  1,  0],
      [-1,  0,  1, -1,  0]],

     [[ 0, -1,  1,  0, -1],
      [ 0,  0,  0,  0,  1],
      [-2,  0,  0, -1,  0],
      [-1,  0,  0,  1,  0]],

     [[ 1,  0,  0,  0, -1],
      [ 0,  0,  0, -1,  0],
      [ 1, -1, -3, -2,  0],
      [-1,  1,  1,  1, -3]]]

test_sub_int64

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=int64
    [[[ 0,  0,  0, -1, -1],
      [-1,  0,  1,  0,  0],
      [ 0,  2,  0,  1,  0],
      [ 0,  0,  0, -1,  0]],

     [[ 0,  0, -1,  0, -1],
      [-1,  0,  0,  1,  1],
      [ 0,  0,  0,  0,  0],
      [-1,  0,  0,  0,  0]],

     [[ 0,  0,  0,  0, -2],
      [ 0,  2,  0,  1,  0],
      [ 0,  0,  0, -1,  0],
      [ 1,  1,  1,  0,  1]]]
  y: shape=(3, 4, 5), dtype=int64
    [[[ 0,  1,  0,  0, -1],
      [-1,  0,  0,  0,  1],
      [ 0,  0,  1,  0, -1],
      [ 1, -2,  0,  0,  0]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0, -1],
      [ 1,  1,  0, -1,  0],
      [ 1,  0, -1,  1,  1]],

     [[ 0, -1,  0,  1,  1],
      [ 0,  1,  0, -2,  0],
      [ 0,  1,  0,  0,  1],
      [ 0, -1,  0,  0, -1]]]

Outputs:
  z: shape=(3, 4, 5), dtype=int64
    [[[ 0, -1,  0, -1,  0],
      [ 0,  0,  1,  0, -1],
      [ 0,  2, -1,  1,  1],
      [-1,  2,  0, -1,  0]],

     [[ 0,  0, -1,  0, -1],
      [-1,  0,  0,  1,  2],
      [-1, -1,  0,  1,  0],
      [-2,  0,  1, -1, -1]],

     [[ 0,  1,  0, -1, -3],
      [ 0,  1,  0,  3,  0],
      [ 0, -1,  0, -1, -1],
      [ 1,  2,  1,  0,  2]]]

test_sub_int8

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=int8
    [[[ 0,  2,  1,  0,  1],
      [ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0,  0],
      [ 0,  1,  2,  1,  0]],

     [[-2,  0, -1,  0,  0],
      [-1, -1,  2,  0,  0],
      [ 0,  0,  0,  0,  1],
      [-1, -1,  1,  0, -1]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0, -1,  0, -1],
      [ 1,  0,  0,  0,  0],
      [-1, -2,  0,  0,  0]]]
  y: shape=(3, 4, 5), dtype=int8
    [[[ 0,  0,  0,  0,  0],
      [-1,  0,  0,  0,  0],
      [ 0,  0, -1,  0, -1],
      [ 0,  1,  0, -1,  0]],

     [[ 1,  0, -1,  0,  0],
      [ 0,  0,  0,  0, -2],
      [ 0,  0,  0,  0,  0],
      [ 1,  0,  1,  0,  0]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0, -1,  0,  1],
      [ 0,  0, -1, -1,  0],
      [ 0,  0,  0,  0,  1]]]

Outputs:
  z: shape=(3, 4, 5), dtype=int8
    [[[ 0,  2,  1,  0,  1],
      [ 1,  0,  0,  0,  0],
      [ 0,  0,  1,  0,  1],
      [ 0,  0,  2,  2,  0]],

     [[-3,  0,  0,  0,  0],
      [-1, -1,  2,  0,  2],
      [ 0,  0,  0,  0,  1],
      [-2, -1,  0,  0, -1]],

     [[ 0,  0,  0,  0,  0],
      [ 0,  0,  0,  0, -2],
      [ 1,  0,  1,  1,  0],
      [-1, -2,  0,  0, -1]]]

test_sub_uint16

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=uint16
    [[[ 3,  1, 20,  3, 22],
      [18, 20,  5, 18,  8],
      [ 0,  2,  5,  6, 21],
      [ 2, 23,  3, 18,  5]],

     [[ 3, 16, 13, 17, 21],
      [11, 19, 23,  1,  8],
      [ 1, 20, 17,  3,  8],
      [11, 16, 23, 18, 15]],

     [[11, 15, 13, 20,  8],
      [19,  6,  0,  7, 19],
      [ 3, 21, 11,  4, 22],
      [ 2,  5, 19, 12, 14]]]
  y: shape=(3, 4, 5), dtype=uint16
    [[[10,  0, 10,  8,  6],
      [ 1,  6,  2,  8,  5],
      [ 0,  0,  2,  1,  1],
      [10, 10,  3, 10,  4]],

     [[ 5,  1,  6,  7, 11],
      [10,  9,  1, 10,  4],
      [ 3,  2,  7,  6, 10],
      [ 0,  6,  0,  2, 11]],

     [[ 6,  1,  2,  7,  7],
      [10,  6,  5,  4,  1],
      [ 9,  8,  3,  2,  9],
      [10,  3,  4,  3,  3]]]

Outputs:
  z: shape=(3, 4, 5), dtype=uint16
    [[[65529,     1,    10, 65531,    16],
      [   17,    14,     3,    10,     3],
      [    0,     2,     3,     5,    20],
      [65528,    13,     0,     8,     1]],

     [[65534,    15,     7,    10,    10],
      [    1,    10,    22, 65527,     4],
      [65534,    18,    10, 65533, 65534],
      [   11,    10,    23,    16,     4]],

     [[    5,    14,    11,    13,     1],
      [    9,     0, 65531,     3,    18],
      [65530,    13,     8,     2,    13],
      [65528,     2,    15,     9,    11]]]

test_sub_uint32

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=uint32
    [[[12,  2,  5,  1,  6],
      [11,  1, 16, 21, 10],
      [19,  5, 23, 21,  4],
      [10, 15, 23, 14,  7]],

     [[ 3, 19,  7,  2,  7],
      [11,  9, 12,  7,  3],
      [10,  8, 20, 20,  3],
      [ 1, 10,  8,  4, 13]],

     [[11,  1, 15,  3, 18],
      [11,  1,  9, 23,  3],
      [21, 10, 22,  2, 16],
      [13, 15,  8,  6, 23]]]
  y: shape=(3, 4, 5), dtype=uint32
    [[[ 0,  5,  7,  4,  7],
      [ 2,  7,  1,  0,  1],
      [ 0,  1,  2,  5,  9],
      [ 3, 11,  7,  2,  0]],

     [[ 6,  5,  7,  7,  5],
      [11,  1,  9,  9, 10],
      [ 2,  6,  2,  4,  4],
      [11,  2,  3,  2,  6]],

     [[ 2,  3,  6,  2,  3],
      [ 6,  3, 10,  4, 11],
      [11,  7,  6,  0, 10],
      [ 7,  6,  5,  6,  5]]]

Outputs:
  z: shape=(3, 4, 5), dtype=uint32
    [[[        12, 4294967293, 4294967294, 4294967293, 4294967295],
      [         9, 4294967290,         15,         21,          9],
      [        19,          4,         21,         16, 4294967291],
      [         7,          4,         16,         12,          7]],

     [[4294967293,         14,          0, 4294967291,          2],
      [         0,          8,          3, 4294967294, 4294967289],
      [         8,          2,         18,         16, 4294967295],
      [4294967286,          8,          5,          2,          7]],

     [[         9, 4294967294,          9,          1,         15],
      [         5, 4294967294, 4294967295,         19, 4294967288],
      [        10,          3,         16,          2,          6],
      [         6,          9,          3,          0,         18]]]

test_sub_uint64

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=uint64
    [[[ 7, 23, 23,  1, 17],
      [23, 14, 17,  6, 20],
      [19, 17, 13, 19,  1],
      [ 8,  8, 17, 10,  3]],

     [[22, 23, 19, 20, 22],
      [ 1,  0, 10, 22, 12],
      [ 1, 17, 12, 23, 13],
      [22,  2, 17,  3,  4]],

     [[19, 14,  4,  5, 14],
      [11, 10,  7, 14,  7],
      [14, 17,  1,  6, 20],
      [14, 20, 14,  9,  5]]]
  y: shape=(3, 4, 5), dtype=uint64
    [[[ 2,  6,  7,  2,  6],
      [ 4,  8,  8,  1,  0],
      [11,  9,  0,  2,  3],
      [10,  2,  3,  7,  8]],

     [[ 9,  6,  2,  7, 10],
      [ 9, 11,  1,  3,  1],
      [ 2,  9, 11,  9, 11],
      [ 7,  0, 10,  4,  2]],

     [[ 3,  3, 11, 10,  0],
      [ 0,  8, 10,  1,  1],
      [ 0,  4,  5,  3,  0],
      [ 8, 10,  4,  6,  5]]]

Outputs:
  z: shape=(3, 4, 5), dtype=uint64
    [[[                   5,                   17,                   16,
       18446744073709551615,                   11],
      [                  19,                    6,                    9,
                          5,                   20],
      [                   8,                    8,                   13,
                         17, 18446744073709551614],
      [18446744073709551614,                    6,                   14,
                          3, 18446744073709551611]],

     [[                  13,                   17,                   17,
                         13,                   12],
      [18446744073709551608, 18446744073709551605,                    9,
                         19,                   11],
      [18446744073709551615,                    8,                    1,
                         14,                    2],
      [                  15,                    2,                    7,
       18446744073709551615,                    2]],

     [[                  16,                   11, 18446744073709551609,
       18446744073709551611,                   14],
      [                  11,                    2, 18446744073709551613,
                         13,                    6],
      [                  14,                   13, 18446744073709551612,
                          3,                   20],
      [                   6,                   10,                   10,
                          3,                    0]]]

test_sub_uint8

Node:
  Sub(x, y) -> (z)
Inputs:
  x: shape=(3, 4, 5), dtype=uint8
    [[[ 5, 16, 11, 23, 10],
      [ 8, 11, 15,  3, 20],
      [10, 17, 20, 16, 15],
      [ 6, 20,  1,  5,  3]],

     [[21, 18,  4,  4, 15],
      [17,  7,  6,  9,  4],
      [19, 13,  1, 13,  4],
      [ 9, 10, 19,  6,  1]],

     [[22, 19, 20, 16, 18],
      [11,  7, 12, 13,  5],
      [ 0, 10, 21, 16,  5],
      [14,  6, 12,  5,  0]]]
  y: shape=(3, 4, 5), dtype=uint8
    [[[11,  7,  4, 10, 10],
      [ 4, 11,  9,  3,  1],
      [ 8,  7,  8,  6,  0],
      [ 5,  9, 11,  7,  1]],

     [[ 4,  1,  3,  1,  8],
      [ 5,  0,  5,  0,  9],
      [ 1,  2,  9,  7,  6],
      [ 4,  8, 10,  1,  2]],

     [[ 9,  5,  2,  1,  1],
      [ 5,  4, 10,  3,  4],
      [ 4,  8,  0,  4,  1],
      [ 3,  8,  8,  7,  1]]]

Outputs:
  z: shape=(3, 4, 5), dtype=uint8
    [[[250,   9,   7,  13,   0],
      [  4,   0,   6,   0,  19],
      [  2,  10,  12,  10,  15],
      [  1,  11, 246, 254,   2]],

     [[ 17,  17,   1,   3,   7],
      [ 12,   7,   1,   9, 251],
      [ 18,  11, 248,   6, 254],
      [  5,   2,   9,   5, 255]],

     [[ 13,  14,  18,  15,  17],
      [  6,   3,   2,  10,   1],
      [252,   2,  21,  12,   4],
      [ 11, 254,   4, 254, 255]]]

Differences with previous version (13)#

SchemaDiff: Sub (domain 'ai.onnx')

  • old version: 13

  • new version: 14

  • breaking: no

Type constraints:

  • changed ‘T’: added types: [‘tensor(int16)’, ‘tensor(int8)’, ‘tensor(uint16)’, ‘tensor(uint8)’]

Version History#