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

Method test_unique_axis_zeros

numpy/lib/tests/test_arraysetops.py:1098–1132  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1096 assert_array_equal(x, np.take(uniq, inv, axis=axis))
1097
1098 def test_unique_axis_zeros(self):
1099 # issue 15559
1100 single_zero = np.empty(shape=(2, 0), dtype=np.int8)
1101 uniq, idx, inv, cnt = unique(single_zero, axis=0, return_index=True,
1102 return_inverse=True, return_counts=True)
1103
1104 # there's 1 element of shape (0,) along axis 0
1105 assert_equal(uniq.dtype, single_zero.dtype)
1106 assert_array_equal(uniq, np.empty(shape=(1, 0)))
1107 assert_array_equal(idx, np.array([0]))
1108 assert_array_equal(inv, np.array([0, 0]))
1109 assert_array_equal(cnt, np.array([2]))
1110
1111 # there's 0 elements of shape (2,) along axis 1
1112 uniq, idx, inv, cnt = unique(single_zero, axis=1, return_index=True,
1113 return_inverse=True, return_counts=True)
1114
1115 assert_equal(uniq.dtype, single_zero.dtype)
1116 assert_array_equal(uniq, np.empty(shape=(2, 0)))
1117 assert_array_equal(idx, np.array([]))
1118 assert_array_equal(inv, np.array([]))
1119 assert_array_equal(cnt, np.array([]))
1120
1121 # test a "complicated" shape
1122 shape = (0, 2, 0, 3, 0, 4, 0)
1123 multiple_zeros = np.empty(shape=shape)
1124 for axis in range(len(shape)):
1125 expected_shape = list(shape)
1126 if shape[axis] == 0:
1127 expected_shape[axis] = 0
1128 else:
1129 expected_shape[axis] = 1
1130
1131 assert_array_equal(unique(multiple_zeros, axis=axis),
1132 np.empty(shape=expected_shape))
1133
1134 def test_unique_masked(self):
1135 # issue 8664

Callers

nothing calls this directly

Calls 3

uniqueFunction · 0.90
assert_equalFunction · 0.90
assert_array_equalFunction · 0.90

Tested by

no test coverage detected