[SciPy-dev] Note on changeset 5878: Add old_behavior arg for convolve2d and correlate2d

Pearu Peterson pearu.peterson@gmail....
Wed Oct 7 06:57:25 CDT 2009


Hi,

Currently scipy.signal.convolve gives the following warning by default:

"""
Current default behavior of convolve and correlate functions is deprecated.

Convolve and corelate currently swap their arguments if the second argument
has dimensions larger than the first one, and the mode is relative to
the input
with the largest dimension. The new behavior is to never swap the
inputs, which
is what most people expects, and is how correlation is usually defined.

You can control the behavior with the old_behavior flag - the flag will
disappear in scipy 0.9.0, and the functions will then implement the new
behavior only.
"""

The problem right now is that it is difficult to write a stable
application that would not give this warning.
Using old_behavior=False argument means that when upgrading to scipy
0.9.0, the application will become broken because the kw argument will
be removed. In my application the old and new behaviors are identical.

My suggestion is to raise the deprecation warning only when the old
and the new behavior are in conflict. For example, consider the diff below.

What do you think?

Pearu

$ svn diff signaltools.py
Index: signaltools.py
===================================================================
--- signaltools.py	(revision 5953)
+++ signaltools.py	(working copy)
@@ -100,10 +100,11 @@
     val = _valfrommode(mode)

     if old_behavior:
-        warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
         if np.iscomplexobj(in2):
+            # hmm, how is this related to deprecation warning?
             in2 = in2.conjugate()
         if in1.size < in2.size:
+            warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
             swp = in2
             in2 = in1
             in1 = swp
@@ -210,8 +211,8 @@
     slice_obj = [slice(None,None,-1)]*len(kernel.shape)

     if old_behavior:
-        warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
         if (product(kernel.shape,axis=0) > product(volume.shape,axis=0)):
+            warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
             temp = kernel
             kernel = volume
             volume = temp
@@ -383,11 +384,8 @@

     """
     if old_behavior:
-        warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
-
-    if old_behavior:
-        warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
         if (product(np.shape(in2),axis=0) > product(np.shape(in1),axis=0)):
+            warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
             temp = in1
             in1 = in2
             in2 = temp
@@ -436,8 +434,8 @@
            cross-correlation of in1 with in2.

     """
-    if old_behavior:
-        warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
+    #if old_behavior:
+    #    warnings.warn(DeprecationWarning(_SWAP_INPUTS_DEPRECATION_MSG))
     val = _valfrommode(mode)
     bval = _bvalfromboundary(boundary)


More information about the Scipy-dev mailing list