test_matrix.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 import numpy as np
4 import matrix as eigenpy
5 
6 verbose = True
7 
8 if verbose:
9  print("===> From empty MatrixXd to Py")
10 M = eigenpy.emptyMatrix()
11 assert M.shape == (0, 0)
12 
13 if verbose:
14  print("===> From empty VectorXd to Py")
15 v = eigenpy.emptyVector()
16 assert v.shape == (0,)
17 
18 if verbose:
19  print("===> From Py to Matrix1")
20 eigenpy.matrix1x1(np.array([1]))
21 
22 if verbose:
23  print("===> From MatrixXd to Py")
24 M = eigenpy.naturals(3, 3, verbose)
25 Mcheck = np.reshape(np.array(range(9), np.double), [3, 3])
26 assert np.array_equal(Mcheck, M)
27 
28 if verbose:
29  print("===> From Matrix3d to Py")
30 M33 = eigenpy.naturals33(verbose)
31 assert np.array_equal(Mcheck, M33)
32 
33 if verbose:
34  print("===> From VectorXd to Py")
35 v = eigenpy.naturalsX(3, verbose)
36 vcheck = np.array(range(3), np.double).T
37 assert np.array_equal(vcheck, v)
38 
39 if verbose:
40  print("===> From Py to Eigen::MatrixXd")
41 if verbose:
42  print("===> From Py to Eigen::MatrixXd")
43 if verbose:
44  print("===> From Py to Eigen::MatrixXd")
45 Mref = np.reshape(np.array(range(64), np.double), [8, 8])
46 
47 # Test base function
48 Mref_from_base = eigenpy.base(Mref)
49 assert np.array_equal(Mref, Mref_from_base)
50 
51 # Test plain function
52 Mref_from_plain = eigenpy.plain(Mref)
53 assert np.array_equal(Mref, Mref_from_plain)
54 
55 if verbose:
56  print("===> Matrix 8x8")
57 M = Mref
58 assert np.array_equal(M, eigenpy.reflex(M, verbose))
59 
60 if verbose:
61  print("===> Block 0:3x0:3")
62 M = Mref[0:3, 0:3]
63 assert np.array_equal(M, eigenpy.reflex(M, verbose))
64 
65 if verbose:
66  print("===> Block 1:3x1:3")
67 M = Mref[1:3, 1:3]
68 assert np.array_equal(M, eigenpy.reflex(M, verbose))
69 
70 if verbose:
71  print("===> Block 1:5:2x1:5:2")
72 M = Mref[1:5:2, 1:5:2]
73 assert np.array_equal(M, eigenpy.reflex(M, verbose))
74 
75 if verbose:
76  print("===> Block 1:8:3x1:5")
77 M = Mref[1:8:3, 1:5]
78 assert np.array_equal(M, eigenpy.reflex(M, verbose))
79 
80 if verbose:
81  print("===> Block transpose 1:8:3x1:6:2")
82 M = Mref[1:8:3, 0:6:2].T
83 assert np.array_equal(M, eigenpy.reflex(M, verbose))
84 
85 if verbose:
86  print("===> Block Vector 1x0:6:2")
87 M = Mref[1:2, 0:6:2]
88 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
89 
90 if verbose:
91  print("===> Block Vector 1x0:6:2 tanspose")
92 M = Mref[1:2, 0:6:2].T
93 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
94 
95 if verbose:
96  print("===> Block Vector 0:6:2x1")
97 M = Mref[0:6:2, 1:2]
98 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
99 
100 if verbose:
101  print("===> Block Vector 0:6:2x1 tanspose")
102 M = Mref[0:6:2, 1:2].T
103 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
104 
105 if verbose:
106  print("===> From Py to Eigen::VectorXd")
107 if verbose:
108  print("===> From Py to Eigen::VectorXd")
109 if verbose:
110  print("===> From Py to Eigen::VectorXd")
111 
112 if verbose:
113  print("===> Block Vector 0:6:2x1 1 dim")
114 M = Mref[0:6:2, 1].T
115 # TODO
116 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
117 
118 if verbose:
119  print("===> Block Vector 0:6:2x1")
120 M = Mref[0:6:2, 1:2]
121 assert np.array_equal(M.squeeze(), eigenpy.reflexV(M, verbose))
122 
123 if verbose:
124  print("===> Block Vector 0:6:2x1 transpose")
125 M = Mref[0:6:2, 1:2].T
126 # TODO
127 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
128 
129 if verbose:
130  print("===> From Py to Eigen::Matrix3d")
131 if verbose:
132  print("===> From Py to Eigen::Matrix3d")
133 if verbose:
134  print("===> From Py to Eigen::Matrix3d")
135 
136 if verbose:
137  print("===> Block Vector 0:3x0:6:2 ")
138 M = Mref[0:3, 0:6:2]
139 assert np.array_equal(M, eigenpy.reflex33(M, verbose))
140 
141 if verbose:
142  print("===> Block Vector 0:3x0:6:2 T")
143 M = Mref[0:3, 0:6].T
144 # TODO
145 # try:
146 # assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
147 # except eigenpy.Exception as e:
148 # if verbose: print("As expected, got the following /ROW/ error:", e.message)
149 
150 if verbose:
151  print("===> From Py to Eigen::Vector3d")
152 if verbose:
153  print("===> From Py to Eigen::Vector3d")
154 if verbose:
155  print("===> From Py to Eigen::Vector3d")
156 
157 # TODO
158 # M = Mref[0:3,1:2]
159 # assert( np.array_equal(M,eigenpy.reflex3(M,verbose)) );
160 
161 value = 2.0
162 mat1x1 = eigenpy.matrix1x1(value)
163 assert mat1x1.size == 1
164 assert mat1x1[0, 0] == value
165 
166 vec1x1 = eigenpy.vector1x1(value)
167 assert vec1x1.size == 1
168 assert vec1x1[0] == value
169 
170 # test registration of matrix6
171 mat6 = eigenpy.matrix6(0.0)
172 assert mat6.size == 36
173 
174 # test RowMajor
175 
176 mat = np.arange(0, 10).reshape(2, 5)
177 assert (eigenpy.asRowMajorFromColMajorMatrix(mat) == mat).all()
178 assert (eigenpy.asRowMajorFromRowMajorMatrix(mat) == mat).all()
179 
180 vec = np.arange(0, 10)
181 assert (eigenpy.asRowMajorFromColMajorMatrix(vec) == vec).all()
182 assert (eigenpy.asRowMajorFromColMajorVector(vec) == vec).all()
183 assert (eigenpy.asRowMajorFromRowMajorMatrix(vec) == vec).all()
184 assert (eigenpy.asRowMajorFromRowMajorVector(vec) == vec).all()
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