{"action":"created","issue":{"url":"https://api.github.com/repos/apache/incubator-mxnet/issues/16990","repository_url":"https://api.github.com/repos/apache/incubator-mxnet","labels_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/16990/labels{/name}","comments_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/16990/comments","events_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/16990/events","html_url":"https://github.com/apache/incubator-mxnet/pull/16990","id":533761053,"node_id":"MDExOlB1bGxSZXF1ZXN0MzQ5Nzc2OTUy","number":16990,"title":"[numpy] add op matmul","user":{"login":"JiangZhaoh","id":54654391,"node_id":"MDQ6VXNlcjU0NjU0Mzkx","avatar_url":"https://avatars1.githubusercontent.com/u/54654391?v=4","gravatar_id":"","url":"https://api.github.com/users/JiangZhaoh","html_url":"https://github.com/JiangZhaoh","followers_url":"https://api.github.com/users/JiangZhaoh/followers","following_url":"https://api.github.com/users/JiangZhaoh/following{/other_user}","gists_url":"https://api.github.com/users/JiangZhaoh/gists{/gist_id}","starred_url":"https://api.github.com/users/JiangZhaoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiangZhaoh/subscriptions","organizations_url":"https://api.github.com/users/JiangZhaoh/orgs","repos_url":"https://api.github.com/users/JiangZhaoh/repos","events_url":"https://api.github.com/users/JiangZhaoh/events{/privacy}","received_events_url":"https://api.github.com/users/JiangZhaoh/received_events","type":"User","site_admin":false},"labels":[{"id":1232775555,"node_id":"MDU6TGFiZWwxMjMyNzc1NTU1","url":"https://api.github.com/repos/apache/incubator-mxnet/labels/Numpy","name":"Numpy","color":"b2ffba","default":false,"description":""}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-12-06T05:51:00Z","updated_at":"2019-12-09T03:31:00Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/apache/incubator-mxnet/pulls/16990","html_url":"https://github.com/apache/incubator-mxnet/pull/16990","diff_url":"https://github.com/apache/incubator-mxnet/pull/16990.diff","patch_url":"https://github.com/apache/incubator-mxnet/pull/16990.patch"},"body":"## Description ##\r\nunary op: matmul\r\nBecause matmul has a special signature (i.e. (n?,k),(k,m?)->(n?,m?)) in official numpy, I comment out the following  code segment in python/mxnet/numpy/multiarray.py :\r\nif ufunc.signature is not None:\r\n                # we don't support generalised-ufuncs (gufuncs)\r\n                return NotImplemented\r\n\r\n## Checklist ##\r\n### Essentials ###\r\nPlease feel free to remove inapplicable items for your PR.\r\n- [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) created (except PRs with tiny changes)\r\n- [ ] Changes are complete (i.e. I finished coding on this PR)\r\n- [ ] All changes have test coverage:\r\n- Unit tests are added for small changes to verify correctness (e.g. adding a new operator)\r\n- Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)\r\n- Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)\r\n- [ ] Code is well-documented: \r\n- For user-facing API changes, API doc string has been updated. \r\n- For new C++ functions in header files, their functionalities and arguments are documented. \r\n- For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable\r\n- Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html\r\n- [ ] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change\r\n\r\n### Changes ###\r\n- [ ] Feature1, tests, (and when applicable, API doc)\r\n- [ ] Feature2, tests, (and when applicable, API doc)\r\n\r\n## Comments ##\r\n- If this change is a backward incompatible change, why must this change be made.\r\n- Interesting edge cases to note here\r\n"},"comment":{"url":"https://api.github.com/repos/apache/incubator-mxnet/issues/comments/563047925","html_url":"https://github.com/apache/incubator-mxnet/pull/16990#issuecomment-563047925","issue_url":"https://api.github.com/repos/apache/incubator-mxnet/issues/16990","id":563047925,"node_id":"MDEyOklzc3VlQ29tbWVudDU2MzA0NzkyNQ==","user":{"login":"sxjscience","id":5178350,"node_id":"MDQ6VXNlcjUxNzgzNTA=","avatar_url":"https://avatars1.githubusercontent.com/u/5178350?v=4","gravatar_id":"","url":"https://api.github.com/users/sxjscience","html_url":"https://github.com/sxjscience","followers_url":"https://api.github.com/users/sxjscience/followers","following_url":"https://api.github.com/users/sxjscience/following{/other_user}","gists_url":"https://api.github.com/users/sxjscience/gists{/gist_id}","starred_url":"https://api.github.com/users/sxjscience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sxjscience/subscriptions","organizations_url":"https://api.github.com/users/sxjscience/orgs","repos_url":"https://api.github.com/users/sxjscience/repos","events_url":"https://api.github.com/users/sxjscience/events{/privacy}","received_events_url":"https://api.github.com/users/sxjscience/received_events","type":"User","site_admin":false},"created_at":"2019-12-09T03:30:59Z","updated_at":"2019-12-09T03:30:59Z","author_association":"MEMBER","body":"I think you may call the BatchedGEMMStrided Kernel directly: https://devblogs.nvidia.com/cublas-strided-batched-matrix-multiply/\n\nGet Outlook for iOS<https://aka.ms/o0ukef>\n________________________________\nFrom: JiangZhaoh <notifications@github.com>\nSent: Sunday, December 8, 2019 6:04:32 PM\nTo: apache/incubator-mxnet <incubator-mxnet@noreply.github.com>\nCc: Xingjian SHI <xshiab@connect.ust.hk>; Comment <comment@noreply.github.com>\nSubject: Re: [apache/incubator-mxnet] [numpy] add op matmul (#16990)\n\n\n@JiangZhaoh commented on this pull request.\n\n________________________________\n\nIn src/operator/numpy/np_matmul_op-inl.h<https://github.com/apache/incubator-mxnet/pull/16990#discussion_r355237851>:\n\n> +            It is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.\n+   * \\param out - output: insert 'value' to 'arr' according to 'index'.\n+   * \\param a - input: the first argument.\n+   * \\param b - input: the second argument.\n+   * \\param ndim - ndim of a, b and output. Because of broadcast, regard their ndim as equal.\n+   */\n+  template<typename DType>\n+  MSHADOW_XINLINE static void Map(int i, DType* out,\n+                                  const DType* a, const DType* b,\n+                                  const mshadow::Shape<10> a_stride,\n+                                  const mshadow::Shape<10> b_stride,\n+                                  const mshadow::Shape<10> out_stride,\n+                                  const mshadow::Shape<10> a_shape,\n+                                  const mshadow::Shape<10> b_shape,\n+                                  const mshadow::Shape<10> out_shape,\n+                                  const size_t ndim){\n\n\nYou may refer to the implementation of batch_dot. There is no need to store the strides and shapes as Shape<10>. You can reshape the array to a 3D array and just dot the last two dimensions:\n\nhttps://github.com/apache/incubator-mxnet/blob/1aa1b5a9ab53bb57a3c653793fb824d01f2d5e81/src/operator/tensor/dot-inl.h#L1348-L1409\n\nThanks for your advice. But, may I ask how could I broadcast the shape if I don't store strides and shapes?\ne.g. Matrix A in shape (2, 1, 3, 4, 5) and matrix B in shape (3, 1, 5, 2), C=np.matmul(A, B) would broadcast A and B to shape (2, 3, 3, 4, 5) and (3, 3, 5, 2) respectively, and C's shape would be (2, 3, 3, 4, 2).\nIf I didn't store shape and stride, I think I should copy the content in each array to get the consistent shape firstly, and use your method then. Is this your mean?\n\n—\nYou are receiving this because you commented.\nReply to this email directly, view it on GitHub<https://github.com/apache/incubator-mxnet/pull/16990?email_source=notifications&email_token=ABHQH3VQJPJ2ICENM5STTDTQXWRTBA5CNFSM4JWMPQEKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCOLORVI#discussion_r355237851>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABHQH3R4ZQCQQAG34ABFOA3QXWRTBANCNFSM4JWMPQEA>.\n"}}
{"actor":{"display_login":"sxjscience"}}