Mul#

  • Domain: ai.onnx

  • Since version: 14

Performs element-wise binary multiplication (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_mul

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
    [[ 10.,  40.,  90.],
     [160., 250., 360.]]

test_cc_mul_bcast

Inputs:
  x: shape=(2, 2), dtype=float32
    [[1., 2.],
     [3., 4.]]
  y: shape=(), dtype=float32
    2.

Outputs:
  z: shape=(2, 2), dtype=float32
    [[2., 4.],
     [6., 8.]]

test_mul

Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[-2.7012961e+00, -5.5849600e-01,  5.7748574e-01,  6.4741242e-01,
       -7.0523366e-02],
      [-1.1587335e+00, -1.4418545e-01,  8.6498004e-01,  3.7774590e-01,
        3.4641349e-01],
      [ 4.6990660e-04, -1.5549998e+00, -2.0975480e+00,  1.6738971e-01,
        2.1831582e+00],
      [-5.0491732e-01, -3.2653490e-01,  1.5034325e-01, -2.0524660e-01,
        7.2178906e-01]],

     [[-6.2757492e-01, -1.3547317e+00,  5.2883095e-01, -1.1516293e+00,
       -1.2801023e+00],
      [-1.9832895e+00, -1.5061821e-01,  3.7848338e-01, -2.3908144e-01,
        3.6100143e-01],
      [-6.9199687e-01,  4.4155270e-01, -4.1688403e-01, -1.1487823e+00,
       -2.6693258e-01],
      [-1.5721604e-02,  5.1507252e-01, -1.3958987e+00,  6.5033323e-01,
        4.0670735e-01]],

     [[ 4.4503558e-02, -1.2224180e+00,  1.2136942e-01,  7.0311397e-01,
        2.2393616e-01],
      [-1.7902220e+00, -1.6657048e-01,  5.4776672e-02,  1.2022861e+00,
       -1.7855827e+00],
      [ 1.4360319e+00, -9.6935105e-01,  5.9004700e-01, -1.9883904e+00,
       -7.9465955e-01],
      [-1.1217067e+00,  2.5306502e-01, -1.4954242e+00,  1.5923914e+00,
       -2.2547159e-02]]]
  y: shape=(3, 4, 5), dtype=float32
    [[[ 0.5481833 , -0.00939301, -0.45271957, -1.0654595 , -0.32869837],
      [-1.047124  ,  0.67519397, -1.3138133 , -1.0276915 ,  0.20252198],
      [ 0.526426  , -1.6724436 ,  1.8785843 , -0.6158553 ,  1.401629  ],
      [-0.93001837, -0.4439309 , -0.874139  ,  0.50153106, -0.07792282]],

     [[-0.26472604,  1.5117631 ,  0.37530467, -0.536582  ,  0.82635224],
      [ 1.2800639 , -0.14349434, -1.1475542 , -0.45632476,  1.2186408 ],
      [ 0.33088845,  0.29447028,  0.11602481,  1.0672623 ,  0.60493374],
      [ 1.3199029 ,  2.2344162 , -0.30853578,  0.30523637, -1.4056478 ]],

     [[ 0.5731787 , -1.1772175 ,  0.11350691,  2.237379  ,  2.60457   ],
      [ 1.463004  ,  0.20312467,  0.05267026, -0.5475567 ,  0.5086455 ],
      [-0.24070813,  0.7578392 ,  0.16877133,  0.38007334, -2.1396735 ],
      [-0.96594673, -0.32528752,  1.8720994 ,  0.75556403,  0.34925982]]]

Outputs:
  z: shape=(3, 4, 5), dtype=float32
    [[[-1.48080552e+00,  5.24596032e-03, -2.61439085e-01, -6.89791679e-01,
        2.31809150e-02],
      [ 1.21333766e+00, -9.73531455e-02, -1.13642228e+00, -3.88206244e-01,
        7.01563433e-02],
      [ 2.47371063e-04,  2.60064960e+00, -3.94042063e+00, -1.03087835e-01,
        3.05997777e+00],
      [ 4.69582379e-01,  1.44958928e-01, -1.31420910e-01, -1.02937542e-01,
       -5.62438406e-02]],

     [[ 1.66135430e-01, -2.04803348e+00,  1.98472723e-01,  6.17943585e-01,
       -1.05781531e+00],
      [-2.53873730e+00,  2.16128603e-02, -4.34330195e-01,  1.09098777e-01,
        4.39931065e-01],
      [-2.28973776e-01,  1.30024150e-01, -4.83688936e-02, -1.22605193e+00,
       -1.61476523e-01],
      [-2.07509901e-02,  1.15088642e+00,  4.30684686e-01,  1.98505357e-01,
       -5.71687281e-01]],

     [[ 2.55084913e-02,  1.43905175e+00,  1.37762688e-02,  1.57313251e+00,
        5.83257377e-01],
      [-2.61910200e+00, -3.38345766e-02,  2.88510183e-03, -6.58319831e-01,
       -9.08228517e-01],
      [-3.45664561e-01, -7.34612226e-01,  9.95830148e-02, -7.55734205e-01,
        1.70031202e+00],
      [ 1.08350897e+00, -8.23188946e-02, -2.79958272e+00,  1.20315361e+00,
       -7.87481666e-03]]]

