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


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Tue Jan 23 2024 03:15:01