Div#
Domain:
ai.onnxSince version: 14
Performs element-wise binary division (with Numpy-style broadcasting support).
This operator supports multidirectional (i.e., Numpy-style) broadcasting; for more details please check the broadcasting behavior in ONNX.
For integer inputs, the result is computed using truncating division (rounding toward zero).
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_div
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(2, 3), dtype=float32
[[10., 20., 30.],
[40., 50., 60.]]
y: shape=(2, 3), dtype=float32
[[ 2., 4., 5.],
[ 8., 10., 12.]]
Outputs:
z: shape=(2, 3), dtype=float32
[[5., 5., 6.],
[5., 5., 5.]]
test_cc_div_bcast
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(2, 2), dtype=float32
[[1., 2.],
[3., 4.]]
y: shape=(), dtype=float32
2.
Outputs:
z: shape=(2, 2), dtype=float32
[[0.5, 1. ],
[1.5, 2. ]]
test_cc_div_bfloat16
Node:
Div(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
[2, 1.33594, 1.20312, 1.14062]
test_cc_div_double
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(2, 3), dtype=float64
[[10., 20., 30.],
[40., 50., 60.]]
y: shape=(2, 3), dtype=float64
[[ 2., 4., 5.],
[ 8., 10., 12.]]
Outputs:
z: shape=(2, 3), dtype=float64
[[5., 5., 6.],
[5., 5., 5.]]
test_cc_div_empty_shape_scalars
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(), dtype=float32
2.5
y: shape=(), dtype=float32
3.5
Outputs:
z: shape=(), dtype=float32
0.71428573
test_cc_div_empty_shape_zero_dim
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(0,), dtype=float32
[]
y: shape=(0,), dtype=float32
[]
Outputs:
z: shape=(0,), dtype=float32
[]
test_cc_div_empty_shape_zero_dim_2d
Node:
Div(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_div_float16
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(2, 3), dtype=float16
[[1., 2., 3.],
[4., 5., 6.]]
y: shape=(2, 3), dtype=float16
[[ 2., 4., 5.],
[10., 2., 3.]]
Outputs:
z: shape=(2, 3), dtype=float16
[[0.5, 0.5, 0.6],
[0.4, 2.5, 2. ]]
test_cc_div_nan_inf
Node:
Div(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, nan, nan, 0.]
test_cc_div_nan_inf_bcast_inf_scalar
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(4,), dtype=float32
[ 1., -1., 2., -2.]
y: shape=(), dtype=float32
inf
Outputs:
z: shape=(4,), dtype=float32
[ 0., -0., 0., -0.]
test_cc_div_nan_inf_bcast_nan_scalar
Node:
Div(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_div
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=float32
[[[-1.049021 , -0.1805252 , 0.37299186, -1.2512525 , -0.81569797],
[-0.51167107, 0.58341527, -0.28096995, 0.2715433 , 1.9851228 ],
[-0.78261596, -0.520758 , -0.79341817, -1.150229 , -0.08576501],
[-1.2088639 , -0.6402479 , -0.5225338 , -1.3520603 , 0.02162574]],
[[-0.4249209 , 1.0771086 , 1.4951609 , 0.90683544, -1.0156072 ],
[ 0.37091243, 0.12427244, -0.29227057, -0.12246624, 1.5876821 ],
[ 1.2864141 , -1.5520498 , -0.9380287 , -1.4733943 , -2.022197 ],
[ 0.86833507, -0.7941745 , -1.3814762 , 0.21208183, -1.630374 ]],
[[-0.03658122, -1.3079208 , 0.38689163, 0.39617118, -0.36848107],
[-0.37426245, 1.1562018 , 0.26353467, 1.0308264 , 0.49909028],
[-0.39126182, -0.20753261, -0.29138264, 0.8988023 , 0.23219402],
[-0.5025339 , -0.8213971 , -0.00865438, -0.06307457, -0.30020058]]]
y: shape=(3, 4, 5), dtype=float32
[[[1.5357083, 1.8058548, 1.452791 , 1.5595028, 1.1919273],
[1.5022644, 1.0285268, 1.2006115, 1.0872525, 1.5033492],
[1.91171 , 1.0404063, 1.539953 , 1.4004827, 1.4956635],
[1.9724481, 1.3472846, 1.9810288, 1.9347854, 1.7963282]],
[[1.2332932, 1.7613184, 1.6210763, 1.444618 , 1.8672727],
[1.497163 , 1.4243505, 1.1764996, 1.166526 , 1.197805 ],
[1.246526 , 1.7593678, 1.2666925, 1.2551589, 1.4532425],
[1.7616735, 1.5010916, 1.3315657, 1.9084283, 1.3779802]],
[[1.5801901, 1.3586056, 1.2933483, 1.2460475, 1.9181892],
[1.6862582, 1.4296997, 1.5208707, 1.4980319, 1.7667483],
[1.1650997, 1.3381588, 1.7704554, 1.1649324, 1.1307691],
[1.678083 , 1.2587595, 1.1164734, 1.0768781, 1.2795889]]]
Outputs:
z: shape=(3, 4, 5), dtype=float32
[[[-0.6830861 , -0.09996662, 0.25674158, -0.8023406 , -0.6843521 ],
[-0.34059986, 0.5672339 , -0.23402238, 0.24975182, 1.3204669 ],
[-0.40938005, -0.5005333 , -0.5152223 , -0.821309 , -0.05734245],
[-0.61287487, -0.47521356, -0.26376888, -0.6988167 , 0.01203886]],
[[-0.34454167, 0.61153543, 0.922326 , 0.6277337 , -0.5438987 ],
[ 0.24774352, 0.0872485 , -0.24842386, -0.10498372, 1.325493 ],
[ 1.0319995 , -0.88216335, -0.7405338 , -1.1738707 , -1.3915069 ],
[ 0.49290353, -0.52906466, -1.0374825 , 0.11112905, -1.1831621 ]],
[[-0.02314989, -0.9626935 , 0.29913956, 0.3179423 , -0.1920984 ],
[-0.22194849, 0.8087026 , 0.17327881, 0.6881205 , 0.28249088],
[-0.3358183 , -0.15508817, -0.16458061, 0.77154887, 0.20534167],
[-0.29946905, -0.6525449 , -0.00775153, -0.0585717 , -0.23460704]]]
test_div_bcast
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=float32
[[[ 0.31121665, 1.0258594 , -3.1395116 , -1.7966223 , 0.06096684],
[ 0.70985043, -0.19639817, -2.1368458 , -1.3620541 , -1.0705928 ],
[ 1.3230867 , 0.44482955, -1.9483898 , -0.28574938, -1.1584307 ],
[-0.8643142 , -0.02712508, -1.7259822 , -0.15632714, 0.911871 ]],
[[-0.79225 , -0.60901046, -1.0763875 , -0.21682826, -0.0795441 ],
[ 0.02737821, -1.2745905 , -0.7107443 , -0.67446405, -0.4757256 ],
[-1.7844657 , -0.91062653, 2.4688623 , -1.4964907 , -0.01263986],
[ 0.4145471 , -2.1071372 , 0.9477474 , -0.739947 , -0.24369246]],
[[ 0.82412815, 0.36990932, -0.1963979 , 0.31643096, 2.1840649 ],
[ 0.366072 , -1.5286286 , -0.5150546 , 1.3649099 , -0.9546026 ],
[ 0.5755407 , 1.6345203 , -1.6135515 , 1.4676467 , -0.73048383],
[-0.44720328, -0.7687108 , -0.48270035, -0.4476123 , 1.1505837 ]]]
y: shape=(5,), dtype=float32
[1.9128889, 1.3388335, 1.2953714, 1.350092 , 1.5780545]
Outputs:
z: shape=(3, 4, 5), dtype=float32
[[[ 0.16269457, 0.76623374, -2.423638 , -1.3307406 , 0.03863418],
[ 0.37108818, -0.1466935 , -1.6496009 , -1.0088602 , -0.6784257 ],
[ 0.6916694 , 0.3322516 , -1.5041167 , -0.21165177, -0.7340879 ],
[-0.45183712, -0.02026024, -1.3324226 , -0.11578999, 0.57784504]],
[[-0.41416413, -0.45488143, -0.83094895, -0.16060257, -0.05040643],
[ 0.01431249, -0.9520157 , -0.54867995, -0.49956894, -0.30146334],
[-0.93286425, -0.68016416, 1.9059107 , -1.1084361 , -0.00800977],
[ 0.21671258, -1.5738606 , 0.7316415 , -0.5480715 , -0.15442587]],
[[ 0.43082908, 0.27629226, -0.15161513, 0.23437732, 1.3840237 ],
[ 0.19137128, -1.1417615 , -0.3976115 , 1.0109755 , -0.6049237 ],
[ 0.30087516, 1.220854 , -1.2456285 , 1.0870715 , -0.4629015 ],
[-0.23378424, -0.5741646 , -0.3726347 , -0.33154204, 0.7291153 ]]]
test_div_example
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(2,), dtype=float32
[3., 4.]
y: shape=(2,), dtype=float32
[1., 2.]
Outputs:
z: shape=(2,), dtype=float32
[3., 2.]
test_div_int16
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=int16
[[[-1, 0, 0, 0, 0],
[ 0, 0, 1, 0, 0],
[-1, 0, 0, 0, 0],
[-1, -1, -1, 0, 0]],
[[ 1, 0, -1, 1, 0],
[ 1, -1, 1, -1, 0],
[ 0, 0, 0, -1, 1],
[-1, 0, 0, -1, 0]],
[[ 0, 0, 0, 0, 0],
[ 2, 0, 0, 0, 0],
[-1, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0]]]
y: shape=(3, 4, 5), dtype=int16
[[[ 1, 1, 1, 2, 1],
[-1, 1, 1, 2, 1],
[ 1, 1, 1, 1, -1],
[ 1, 1, -1, 1, 1]],
[[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, -1, 1],
[-1, 1, 1, 1, 1]],
[[ 1, 1, 1, -1, 1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, -1]]]
Outputs:
z: shape=(3, 4, 5), dtype=int16
[[[-1, 0, 0, 0, 0],
[ 0, 0, 1, 0, 0],
[-1, 0, 0, 0, 0],
[-1, -1, 1, 0, 0]],
[[ 1, 0, -1, 1, 0],
[ 1, -1, 1, -1, 0],
[ 0, 0, 0, 1, 1],
[ 1, 0, 0, -1, 0]],
[[ 0, 0, 0, 0, 0],
[ 2, 0, 0, 0, 0],
[-1, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0]]]
test_div_int32_trunc
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(4,), dtype=int32
[-3, 3, -3, 3]
y: shape=(4,), dtype=int32
[ 2, 2, -2, -2]
Outputs:
z: shape=(4,), dtype=int32
[-1, 1, 1, -1]
test_div_int64
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=int64
[[[ 0, 0, -1, -1, 0],
[-1, 0, 0, 0, 0],
[-1, 2, 0, -1, 0],
[ 0, 1, 0, -2, 0]],
[[-1, 0, 0, 0, 0],
[ 2, 0, 0, 1, 1],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 1]],
[[ 0, -1, 0, 0, -1],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
[ 0, 1, 0, 0, 0]]]
y: shape=(3, 4, 5), dtype=int64
[[[ 1, 1, 1, 1, -2],
[ 1, 1, 1, -1, 1],
[ 1, 1, -1, 1, 1],
[ 1, 1, 1, 1, -1]],
[[ 1, 1, 1, 1, -1],
[ 1, 1, 1, 2, 1],
[ 1, 1, -1, 1, 1],
[ 1, 1, 1, 1, 1]],
[[ 1, -1, 1, 1, 1],
[ 1, -1, -1, 1, -1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1]]]
Outputs:
z: shape=(3, 4, 5), dtype=int64
[[[ 0, 0, -1, -1, 0],
[-1, 0, 0, 0, 0],
[-1, 2, 0, -1, 0],
[ 0, 1, 0, -2, 0]],
[[-1, 0, 0, 0, 0],
[ 2, 0, 0, 0, 1],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 1]],
[[ 0, 1, 0, 0, -1],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
[ 0, 1, 0, 0, 0]]]
test_div_int8
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=int8
[[[-1, 0, -1, 0, 0],
[ 0, 1, 0, 0, 0],
[-1, -1, 0, 0, 0],
[-1, 0, 0, 1, 0]],
[[ 0, -1, 0, 0, 0],
[ 0, 0, 0, 0, 1],
[-2, -1, 0, -1, 0],
[ 0, 1, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 1, 0, 0, 0, 1],
[-2, 0, -1, -1, 0],
[ 0, 1, -1, 0, 0]]]
y: shape=(3, 4, 5), dtype=int8
[[[ 1, 1, 1, 1, 1],
[-1, -1, -1, 1, 1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1]],
[[ 1, -1, 1, 1, 1],
[-3, 1, 1, 1, 1],
[ 1, 1, -1, -1, 1],
[-1, 1, 1, -1, -1]],
[[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1],
[ 1, 1, 1, 1, 1],
[-1, 1, -1, -1, -1]]]
Outputs:
z: shape=(3, 4, 5), dtype=int8
[[[-1, 0, -1, 0, 0],
[ 0, -1, 0, 0, 0],
[-1, -1, 0, 0, 0],
[-1, 0, 0, 1, 0]],
[[ 0, 1, 0, 0, 0],
[ 0, 0, 0, 0, 1],
[-2, -1, 0, 1, 0],
[ 0, 1, 0, 0, 0]],
[[ 0, 0, 0, 0, 0],
[ 1, 0, 0, 0, 1],
[-2, 0, -1, -1, 0],
[ 0, 1, 1, 0, 0]]]
test_div_uint16
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=uint16
[[[12, 9, 7, 12, 4],
[18, 14, 6, 1, 11],
[22, 21, 23, 23, 1],
[18, 11, 21, 16, 1]],
[[11, 6, 17, 8, 5],
[ 2, 19, 9, 10, 2],
[23, 8, 8, 22, 16],
[12, 1, 1, 20, 11]],
[[14, 20, 7, 7, 19],
[17, 21, 13, 18, 23],
[ 1, 10, 8, 7, 4],
[ 9, 5, 4, 23, 5]]]
y: shape=(3, 4, 5), dtype=uint16
[[[11, 11, 14, 24, 21],
[14, 20, 14, 6, 14],
[ 9, 15, 22, 22, 18],
[14, 7, 7, 13, 11]],
[[16, 5, 6, 24, 4],
[15, 5, 10, 21, 15],
[ 5, 21, 14, 7, 6],
[18, 6, 7, 6, 20]],
[[13, 7, 15, 24, 1],
[20, 19, 10, 11, 5],
[ 9, 7, 12, 3, 8],
[17, 6, 20, 13, 10]]]
Outputs:
z: shape=(3, 4, 5), dtype=uint16
[[[ 1, 0, 0, 0, 0],
[ 1, 0, 0, 0, 0],
[ 2, 1, 1, 1, 0],
[ 1, 1, 3, 1, 0]],
[[ 0, 1, 2, 0, 1],
[ 0, 3, 0, 0, 0],
[ 4, 0, 0, 3, 2],
[ 0, 0, 0, 3, 0]],
[[ 1, 2, 0, 0, 19],
[ 0, 1, 1, 1, 4],
[ 0, 1, 0, 2, 0],
[ 0, 0, 0, 1, 0]]]
test_div_uint32
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=uint32
[[[15, 13, 5, 19, 16],
[15, 8, 14, 12, 4],
[ 5, 6, 19, 22, 18],
[ 9, 2, 2, 8, 16]],
[[15, 9, 18, 7, 3],
[10, 15, 3, 18, 9],
[19, 7, 1, 14, 3],
[ 1, 17, 20, 16, 1]],
[[14, 17, 23, 9, 23],
[ 7, 8, 19, 14, 4],
[ 4, 10, 11, 14, 4],
[10, 16, 17, 1, 3]]]
y: shape=(3, 4, 5), dtype=uint32
[[[16, 17, 4, 4, 15],
[15, 19, 22, 22, 8],
[12, 15, 20, 24, 20],
[15, 17, 1, 23, 24]],
[[ 4, 17, 18, 15, 16],
[ 7, 21, 19, 21, 15],
[21, 6, 10, 4, 15],
[15, 10, 3, 18, 11]],
[[14, 19, 7, 1, 6],
[11, 23, 7, 21, 18],
[18, 8, 23, 20, 1],
[ 7, 14, 13, 9, 9]]]
Outputs:
z: shape=(3, 4, 5), dtype=uint32
[[[0, 0, 1, 4, 1],
[1, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 2, 0, 0]],
[[3, 0, 1, 0, 0],
[1, 0, 0, 0, 0],
[0, 1, 0, 3, 0],
[0, 1, 6, 0, 0]],
[[1, 0, 3, 9, 3],
[0, 0, 2, 0, 0],
[0, 1, 0, 0, 4],
[1, 1, 1, 0, 0]]]
test_div_uint64
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=uint64
[[[15, 18, 3, 16, 19],
[ 0, 4, 3, 11, 5],
[10, 8, 12, 14, 12],
[ 1, 11, 21, 4, 6]],
[[ 0, 9, 21, 7, 14],
[ 0, 8, 6, 6, 10],
[ 3, 4, 1, 8, 12],
[19, 13, 21, 16, 13]],
[[20, 14, 10, 2, 12],
[15, 10, 18, 16, 16],
[23, 12, 20, 6, 1],
[17, 20, 23, 19, 2]]]
y: shape=(3, 4, 5), dtype=uint64
[[[19, 17, 23, 16, 11],
[ 4, 7, 21, 3, 3],
[15, 2, 23, 4, 19],
[20, 5, 12, 16, 3]],
[[12, 20, 3, 15, 16],
[24, 6, 15, 4, 3],
[22, 8, 4, 10, 12],
[18, 1, 4, 24, 20]],
[[10, 22, 24, 19, 3],
[23, 20, 7, 3, 13],
[11, 9, 8, 11, 14],
[12, 2, 1, 5, 5]]]
Outputs:
z: shape=(3, 4, 5), dtype=uint64
[[[ 0, 1, 0, 1, 1],
[ 0, 0, 0, 3, 1],
[ 0, 4, 0, 3, 0],
[ 0, 2, 1, 0, 2]],
[[ 0, 0, 7, 0, 0],
[ 0, 1, 0, 1, 3],
[ 0, 0, 0, 0, 1],
[ 1, 13, 5, 0, 0]],
[[ 2, 0, 0, 0, 4],
[ 0, 0, 2, 5, 1],
[ 2, 1, 2, 0, 0],
[ 1, 10, 23, 3, 0]]]
test_div_uint8
Node:
Div(x, y) -> (z)
Inputs:
x: shape=(3, 4, 5), dtype=uint8
[[[ 9, 4, 18, 4, 20],
[ 3, 14, 15, 20, 22],
[ 8, 5, 6, 12, 13],
[ 3, 16, 13, 4, 7]],
[[13, 14, 0, 10, 5],
[22, 17, 17, 3, 13],
[ 5, 9, 18, 4, 1],
[19, 6, 11, 13, 3]],
[[18, 19, 14, 10, 7],
[17, 3, 19, 19, 22],
[ 2, 1, 17, 23, 23],
[19, 2, 13, 0, 22]]]
y: shape=(3, 4, 5), dtype=uint8
[[[10, 21, 22, 10, 11],
[ 9, 16, 10, 12, 15],
[24, 7, 23, 4, 19],
[ 3, 12, 8, 8, 18]],
[[ 5, 17, 24, 20, 4],
[ 5, 4, 21, 10, 7],
[14, 11, 10, 5, 5],
[11, 6, 14, 2, 9]],
[[11, 19, 15, 12, 4],
[23, 12, 10, 5, 13],
[22, 19, 4, 4, 14],
[ 2, 20, 4, 8, 4]]]
Outputs:
z: shape=(3, 4, 5), dtype=uint8
[[[0, 0, 0, 0, 1],
[0, 0, 1, 1, 1],
[0, 0, 0, 3, 0],
[1, 1, 1, 0, 0]],
[[2, 0, 0, 0, 1],
[4, 4, 0, 0, 1],
[0, 0, 1, 0, 0],
[1, 1, 0, 6, 0]],
[[1, 1, 0, 0, 1],
[0, 0, 1, 3, 1],
[0, 0, 4, 5, 1],
[9, 0, 3, 0, 5]]]
Differences with previous version (13)#
SchemaDiff: Div (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)’]