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 
18 
19 def checkAllValues(li1, li2):
20  assert len(li1) == len(li2)
21  n = len(li1)
22  for i in range(n):
23  assert np.array_equal(li1[i], li2[i])
24 
25 
26 checkAllValues(l1, l2)
27 checkAllValues(l1, copyStdVector(l1))
28 
29 l2[0][:2] = 0.0
30 assert np.allclose(l2[0][:2], 0.0)
31 
32 print("l1")
34 print("l2")
36 print("l3")
38 
39 
40 l4_copy = copyStdVector(l4)
41 assert isinstance(l4_copy, eigenpy.StdVec_MatrixXd)
42 
43 assert "StdVec_Mat3d" in printVectorOf3x3.__doc__
44 printVectorOf3x3(l4)
45 
46 l4_copy2 = std_vector.copyStdVec_3x3(l4)
47 assert isinstance(l4_copy2, std_vector.StdVec_Mat3d)
48 
49 
50 def checkZero(l):
51  for x in l:
52  assert np.allclose(x, 0.0), "x = {}".format(x)
53 
54 
55 print("Check setZero() works:")
56 std_vector.setZero(l1)
57 print("l1:")
58 print(l1)
59 checkZero(l1)
60 print("-----------------")
61 
62 print("l2:")
63 l2_py = l2.tolist()
64 std_vector.setZero(l2_py)
65 pprint.pprint(l2_py)
66 checkZero(l2_py)
67 print("-----------------")
68 
69 l3_copy = copyStdVector(l3)
70 print("l3_std:")
71 std_vector.setZero(l3_copy)
72 pprint.pprint(list(l3_copy))
73 checkZero(l3_copy)
74 print("-----------------")
75 
76 # print("l3_python:")
77 # vector.setZero(l3)
78 # pprint.pprint(list(l3))
79 # checkZero(l3)
80 # print("-----------------")
81 
82 # print("l4:")
83 # vector.setZero(l4)
84 # pprint.pprint(list(l4))
85 # checkZero(l4)
def checkAllValues(li1, li2)
void printVectorOfMatrix(const std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Definition: std_vector.cpp:11
void print(const Tensor &tensor)
Definition: tensor.cpp:35


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26