-
-
Notifications
You must be signed in to change notification settings - Fork 2
FEAT: Implementing NPY_DT_PyArray_ArrFuncs_compare
#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SwayamInSync
wants to merge
3
commits into
numpy:main
Choose a base branch
from
SwayamInSync:46
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−8
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5688,3 +5688,60 @@ def test_quadprecision_large_exponents(val, pow): | |
| value_str = mp.nstr(mp.mpf(str(value)), 33) | ||
| expected_str = mp.nstr(mp_value, 33) | ||
| assert value_str == expected_str, f"QuadPrecision({val}) ** {pow} = {value_str}, expected {expected_str}" | ||
|
|
||
| class TestSortingOperations: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a newline above
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| """Test suite for sorting operations using the compare slot.""" | ||
|
|
||
| @pytest.mark.parametrize("backend", ["sleef", "longdouble"]) | ||
| @pytest.mark.parametrize("input_arr,expected_sorted,expected_indices", [ | ||
| # Basic integers: [3, 1, 4, 1, 5, 9, 2, 6] -> sorted: [1, 1, 2, 3, 4, 5, 6, 9] | ||
| ([3, 1, 4, 1, 5, 9, 2, 6], [1, 1, 2, 3, 4, 5, 6, 9], [1, 3, 6, 0, 2, 4, 7, 5]), | ||
| # Negative numbers | ||
| ([3, -1, 4, -5, 2, -6], [-6, -5, -1, 2, 3, 4], [5, 3, 1, 4, 0, 2]), | ||
| # Floating-point values | ||
| ([3.14, 1.41, 2.72, 0.57], [0.57, 1.41, 2.72, 3.14], [3, 1, 2, 0]), | ||
| # Single element | ||
| ([42], [42], [0]), | ||
| # Empty array | ||
| ([], [], []), | ||
| ]) | ||
| def test_sort_and_argsort(self, backend, input_arr, expected_sorted, expected_indices): | ||
| """Test sort and argsort with various inputs.""" | ||
| x = np.array(input_arr, dtype=QuadPrecDType(backend=backend)) | ||
|
|
||
| # Test sort | ||
| sorted_x = np.sort(x) | ||
| expected = np.array(expected_sorted, dtype=QuadPrecDType(backend=backend)) | ||
| np.testing.assert_array_equal(sorted_x, expected) | ||
|
|
||
| # Test argsort | ||
| indices = np.argsort(x) | ||
| np.testing.assert_array_equal(indices, np.array(expected_indices)) | ||
| # Verify argsort returns integer type | ||
| assert np.issubdtype(indices.dtype, np.integer) | ||
|
|
||
| @pytest.mark.parametrize("backend", ["sleef", "longdouble"]) | ||
| @pytest.mark.parametrize("input_arr,check_fn", [ | ||
| # NaN should be sorted to the end | ||
| ([3, float('nan'), 1, 2], lambda s: s[0] == 1 and s[1] == 2 and s[2] == 3 and np.isnan(s[3])), | ||
| # Inf handling | ||
| ([3, float('inf'), 1, float('-inf'), 2], | ||
| lambda s: s[0] == float('-inf') and s[1] == 1 and s[2] == 2 and s[3] == 3 and s[4] == float('inf')), | ||
| # Multiple NaNs | ||
| ([float('nan'), 1, float('nan'), 2], lambda s: s[0] == 1 and s[1] == 2 and np.isnan(s[2]) and np.isnan(s[3])), | ||
| ]) | ||
| def test_sort_special_values(self, backend, input_arr, check_fn): | ||
| """Test sorting with NaN and Inf values.""" | ||
| x = np.array(input_arr, dtype=QuadPrecDType(backend=backend)) | ||
| sorted_x = np.sort(x) | ||
| assert check_fn(sorted_x) | ||
|
|
||
| @pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"]) | ||
| @pytest.mark.parametrize("backend", ["sleef", "longdouble"]) | ||
| def test_sort_algorithms(self, backend, kind): | ||
| """Test that different sorting algorithms work with the compare function.""" | ||
| x = np.array([5, 2, 8, 1, 9, 3], dtype=QuadPrecDType(backend=backend)) | ||
| sorted_x = np.sort(x, kind=kind) | ||
| expected = np.array([1, 2, 3, 5, 8, 9], dtype=QuadPrecDType(backend=backend)) | ||
| np.testing.assert_array_equal(sorted_x, expected) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, as in the main comment this will be set for deprecation soon, technically is already an older version of the API.