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: print("===> From empty MatrixXd to Py")
9 M = eigenpy.emptyMatrix()
10 assert M.shape == (0,0)
11 
12 if verbose: print("===> From empty VectorXd to Py")
13 v = eigenpy.emptyVector()
14 assert v.shape == (0,)
15 
16 if verbose: print("===> From MatrixXd to Py")
17 M = eigenpy.naturals(3,3,verbose)
18 Mcheck = np.reshape(np.array(range(9),np.double),[3,3])
19 assert np.array_equal(Mcheck,M)
20 
21 if verbose: print("===> From Matrix3d to Py")
22 M33= eigenpy.naturals33(verbose)
23 assert np.array_equal(Mcheck,M33)
24 
25 if verbose: print("===> From VectorXd to Py")
26 v = eigenpy.naturalsX(3,verbose)
27 vcheck = np.array(range(3),np.double).T
28 assert np.array_equal(vcheck ,v)
29 
30 if verbose: print("===> From Py to Eigen::MatrixXd")
31 if verbose: print("===> From Py to Eigen::MatrixXd")
32 if verbose: print("===> From Py to Eigen::MatrixXd")
33 Mref = np.reshape(np.array(range(64),np.double),[8,8])
34 
35 # Test base function
36 Mref_from_base = eigenpy.base(Mref)
37 assert( np.array_equal(Mref,Mref_from_base) );
38 
39 # Test plain function
40 Mref_from_plain = eigenpy.plain(Mref)
41 assert( np.array_equal(Mref,Mref_from_plain) );
42 
43 if verbose: print("===> Matrix 8x8")
44 M = Mref
45 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
46 
47 if verbose: print("===> Block 0:3x0:3")
48 M = Mref[0:3,0:3]
49 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
50 
51 if verbose: print("===> Block 1:3x1:3")
52 M = Mref[1:3,1:3]
53 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
54 
55 if verbose: print("===> Block 1:5:2x1:5:2")
56 M = Mref[1:5:2,1:5:2]
57 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
58 
59 if verbose: print("===> Block 1:8:3x1:5")
60 M = Mref[1:8:3,1:5]
61 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
62 
63 if verbose: print("===> Block transpose 1:8:3x1:6:2")
64 M = Mref[1:8:3,0:6:2].T
65 assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
66 
67 if verbose: print("===> Block Vector 1x0:6:2")
68 M = Mref[1:2,0:6:2]
69 assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
70 
71 if verbose: print("===> Block Vector 1x0:6:2 tanspose")
72 M = Mref[1:2,0:6:2].T
73 assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
74 
75 if verbose: print("===> Block Vector 0:6:2x1")
76 M = Mref[0:6:2,1:2]
77 assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
78 
79 if verbose: print("===> Block Vector 0:6:2x1 tanspose")
80 M = Mref[0:6:2,1:2].T
81 assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
82 
83 if verbose: print("===> From Py to Eigen::VectorXd")
84 if verbose: print("===> From Py to Eigen::VectorXd")
85 if verbose: print("===> From Py to Eigen::VectorXd")
86 
87 if verbose: print("===> Block Vector 0:6:2x1 1 dim")
88 M = Mref[0:6:2,1].T
89 # TODO
90 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
91 
92 if verbose: print("===> Block Vector 0:6:2x1")
93 M = Mref[0:6:2,1:2]
94 assert( np.array_equal(M.squeeze(),eigenpy.reflexV(M,verbose)) );
95 
96 if verbose: print("===> Block Vector 0:6:2x1 transpose")
97 M = Mref[0:6:2,1:2].T
98 # TODO
99 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
100 
101 if verbose: print("===> From Py to Eigen::Matrix3d")
102 if verbose: print("===> From Py to Eigen::Matrix3d")
103 if verbose: print("===> From Py to Eigen::Matrix3d")
104 
105 if verbose: print("===> Block Vector 0:3x0:6:2 ")
106 M = Mref[0:3,0:6:2]
107 assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
108 
109 if verbose: print("===> Block Vector 0:3x0:6:2 T")
110 M = Mref[0:3,0:6].T
111 # TODO
112 # try:
113  # assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
114 # except eigenpy.Exception as e:
115  # if verbose: print("As expected, got the following /ROW/ error:", e.message)
116 
117 if verbose: print("===> From Py to Eigen::Vector3d")
118 if verbose: print("===> From Py to Eigen::Vector3d")
119 if verbose: print("===> From Py to Eigen::Vector3d")
120 
121 # TODO
122 # M = Mref[0:3,1:2]
123 # assert( np.array_equal(M,eigenpy.reflex3(M,verbose)) );
124 
125 value = 2.
126 mat1x1 = eigenpy.matrix1x1(value)
127 assert(mat1x1.size == 1)
128 assert(mat1x1[0,0] == value)
129 
130 vec1x1 = eigenpy.vector1x1(value)
131 assert(vec1x1.size == 1)
132 assert(vec1x1[0] == value)
133 
134 # test registration of matrix6
135 mat6 = eigenpy.matrix6(0.)
136 assert(mat6.size == 36)


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Apr 17 2021 02:37:59