From 09995d48e4d9f16069b74d311cf9981ff247e202 Mon Sep 17 00:00:00 2001 From: bradley-solliday-skydio Date: Fri, 4 Nov 2022 05:24:01 -0700 Subject: [PATCH] Allow nested lists to be passed into genned code This is done by adding `sym.util.check_matrix_size_and_numpify` and calling it on the matrix inputs (when `use_numba=False` and `reshape_vectors=True`). This function converts list arguments to ndarrays and checks that the shape is what is expected. Note, numpy only raises a deprecation warning if a ragged nested list is passed in. If `use_numba=True`, just performs an inline check on the shape of the input, raising an `IndexError` if it is not what was expected. It never performs a reshape on matrix arguments. Also adds the type alias `sym.util.MatrixType` and `sym.util.VectorType`. This is to make the type annotations less verbose. --- gen/python/sym/atan_camera_cal.py | 11 ++--- gen/python/sym/double_sphere_camera_cal.py | 11 ++--- gen/python/sym/equirectangular_camera_cal.py | 11 ++--- gen/python/sym/linear_camera_cal.py | 11 ++--- .../sym/ops/atan_camera_cal/camera_ops.py | 18 ++++---- .../sym/ops/atan_camera_cal/group_ops.py | 2 +- .../sym/ops/atan_camera_cal/lie_group_ops.py | 10 ++--- .../double_sphere_camera_cal/camera_ops.py | 18 ++++---- .../ops/double_sphere_camera_cal/group_ops.py | 2 +- .../double_sphere_camera_cal/lie_group_ops.py | 10 ++--- .../equirectangular_camera_cal/camera_ops.py | 18 ++++---- .../equirectangular_camera_cal/group_ops.py | 2 +- .../lie_group_ops.py | 10 ++--- .../sym/ops/linear_camera_cal/camera_ops.py | 18 ++++---- .../sym/ops/linear_camera_cal/group_ops.py | 2 +- .../ops/linear_camera_cal/lie_group_ops.py | 10 ++--- .../ops/polynomial_camera_cal/camera_ops.py | 10 ++--- .../ops/polynomial_camera_cal/group_ops.py | 2 +- .../polynomial_camera_cal/lie_group_ops.py | 10 ++--- gen/python/sym/ops/pose2/group_ops.py | 2 +- gen/python/sym/ops/pose2/lie_group_ops.py | 10 ++--- gen/python/sym/ops/pose3/group_ops.py | 2 +- gen/python/sym/ops/pose3/lie_group_ops.py | 10 ++--- gen/python/sym/ops/rot2/group_ops.py | 2 +- gen/python/sym/ops/rot2/lie_group_ops.py | 10 ++--- gen/python/sym/ops/rot3/group_ops.py | 2 +- gen/python/sym/ops/rot3/lie_group_ops.py | 10 ++--- .../ops/spherical_camera_cal/camera_ops.py | 10 ++--- .../sym/ops/spherical_camera_cal/group_ops.py | 2 +- .../ops/spherical_camera_cal/lie_group_ops.py | 10 ++--- gen/python/sym/polynomial_camera_cal.py | 7 +-- gen/python/sym/pose2.py | 11 ++--- gen/python/sym/pose3.py | 11 ++--- gen/python/sym/rot2.py | 6 +-- gen/python/sym/rot3.py | 6 +-- gen/python/sym/spherical_camera_cal.py | 7 +-- gen/python/sym/util.py | 22 +++++++++- .../templates/cam_package/CLASS.py.jinja | 3 +- .../cam_package/ops/CLASS/camera_ops.py.jinja | 2 +- .../templates/function/FUNCTION.py.jinja | 2 +- .../templates/geo_package/CLASS.py.jinja | 3 +- .../templates/ops/CLASS/group_ops.py.jinja | 2 +- .../ops/CLASS/lie_group_ops.py.jinja | 2 +- .../backends/python/templates/util.py.jinja | 20 ++++++++- .../backends/python/templates/util/util.jinja | 20 ++++++--- test/symforce_codegen_test.py | 44 ++++++++++++++----- .../symengine/az_el_from_point.py | 6 +-- .../codegen_dataclass_in_values_test.py | 2 +- .../codegen_python_test/python_function.py | 5 ++- .../symforce/buffer_test/buffer_func.py | 2 +- .../sympy/az_el_from_point.py | 6 +-- .../codegen_dataclass_in_values_test.py | 2 +- .../codegen_python_test/python_function.py | 5 ++- .../symforce/buffer_test/buffer_func.py | 2 +- 54 files changed, 266 insertions(+), 188 deletions(-) diff --git a/gen/python/sym/atan_camera_cal.py b/gen/python/sym/atan_camera_cal.py index f3f000d36..f95a122df 100644 --- a/gen/python/sym/atan_camera_cal.py +++ b/gen/python/sym/atan_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import atan_camera_cal as ops -from .util import check_size_and_reshape class ATANCameraCal(object): @@ -94,7 +95,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -106,7 +107,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -120,7 +121,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point_with_jacobians(self, point, epsilon) def camera_ray_from_pixel(self, pixel, epsilon): - # type: (ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -134,7 +135,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): return ops.CameraOps.camera_ray_from_pixel(self, pixel, epsilon) def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. diff --git a/gen/python/sym/double_sphere_camera_cal.py b/gen/python/sym/double_sphere_camera_cal.py index 71d6b7609..ea2630563 100644 --- a/gen/python/sym/double_sphere_camera_cal.py +++ b/gen/python/sym/double_sphere_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import double_sphere_camera_cal as ops -from .util import check_size_and_reshape class DoubleSphereCameraCal(object): @@ -107,7 +108,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -119,7 +120,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -133,7 +134,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point_with_jacobians(self, point, epsilon) def camera_ray_from_pixel(self, pixel, epsilon): - # type: (DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -147,7 +148,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): return ops.CameraOps.camera_ray_from_pixel(self, pixel, epsilon) def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. diff --git a/gen/python/sym/equirectangular_camera_cal.py b/gen/python/sym/equirectangular_camera_cal.py index 267d8f1d0..8d3b07300 100644 --- a/gen/python/sym/equirectangular_camera_cal.py +++ b/gen/python/sym/equirectangular_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import equirectangular_camera_cal as ops -from .util import check_size_and_reshape class EquirectangularCameraCal(object): @@ -89,7 +90,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -101,7 +102,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -115,7 +116,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point_with_jacobians(self, point, epsilon) def camera_ray_from_pixel(self, pixel, epsilon): - # type: (EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -129,7 +130,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): return ops.CameraOps.camera_ray_from_pixel(self, pixel, epsilon) def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. diff --git a/gen/python/sym/linear_camera_cal.py b/gen/python/sym/linear_camera_cal.py index 4307b30bc..9a6d6ab77 100644 --- a/gen/python/sym/linear_camera_cal.py +++ b/gen/python/sym/linear_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import linear_camera_cal as ops -from .util import check_size_and_reshape class LinearCameraCal(object): @@ -89,7 +90,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -101,7 +102,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -115,7 +116,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point_with_jacobians(self, point, epsilon) def camera_ray_from_pixel(self, pixel, epsilon): - # type: (LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -129,7 +130,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): return ops.CameraOps.camera_ray_from_pixel(self, pixel, epsilon) def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. diff --git a/gen/python/sym/ops/atan_camera_cal/camera_ops.py b/gen/python/sym/ops/atan_camera_cal/camera_ops.py index 7543d6f5e..95b5924bc 100644 --- a/gen/python/sym/ops/atan_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/atan_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (4) _tmp0 = max(epsilon, point[2, 0]) @@ -90,7 +90,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -105,7 +105,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (46) _tmp0 = 0.5 * _self[4] @@ -184,7 +184,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): @staticmethod def camera_ray_from_pixel(self, pixel, epsilon): - # type: (sym.ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -199,7 +199,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (5) _tmp0 = -_self[2] + pixel[0, 0] @@ -225,7 +225,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): @staticmethod def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (sym.ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.ATANCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -240,7 +240,7 @@ def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (54) _tmp0 = -_self[2] + pixel[0, 0] diff --git a/gen/python/sym/ops/atan_camera_cal/group_ops.py b/gen/python/sym/ops/atan_camera_cal/group_ops.py index b40975149..f52db5a07 100644 --- a/gen/python/sym/ops/atan_camera_cal/group_ops.py +++ b/gen/python/sym/ops/atan_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/atan_camera_cal/lie_group_ops.py b/gen/python/sym/ops/atan_camera_cal/lie_group_ops.py index 9260e42a9..a9b76cc89 100644 --- a/gen/python/sym/ops/atan_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/atan_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.ATANCameraCal + # type: (sym.util.VectorType, float) -> sym.ATANCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (5, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (5, 1)) # Intermediate terms (0) @@ -60,13 +60,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.ATANCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.ATANCameraCal + # type: (sym.ATANCameraCal, sym.util.VectorType, float) -> sym.ATANCameraCal # Total ops: 5 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (5, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (5, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/ops/double_sphere_camera_cal/camera_ops.py b/gen/python/sym/ops/double_sphere_camera_cal/camera_ops.py index d0428f8a7..786081f2a 100644 --- a/gen/python/sym/ops/double_sphere_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/double_sphere_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (13) _tmp0 = epsilon ** 2 + point[0, 0] ** 2 + point[1, 0] ** 2 @@ -143,7 +143,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -158,7 +158,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (40) _tmp0 = epsilon ** 2 + point[0, 0] ** 2 + point[1, 0] ** 2 @@ -271,7 +271,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): @staticmethod def camera_ray_from_pixel(self, pixel, epsilon): - # type: (sym.DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -286,7 +286,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (12) _tmp0 = -_self[2] + pixel[0, 0] @@ -317,7 +317,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): @staticmethod def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (sym.DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.DoubleSphereCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -332,7 +332,7 @@ def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (111) _tmp0 = -_self[2] + pixel[0, 0] diff --git a/gen/python/sym/ops/double_sphere_camera_cal/group_ops.py b/gen/python/sym/ops/double_sphere_camera_cal/group_ops.py index 4a3189cbf..0f7041395 100644 --- a/gen/python/sym/ops/double_sphere_camera_cal/group_ops.py +++ b/gen/python/sym/ops/double_sphere_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/double_sphere_camera_cal/lie_group_ops.py b/gen/python/sym/ops/double_sphere_camera_cal/lie_group_ops.py index 50f2c2bde..f205a6198 100644 --- a/gen/python/sym/ops/double_sphere_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/double_sphere_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.DoubleSphereCameraCal + # type: (sym.util.VectorType, float) -> sym.DoubleSphereCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (6, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (6, 1)) # Intermediate terms (0) @@ -62,13 +62,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.DoubleSphereCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.DoubleSphereCameraCal + # type: (sym.DoubleSphereCameraCal, sym.util.VectorType, float) -> sym.DoubleSphereCameraCal # Total ops: 6 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (6, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (6, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/ops/equirectangular_camera_cal/camera_ops.py b/gen/python/sym/ops/equirectangular_camera_cal/camera_ops.py index 84de019f7..750a4bd62 100644 --- a/gen/python/sym/ops/equirectangular_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/equirectangular_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (1) _tmp0 = point[0, 0] ** 2 + point[2, 0] ** 2 @@ -98,7 +98,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -113,7 +113,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (10) _tmp0 = ( @@ -155,7 +155,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): @staticmethod def camera_ray_from_pixel(self, pixel, epsilon): - # type: (sym.EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -170,7 +170,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (3) _tmp0 = (-_self[3] + pixel[1, 0]) / _self[1] @@ -197,7 +197,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): @staticmethod def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (sym.EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.EquirectangularCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -212,7 +212,7 @@ def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (21) _tmp0 = -_self[3] + pixel[1, 0] diff --git a/gen/python/sym/ops/equirectangular_camera_cal/group_ops.py b/gen/python/sym/ops/equirectangular_camera_cal/group_ops.py index 40351acd4..d9b3f6506 100644 --- a/gen/python/sym/ops/equirectangular_camera_cal/group_ops.py +++ b/gen/python/sym/ops/equirectangular_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/equirectangular_camera_cal/lie_group_ops.py b/gen/python/sym/ops/equirectangular_camera_cal/lie_group_ops.py index d9752a870..5de7ba1e9 100644 --- a/gen/python/sym/ops/equirectangular_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/equirectangular_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.EquirectangularCameraCal + # type: (sym.util.VectorType, float) -> sym.EquirectangularCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (4, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (4, 1)) # Intermediate terms (0) @@ -58,13 +58,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.EquirectangularCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.EquirectangularCameraCal + # type: (sym.EquirectangularCameraCal, sym.util.VectorType, float) -> sym.EquirectangularCameraCal # Total ops: 4 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (4, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (4, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/ops/linear_camera_cal/camera_ops.py b/gen/python/sym/ops/linear_camera_cal/camera_ops.py index 64b56a3c8..4056d5ffa 100644 --- a/gen/python/sym/ops/linear_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/linear_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (1) _tmp0 = 1 / max(epsilon, point[2, 0]) @@ -87,7 +87,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -102,7 +102,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (5) _tmp0 = max(epsilon, point[2, 0]) @@ -143,7 +143,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): @staticmethod def camera_ray_from_pixel(self, pixel, epsilon): - # type: (sym.LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -158,7 +158,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (0) @@ -172,7 +172,7 @@ def camera_ray_from_pixel(self, pixel, epsilon): @staticmethod def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): - # type: (sym.LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.LinearCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Backproject a 2D pixel coordinate into a 3D ray in the camera frame. @@ -187,7 +187,7 @@ def camera_ray_from_pixel_with_jacobians(self, pixel, epsilon): # Input arrays _self = self.data - pixel = check_size_and_reshape(pixel, "pixel", (2, 1)) + pixel = sym.util.check_size_and_reshape(pixel, "pixel", (2, 1)) # Intermediate terms (4) _tmp0 = -_self[2] + pixel[0, 0] diff --git a/gen/python/sym/ops/linear_camera_cal/group_ops.py b/gen/python/sym/ops/linear_camera_cal/group_ops.py index ceeb6c1cc..27bca20aa 100644 --- a/gen/python/sym/ops/linear_camera_cal/group_ops.py +++ b/gen/python/sym/ops/linear_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/linear_camera_cal/lie_group_ops.py b/gen/python/sym/ops/linear_camera_cal/lie_group_ops.py index e8072b697..97603dc3c 100644 --- a/gen/python/sym/ops/linear_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/linear_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.LinearCameraCal + # type: (sym.util.VectorType, float) -> sym.LinearCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (4, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (4, 1)) # Intermediate terms (0) @@ -58,13 +58,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.LinearCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.LinearCameraCal + # type: (sym.LinearCameraCal, sym.util.VectorType, float) -> sym.LinearCameraCal # Total ops: 4 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (4, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (4, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/ops/polynomial_camera_cal/camera_ops.py b/gen/python/sym/ops/polynomial_camera_cal/camera_ops.py index 0b81877ad..1af00e081 100644 --- a/gen/python/sym/ops/polynomial_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/polynomial_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.PolynomialCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.PolynomialCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (4) _tmp0 = max(epsilon, point[2, 0]) @@ -102,7 +102,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.PolynomialCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.PolynomialCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -117,7 +117,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (35) _tmp0 = point[1, 0] ** 2 diff --git a/gen/python/sym/ops/polynomial_camera_cal/group_ops.py b/gen/python/sym/ops/polynomial_camera_cal/group_ops.py index 800f9b407..20aebcc0c 100644 --- a/gen/python/sym/ops/polynomial_camera_cal/group_ops.py +++ b/gen/python/sym/ops/polynomial_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/polynomial_camera_cal/lie_group_ops.py b/gen/python/sym/ops/polynomial_camera_cal/lie_group_ops.py index b8f97fe2e..a51ecdc89 100644 --- a/gen/python/sym/ops/polynomial_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/polynomial_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.PolynomialCameraCal + # type: (sym.util.VectorType, float) -> sym.PolynomialCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (8, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (8, 1)) # Intermediate terms (0) @@ -66,13 +66,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.PolynomialCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.PolynomialCameraCal + # type: (sym.PolynomialCameraCal, sym.util.VectorType, float) -> sym.PolynomialCameraCal # Total ops: 8 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (8, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (8, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/ops/pose2/group_ops.py b/gen/python/sym/ops/pose2/group_ops.py index 9d103ec7b..4015f16be 100644 --- a/gen/python/sym/ops/pose2/group_ops.py +++ b/gen/python/sym/ops/pose2/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/pose2/lie_group_ops.py b/gen/python/sym/ops/pose2/lie_group_ops.py index 2a8625003..965075f76 100644 --- a/gen/python/sym/ops/pose2/lie_group_ops.py +++ b/gen/python/sym/ops/pose2/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Pose2 + # type: (sym.util.VectorType, float) -> sym.Pose2 # Total ops: 2 # Input arrays - vec = check_size_and_reshape(vec, "vec", (3, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (3, 1)) # Intermediate terms (0) @@ -59,13 +59,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.Pose2, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Pose2 + # type: (sym.Pose2, sym.util.VectorType, float) -> sym.Pose2 # Total ops: 10 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (3, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (3, 1)) # Intermediate terms (2) _tmp0 = math.sin(vec[0, 0]) diff --git a/gen/python/sym/ops/pose3/group_ops.py b/gen/python/sym/ops/pose3/group_ops.py index 597f9dae8..28c79cc5d 100644 --- a/gen/python/sym/ops/pose3/group_ops.py +++ b/gen/python/sym/ops/pose3/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/pose3/lie_group_ops.py b/gen/python/sym/ops/pose3/lie_group_ops.py index 63dec50d6..dffb90df9 100644 --- a/gen/python/sym/ops/pose3/lie_group_ops.py +++ b/gen/python/sym/ops/pose3/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Pose3 + # type: (sym.util.VectorType, float) -> sym.Pose3 # Total ops: 15 # Input arrays - vec = check_size_and_reshape(vec, "vec", (6, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (6, 1)) # Intermediate terms (3) _tmp0 = math.sqrt(epsilon ** 2 + vec[0, 0] ** 2 + vec[1, 0] ** 2 + vec[2, 0] ** 2) @@ -73,13 +73,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.Pose3, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Pose3 + # type: (sym.Pose3, sym.util.VectorType, float) -> sym.Pose3 # Total ops: 47 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (6, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (6, 1)) # Intermediate terms (8) _tmp0 = math.sqrt(epsilon ** 2 + vec[0, 0] ** 2 + vec[1, 0] ** 2 + vec[2, 0] ** 2) diff --git a/gen/python/sym/ops/rot2/group_ops.py b/gen/python/sym/ops/rot2/group_ops.py index 5acca2951..974dab6ed 100644 --- a/gen/python/sym/ops/rot2/group_ops.py +++ b/gen/python/sym/ops/rot2/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/rot2/lie_group_ops.py b/gen/python/sym/ops/rot2/lie_group_ops.py index e6e44fcfa..ab14506be 100644 --- a/gen/python/sym/ops/rot2/lie_group_ops.py +++ b/gen/python/sym/ops/rot2/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Rot2 + # type: (sym.util.VectorType, float) -> sym.Rot2 # Total ops: 2 # Input arrays - vec = check_size_and_reshape(vec, "vec", (1, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (1, 1)) # Intermediate terms (0) @@ -55,13 +55,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.Rot2, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Rot2 + # type: (sym.Rot2, sym.util.VectorType, float) -> sym.Rot2 # Total ops: 8 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (1, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (1, 1)) # Intermediate terms (2) _tmp0 = math.sin(vec[0, 0]) diff --git a/gen/python/sym/ops/rot3/group_ops.py b/gen/python/sym/ops/rot3/group_ops.py index 32dcbf212..e361db0dd 100644 --- a/gen/python/sym/ops/rot3/group_ops.py +++ b/gen/python/sym/ops/rot3/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/rot3/lie_group_ops.py b/gen/python/sym/ops/rot3/lie_group_ops.py index 587ccac90..ab1e1b9e2 100644 --- a/gen/python/sym/ops/rot3/lie_group_ops.py +++ b/gen/python/sym/ops/rot3/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Rot3 + # type: (sym.util.VectorType, float) -> sym.Rot3 # Total ops: 15 # Input arrays - vec = check_size_and_reshape(vec, "vec", (3, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (3, 1)) # Intermediate terms (3) _tmp0 = math.sqrt(epsilon ** 2 + vec[0, 0] ** 2 + vec[1, 0] ** 2 + vec[2, 0] ** 2) @@ -67,13 +67,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.Rot3, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.Rot3 + # type: (sym.Rot3, sym.util.VectorType, float) -> sym.Rot3 # Total ops: 44 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (3, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (3, 1)) # Intermediate terms (8) _tmp0 = math.sqrt(epsilon ** 2 + vec[0, 0] ** 2 + vec[1, 0] ** 2 + vec[2, 0] ** 2) diff --git a/gen/python/sym/ops/spherical_camera_cal/camera_ops.py b/gen/python/sym/ops/spherical_camera_cal/camera_ops.py index 17b2aa930..374dbb003 100644 --- a/gen/python/sym/ops/spherical_camera_cal/camera_ops.py +++ b/gen/python/sym/ops/spherical_camera_cal/camera_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): @@ -60,7 +60,7 @@ def principal_point(self): @staticmethod def pixel_from_camera_point(self, point, epsilon): - # type: (sym.SphericalCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (sym.SphericalCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -73,7 +73,7 @@ def pixel_from_camera_point(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (4) _tmp0 = math.sqrt(epsilon + point[0, 0] ** 2 + point[1, 0] ** 2) @@ -96,7 +96,7 @@ def pixel_from_camera_point(self, point, epsilon): @staticmethod def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (sym.SphericalCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (sym.SphericalCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -111,7 +111,7 @@ def pixel_from_camera_point_with_jacobians(self, point, epsilon): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (40) _tmp0 = -epsilon diff --git a/gen/python/sym/ops/spherical_camera_cal/group_ops.py b/gen/python/sym/ops/spherical_camera_cal/group_ops.py index 730137d0b..88cd0a592 100644 --- a/gen/python/sym/ops/spherical_camera_cal/group_ops.py +++ b/gen/python/sym/ops/spherical_camera_cal/group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/gen/python/sym/ops/spherical_camera_cal/lie_group_ops.py b/gen/python/sym/ops/spherical_camera_cal/lie_group_ops.py index a2e7c60c5..a66260658 100644 --- a/gen/python/sym/ops/spherical_camera_cal/lie_group_ops.py +++ b/gen/python/sym/ops/spherical_camera_cal/lie_group_ops.py @@ -10,7 +10,7 @@ import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): @@ -20,12 +20,12 @@ class LieGroupOps(object): @staticmethod def from_tangent(vec, epsilon): - # type: (T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.SphericalCameraCal + # type: (sym.util.VectorType, float) -> sym.SphericalCameraCal # Total ops: 0 # Input arrays - vec = check_size_and_reshape(vec, "vec", (9, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (9, 1)) # Intermediate terms (0) @@ -68,13 +68,13 @@ def to_tangent(a, epsilon): @staticmethod def retract(a, vec, epsilon): - # type: (sym.SphericalCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> sym.SphericalCameraCal + # type: (sym.SphericalCameraCal, sym.util.VectorType, float) -> sym.SphericalCameraCal # Total ops: 9 # Input arrays _a = a.data - vec = check_size_and_reshape(vec, "vec", (9, 1)) + vec = sym.util.check_size_and_reshape(vec, "vec", (9, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/polynomial_camera_cal.py b/gen/python/sym/polynomial_camera_cal.py index 686abaa2a..960e842b0 100644 --- a/gen/python/sym/polynomial_camera_cal.py +++ b/gen/python/sym/polynomial_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import polynomial_camera_cal as ops -from .util import check_size_and_reshape class PolynomialCameraCal(object): @@ -116,7 +117,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (PolynomialCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (PolynomialCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -128,7 +129,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (PolynomialCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (PolynomialCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. diff --git a/gen/python/sym/pose2.py b/gen/python/sym/pose2.py index 7ace0c5b6..50a10bc0b 100644 --- a/gen/python/sym/pose2.py +++ b/gen/python/sym/pose2.py @@ -9,8 +9,9 @@ import numpy +import sym.util + from .rot2 import Rot2 -from .util import check_size_and_reshape # isort: split from .ops import pose2 as ops @@ -133,7 +134,7 @@ def position(self): return _res def compose_with_point(self, right): - # type: (Pose2, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Pose2, sym.util.VectorType) -> numpy.ndarray """ Left-multiply with a compatible quantity. @@ -148,7 +149,7 @@ def compose_with_point(self, right): # Input arrays _self = self.data - right = check_size_and_reshape(right, "right", (2, 1)) + right = sym.util.check_size_and_reshape(right, "right", (2, 1)) # Intermediate terms (0) @@ -159,7 +160,7 @@ def compose_with_point(self, right): return _res def inverse_compose(self, point): - # type: (Pose2, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Pose2, sym.util.VectorType) -> numpy.ndarray """ This function was autogenerated from a symbolic function. Do not modify by hand. @@ -176,7 +177,7 @@ def inverse_compose(self, point): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (2, 1)) + point = sym.util.check_size_and_reshape(point, "point", (2, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/pose3.py b/gen/python/sym/pose3.py index 18b9d5a69..0d1054640 100644 --- a/gen/python/sym/pose3.py +++ b/gen/python/sym/pose3.py @@ -9,8 +9,9 @@ import numpy +import sym.util + from .rot3 import Rot3 -from .util import check_size_and_reshape # isort: split from .ops import pose3 as ops @@ -132,7 +133,7 @@ def position(self): return _res def compose_with_point(self, right): - # type: (Pose3, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Pose3, sym.util.VectorType) -> numpy.ndarray """ Left-multiply with a compatible quantity. """ @@ -141,7 +142,7 @@ def compose_with_point(self, right): # Input arrays _self = self.data - right = check_size_and_reshape(right, "right", (3, 1)) + right = sym.util.check_size_and_reshape(right, "right", (3, 1)) # Intermediate terms (11) _tmp0 = 2 * _self[2] @@ -179,7 +180,7 @@ def compose_with_point(self, right): return _res def inverse_compose(self, point): - # type: (Pose3, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Pose3, sym.util.VectorType) -> numpy.ndarray """ This function was autogenerated from a symbolic function. Do not modify by hand. @@ -196,7 +197,7 @@ def inverse_compose(self, point): # Input arrays _self = self.data - point = check_size_and_reshape(point, "point", (3, 1)) + point = sym.util.check_size_and_reshape(point, "point", (3, 1)) # Intermediate terms (20) _tmp0 = 2 * _self[2] diff --git a/gen/python/sym/rot2.py b/gen/python/sym/rot2.py index 7e0967c19..8ef3e06eb 100644 --- a/gen/python/sym/rot2.py +++ b/gen/python/sym/rot2.py @@ -9,7 +9,7 @@ import numpy -from .util import check_size_and_reshape +import sym.util # isort: split from .ops import rot2 as ops @@ -58,7 +58,7 @@ def __init__(self, z=None): # -------------------------------------------------------------------------- def compose_with_point(self, right): - # type: (Rot2, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Rot2, sym.util.VectorType) -> numpy.ndarray """ Left-multiplication. Either rotation concatenation or point transform. """ @@ -67,7 +67,7 @@ def compose_with_point(self, right): # Input arrays _self = self.data - right = check_size_and_reshape(right, "right", (2, 1)) + right = sym.util.check_size_and_reshape(right, "right", (2, 1)) # Intermediate terms (0) diff --git a/gen/python/sym/rot3.py b/gen/python/sym/rot3.py index 5f36745c8..73f7f1577 100644 --- a/gen/python/sym/rot3.py +++ b/gen/python/sym/rot3.py @@ -9,7 +9,7 @@ import numpy -from .util import check_size_and_reshape +import sym.util # isort: split from .ops import rot3 as ops @@ -81,7 +81,7 @@ def from_rotation_matrix(cls, R, epsilon=0.0): # -------------------------------------------------------------------------- def compose_with_point(self, right): - # type: (Rot3, T.Union[T.Sequence[float], numpy.ndarray]) -> numpy.ndarray + # type: (Rot3, sym.util.VectorType) -> numpy.ndarray """ Left-multiplication. Either rotation concatenation or point transform. """ @@ -90,7 +90,7 @@ def compose_with_point(self, right): # Input arrays _self = self.data - right = check_size_and_reshape(right, "right", (3, 1)) + right = sym.util.check_size_and_reshape(right, "right", (3, 1)) # Intermediate terms (11) _tmp0 = 2 * _self[0] diff --git a/gen/python/sym/spherical_camera_cal.py b/gen/python/sym/spherical_camera_cal.py index ffdb603d5..c19275ef9 100644 --- a/gen/python/sym/spherical_camera_cal.py +++ b/gen/python/sym/spherical_camera_cal.py @@ -8,8 +8,9 @@ import numpy +import sym.util + from .ops import spherical_camera_cal as ops -from .util import check_size_and_reshape class SphericalCameraCal(object): @@ -131,7 +132,7 @@ def principal_point(self): return ops.CameraOps.principal_point(self) def pixel_from_camera_point(self, point, epsilon): - # type: (SphericalCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float] + # type: (SphericalCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float] """ Project a 3D point in the camera frame into 2D pixel coordinates. @@ -143,7 +144,7 @@ def pixel_from_camera_point(self, point, epsilon): return ops.CameraOps.pixel_from_camera_point(self, point, epsilon) def pixel_from_camera_point_with_jacobians(self, point, epsilon): - # type: (SphericalCameraCal, T.Union[T.Sequence[float], numpy.ndarray], float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] + # type: (SphericalCameraCal, sym.util.VectorType, float) -> T.Tuple[numpy.ndarray, float, numpy.ndarray, numpy.ndarray] """ Project a 3D point in the camera frame into 2D pixel coordinates. diff --git a/gen/python/sym/util.py b/gen/python/sym/util.py index edf835a61..4db3f685c 100644 --- a/gen/python/sym/util.py +++ b/gen/python/sym/util.py @@ -8,14 +8,17 @@ import numpy +VectorType = T.Union[T.Sequence[float], numpy.ndarray] +MatrixType = T.Union[T.Sequence[T.Sequence[float]], numpy.ndarray] + def check_size_and_reshape(array, name, expected_shape): - # type: (T.Union[T.Sequence[float], numpy.ndarray], str, T.Tuple[int, int]) -> numpy.ndarray + # type: (VectorType, str, T.Tuple[int, int]) -> numpy.ndarray if not isinstance(array, numpy.ndarray): expected_len = max(expected_shape) if len(array) != expected_len: raise IndexError( - "{} is expected to have length {}; instead had length{}".format( + "{} is expected to have length {}; instead had length {}".format( name, expected_len, len(array) ) ) @@ -29,3 +32,18 @@ def check_size_and_reshape(array, name, expected_shape): ) ) return array + + +def check_matrix_size_and_numpify(array, name, expected_shape): + # type: (MatrixType, str, T.Tuple[int, int]) -> numpy.ndarray + if not isinstance(array, numpy.ndarray): + array = numpy.array(array) + + if array.shape != expected_shape: + raise IndexError( + "{} is expected to have shape {}; instead had shape {}".format( + name, expected_shape, array.shape + ) + ) + + return array diff --git a/symforce/codegen/backends/python/templates/cam_package/CLASS.py.jinja b/symforce/codegen/backends/python/templates/cam_package/CLASS.py.jinja index 5151a2954..03d306c89 100644 --- a/symforce/codegen/backends/python/templates/cam_package/CLASS.py.jinja +++ b/symforce/codegen/backends/python/templates/cam_package/CLASS.py.jinja @@ -7,8 +7,9 @@ import typing as T import numpy +import sym.util + from .ops import {{ camelcase_to_snakecase(cls.__name__) }} as ops -from .util import check_size_and_reshape class {{ cls.__name__ }}(object): {% if doc %} diff --git a/symforce/codegen/backends/python/templates/cam_package/ops/CLASS/camera_ops.py.jinja b/symforce/codegen/backends/python/templates/cam_package/ops/CLASS/camera_ops.py.jinja index b65d4328e..58a0367f6 100644 --- a/symforce/codegen/backends/python/templates/cam_package/ops/CLASS/camera_ops.py.jinja +++ b/symforce/codegen/backends/python/templates/cam_package/ops/CLASS/camera_ops.py.jinja @@ -10,7 +10,7 @@ import typing as T import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class CameraOps(object): diff --git a/symforce/codegen/backends/python/templates/function/FUNCTION.py.jinja b/symforce/codegen/backends/python/templates/function/FUNCTION.py.jinja index b8a6d1c97..257410c19 100644 --- a/symforce/codegen/backends/python/templates/function/FUNCTION.py.jinja +++ b/symforce/codegen/backends/python/templates/function/FUNCTION.py.jinja @@ -18,7 +18,7 @@ from scipy import sparse import sym # pylint: disable=unused-import {% if not spec.config.use_numba %} -from sym.util import check_size_and_reshape +import sym.util {% endif %} # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument diff --git a/symforce/codegen/backends/python/templates/geo_package/CLASS.py.jinja b/symforce/codegen/backends/python/templates/geo_package/CLASS.py.jinja index 97b0e0e3e..bf0492b1e 100644 --- a/symforce/codegen/backends/python/templates/geo_package/CLASS.py.jinja +++ b/symforce/codegen/backends/python/templates/geo_package/CLASS.py.jinja @@ -7,13 +7,14 @@ import typing as T import numpy +import sym.util + {# If a pose type, include the necessary rotation type. #} {% if imported_classes is defined %} {% for imported_cls in imported_classes %} from .{{ camelcase_to_snakecase(imported_cls.__name__ )}} import {{ imported_cls.__name__ }} {% endfor %} {% endif -%} -from .util import check_size_and_reshape # isort: split from .ops import {{ camelcase_to_snakecase(cls.__name__) }} as ops diff --git a/symforce/codegen/backends/python/templates/ops/CLASS/group_ops.py.jinja b/symforce/codegen/backends/python/templates/ops/CLASS/group_ops.py.jinja index 506096841..2d93aa3b5 100644 --- a/symforce/codegen/backends/python/templates/ops/CLASS/group_ops.py.jinja +++ b/symforce/codegen/backends/python/templates/ops/CLASS/group_ops.py.jinja @@ -10,7 +10,7 @@ import typing as T import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class GroupOps(object): diff --git a/symforce/codegen/backends/python/templates/ops/CLASS/lie_group_ops.py.jinja b/symforce/codegen/backends/python/templates/ops/CLASS/lie_group_ops.py.jinja index cda159fde..fac45f747 100644 --- a/symforce/codegen/backends/python/templates/ops/CLASS/lie_group_ops.py.jinja +++ b/symforce/codegen/backends/python/templates/ops/CLASS/lie_group_ops.py.jinja @@ -10,7 +10,7 @@ import typing as T import numpy import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util class LieGroupOps(object): diff --git a/symforce/codegen/backends/python/templates/util.py.jinja b/symforce/codegen/backends/python/templates/util.py.jinja index 03b92841f..d906eb8b1 100644 --- a/symforce/codegen/backends/python/templates/util.py.jinja +++ b/symforce/codegen/backends/python/templates/util.py.jinja @@ -6,14 +6,16 @@ import typing as T import numpy +VectorType = T.Union[T.Sequence[float], numpy.ndarray] +MatrixType = T.Union[T.Sequence[T.Sequence[float]], numpy.ndarray] def check_size_and_reshape(array, name, expected_shape): - # type: (T.Union[T.Sequence[float], numpy.ndarray], str, T.Tuple[int, int]) -> numpy.ndarray + # type: (VectorType, str, T.Tuple[int, int]) -> numpy.ndarray if not isinstance(array, numpy.ndarray): expected_len = max(expected_shape) if len(array) != expected_len: raise IndexError( - "{} is expected to have length {}; instead had length{}".format( + "{} is expected to have length {}; instead had length {}".format( name, expected_len, len(array) ) ) @@ -30,3 +32,17 @@ def check_size_and_reshape(array, name, expected_shape): ) ) return array + +def check_matrix_size_and_numpify(array, name, expected_shape): + # type: (MatrixType, str, T.Tuple[int, int]) -> numpy.ndarray + if not isinstance(array, numpy.ndarray): + array = numpy.array(array) + + if array.shape != expected_shape: + raise IndexError( + "{} is expected to have shape {}; instead had shape {}".format( + name, expected_shape, array.shape + ) + ) + + return array \ No newline at end of file diff --git a/symforce/codegen/backends/python/templates/util/util.jinja b/symforce/codegen/backends/python/templates/util/util.jinja index 98d1f53ae..0ea3c4370 100644 --- a/symforce/codegen/backends/python/templates/util/util.jinja +++ b/symforce/codegen/backends/python/templates/util/util.jinja @@ -26,8 +26,12 @@ {%- elif T.__name__ == 'NoneType' -%} None {%- elif issubclass(T, Matrix) -%} - {%- if sequence_vecs and is_input and (T.SHAPE | min) == 1 -%} - T.Union[T.Sequence[float], numpy.ndarray] + {%- if sequence_vecs and is_input -%} + {%- if (T.SHAPE | min) == 1 -%} + sym.util.VectorType + {%- else -%} + sym.util.MatrixType + {%- endif -%} {%- else -%} numpy.ndarray {%- endif -%} @@ -135,9 +139,6 @@ def {{ function_name_and_args(spec) }}: # messages known at compile time. Similarly, the reshaping is always performed # because numba compatible code cannot reshape an array in a conditional. # - # Prints nothing if shape is not of the form (1, N) or (N, 1). This is because - # only row and column vectors might also be reasonably represented with (N,). - # # Args: # name (str): The name of the array to be checked and resized. Should be a user # argument name, as it is used in the error message. @@ -153,7 +154,14 @@ if not ({{ name }}.shape == {{ shape }} or {{ name }}.shape == ({{ size }},)): raise IndexError("{{ name }} is expected to have shape {{ shape }} or ({{ size }},)") {{ name }} = {{ name }}.reshape({{ shape }}) {% else %} -{{ name }} = check_size_and_reshape({{ name }}, "{{ name }}", {{ shape }}) +{{ name }} = sym.util.check_size_and_reshape({{ name }}, "{{ name }}", {{ shape }}) + {% endif %} +{% else %} + {% if use_numba %} +if not {{ name }}.shape == {{ shape }}: + raise IndexError("{{ name }} is expected to have shape {{ shape }}") + {% else %} +{{ name }} = sym.util.check_matrix_size_and_numpify({{ name }}, "{{ name }}", {{ shape }}) {% endif %} {% endif %} {% endmacro %} diff --git a/test/symforce_codegen_test.py b/test/symforce_codegen_test.py index f77a3746e..c56dbf041 100644 --- a/test/symforce_codegen_test.py +++ b/test/symforce_codegen_test.py @@ -529,30 +529,54 @@ def assert_config_works( # --------------------------------------------------------------------- with self.subTest( - msg="If reshape_vectors=True and use_numba=False, lists are accepted for vec args" + msg="If reshape_vectors=True and use_numba=False, lists are accepted for matrix args" ): generated_pass_matrices = gen_pass_matrices(use_numba=False, reshape_vectors=True) - row = [1, 2, 3, 4] - col = [5, 6, 7, 8] - mat = np.random.random((2, 2)) + list_row = [1, 2, 3, 4] + list_col = [5, 6, 7, 8] + list_mat = [[9, 10], [11, 12]] - out_row, out_col, out_mat = generated_pass_matrices(row, col, mat) + out_row, out_col, out_mat = generated_pass_matrices(list_row, list_col, list_mat) self.assertEqual(out_row.shape, (1, 4)) - np.testing.assert_array_equal(row, out_row.flatten()) + np.testing.assert_array_equal(list_row, out_row.flatten()) self.assertEqual(out_col.shape, (4, 1)) - np.testing.assert_array_equal(col, out_col.flatten()) - np.testing.assert_array_equal(mat, out_mat) + np.testing.assert_array_equal(list_col, out_col.flatten()) + np.testing.assert_array_equal(list_mat, out_mat) # --------------------------------------------------------------------- with self.subTest(msg="IndexError is raised if a list vector arg is too long"): generated_pass_matrices = gen_pass_matrices(use_numba=False, reshape_vectors=True) - row = [1, 2, 3, 4, 5] - col = [5, 6, 7, 8] + list_row = [1, 2, 3, 4, 5] + list_col = [5, 6, 7, 8] mat = np.random.random((2, 2)) + with self.assertRaises(IndexError): + generated_pass_matrices(list_row, list_col, mat) + + # --------------------------------------------------------------------- + + with self.subTest(msg="IndexError is raised if a nested list matrix arg is too big"): + generated_pass_matrices = gen_pass_matrices(use_numba=False, reshape_vectors=True) + + list_row = [1, 2, 3, 4] + list_col = [5, 6, 7, 8] + list_mat = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + + with self.assertRaises(IndexError): + generated_pass_matrices(list_row, list_col, list_mat) + + # --------------------------------------------------------------------- + + with self.subTest(msg="IndexError is raised if matrix arg is too big [use_numba=True]"): + generated_pass_matrices = gen_pass_matrices(use_numba=True, reshape_vectors=True) + + row = np.random.random((1, 4)) + col = np.random.random((4, 1)) + mat = np.random.random((3, 3)) + with self.assertRaises(IndexError): generated_pass_matrices(row, col, mat) diff --git a/test/symforce_function_codegen_test_data/symengine/az_el_from_point.py b/test/symforce_function_codegen_test_data/symengine/az_el_from_point.py index eb6893c3f..3b02aefa5 100644 --- a/test/symforce_function_codegen_test_data/symengine/az_el_from_point.py +++ b/test/symforce_function_codegen_test_data/symengine/az_el_from_point.py @@ -10,13 +10,13 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument def az_el_from_point(nav_T_cam, nav_t_point, epsilon): - # type: (sym.Pose3, T.Union[T.Sequence[float], numpy.ndarray], float) -> numpy.ndarray + # type: (sym.Pose3, sym.util.VectorType, float) -> numpy.ndarray """ Transform a nav point into azimuth / elevation angles in the camera frame. @@ -34,7 +34,7 @@ def az_el_from_point(nav_T_cam, nav_t_point, epsilon): # Input arrays _nav_T_cam = nav_T_cam.data - nav_t_point = check_size_and_reshape(nav_t_point, "nav_t_point", (3, 1)) + nav_t_point = sym.util.check_size_and_reshape(nav_t_point, "nav_t_point", (3, 1)) # Intermediate terms (23) _tmp0 = 2 * _nav_T_cam[0] diff --git a/test/symforce_function_codegen_test_data/symengine/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py b/test/symforce_function_codegen_test_data/symengine/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py index 1e1138e5e..2de1ed9e8 100644 --- a/test/symforce_function_codegen_test_data/symengine/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py +++ b/test/symforce_function_codegen_test_data/symengine/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument diff --git a/test/symforce_function_codegen_test_data/symengine/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py b/test/symforce_function_codegen_test_data/symengine/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py index 4ea8f5031..9685f4466 100644 --- a/test/symforce_function_codegen_test_data/symengine/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py +++ b/test/symforce_function_codegen_test_data/symengine/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument @@ -28,7 +28,7 @@ def python_function( big_matrix, states, ): - # type: (float, float, sym.Rot3, T.Sequence[sym.Rot3], T.Sequence[float], T.Sequence[T.Sequence[sym.Rot3]], T.Sequence[T.Any], T.Sequence[T.Sequence[T.Any]], T.Any, numpy.ndarray, T.Any) -> T.Tuple[float, float, T.List[float], T.List[float], T.List[float]] + # type: (float, float, sym.Rot3, T.Sequence[sym.Rot3], T.Sequence[float], T.Sequence[T.Sequence[sym.Rot3]], T.Sequence[T.Any], T.Sequence[T.Sequence[T.Any]], T.Any, sym.util.MatrixType, T.Any) -> T.Tuple[float, float, T.List[float], T.List[float], T.List[float]] """ This function was autogenerated. Do not modify by hand. @@ -57,6 +57,7 @@ def python_function( # Input arrays _rot = rot.data + big_matrix = sym.util.check_matrix_size_and_numpify(big_matrix, "big_matrix", (5, 5)) # Intermediate terms (66) _tmp0 = x ** 2 diff --git a/test/symforce_function_codegen_test_data/symengine/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py b/test/symforce_function_codegen_test_data/symengine/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py index 7ee224c85..4f5078e19 100644 --- a/test/symforce_function_codegen_test_data/symengine/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py +++ b/test/symforce_function_codegen_test_data/symengine/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument diff --git a/test/symforce_function_codegen_test_data/sympy/az_el_from_point.py b/test/symforce_function_codegen_test_data/sympy/az_el_from_point.py index 849046ff3..c3de94742 100644 --- a/test/symforce_function_codegen_test_data/sympy/az_el_from_point.py +++ b/test/symforce_function_codegen_test_data/sympy/az_el_from_point.py @@ -10,13 +10,13 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument def az_el_from_point(nav_T_cam, nav_t_point, epsilon): - # type: (sym.Pose3, T.Union[T.Sequence[float], numpy.ndarray], float) -> numpy.ndarray + # type: (sym.Pose3, sym.util.VectorType, float) -> numpy.ndarray """ Transform a nav point into azimuth / elevation angles in the camera frame. @@ -34,7 +34,7 @@ def az_el_from_point(nav_T_cam, nav_t_point, epsilon): # Input arrays _nav_T_cam = nav_T_cam.data - nav_t_point = check_size_and_reshape(nav_t_point, "nav_t_point", (3, 1)) + nav_t_point = sym.util.check_size_and_reshape(nav_t_point, "nav_t_point", (3, 1)) # Intermediate terms (23) _tmp0 = 2 * _nav_T_cam[3] diff --git a/test/symforce_function_codegen_test_data/sympy/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py b/test/symforce_function_codegen_test_data/sympy/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py index 1e1138e5e..2de1ed9e8 100644 --- a/test/symforce_function_codegen_test_data/sympy/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py +++ b/test/symforce_function_codegen_test_data/sympy/codegen_dataclass_in_values_test_data/python/symforce/codegen_test/codegen_dataclass_in_values_test.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument diff --git a/test/symforce_function_codegen_test_data/sympy/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py b/test/symforce_function_codegen_test_data/sympy/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py index 4ea8f5031..9685f4466 100644 --- a/test/symforce_function_codegen_test_data/sympy/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py +++ b/test/symforce_function_codegen_test_data/sympy/codegen_python_test_data/python/symforce/codegen_python_test/python_function.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument @@ -28,7 +28,7 @@ def python_function( big_matrix, states, ): - # type: (float, float, sym.Rot3, T.Sequence[sym.Rot3], T.Sequence[float], T.Sequence[T.Sequence[sym.Rot3]], T.Sequence[T.Any], T.Sequence[T.Sequence[T.Any]], T.Any, numpy.ndarray, T.Any) -> T.Tuple[float, float, T.List[float], T.List[float], T.List[float]] + # type: (float, float, sym.Rot3, T.Sequence[sym.Rot3], T.Sequence[float], T.Sequence[T.Sequence[sym.Rot3]], T.Sequence[T.Any], T.Sequence[T.Sequence[T.Any]], T.Any, sym.util.MatrixType, T.Any) -> T.Tuple[float, float, T.List[float], T.List[float], T.List[float]] """ This function was autogenerated. Do not modify by hand. @@ -57,6 +57,7 @@ def python_function( # Input arrays _rot = rot.data + big_matrix = sym.util.check_matrix_size_and_numpify(big_matrix, "big_matrix", (5, 5)) # Intermediate terms (66) _tmp0 = x ** 2 diff --git a/test/symforce_function_codegen_test_data/sympy/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py b/test/symforce_function_codegen_test_data/sympy/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py index 2d8f9ce86..7d7b3ebd4 100644 --- a/test/symforce_function_codegen_test_data/sympy/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py +++ b/test/symforce_function_codegen_test_data/sympy/databuffer_codegen_test_data/python/symforce/buffer_test/buffer_func.py @@ -10,7 +10,7 @@ import numpy # pylint: disable=unused-import import sym # pylint: disable=unused-import -from sym.util import check_size_and_reshape +import sym.util # pylint: disable=too-many-locals,too-many-lines,too-many-statements,unused-argument