summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorseberg <sebastian@sipsolutions.net>2014-08-27 13:23:22 +0100
committerseberg <sebastian@sipsolutions.net>2014-08-27 13:23:22 +0100
commit145422826e34e880eb16a85bea6cee01cb83556f (patch)
tree5fd0ffe463ef90122e94dc37dadfb7576bacb90f /numpy
parent0104e62e27e9fede5ffd066da16e029a3e8d99cc (diff)
parent8724ed764fbcab88b4962aeda23c84fba972ac4b (diff)
downloadnumpy-145422826e34e880eb16a85bea6cee01cb83556f.tar.gz
Merge pull request #5002 from juliantaylor/convolve-nocopy
ENH: remove unnecessary copy of convolve inputs
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/numeric.py2
-rw-r--r--numpy/core/tests/test_numeric.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 5d7407ce0..efd8af45d 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -985,7 +985,7 @@ def convolve(a,v,mode='full'):
array([ 2.5])
"""
- a, v = array(a, ndmin=1), array(v, ndmin=1)
+ a, v = array(a, copy=False, ndmin=1), array(v, copy=False, ndmin=1)
if (len(v) > len(a)):
a, v = v, a
if len(a) == 0 :
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 483484467..3dea80d14 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1920,6 +1920,13 @@ class _TestCorrelate(TestCase):
z = np.correlate(self.y, self.x, 'full', old_behavior=self.old_behavior)
assert_array_almost_equal(z, self.z2)
+ def test_no_overwrite(self):
+ d = np.ones(100)
+ k = np.ones(3)
+ np.correlate(d, k)
+ assert_array_equal(d, np.ones(100))
+ assert_array_equal(k, np.ones(3))
+
class TestCorrelate(_TestCorrelate):
old_behavior = True
def _setup(self, dt):
@@ -1958,6 +1965,19 @@ class TestCorrelateNew(_TestCorrelate):
z = np.correlate(y, x, 'full', old_behavior=self.old_behavior)
assert_array_almost_equal(z, r_z)
+class TestConvolve(TestCase):
+ def test_object(self):
+ d = [1.] * 100
+ k = [1.] * 3
+ assert_array_almost_equal(np.convolve(d, k)[2:-2], np.full(98, 3))
+
+ def test_no_overwrite(self):
+ d = np.ones(100)
+ k = np.ones(3)
+ np.convolve(d, k)
+ assert_array_equal(d, np.ones(100))
+ assert_array_equal(k, np.ones(3))
+
class TestArgwhere(object):
def test_2D(self):
x = np.arange(6).reshape((2, 3))