test_mul_bcast

Inputs:
  x: shape=(3, 4, 5), dtype=float32
    [[[ 0.6912245 ,  0.83742934, -0.78804463,  0.6222988 , -0.937902  ],
      [-0.7905085 , -1.8190296 , -0.00926822, -0.08620772, -1.7776535 ],
      [-1.2516913 , -2.1189528 , -0.58901966, -0.08016641, -0.27220273],
      [ 1.530932  , -1.1512946 ,  0.29099432,  0.77937835, -1.1295451 ]],

     [[ 1.4143744 , -0.45160192,  0.1012274 ,  0.30958763,  0.6801167 ],
      [-0.6964468 , -0.02173506,  0.13951953, -1.0011435 ,  0.39252087],
      [-0.74063575,  0.2843027 ,  1.1269056 , -0.16112943,  0.59980184],
      [ 0.01580627, -0.9458842 , -1.501708  , -0.1421285 ,  0.78979415]],

     [[-0.13511205,  0.7731889 , -0.6315761 ,  0.25489986,  0.9365216 ],
      [ 0.6382908 ,  0.41903594,  0.47215635, -0.6030296 ,  1.8355596 ],
      [-0.9491966 , -2.2865195 ,  1.0954932 ,  0.8890692 ,  0.17526741],
      [-0.24671945, -0.6809021 ,  0.22167785,  0.14919838,  0.5840164 ]]]
  y: shape=(5,), dtype=float32
    [-2.4143047 , -0.6895737 , -0.16998304,  1.3226604 , -0.18856247]

Outputs:
  z: shape=(3, 4, 5), dtype=float32
    [[[-1.66882658e+00, -5.77469230e-01,  1.33954227e-01,  8.23089957e-01,
        1.76853105e-01],
      [ 1.90852845e+00,  1.25435495e+00,  1.57544052e-03, -1.14023536e-01,
        3.35198730e-01],
      [ 3.02196431e+00,  1.46117413e+00,  1.00123353e-01, -1.06032938e-01,
        5.13272174e-02],
      [-3.69613624e+00,  7.93902457e-01, -4.94640991e-02,  1.03085291e+00,
        2.12989807e-01]],

     [[-3.41473079e+00,  3.11412811e-01, -1.72069427e-02,  4.09479320e-01,
       -1.28244489e-01],
      [ 1.68143475e+00,  1.49879251e-02, -2.37159543e-02, -1.32417285e+00,
       -7.40147084e-02],
      [ 1.78812039e+00, -1.96047679e-01, -1.91554844e-01, -2.13119522e-01,
       -1.13100111e-01],
      [-3.81611548e-02,  6.52256906e-01,  2.55264908e-01, -1.87987745e-01,
       -1.48925528e-01]],

     [[ 3.26201648e-01, -5.33170700e-01,  1.07357234e-01,  3.37145954e-01,
       -1.76592827e-01],
      [-1.54102850e+00, -2.88956165e-01, -8.02585706e-02, -7.97603428e-01,
       -3.46117646e-01],
      [ 2.29164982e+00,  1.57672369e+00, -1.86215267e-01,  1.17593670e+00,
       -3.30488570e-02],
      [ 5.95655918e-01,  4.69532192e-01, -3.76814753e-02,  1.97338805e-01,
       -1.10123567e-01]]]

test_mul_example

Inputs:
  x: shape=(3,), dtype=float32
    [1., 2., 3.]
  y: shape=(3,), dtype=float32
    [4., 5., 6.]

Outputs:
  z: shape=(3,), dtype=float32
    [ 4., 10., 18.]

Differences with previous version (13)#

SchemaDiff: Mul (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#