{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/11132","repository_url":"https://api.github.com/repos/numpy/numpy","labels_url":"https://api.github.com/repos/numpy/numpy/issues/11132/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/11132/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/11132/events","html_url":"https://github.com/numpy/numpy/pull/11132","id":325099541,"number":11132,"title":"WIP: ENH: Expand gufunc signature to allow flexible dimension specs","user":{"login":"mattip","id":823911,"avatar_url":"https://avatars0.githubusercontent.com/u/823911?v=4","gravatar_id":"","url":"https://api.github.com/users/mattip","html_url":"https://github.com/mattip","followers_url":"https://api.github.com/users/mattip/followers","following_url":"https://api.github.com/users/mattip/following{/other_user}","gists_url":"https://api.github.com/users/mattip/gists{/gist_id}","starred_url":"https://api.github.com/users/mattip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattip/subscriptions","organizations_url":"https://api.github.com/users/mattip/orgs","repos_url":"https://api.github.com/users/mattip/repos","events_url":"https://api.github.com/users/mattip/events{/privacy}","received_events_url":"https://api.github.com/users/mattip/received_events","type":"User","site_admin":false},"labels":[{"id":6359239,"url":"https://api.github.com/repos/numpy/numpy/labels/01%20-%20Enhancement","name":"01 - Enhancement","color":"fef2c0","default":false},{"id":6359893,"url":"https://api.github.com/repos/numpy/numpy/labels/15%20-%20Discussion","name":"15 - Discussion","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-05-22T00:13:54Z","updated_at":"2018-05-24T13:59:08Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/11132","html_url":"https://github.com/numpy/numpy/pull/11132","diff_url":"https://github.com/numpy/numpy/pull/11132.diff","patch_url":"https://github.com/numpy/numpy/pull/11132.patch"},"body":"The discussion of issue #9028 yielded two different possible directions for allowing `ndarray` subclasses to override `__matmul__` via `__array_ufunc__`. This is option 1 - extend the core signature of a generalized `ufunc` to allow a single ufunc `matmul` which will implement vector-vector, vector-matrix, matrix-vector, and matrix-matrix multiplication. In this PR, the syntax of a signature is expanded to allow `(n?, k),(k, m?)->(n?, m?)` syntax, where the `?` means \"this dimension is optional\" [0],[1]. I also incorporated PR #5015 where signatures can have a fixed dimension `(3),(3)->(3)`.\r\n\r\n**What changed?**\r\n- There is a change in the PyUFuncObject structure. I added two fields, and repurposed the unused field `reserved1` to become a `version` field for downstream consumers of the C-API.\r\n- The parsing code during `ufunc` instantiation now parses the expanded signature\r\n- When calling a `ufunc` with flexible or fixed dimensions, extra checks are done to ensure consistency\r\n\r\n**What is yet to be done?**\r\n- The code needs cleanup and refactoring\r\n- Tests were added but there is a good chance I missed corner cases\r\n- I wrote the code together with the PR making `matmul` a true `ufunc`, I probably have chages there that belong here and visa-versa\r\n\r\n**What is next?**\r\n- Use this mechanism to make `matmul` a true `ufunc`\r\n- Get feedback on the relative merits of this approach vs. the one taken in PR #11061, where I produced a demi-`ufunc` with a wrapper function that can be used to convert any function into a `ufunc`.\r\n\r\n[0]: Note that, following the [PEP for matrix multiplication](https://www.python.org/dev/peps/pep-0465/#semantics), there is no broadcasting over the optional dimensions, in the example given if the first operand has 2 or more dimensions, the second-to-the-last will be 'n', no `newaxis` will be inserted instead.\r\n\r\n[1] The syntax '(n,k),(k,m)->(n,m);(n,k),(k)->(n);(k),(k,m)->(m);(k),(k)->()` was also considered and rejected as allowing too much flexibility in stacking alternate core signatures."},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/391725046","html_url":"https://github.com/numpy/numpy/pull/11132#issuecomment-391725046","issue_url":"https://api.github.com/repos/numpy/numpy/issues/11132","id":391725046,"user":{"login":"mhvk","id":2789820,"avatar_url":"https://avatars0.githubusercontent.com/u/2789820?v=4","gravatar_id":"","url":"https://api.github.com/users/mhvk","html_url":"https://github.com/mhvk","followers_url":"https://api.github.com/users/mhvk/followers","following_url":"https://api.github.com/users/mhvk/following{/other_user}","gists_url":"https://api.github.com/users/mhvk/gists{/gist_id}","starred_url":"https://api.github.com/users/mhvk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhvk/subscriptions","organizations_url":"https://api.github.com/users/mhvk/orgs","repos_url":"https://api.github.com/users/mhvk/repos","events_url":"https://api.github.com/users/mhvk/events{/privacy}","received_events_url":"https://api.github.com/users/mhvk/received_events","type":"User","site_admin":false},"created_at":"2018-05-24T13:59:08Z","updated_at":"2018-05-24T13:59:08Z","author_association":"CONTRIBUTOR","body":"p.s. If the `p?` description is controversial, I'd be in favour of still doing the fixed dimensions."}}
{"actor":{"display_login":"mhvk"}}