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

Scalar left multiplication operators missing from swig python bindings #241

Closed
scpeters opened this issue Sep 16, 2021 · 1 comment
Closed
Labels
enhancement New feature or request help wanted Extra attention is needed scripting Scripting interfaces to Ignition

Comments

@scpeters
Copy link
Member

We now have swig python bindings for several math classes, such as Vector[234] and Matrix[34]. The c++ classes, such as Matrix3, declare scalar left multiplication operators using friend inline Matrix3<T> operator*(T _s, const Matrix3<T> &_m) (see Matrix3.hh:331-338), but these are not yet included in the python swig bindings, as discussed in #221 (comment).

Desired behavior

We should add bindings for these operators, and confirm it by adding to our tests, such as the following:

diff --git a/src/python/Matrix3_TEST.py b/src/python/Matrix3_TEST.py
index 535e1500..cb50a6b2 100644
--- a/src/python/Matrix3_TEST.py
+++ b/src/python/Matrix3_TEST.py
@@ -123,6 +123,7 @@ class TestMatrix3(unittest.TestCase):
 
         # Scalar
         self.assertAlmostEqual(Matrix3d.ZERO, matrix * 0)
+        self.assertAlmostEqual(Matrix3d.ZERO, 0 * matrix)
 
         # Vector3.ZERO
         self.assertAlmostEqual(Vector3d.ZERO, matrix * Vector3d.ZERO)
@@ -135,6 +136,7 @@ class TestMatrix3(unittest.TestCase):
 
         # scalar 1.0
         self.assertAlmostEqual(matrix, matrix * 1.0)
+        self.assertAlmostEqual(matrix, 1.0 * matrix)
 
         # Vector3.Unit
         # right multiply

Alternatives considered

We could focus on using numpy types instead.

Implementation suggestion

I'm not sure how to implement a friend operator with swig.

Additional context

@scpeters scpeters added enhancement New feature or request scripting Scripting interfaces to Ignition labels Sep 16, 2021
@chapulina chapulina added the help wanted Extra attention is needed label Sep 27, 2021
@azeey
Copy link
Contributor

azeey commented Oct 5, 2023

Can this be closed since we're using pybind11 now?

@scpeters scpeters closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed scripting Scripting interfaces to Ignition
Projects
None yet
Development

No branches or pull requests

3 participants