MCPcopy Create free account
hub / github.com/numpy/numpy / test_simple

Method test_simple

numpy/core/tests/test_item_selection.py:12–49  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

10
11class TestTake:
12 def test_simple(self):
13 a = [[1, 2], [3, 4]]
14 a_str = [[b'1', b'2'], [b'3', b'4']]
15 modes = ['raise', 'wrap', 'clip']
16 indices = [-1, 4]
17 index_arrays = [np.empty(0, dtype=np.intp),
18 np.empty(tuple(), dtype=np.intp),
19 np.empty((1, 1), dtype=np.intp)]
20 real_indices = {'raise': {-1: 1, 4: IndexError},
21 'wrap': {-1: 1, 4: 0},
22 'clip': {-1: 0, 4: 1}}
23 # Currently all types but object, use the same function generation.
24 # So it should not be necessary to test all. However test also a non
25 # refcounted struct on top of object, which has a size that hits the
26 # default (non-specialized) path.
27 types = int, object, np.dtype([('', 'i2', 3)])
28 for t in types:
29 # ta works, even if the array may be odd if buffer interface is used
30 ta = np.array(a if np.issubdtype(t, np.number) else a_str, dtype=t)
31 tresult = list(ta.T.copy())
32 for index_array in index_arrays:
33 if index_array.size != 0:
34 tresult[0].shape = (2,) + index_array.shape
35 tresult[1].shape = (2,) + index_array.shape
36 for mode in modes:
37 for index in indices:
38 real_index = real_indices[mode][index]
39 if real_index is IndexError and index_array.size != 0:
40 index_array.put(0, index)
41 assert_raises(IndexError, ta.take, index_array,
42 mode=mode, axis=1)
43 elif index_array.size != 0:
44 index_array.put(0, index)
45 res = ta.take(index_array, mode=mode, axis=1)
46 assert_array_equal(res, tresult[real_index])
47 else:
48 res = ta.take(index_array, mode=mode, axis=1)
49 assert_(res.shape == (2,) + index_array.shape)
50
51 def test_refcounting(self):
52 objects = [object() for i in range(10)]

Callers

nothing calls this directly

Calls 7

assert_raisesFunction · 0.90
assert_array_equalFunction · 0.90
assert_Function · 0.90
putMethod · 0.80
takeMethod · 0.80
dtypeMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected