summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_index_tricks.py
diff options
context:
space:
mode:
authorJaime Fernandez <jaime.frio@gmail.com>2015-04-27 06:15:03 -0700
committerJaime Fernandez <jaime.frio@gmail.com>2015-04-27 06:15:03 -0700
commitf06b1210d7171b4a452d0c9c67cde7b1a130303e (patch)
treefde0a4a79f8c02f736d851a10565563639cd1da3 /numpy/lib/tests/test_index_tricks.py
parent2a8efb1850f9be15c5129369a127fb56dabf0fb3 (diff)
downloadnumpy-f06b1210d7171b4a452d0c9c67cde7b1a130303e.tar.gz
TST: Added tests for ix_
Diffstat (limited to 'numpy/lib/tests/test_index_tricks.py')
-rw-r--r--numpy/lib/tests/test_index_tricks.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 97047c53a..fc3b90900 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -7,7 +7,7 @@ from numpy.testing import (
)
from numpy.lib.index_tricks import (
mgrid, ndenumerate, fill_diagonal, diag_indices, diag_indices_from,
- index_exp, ndindex, r_, s_
+ index_exp, ndindex, r_, s_, ix_
)
@@ -169,6 +169,30 @@ class TestIndexExpression(TestCase):
assert_equal(a[:, :3, [1, 2]], a[s_[:, :3, [1, 2]]])
+class TestIx_(TestCase):
+ def test_regression_1(self):
+ # Empty inputs create ouputs of indexing type, gh-5804
+ a, = np.ix_(range(0, 0))
+ assert_equal(a.dtype, np.intp)
+
+ def test_shape_and_dtype(self):
+ sizes = (4, 5, 3, 2)
+ arrays = np.ix_(*[range(sz) for sz in sizes])
+ for k, (a, sz) in enumerate(zip(arrays, sizes)):
+ assert_equal(a.shape[k], sz)
+ assert_(all(sh == 1 for j, sh in enumerate(a.shape) if j != k))
+ assert_(np.issubdtype(a.dtype, int))
+
+ def test_bool(self):
+ bool_a = [True, False, True, True]
+ int_a, = np.nonzero(bool_a)
+ assert_equal(np.ix_(bool_a)[0], int_a)
+
+ def test_1d_only(self):
+ idx2d = [[1, 2, 3], [4, 5, 6]]
+ assert_raises(ValueError, np.ix_, idx2d)
+
+
def test_c_():
a = np.c_[np.array([[1, 2, 3]]), 0, 0, np.array([[4, 5, 6]])]
assert_equal(a, [[1, 2, 3, 0, 0, 4, 5, 6]])