From a28bcaaec8c749c6942af48be2098a4cd459fa39 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Sat, 7 Jan 2023 16:56:07 +0100 Subject: [PATCH] test: update test to account for alignment issues --- unittest/python/test_geometry.py | 3 ++- unittest/python/test_std_vector.py | 2 +- unittest/std_vector.cpp | 18 +++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/unittest/python/test_geometry.py b/unittest/python/test_geometry.py index c2bd1b1a..cbcdc8ec 100644 --- a/unittest/python/test_geometry.py +++ b/unittest/python/test_geometry.py @@ -32,7 +32,8 @@ assert isapprox(np.linalg.norm(q.coeffs()), 1) # Coefficient-vector initialisation verbose and print("[Quaternion] Coefficient-vector initialisation") v = np.array([0.5, -0.5, 0.5, 0.5]) -qv = Quaternion(v) +for k in range(10000): + qv = Quaternion(v) assert isapprox(qv.coeffs(), v) # Angle axis initialisation diff --git a/unittest/python/test_std_vector.py b/unittest/python/test_std_vector.py index 52fd4c0d..8cd6ab76 100644 --- a/unittest/python/test_std_vector.py +++ b/unittest/python/test_std_vector.py @@ -53,8 +53,8 @@ def checkZero(l): print("Check setZero() works:") -print("l1:") std_vector.setZero(l1) +print("l1:") print(l1) checkZero(l1) print("-----------------") diff --git a/unittest/std_vector.cpp b/unittest/std_vector.cpp index a3679917..12bb9e2c 100644 --- a/unittest/std_vector.cpp +++ b/unittest/std_vector.cpp @@ -7,22 +7,26 @@ #include "eigenpy/eigen-from-python.hpp" #include "eigenpy/std-vector.hpp" -template <typename MatType> -void printVectorOfMatrix(const std::vector<MatType> &Ms) { +template <typename MatType, + typename Allocator = Eigen::aligned_allocator<MatType> > +void printVectorOfMatrix(const std::vector<MatType, Allocator> &Ms) { const std::size_t n = Ms.size(); for (std::size_t i = 0; i < n; i++) { std::cout << "el[" << i << "] =\n" << Ms[i] << '\n'; } } -template <typename MatType> -std::vector<MatType> copy(const std::vector<MatType> &Ms) { - std::vector<MatType> out = Ms; +template <typename MatType, + typename Allocator = Eigen::aligned_allocator<MatType> > +std::vector<MatType, Allocator> copy( + const std::vector<MatType, Allocator> &Ms) { + std::vector<MatType, Allocator> out = Ms; return out; } -template <typename MatType> -void setZero(std::vector<MatType> &Ms) { +template <typename MatType, + typename Allocator = Eigen::aligned_allocator<MatType> > +void setZero(std::vector<MatType, Allocator> &Ms) { for (std::size_t i = 0; i < Ms.size(); i++) { Ms[i].setZero(); } -- GitLab