3 import matrix
as eigenpy
9 print(
"===> From empty MatrixXd to Py")
10 M = eigenpy.emptyMatrix()
11 assert M.shape == (0, 0)
14 print(
"===> From empty VectorXd to Py")
15 v = eigenpy.emptyVector()
16 assert v.shape == (0,)
19 print(
"===> From Py to Matrix1")
20 eigenpy.matrix1x1(np.array([1]))
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)
29 print(
"===> From Matrix3d to Py")
30 M33 = eigenpy.naturals33(verbose)
31 assert np.array_equal(Mcheck, M33)
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)
40 print(
"===> From Py to Eigen::MatrixXd")
42 print(
"===> From Py to Eigen::MatrixXd")
44 print(
"===> From Py to Eigen::MatrixXd")
45 Mref = np.reshape(np.array(range(64), np.double), [8, 8])
48 Mref_from_base = eigenpy.base(Mref)
49 assert np.array_equal(Mref, Mref_from_base)
52 Mref_from_plain = eigenpy.plain(Mref)
53 assert np.array_equal(Mref, Mref_from_plain)
56 print(
"===> Matrix 8x8")
58 assert np.array_equal(M, eigenpy.reflex(M, verbose))
61 print(
"===> Block 0:3x0:3")
63 assert np.array_equal(M, eigenpy.reflex(M, verbose))
66 print(
"===> Block 1:3x1:3")
68 assert np.array_equal(M, eigenpy.reflex(M, 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))
76 print(
"===> Block 1:8:3x1:5")
78 assert np.array_equal(M, eigenpy.reflex(M, 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))
86 print(
"===> Block Vector 1x0:6:2")
88 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, 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))
96 print(
"===> Block Vector 0:6:2x1")
98 assert np.array_equal(M.squeeze(), eigenpy.reflex(M, 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))
106 print(
"===> From Py to Eigen::VectorXd")
108 print(
"===> From Py to Eigen::VectorXd")
110 print(
"===> From Py to Eigen::VectorXd")
113 print(
"===> Block Vector 0:6:2x1 1 dim")
119 print(
"===> Block Vector 0:6:2x1")
121 assert np.array_equal(M.squeeze(), eigenpy.reflexV(M, verbose))
124 print(
"===> Block Vector 0:6:2x1 transpose")
125 M = Mref[0:6:2, 1:2].T
130 print(
"===> From Py to Eigen::Matrix3d")
132 print(
"===> From Py to Eigen::Matrix3d")
134 print(
"===> From Py to Eigen::Matrix3d")
137 print(
"===> Block Vector 0:3x0:6:2 ")
139 assert np.array_equal(M, eigenpy.reflex33(M, verbose))
142 print(
"===> Block Vector 0:3x0:6:2 T")
151 print(
"===> From Py to Eigen::Vector3d")
153 print(
"===> From Py to Eigen::Vector3d")
155 print(
"===> From Py to Eigen::Vector3d")
162 mat1x1 = eigenpy.matrix1x1(value)
163 assert mat1x1.size == 1
164 assert mat1x1[0, 0] == value
166 vec1x1 = eigenpy.vector1x1(value)
167 assert vec1x1.size == 1
168 assert vec1x1[0] == value
171 mat6 = eigenpy.matrix6(0.0)
172 assert mat6.size == 36
176 mat = np.arange(0, 10).reshape(2, 5)
177 assert (eigenpy.asRowMajorFromColMajorMatrix(mat) == mat).all()
178 assert (eigenpy.asRowMajorFromRowMajorMatrix(mat) == mat).all()
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()
190 input_array = np.array([1, 0], dtype=dtype)
191 assert input_array.dtype == dtype
192 output_array = function(input_array)
193 assert output_array.dtype == dtype
194 assert (output_array == input_array).all()
197 bool_t = np.dtype(np.bool_)
198 int8_t = np.dtype(np.int8)
199 uint8_t = np.dtype(np.uint8)
200 int16_t = np.dtype(np.int16)
201 uint16_t = np.dtype(np.uint16)
202 int32_t = np.dtype(np.int32)
203 uint32_t = np.dtype(np.uint32)
204 int64_t = np.dtype(np.int64)
205 uint64_t = np.dtype(np.uint64)
207 long_t = np.dtype(np.int32
if platform.system() ==
"Windows" else np.int64)
208 ulong_t = np.dtype(np.uint32
if platform.system() ==
"Windows" else np.uint64)
209 longlong_t = np.dtype(np.longlong)
210 ulonglong_t = np.dtype(np.ulonglong)
212 float32_t = np.dtype(np.float32)
213 float64_t = np.dtype(np.float64)
215 complex64_t = np.dtype(np.complex64)
216 complex128_t = np.dtype(np.complex128)
217 complex256_t = np.dtype(np.clongdouble)
254 test_conversion(eigenpy.copyLongDoubleToLongDouble, np.dtype(np.longdouble))
266 input_array = np.array([1, 0], dtype=input_dtype)
267 assert input_array.dtype == input_dtype
268 output_array = function(input_array)
269 assert output_array.dtype == output_dtype
270 assert (output_array == input_array).all()
336 eigenpy.copyCLongDoubleToCLongDouble,
343 if platform.system() ==
"Linux":
345 eigenpy.copyCLongDoubleToCLongDouble,