MCPcopy
hub / github.com/numpy/numpy / test_partition_int

Function test_partition_int

numpy/_core/tests/test_multiarray.py:11288–11309  ·  view source on GitHub ↗
(N, dtype)

Source from the content-addressed store, hash-verified

11286@pytest.mark.parametrize("dtype", [np.int16, np.uint16,
11287 np.int32, np.uint32, np.int64, np.uint64])
11288def test_partition_int(N, dtype):
11289 rnd = np.random.RandomState(1100710816)
11290 # (1) random data with min and max values
11291 minv = np.iinfo(dtype).min
11292 maxv = np.iinfo(dtype).max
11293 arr = rnd.randint(low=minv, high=maxv, size=N, dtype=dtype)
11294 i, j = rnd.choice(N, 2, replace=False)
11295 arr[i] = minv
11296 arr[j] = maxv
11297 k = rnd.choice(N, 1)[0]
11298 assert_arr_partitioned(np.sort(arr)[k], k,
11299 np.partition(arr, k, kind='introselect'))
11300 assert_arr_partitioned(np.sort(arr)[k], k,
11301 arr[np.argpartition(arr, k, kind='introselect')])
11302
11303 # (2) random data with max value at the end of array
11304 arr = rnd.randint(low=minv, high=maxv, size=N, dtype=dtype)
11305 arr[N - 1] = maxv
11306 assert_arr_partitioned(np.sort(arr)[k], k,
11307 np.partition(arr, k, kind='introselect'))
11308 assert_arr_partitioned(np.sort(arr)[k], k,
11309 arr[np.argpartition(arr, k, kind='introselect')])
11310
11311
11312@pytest.mark.parametrize("N", np.arange(2, 512))

Callers

nothing calls this directly

Calls 4

assert_arr_partitionedFunction · 0.85
argpartitionMethod · 0.80
sortMethod · 0.45
partitionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…