test_std_vector.py
Go to the documentation of this file.
1 import pprint
2 
3 import numpy as np
4 import std_vector
5 from std_vector import copyStdVector, printVectorOf3x3, printVectorOfMatrix
6 
7 import eigenpy
8 
9 rng = np.random.default_rng(0)
10 
11 l1 = [rng.standard_normal(3), rng.standard_normal(2)]
12 l2 = eigenpy.StdVec_VectorXd(l1)
13 l3 = [rng.standard_normal((2, 2)), rng.standard_normal((3, 1))]
14 l3.append(np.asfortranarray(np.eye(2)))
15 l3.append(np.eye(2))
16 l4 = [rng.standard_normal((3, 3)).T for _ in range(3)]
17 l4[-1] = l4[-1].T
18 l5 = [rng.standard_normal((2, 2)).T for _ in range(3)]
19 
20 
21 def checkAllValues(li1, li2):
22  assert len(li1) == len(li2)
23  n = len(li1)
24  for i in range(n):
25  assert np.array_equal(li1[i], li2[i])
26 
27 
28 checkAllValues(l1, l2)
29 checkAllValues(l1, copyStdVector(l1))
30 
31 l2[0][:2] = 0.0
32 assert np.allclose(l2[0][:2], 0.0)
33 
34 print("l1")
36 print("l2")
38 print("l3")
40 
41 
42 l4_copy = copyStdVector(l4)
43 assert isinstance(l4_copy, eigenpy.StdVec_MatrixXd)
44 
45 assert "StdVec_Mat3d" in printVectorOf3x3.__doc__
46 printVectorOf3x3(l4)
47 
48 l4_copy2 = std_vector.copyStdVec_3x3(l4)
49 assert isinstance(l4_copy2, std_vector.StdVec_Mat3d)
50 
51 
52 def checkZero(v):
53  for x in v:
54  assert np.allclose(x, 0.0), f"x = {x}"
55 
56 
57 print("Check setZero() works:")
58 std_vector.setZero(l1)
59 print("l1:")
60 print(l1)
61 checkZero(l1)
62 print("-----------------")
63 
64 print("l2:")
65 l2_py = l2.tolist()
66 std_vector.setZero(l2_py)
67 pprint.pprint(l2_py)
68 checkZero(l2_py)
69 print("-----------------")
70 
71 l3_copy = copyStdVector(l3)
72 print("l3_std:")
73 std_vector.setZero(l3_copy)
74 pprint.pprint(list(l3_copy))
75 checkZero(l3_copy)
76 print("-----------------")
77 
78 # print("l3_python:")
79 # vector.setZero(l3)
80 # pprint.pprint(list(l3))
81 # checkZero(l3)
82 # print("-----------------")
83 
84 # print("l4:")
85 # vector.setZero(l4)
86 # pprint.pprint(list(l4))
87 # checkZero(l4)
88 
89 # Test StdVec_Mat2d that had been registered
90 # before calling exposeStdVectorEigenSpecificType
91 
92 # Test conversion and tolistl5 == l5_copy == l5_py
93 l5_copy = std_vector.StdVec_Mat2d(l5)
94 l5_py = l5_copy.tolist()
95 checkAllValues(l5, l5_copy)
96 checkAllValues(l5, l5_py)
97 
98 # Test mutable __getitem__
99 l5[0][:] = 0.0
100 assert np.allclose(l5[0], 0.0)
print
void print(const Eigen::SparseMatrix< Scalar, Options > &mat)
Definition: sparse_matrix.cpp:50
test_std_vector.checkZero
def checkZero(v)
Definition: test_std_vector.py:52
printVectorOfMatrix
void printVectorOfMatrix(const std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Definition: std_vector.cpp:11
test_std_vector.checkAllValues
def checkAllValues(li1, li2)
Definition: test_std_vector.py:21


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45