Repository navigation
Fix Variable arithmetic with Eigen matrices and NumPy arrays - #1458
Merged
calcmogul merged 1 commit intoNov 8, 2026
Conversation
calcmogul
force-pushed
the
fix-variable-arithmetic-with-eigen-matrices-and-numpy-arrays
branch
4 times, most recently
from
November 8, 2026 19:48
c5e91d2 to
1413e66
Compare
The Eigen * Variable, Variable * Eigen, and Eigen / Variable operators were hidden friends of VariableMatrix, so argument-dependent lookup never found them since neither argument is a VariableMatrix. They're now namespace-scope templates. They only accept Eigen matrices of Scalar, so Eigen's own operators still handle Eigen matrices of Variable (e.g., in solve()). In Python, multiplying or dividing a 2D NumPy array by a Variable now returns a VariableMatrix. Previously, NumPy applied the operation elementwise and returned an object array of Variables. Variable now defines __array_ufunc__, so other operations between a Variable and a NumPy array raise TypeError instead, like they already do for VariableMatrix. NumPy scalars (e.g., np.float64) still work with Variable's arithmetic and comparison operators.
calcmogul
force-pushed
the
fix-variable-arithmetic-with-eigen-matrices-and-numpy-arrays
branch
from
November 8, 2026 19:58
1413e66 to
564c2ab
Compare
calcmogul
deleted the
fix-variable-arithmetic-with-eigen-matrices-and-numpy-arrays
branch
November 8, 2026 20:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Eigen * Variable, Variable * Eigen, and Eigen / Variable operators were hidden friends of VariableMatrix, so argument-dependent lookup never found them since neither argument is a VariableMatrix. They're now namespace-scope templates. They only accept Eigen matrices of Scalar, so Eigen's own operators still handle Eigen matrices of Variable (e.g., in solve()).
In Python, multiplying or dividing a 2D NumPy array by a Variable now returns a VariableMatrix. Previously, NumPy applied the operation elementwise and returned an object array of Variables. Variable now defines array_ufunc, so other operations between a Variable and a NumPy array raise TypeError instead, like they already do for VariableMatrix. NumPy scalars (e.g., np.float64) still work with Variable's arithmetic and comparison operators.