MCPcopy Index your code
hub / github.com/numpy/numpy / test_simple

Method test_simple

numpy/_core/tests/test_item_selection.py:137–168  ·  view source on GitHub ↗
(self, dtype, mode)

Source from the content-addressed store, hash-verified

135 @pytest.mark.parametrize("dtype", list(np.typecodes["All"])[1:] + ["i,O"])
136 @pytest.mark.parametrize("mode", ["raise", "wrap", "clip"])
137 def test_simple(self, dtype, mode):
138 if dtype.lower() == "m":
139 dtype += "8[ns]"
140
141 # put is weird and doesn't care about value length (even shorter)
142 vals = np.arange(1001).astype(dtype=dtype)
143
144 # Use vals.dtype in case of flexible dtype (i.e. string)
145 arr = np.zeros(1000, dtype=vals.dtype)
146 zeros = arr.copy()
147
148 if mode == "clip":
149 # Special because 0 and -1 value are "reserved" for clip test
150 indx = np.random.permutation(len(arr) - 2)[:-500] + 1
151
152 indx[-1] = 0
153 indx[-2] = len(arr) - 1
154 indx_put = indx.copy()
155 indx_put[-1] = -1389
156 indx_put[-2] = 1321
157 else:
158 # Avoid duplicates (for simplicity) and fill half only
159 indx = np.random.permutation(len(arr) - 3)[:-500]
160 indx_put = indx
161 if mode == "wrap":
162 indx_put = indx_put + len(arr)
163
164 np.put(arr, indx_put, vals, mode=mode)
165 assert_array_equal(arr[indx], vals[:len(indx)])
166 untouched = np.ones(len(arr), dtype=bool)
167 untouched[indx] = False
168 assert_array_equal(arr[untouched], zeros[:untouched.sum()])
169
170 @pytest.mark.parametrize("dtype", list(np.typecodes["All"])[1:] + ["i,O"])
171 @pytest.mark.parametrize("mode", ["raise", "wrap", "clip"])

Callers

nothing calls this directly

Calls 6

assert_array_equalFunction · 0.90
lowerMethod · 0.80
astypeMethod · 0.80
putMethod · 0.80
copyMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected