Onnx: Does MatMul operator implement broadcasting for inputs having more than 2 dimensions?

Created on 14 Jul 2020  路  3Comments  路  Source: onnx/onnx

Question

Does ONNX MatMul operator implement broadcasting for inputs having more than 2 dimensions?
The doc page for MatMul says that it behaves like: numpy.matmul.

numpy.matmul seems to do broadcasting if either argument is N-D with N > 2, ("each input treated as a stack of matrices residing in the last two indexes and broadcast accordingly").

Further information

  • Relevant Area:
    backend, operators.

  • Is this issue related to a specific model?
    No

Notes

If MatMul indeed does some kind of broadcasting, this should be explicitly stated somewhere, e.g. the doc page and here: https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md

operator question

All 3 comments

Hi @meghendra,
According to here, I think onnx does have broadcasting for MatMul, but it is slightly different from general Broadcasting so it is not mentioned in Broadcasting.md.

Still, I agree with you that it's better to mention supporting broadcasting in document for users to use MatMul.
Thank you for pointing out!

@askhade It seems that you have worked with this before. Could you help me to confirm whether MatMul supports broadcasting? If so, I can help to improve the document for MatMul. Thanks!

@meghendra : As stated in the operator documentation for Matmul (Matrix product that behaves like numpy.matmul: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.matmul.html)
It does behave like numpy matmul and also follows numpy broadcasting.

Are you seeing a different behavior than numpy?

@askhade No, I don't see a different behavior as such, just that the doc page for MatMul or the Broadcasting.md do not talk about MatMul broadcasting (at least not directly).

Was this page helpful?
0 / 5 - 0 ratings