test_std_array.py
Go to the documentation of this file.
1 import std_array
2 
3 ints = std_array.get_arr_3_ints()
4 print(ints[0])
5 print(ints[1])
6 print(ints[2])
7 print(ints.tolist())
8 assert ints.tolist() == [1, 2, 3]
9 
10 _ints_slice = ints[1:3]
11 print("Printing slice...")
12 for el in _ints_slice:
13  print(el)
14 
15 ref = [1, 2, 3]
16 assert len(ref[1:2]) == 1 # sanity check
17 
18 assert len(_ints_slice) == 2, "Slice size should be 1, got %d" % len(_ints_slice)
19 assert _ints_slice[0] == 2
20 assert _ints_slice[1] == 3
21 
22 # Test that insert/delete is impossible with the slice operator
23 
24 # prepend
25 try:
26  ints[0:0] = [0, 1]
27 except NotImplementedError:
28  pass
29 else:
30  assert False, "Insert value with slice operator should be impossible"
31 
32 # append
33 try:
34  ints[10:12] = [0]
35 except NotImplementedError:
36  pass
37 else:
38  assert False, "Insert value with slice operator should be impossible"
39 
40 # append
41 try:
42  ints[3:3] = [0]
43 except NotImplementedError:
44  pass
45 else:
46  assert False, "Insert value with slice operator should be impossible"
47 
48 # Erase two elements and replace by one
49 try:
50  ints[1:3] = [0]
51 except NotImplementedError:
52  pass
53 else:
54  assert False, "Insert value with slice operator should be impossible"
55 
56 # Erase two elements and replace by three
57 try:
58  ints[1:3] = [0, 1, 2]
59 except NotImplementedError:
60  pass
61 else:
62  assert False, "Insert value with slice operator should be impossible"
63 
64 # Test that delete operator is not implemented
65 # Index delete
66 try:
67  del ints[0]
68 except NotImplementedError:
69  pass
70 else:
71  assert False, "del is not implemented"
72 
73 # Slice delete
74 try:
75  del ints[1:3]
76 except NotImplementedError:
77  pass
78 else:
79  assert False, "del is not implemented"
80 
81 # Slice delete
82 try:
83  del ints[1:3]
84 except NotImplementedError:
85  pass
86 else:
87  assert False, "del is not implemented"
88 
89 # Test that append/extend are not implemented
90 # append
91 try:
92  ints.append(4)
93 except AttributeError:
94  pass
95 else:
96  assert False, "append is not implemented"
97 
98 # extend
99 try:
100  ints.extend([4, 5])
101 except AttributeError:
102  pass
103 else:
104  assert False, "extend is not implemented"
105 
106 # Test set_slice nominal case
107 ints[1:3] = [10, 20]
108 assert ints[1] == 10
109 assert ints[2] == 20
110 
111 # print(ints.tolist())
112 
113 vecs = std_array.get_arr_3_vecs()
114 assert len(vecs) == 3
115 print(vecs[0])
116 print(vecs[1])
117 print(vecs[2])
118 
119 # slices do not work for Eigen objects...
120 
121 # v2 = vecs[:]
122 # assert isinstance(v2, std_array.StdVec_VectorXd)
123 # assert len(v2) == 3
124 # print(v2.tolist())
125 # print(v2[0])
126 
127 ts = std_array.test_struct()
128 assert len(ts.integs) == 3
129 assert len(ts.vecs) == 2
130 print(ts.integs[:].tolist())
131 print(ts.vecs[0])
132 print(ts.vecs[1])
133 
134 ts.integs[:] = 111
135 print("Test of set_slice for std::array<int>:", ts.integs[:].tolist())
136 for el in ts.integs:
137  assert el == 111
138 
139 ts.vecs[0][0] = 0.0
140 ts.vecs[1][0] = -243
141 print(ts.vecs[0])
142 print(ts.vecs[1])
print
void print(const Eigen::SparseMatrix< Scalar, Options > &mat)
Definition: sparse_matrix.cpp:50


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45