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

fix bugs in unwrap function #16977

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions numpy/lib/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,10 +1537,10 @@ def unwrap(p, discont=pi, axis=-1):
slice1 = [slice(None, None)]*nd # full slices
slice1[axis] = slice(1, None)
slice1 = tuple(slice1)
ddmod = mod(dd + pi, 2*pi) - pi
_nx.copyto(ddmod, pi, where=(ddmod == -pi) & (dd > 0))
ddmod = mod(dd + discont, 2 * discont) - discont
Copy link
Member

@eric-wieser eric-wieser Aug 1, 2020

Choose a reason for hiding this comment

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

This 2*pi change is definitely incorrect - the docs refer specifically to comparing discont to pi and 2*pi, but after this change the function does not mention pi at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, absolutely true, the meaning of discont was misused here. But the logic is correct. I will correct this. I would propose a name like ´interval_sizesincemin_valandmax_val` from #14877 don't make sense at all. It only corrects differences, so it will do the same correction for

unwrap([ 1, 2, 3, 4, 5, 6, 1, 2, 3], min_val=1, max_val=7)

as for

unwrap([ 1, 2, 3, 4, 5, 6, 1, 2, 3], min_val=0, max_val=6)

. Only the difference max_val - min_val matters.

Copy link
Member

Choose a reason for hiding this comment

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

since min_valandmax_val from #14877 don't make sense at all.

I don't agree with that - they makes sense to me, and should satisfy unwrap(arr, min=-a, max=a) + b== unwrap(arr + b, min=-a + b, max=a + b)

_nx.copyto(ddmod, discont, where=(ddmod == -discont) & (dd > 0))
ph_correct = ddmod - dd
_nx.copyto(ph_correct, 0, where=abs(dd) < discont)
_nx.copyto(ph_correct, 0, where=abs(dd) < discont * 1.5)
up = array(p, copy=True, dtype='d')
up[slice1] = p[slice1] + ph_correct.cumsum(axis)
return up
Expand Down