Skip to content

ENH: Adding parameters to unwrap#14877

Closed
kmader wants to merge 20 commits intonumpy:mainfrom
kmader:patch-1
Closed

ENH: Adding parameters to unwrap#14877
kmader wants to merge 20 commits intonumpy:mainfrom
kmader:patch-1

Conversation

@kmader
Copy link
Copy Markdown

@kmader kmader commented Nov 11, 2019

Adding optional min_val and max_val to unwrap without changing normal behavior (discont is overwritten unless it is explicitly specified).

I unfortunately not yet followed any of the guidelines and did the PR more to provide a simple reference implementation, I'll try to clean it up

Adding optional min_val and max_val to unwrap without changing normal behavior (discont is overwritten unless it is explicitly specified)
@@ -1501,14 +1506,16 @@ def unwrap(p, discont=pi, axis=-1):
array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) # may vary
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An example here with integers would be good

Copy link
Copy Markdown
Author

@kmader kmader Nov 11, 2019

Choose a reason for hiding this comment

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

how about something like this

>>> unwrap([0, 1, 2, -1, 0], min_val=-1, max_val=3)
array([0., 1., 2., 3., 4.])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You shouldn't need may vary, because it doesn't use floating point printing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add that example

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ping

@eric-wieser eric-wieser changed the title Adding parameters to unwrap ENH: Adding parameters to unwrap Nov 11, 2019
@eric-wieser eric-wieser added 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes 59 - Needs tests labels Nov 11, 2019
kmader and others added 5 commits November 11, 2019 17:42
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
improving documentation in response to input from @eric-wieser
@kmader
Copy link
Copy Markdown
Author

kmader commented Nov 27, 2019

@eric-wieser anything else I should do for this PR?

@eric-wieser eric-wieser removed 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes 59 - Needs tests labels Nov 27, 2019
ddmod = mod(dd + pi, 2*pi) - pi
_nx.copyto(ddmod, pi, where=(ddmod == -pi) & (dd > 0))
ddmod = mod(dd - min_val, max_val - min_val) + min_val
_nx.copyto(ddmod, max_val, where=(ddmod == min_val) & (dd > 0))
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser Nov 27, 2019

Choose a reason for hiding this comment

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

Any idea what this ddmod == min_val condition is for? Can you produce a case that changes behavior based on whether this condition is here?

(I realize it was here before, but wonder if it was never hit due to floating point innacuracies)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not sure, I guess it might come up more with radian sequences and things actually equalling pi?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably easier to investigate only the integer case, floating point rounding is just a distraction.

kmader and others added 5 commits November 27, 2019 23:10
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
changing the input and adding explicit sequences
updating examples
array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) # may vary

>>> unwrap([0, 1, 2, -1, 0], min_val=-1, max_val=3)
array([0., 1., 2., 3., 4.])
Copy link
Copy Markdown
Member

@eric-wieser eric-wieser Jun 26, 2020

Choose a reason for hiding this comment

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

This output should be integral, not floating-point

Copy link
Copy Markdown
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Something is wrong with this function as implemented:

In [16]: unwrap([0, 1, 2, 3, 0, 1, 2, 3], min_val=0, max_val=4)
Out[16]: array([0., 1., 2., 3., 4., 5., 6., 7.])  # ok

In [17]: unwrap([1, 2, 3, 4, 1, 2, 3, 4], min_val=1, max_val=5)
Out[17]: array([1., 2., 3., 4., 5., 6., 7., 8.])  # ok

In [18]: unwrap([2, 3, 4, 5, 2, 3, 4, 5], min_val=2, max_val=6)
Out[18]: array([ 2.,  3.,  4.,  5., 10., 11., 12., 13.])  # wrong?

scimax added a commit to scimax/numpy that referenced this pull request Aug 2, 2020
Base automatically changed from master to main March 4, 2021 02:04
@InessaPawson InessaPawson added 52 - Inactive Pending author response and removed 61 - Stale labels Jun 16, 2022
@mattip
Copy link
Copy Markdown
Member

mattip commented Sep 4, 2024

Closing.

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

Labels

01 - Enhancement 52 - Inactive Pending author response

Projects

Development

Successfully merging this pull request may close these issues.

Parameterize unwrap to allow for different ranges (not just -pi, pi)

5 participants