-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: Implement matmul function #4464
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
Comments
The @@ in the current draft PEP is the same as np.linalg.matrix_power, The @ operator in the current PEP draft is what we want np.dot to be On Sun, Mar 9, 2014 at 3:53 AM, abalkin [email protected] wrote:
Nathaniel J. Smith |
Related: gh-4397 |
I see. That's really a good thing, because the logical operations ~, &, |, and so on act on booleans, not bitwise (e.g., in Python |
@asmeurer - so what should matmul do for two boolean matrices? |
Just the regular algorithm. It looks like NumPy considers booleans to be the elements of the finite field Z_2, so true + true = true, true*true = true, and so on. |
It's more like Z_2 semi-ring. In the Z_2 field 1 + 1 = 0. |
Oh you're right. I didn't notice that inconsistency. I that case, I have no idea why they did that, and really no idea what matmul should do, other than just give whatever you would get with the normal matrix multiplication formula. |
Since final PEP 465 does not include matpow, I am changing the title of this issue to focus on matmul. |
Here is the preliminary list of classes that should implement
Any additions? |
The ideal implementation I think would be:
This would involve messing with two potentially messy pieces of code
|
Python 3.5.0a3 has added the |
I had a toy implementation and it worked fine with 3.5 as far as I tested. I'm working on an 'official' version now for Numpy 1.10. |
@nicktimko - if you would like to contribute pure python code to this effort, try implementing |
What's the procedure for writing tests that involve new syntax? Just don't use it and manually call the method, i.e. |
Check Python version, and use eval("a @ b")?
|
Both! (Because we'd like the tests to actually exercise the code now, even
|
We would want to test both older an newer versions of Python. For the older On Tue, Apr 7, 2015 at 10:09 AM, Nick Timkovich [email protected]
|
Not sure if it is practical, but I guess you could also avoid writing "@" completly by doing something like this (not quite sure I got all the magic python does right):
Edit: had forgotten to return False ;). |
Can you capture |
Oh, yeah.... |
Operators seem to return
|
Maybe I'm not following correctly, but I thought the problem was something like this: >>> from operator import matmul
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name matmul
>>> (1).__add__([])
NotImplemented
>>> (1).__matmul__([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__matmul__' |
Ah, I see. That is even in Python 3.5. |
Would it work to directly dig out the method for some tests (
|
Sure, that would work.
|
This is just a thought, but what about using a module that is not imported unless you know the Python version can deal with |
On Mon, Apr 6, 2015 at 4:16 PM, Nick Timkovich [email protected]
Chuck |
@charris maybe put it up as a gist for convenience? |
@nicktimko I've implemented |
This was fixed by #5878 |
The @-operator PEP (gh-4351) describes two operations that would be a valuable addition to numpy independently of the main purpose of the PEP.
Most of the functionality is already available in various places (
np.dot
,np.linalg.matrix_power
, etc.) but no single function conforms to the PEP.The text was updated successfully, but these errors were encountered: