summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMax Kellermeier <max.kellermeier@hotmail.de>2020-08-21 22:55:29 +0200
committerMax Kellermeier <max.kellermeier@hotmail.de>2020-08-21 22:55:29 +0200
commit00dcda244bc1eb58cb3b4f30c7b18a71a8569194 (patch)
treeb04c853e60ae1b4a0b7d4cece2061ec0fe6bfca9 /numpy
parent3da050660f2140ae387d67218f457442f89fe94e (diff)
downloadnumpy-00dcda244bc1eb58cb3b4f30c7b18a71a8569194.tar.gz
Updated incorrect argument in tests. boundary correction for int and float.
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/function_base.py4
-rw-r--r--numpy/lib/tests/test_function_base.py11
2 files changed, 9 insertions, 6 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 491b25915..2a942a13a 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1554,11 +1554,13 @@ def unwrap(p, discont=None, axis=-1, *, period=2*pi):
if _nx.issubdtype(dtype, _nx.integer):
interval_low = -(period // 2)
interval_high = -interval_low
+ boundary_ambiguous = (period % 2 == 0)
else:
interval_low = -period / 2
interval_high = -interval_low
+ boundary_ambiguous = True
ddmod = mod(dd - interval_low, period) + interval_low
- if period % 2 == 0:
+ if boundary_ambiguous:
# for `mask = (abs(dd) == period/2)`, the above line made `ddmod[mask] == -period/2`.
# correct these such that `ddmod[mask] == sign(dd[mask])*period/2`.
_nx.copyto(ddmod, interval_high, where=(ddmod == interval_low) & (dd > 0))
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 44ff7ea81..2ebde9aec 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1759,20 +1759,21 @@ class TestUnwrap:
def test_period(self):
# check that unwrap removes jumps greater that 255
- assert_array_equal(unwrap([1, 1 + 256], interval_size=255), [1, 2])
+ assert_array_equal(unwrap([1, 1 + 256], period=255), [1, 2])
# check that unwrap maintains continuity
- assert_(np.all(diff(unwrap(rand(10) * 1000, interval_size=255)) < 255))
+ assert_(np.all(diff(unwrap(rand(10) * 1000, period=255)) < 255))
# check simple case
simple_seq = np.array([0, 75, 150, 225, 300])
wrap_seq = np.mod(simple_seq, 255)
- assert_array_equal(unwrap(wrap_seq, interval_size=255), simple_seq)
+ assert_array_equal(unwrap(wrap_seq, period=255), simple_seq)
# check custom discont value
uneven_seq = np.array([0, 75, 150, 225, 300, 430])
wrap_uneven = np.mod(uneven_seq, 250)
- no_discont = unwrap(wrap_uneven, interval_size=250)
+ no_discont = unwrap(wrap_uneven, period=250)
assert_array_equal(no_discont, [0, 75, 150, 225, 300, 180])
- sm_discont = unwrap(wrap_uneven, interval_size=250, discont=140)
+ sm_discont = unwrap(wrap_uneven, period=250, discont=140)
assert_array_equal(sm_discont, [0, 75, 150, 225, 300, 430])
+ assert sm_discont.dtype == wrap_uneven.dtype
class TestFilterwindows: