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


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Tue Jan 23 2024 03:15:01