Skip to content

MAINT: Deprecate Complex Ordering comparisons #17030

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

Closed
wants to merge 2 commits into from

Conversation

vrakesh
Copy link
Member

@vrakesh vrakesh commented Aug 8, 2020

Depends on gh-16700

Follows up on the above PR. This PR deals with deprecation messages, and relevant tests that used complex type ordering comparisons

Comment on lines +332 to +333
if (PyArray_ISCOMPLEX(operands[0]) &&
PyArray_ISCOMPLEX(operands[1]) &&(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should apply if even one of the operands is complex.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, will make the change.

return -1;
}
const char *ufunc_name = ufunc_get_name_cstr(ufunc);
if (PyArray_ISCOMPLEX(operands[0]) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the other operand here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is operation on a single ndarray, hence we do not need check more i assume.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's not. You can see the signature for fmax, fmin, minimum and maximum here: https://numpy.org/doc/stable/reference/ufuncs.html#comparison-functions

All of them also have x2. Though I do realize why this can be confusing: np.max and np.min only take a single array. However, np.max is (roughly) np.maximum.reduce, and you can find the definition for ufunc.reduce here: https://numpy.org/doc/stable/reference/generated/numpy.ufunc.reduce.html#numpy.ufunc.reduce

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I understand

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uniform type resolvers output are uniform types though. So you may be able to only check one of them if you move this to the end of the function.

In fact, I may suggest creating a PyUFunc_SimpleUniformOperationTypeResolverDeprecateComplex which just calls the original version and then does this check. I am not a big fan of the strcmp here, and its not necessary (you will have to change type resolver in the ufunc API creation python script in code generators.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seberg Sure will look into that approach.

@@ -4101,19 +4101,6 @@ class TestArgmax:
([0, 1, 2, np.nan, 3], 3),
([np.nan, 0, 1, 2, 3], 0),
([np.nan, 0, np.nan, 2, 3], 0),
([0, 1, 2, 3, complex(0, np.nan)], 4),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed tests should be put into test_deprecations.py I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see will look into that

Base automatically changed from master to main March 4, 2021 02:05
@InessaPawson
Copy link
Member

@vrakesh Thank you for working on this PR! Do you think you could implement the suggestions above some time soon?

@vrakesh
Copy link
Member Author

vrakesh commented Jul 28, 2022

@InessaPawson I will take a look at this soon (I will get to this by end of July)

@vrakesh
Copy link
Member Author

vrakesh commented Aug 4, 2022

Actively working on this , will have it up as early as I can.

@charris
Copy link
Member

charris commented Feb 20, 2023

@seberg Is this still relevant? @asmeurer Does the array-api have anything to say about this?

@seberg
Copy link
Member

seberg commented Feb 20, 2023

Yeah, we had just talked about it 2 weeks or so ago, that maybe we can do this without worrying too much about having a short-hand replacement (i.e. lexsort being good enough).

@asmeurer
Copy link
Member

I believe the array API doesn't require complex ordering but doesn't restrict it either, but maybe @kgryte can confirm.

@kgryte
Copy link

kgryte commented Feb 20, 2023

@asmeurer Correct. As stated in the design document for complex numbers,

...this specification does not require that a conforming implementation of the array API standard adopt any specific complex number order relation. ... If a conforming implementation chooses to define an ordering for complex numbers, the ordering must be clearly documented.

@ngoldbaum
Copy link
Member

This depends on #16700, which we closed in 2023, so I'm closing this one as well.

@ngoldbaum ngoldbaum closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants