Skip to content
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

BUG: complex special case for clip #15640

Closed
wants to merge 20 commits into from
Closed

BUG: complex special case for clip #15640

wants to merge 20 commits into from

Conversation

birm
Copy link

@birm birm commented Feb 25, 2020

fixes: #15630

I'm not convinced that this is what's desired, or that the test added is sufficient and/or in the right place. But, it's hopefully a start.

(If someone sees this early, I'll squash my fixup commits once things look passable)

@mattip
Copy link
Member

mattip commented Feb 25, 2020

Maybe you could run python runtests.py to build and test locally rather than starting ~20 CI runs for each small change

def test_complex(self):
val = np.array([0+7j, 1+6j, 2+5j, 3+4j])
result = val.clip(1+5j, 2+6j)
expected = np.array([1+6j, 1+6j, 2+5j, 2+5j])
Copy link
Member

@Qiyu8 Qiyu8 Feb 25, 2020

Choose a reason for hiding this comment

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

According to the clip definition, values outside the interval are clipped to the interval edges, so the value of expected should be np.array([1+5j, 1+6j, 2+5j, 2+6j]) ? But as far as I know, complex cannot be compared, and any operation involving comparison should be disallowed.

@eric-wieser
Copy link
Member

Is this change worth it vs just having the user write:

a.real = a.real.clip(...)
a.imag = a.imag.clip(...)

It's not clear to me that what you're proposing is a sensible generalization of clip

@birm
Copy link
Author

birm commented Feb 25, 2020

Honestly, I don't think there is a fully sensible definition of clip for imaginary numbers. Both of the proposals from the linked issue make some sense, but trying to compare values of incomparable values doesn't make much sense to me personally. That said, right now the behavior of clip on complex inputs is just wrong. Would it be preferable to disallow complex inputs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

np.clip with complex input is untested and has odd behavior
4 participants