fix bugs in unwrap function#16977
fix bugs in unwrap function#16977tatsuoka999 wants to merge 1 commit intonumpy:masterfrom tatsuoka999:fix_unwrap
Conversation
|
See also #14877, where some questions were raised about the correctness of this function. |
@eric-wieser, thank you for your prompt reply. The following code draws two normalized phase response, one is calculated in radian and another is in degree. Code (Python ver 3.7.7): The correct result is obtained in degree by using the pull request code. @scimax also mentioned about the problem in the case discont=180 in #14877. |
|
I withdraw about L1543. It was wrong. I am sorry to bother you. |
|
I have to say I took a quick look yesterday and was very confused about the factor 1.5, but as I had no time to think this through I didn't want to ask yet. |
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
since
min_valandmax_valfrom #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)
|
I compared it to my solution, and, from a semantics point of view I came up with the same solution. But I couldn't solve the issue with integers returning floats, which are mentioned in #14877 . @eric-wieser , the tests you mentioned in #14877 which failed, are working with this. It's just a mistake in L1540. |
|
I just realized, I can't propose corrections. Neither here nor in #14877 . Shall I open another PR for that? |
|
I misunderstood that unwrap() could also be used in degree by changing discont to 180. Also, I confirmed #16987. |
|
Thanks for the thorough summary @tatsuoka999, reports with graphs make a nice change :) |



Fixed the following two bugs.
Bug1: Returned wrong result when the parameter "discont" is not pi.
Bug2: Wrapped when the diff value is a little larger than pi or discont.
Changes:
L1540, L1541 for Bug1.
L1543 for Bug2.
Example for Bug2:
