Skip to content
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

Raise AffineError from __rmul__ #48

Closed
sgillies opened this issue Sep 4, 2019 · 2 comments
Closed

Raise AffineError from __rmul__ #48

sgillies opened this issue Sep 4, 2019 · 2 comments
Assignees

Comments

@sgillies
Copy link
Member

sgillies commented Sep 4, 2019

See #32.

@sgillies sgillies added this to the 3.0 milestone Sep 4, 2019
@sgillies sgillies self-assigned this Sep 4, 2019
@sgillies
Copy link
Member Author

sgillies commented Jan 23, 2025

After some thought, I think we do want __rmatmul__() and __rmul__() to allow for vector (transpose) @ matrix multiplication that yields another transposed vector. So, only for 2-tuples on the left side.

@mwtoews
Copy link
Contributor

mwtoews commented Jan 24, 2025

I think these right-hand multipliers introduce trouble, since matrix math is not commutative. The __rmul__ op is intended for vector-matrix multiplication, whereas affine transforms need matrix-matrix or matrix-vector multiplication which is already supported by __mul__.

Demo, cross-referencing with NumPy. Note that vectors for matmul are in the form (x, y, 1):

>>> import numpy as np
>>> from affine import Affine
>>> A = Affine.translation(1, 1) * Affine.scale(2, 3)
>>> print(A)
| 2.00, 0.00, 1.00|
| 0.00, 3.00, 1.00|
| 0.00, 0.00, 1.00|
>>> A * (1, 1)
(3.0, 4.0)
>>> (1, 1) * A
<stdin>:1: DeprecationWarning: Right multiplication will be prohibited in version 3.0
(3.0, 4.0)
>>> np.array(A) @ (1, 1, 1)
array([3., 4., 1.])
>>> (1, 1, 1) @ np.array(A)
array([2., 3., 3.])

The last row is the correct answer from a linear algebra perspective, but this doesn't make sense for affine transformations. So I think the idea to raising an error was a good one to follow through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants