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

Method test_sort

numpy/core/tests/test_multiarray.py:2021–2038  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2019 assert_raises(ValueError, lambda: a.transpose(0, 1, 2))
2020
2021 def test_sort(self):
2022 # test ordering for floats and complex containing nans. It is only
2023 # necessary to check the less-than comparison, so sorts that
2024 # only follow the insertion sort path are sufficient. We only
2025 # test doubles and complex doubles as the logic is the same.
2026
2027 # check doubles
2028 msg = "Test real sort order with nans"
2029 a = np.array([np.nan, 1, 0])
2030 b = np.sort(a)
2031 assert_equal(b, a[::-1], msg)
2032 # check complex
2033 msg = "Test complex sort order with nans"
2034 a = np.zeros(9, dtype=np.complex128)
2035 a.real += [np.nan, np.nan, np.nan, 1, 0, 1, 1, 0, 0]
2036 a.imag += [np.nan, 1, 0, np.nan, np.nan, 1, 0, 1, 0]
2037 b = np.sort(a)
2038 assert_equal(b, a[::-1], msg)
2039
2040 # all c scalar sorts use the same code with different types
2041 # so it suffices to run a quick check with one type. The number

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
sortMethod · 0.80

Tested by

no test coverage detected