[Numpy-svn] r8633 - in branches/1.5.x/numpy/core: . tests

numpy-svn@scip... numpy-svn@scip...
Sat Aug 14 08:58:18 CDT 2010


Author: rgommers
Date: 2010-08-14 08:58:18 -0500 (Sat, 14 Aug 2010)
New Revision: 8633

Modified:
   branches/1.5.x/numpy/core/numeric.py
   branches/1.5.x/numpy/core/tests/test_numeric.py
Log:
DEP: (backport of r8627) change default behavior of correlate(), old behavior was deprecated in
1.4.0.

The old behavior should be preserved and made available under the name xcorr or
similar. Should be done for 2.0, then the old_behavior keyword can be removed.

Modified: branches/1.5.x/numpy/core/numeric.py
===================================================================
--- branches/1.5.x/numpy/core/numeric.py	2010-08-14 13:58:01 UTC (rev 8632)
+++ branches/1.5.x/numpy/core/numeric.py	2010-08-14 13:58:18 UTC (rev 8633)
@@ -640,16 +640,17 @@
         return _mode_from_name_dict[mode.lower()[0]]
     return mode
 
-def correlate(a,v,mode='valid',old_behavior=True):
+def correlate(a, v, mode='valid', old_behavior=False):
     """
-    Discrete, linear correlation of two 1-dimensional sequences.
+    Cross-correlation of two 1-dimensional sequences.
 
-    This function is equivalent to
+    This function computes the correlation as generally defined in signal
+    processing texts::
 
-    >>> np.convolve(a, v[::-1], mode=mode)
-    ... #doctest: +SKIP
+        z[k] = sum_n a[n] * conj(v[n+k])
 
-    where ``v[::-1]`` is the reverse of `v`.
+    with a and v sequences being zero-padded where necessary and conj being
+    the conjugate.
 
     Parameters
     ----------
@@ -659,28 +660,14 @@
         Refer to the `convolve` docstring.  Note that the default
         is `valid`, unlike `convolve`, which uses `full`.
     old_behavior : bool
-        If True, uses the old, numeric behavior (correlate(a,v) == correlate(v,
+        If True, uses the old behavior from Numeric, (correlate(a,v) == correlate(v,
         a), and the conjugate is not taken for complex arrays). If False, uses
         the conventional signal processing definition (see note).
 
     See Also
     --------
-    convolve : Discrete, linear convolution of two
-               one-dimensional sequences.
-    acorrelate : Discrete correlation following the usual signal processing
-               definition for complex arrays, and without assuming that
-               ``correlate(a, b) == correlate(b, a)``.
+    convolve : Discrete, linear convolution of two one-dimensional sequences.
 
-    Notes
-    -----
-    If `old_behavior` is False, this function computes the correlation as
-    generally defined in signal processing texts::
-
-        z[k] = sum_n a[n] * conj(v[n+k])
-
-    with a and v sequences being zero-padded where necessary and conj being
-    the conjugate.
-
     Examples
     --------
     >>> np.correlate([1, 2, 3], [0, 1, 0.5])
@@ -692,10 +679,12 @@
 
     """
     mode = _mode_from_name(mode)
+# the old behavior should be made available under a different name, see thread
+# http://thread.gmane.org/gmane.comp.python.numeric.general/12609/focus=12630
     if old_behavior:
         warnings.warn("""
-The current behavior of correlate is deprecated for 1.4.0, and will be removed
-for NumPy 1.5.0.
+The old behavior of correlate was deprecated for 1.4.0, and will be completely removed
+for NumPy 2.0.
 
 The new behavior fits the conventional definition of correlation: inputs are
 never swapped, and the second argument is conjugated for complex arrays.""",

Modified: branches/1.5.x/numpy/core/tests/test_numeric.py
===================================================================
--- branches/1.5.x/numpy/core/tests/test_numeric.py	2010-08-14 13:58:01 UTC (rev 8632)
+++ branches/1.5.x/numpy/core/tests/test_numeric.py	2010-08-14 13:58:18 UTC (rev 8633)
@@ -938,7 +938,7 @@
         x = np.array([1, 2, 3, 4+1j], dtype=np.complex)
         y = np.array([-1, -2j, 3+1j], dtype=np.complex)
         r_z = np.array([3+1j, 6, 8-1j, 9+1j, -1-8j, -4-1j], dtype=np.complex)
-        z = np.correlate(x, y, 'full')
+        z = np.correlate(x, y, 'full', old_behavior=self.old_behavior)
         assert_array_almost_equal(z, r_z)
 
     @dec.deprecated()



More information about the Numpy-svn mailing list