-
Notifications
You must be signed in to change notification settings - Fork 108
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
Compatibility with numpy arrays and other matrices #109
Comments
Hi, Let me know if that works :) |
Thank you for the swift reply. That certainly works, and this is how I use it for now, but I opened this issue as I feel like this line should be avoided, as the matrix functionality (like indexing) is then lost. It seems like it is perfectly doable to have numpy or sparse matrices interact with linear operators, by simply using their @ operator instead of .matvec. Is it a design choice to not support this? (In that case I will probably patch it for myself) |
Ok, I see, that makes sense. Let me take a look where the error actually arises as it may be easy to replace matvec with @ but not so easy to replace rmatvec. Basically this would require checking if the operator is really an Pylops operator or a numpy array and behave differently. Alternatively we could do the check once at initialization and recast numpy/scipy arrays to MatrixMult so the forward and adjoins of stacking operators would remain efficient with no further checks. This would be my preferred solution, would that make sense to use that we still use MatrixMult but we avoid the user having to do it themselves? |
Yes, that makes sense. Letting the functions VStack, HStack, Block, etc. do the conversions internally is a good solution. |
Solved here ed193ea |
Add the ability to combine linear operators with a numpy 2D arrays (or other matrices like the ones from scipy.sparse) using VStack, HStack, Block, etc. like this:
Currently this results in
AttributeError: 'numpy.ndarray' object has no attribute 'matvec'
while a numpy 2D array does support the @ operator (as substitute for .matvec()). The same holds for other types of matrices. The implementation of VStack, HStack, Block, etc. should use the @ operator if .matvec is not implemented.
The text was updated successfully, but these errors were encountered: