-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use _matmul_ operator (@) for matrix multiplication, map composition, tensor contraction #30244
Comments
comment:1
I think in most cases we don't need it. In a matrix algebra, it's pretty clear that multiplication means matrix multiplication; not Hadamard product. The first place I'd see a possible application is for self-maps of a ring, where one may want to consider both composition and point-wise products. |
comment:2
Replying to @nbruin:
+1. Wondering now if we need a category of @-itive semigroups. |
comment:3
I think using |
comment:4
Replying to @jhpalmieri:
+1 for this. This would be a good place to start providing an implementation. |
comment:6
I think '@' for tensor products would be very confusing for other uses in python. While it was introduced non-prescriptively as another binary operator, the implementation name It would seem to me that the place where having operator notation for tensor products might be interesting is for Kronecker products of matrices. That's exactly the place where it directly clashes with numpy notation!! I also think it's very inefficient for multivariate Kronecker products, because the infix notation necessitates the construction of intermediate results. For modules, I would expect tensor products and homs to be equally prevalent, so keeping a symmetry in their notation seems like a desirable thing to have. So, I think "@" is a poor fit for tensor product. |
comment:7
+1 on giving the "map composition" priority for this operator. In the realm of tensors, matrix multiplication would generalize to tensor contraction, not tensor product. |
comment:8
Replying to @mkoeppe:
Any thoughts on this? Do we need a category |
comment:9
I'd say no, for the same reason why we don't have this for "|", "&", "<<", ">>", and other binary operators that python provides. I think we first need a convincing use-case before we start building infrastructure. Code is a burden, not an asset :-). |
comment:10
Note that these other binary operators do not actually participate in the coercion framework... But great point, of course, that we should start with something concrete first. |
comment:12
I think you may want to reconsider #22760 in the light of possible usage scenarios. The coercion framework is particularly designed to figure out common parents into which the operands can be coerced so that the operation can be applied. This does not apply to all cases; for instance, for actions there is no appropriate common parent. For actions, other procedures are followed (and generally, less powerful ones; which is appropriate). If New commits:
|
Commit: |
comment:13
This is a great point. On this branch, as you perhaps saw, I am already overriding the (double-underscore) |
comment:14
But a concern is that by overriding it, it is disabling coerce actions... |
comment:15
I don't think there is any harm in #22760 by adding the hook for it. However, I thought the coercion framework was designed to also handle actions. For example, you need coercion for That being said, I see your point about |
comment:16
Replying to @mkoeppe:
+1 |
comment:17
Replying to @tscrim:
Indeed, some coercion steps are possible for actions, but not nearly as much as for operations internal to structures. For instance, for addition between I'd hope there are better tools available for exploring what coercion to take than to query and see "what works". If that's actually what happens, then applying it to partial operators such as composition is definitely inappropriate. In general, I'm not so sure coercion will help for |
comment:18
I think I will try out an alternative implementation of composition as a coerce-action (keeping the inherited |
comment:20
Replying to @jhpalmieri:
As notation for tensor products, perhaps we can use a different operator ... how about the bitwise-and operator |
comment:22
Setting new milestone based on a cursory review of ticket status, priority, and last modification date. |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Author: Matthias Koeppe |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:32
Not sure if @ should also be used for matrix-vector multiplication. The current code on the branch does not do this; but scipy seems to think so (see for example https://docs.scipy.org/doc/scipy/reference/optimize.linprog-highs.html) |
#22760 added support for
__matmul__
in the coercion model.We should start using it.
First step: Review the semantics of this operator in major Python software for matrix and tensor computation (NumPy, Numba, TensorFlow, PyTorch, ...) so that we do not paint ourselves into a corner.
Follow-up tickets:
sage.geometry.hyperbolic_space
CC: @tscrim @egourgoulhon
Component: linear algebra
Author: Matthias Koeppe
Branch/Commit: u/mkoeppe/use__matmul__operator____ @
da5104c
Issue created by migration from https://trac.sagemath.org/ticket/30244
The text was updated successfully, but these errors were encountered: