[Numpy-svn] r3207 - in trunk/numpy: . core core/src lib oldnumeric

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Sep 22 14:42:53 CDT 2006


Author: oliphant
Date: 2006-09-22 14:42:43 -0500 (Fri, 22 Sep 2006)
New Revision: 3207

Modified:
   trunk/numpy/add_newdocs.py
   trunk/numpy/core/fromnumeric.py
   trunk/numpy/core/numeric.py
   trunk/numpy/core/src/arraymethods.c
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/src/scalartypes.inc.src
   trunk/numpy/lib/shape_base.py
   trunk/numpy/oldnumeric/misc.py
Log:
Switch order of .put arguments to match the function call.  Eliminate .putmask as a method and make it only a function.

Modified: trunk/numpy/add_newdocs.py
===================================================================
--- trunk/numpy/add_newdocs.py	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/add_newdocs.py	2006-09-22 19:42:43 UTC (rev 3207)
@@ -878,20 +878,19 @@
 
 
 add_newdoc('numpy.core.multiarray', 'ndarray', ('put',
-    """a.put(values, indices, mode) sets a.flat[n] = values[n] for
-    each n in indices. v can be scalar or shorter than indices, and
-    it will repeat.
-
+    """a.put(indices, values, mode) sets a.flat[n] = values[n] for
+    each n in indices. If values is shorter than indices then it
+    will repeat.
     """))
 
 
-add_newdoc('numpy.core.multiarray', 'ndarray', ('putmask',
-    """a.putmask(values, mask) sets a.flat[n] = v[n] for each n where
-    mask.flat[n] is true. v can be scalar.
+add_newdoc('numpy.core.multiarray', 'putmask',
+    """putmask(a, mask, values) sets a.flat[n] = values[n] for each n where
+    mask.flat[n] is true.  If values is not the same size of a and mask then
+    it will repeat.  This gives different behavior than a[mask] = values.
+    """)
 
-    """))
 
-
 add_newdoc('numpy.core.multiarray', 'ndarray', ('ravel',
     """a.ravel([fortran]) return a 1-d array (copy only if needed)
 

Modified: trunk/numpy/core/fromnumeric.py
===================================================================
--- trunk/numpy/core/fromnumeric.py	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/core/fromnumeric.py	2006-09-22 19:42:43 UTC (rev 3207)
@@ -1,7 +1,7 @@
 # Module containing non-deprecated functions borrowed from Numeric.
 
 # functions that are now methods
-__all__ = ['take', 'reshape', 'choose', 'repeat', 'put', 'putmask',
+__all__ = ['take', 'reshape', 'choose', 'repeat', 'put',
            'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',
            'searchsorted', 'alen',
            'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',
@@ -94,15 +94,8 @@
            for i in ind: a.flat[i] = v[i]
        a must be a contiguous numpy array.
     """
-    return a.put(v,ind, mode)
+    return a.put(ind, v, mode)
 
-def putmask (a, mask, v):
-    """putmask(a, mask, v) results in a = v for all places mask is true.
-       If v is shorter than mask it will be repeated as necessary.
-       In particular v can be a scalar or length 1 array.
-    """
-    return a.putmask(v, mask)
-
 def swapaxes(a, axis1, axis2):
     """swapaxes(a, axis1, axis2) returns array a with axis1 and axis2
     interchanged.

Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/core/numeric.py	2006-09-22 19:42:43 UTC (rev 3207)
@@ -14,7 +14,7 @@
            'fromiter', 'array_equal', 'array_equiv',
            'indices', 'fromfunction',
            'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',
-           'ones', 'identity', 'allclose', 'compare_chararrays',
+           'ones', 'identity', 'allclose', 'compare_chararrays', 'putmask',
            'seterr', 'geterr', 'setbufsize', 'getbufsize',
            'seterrcall', 'geterrcall', 'flatnonzero',
            'Inf', 'inf', 'infty', 'Infinity',
@@ -120,8 +120,8 @@
 can_cast = multiarray.can_cast
 lexsort = multiarray.lexsort
 compare_chararrays = multiarray.compare_chararrays
+putmask = multiarray.putmask
 
-
 def asarray(a, dtype=None, order=None):
     """Returns a as an array.
 

Modified: trunk/numpy/core/src/arraymethods.c
===================================================================
--- trunk/numpy/core/src/arraymethods.c	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/core/src/arraymethods.c	2006-09-22 19:42:43 UTC (rev 3207)
@@ -40,10 +40,10 @@
 {
 	PyObject *indices, *values;
         NPY_CLIPMODE mode=NPY_RAISE;
-	static char *kwlist[] = {"values", "indices", "mode", NULL};
+	static char *kwlist[] = {"indices", "values", "mode", NULL};
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&", kwlist,
-					 &values, &indices,
+					 &indices, &values,
                                          PyArray_ClipmodeConverter,
                                          &mode))
 		return NULL;
@@ -51,19 +51,6 @@
 }
 
 static PyObject *
-array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds)
-{
-	PyObject *mask, *values;
-
-	static char *kwlist[] = {"values", "mask", NULL};
-
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist,
-					 &values, &mask))
-		return NULL;
-	return PyArray_PutMask(self, values, mask);
-}
-
-static PyObject *
 array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds)
 {
         PyArray_Dims newshape;
@@ -1827,8 +1814,6 @@
 	    METH_VARARGS | METH_KEYWORDS, NULL},
 	{"put",	(PyCFunction)array_put,
 	    METH_VARARGS | METH_KEYWORDS, NULL},
-	{"putmask", (PyCFunction)array_putmask,
-	    METH_VARARGS | METH_KEYWORDS, NULL},
 	{"ravel", (PyCFunction)array_ravel,
 	    METH_VARARGS, NULL},
 	{"repeat", (PyCFunction)array_repeat,

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/core/src/multiarraymodule.c	2006-09-22 19:42:43 UTC (rev 3207)
@@ -3648,6 +3648,22 @@
         return NULL;
 }
 
+static PyObject *
+array_putmask(PyObject *module, PyObject *args, PyObject *kwds)
+{
+	PyObject *mask, *values;
+        PyObject *array; 
+        
+	static char *kwlist[] = {"arr", "mask", "values", NULL};
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:putmask", kwlist,
+                                         &PyArray_Type,
+					 &array, &mask, &values))
+		return NULL;
+
+	return PyArray_PutMask(array, values, mask);
+}
+
 /*MULTIARRAY_API
  Put values into an array according to a mask.
 */
@@ -6687,6 +6703,8 @@
 	 METH_VARARGS, NULL},
 	{"lexsort", (PyCFunction)array_lexsort,
 	 METH_VARARGS | METH_KEYWORDS, NULL},
+        {"putmask", (PyCFunction)array_putmask,
+         METH_VARARGS | METH_KEYWORDS, NULL},
 	{"fromstring",(PyCFunction)array_fromString,
 	 METH_VARARGS|METH_KEYWORDS, NULL},
 	{"fromiter",(PyCFunction)array_fromIter,

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/core/src/scalartypes.inc.src	2006-09-22 19:42:43 UTC (rev 3207)
@@ -1122,7 +1122,7 @@
 
 /**begin repeat
 
-#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape, choose#
+#name=take, getfield, put, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort, round, argmax, argmin, max, min, ptp, any, all, resize, reshape, choose#
 */
 
 static PyObject *
@@ -1331,8 +1331,6 @@
          METH_VARARGS|METH_KEYWORDS, NULL},
         {"put", (PyCFunction)gentype_put,
          METH_VARARGS|METH_KEYWORDS, NULL},
-        {"putmask",     (PyCFunction)gentype_putmask,
-         METH_VARARGS|METH_KEYWORDS, NULL},
         {"repeat",      (PyCFunction)gentype_repeat,
          METH_VARARGS|METH_KEYWORDS, NULL},
         {"choose",      (PyCFunction)gentype_choose,

Modified: trunk/numpy/lib/shape_base.py
===================================================================
--- trunk/numpy/lib/shape_base.py	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/lib/shape_base.py	2006-09-22 19:42:43 UTC (rev 3207)
@@ -26,7 +26,7 @@
     indlist.remove(axis)
     i[axis] = slice(None,None)
     outshape = asarray(arr.shape).take(indlist)
-    i.put(ind, indlist)
+    i.put(indlist, ind)
     res = func1d(arr[tuple(i.tolist())],*args)
     #  if res is a number, then we have a smaller output array
     if isscalar(res):
@@ -42,7 +42,7 @@
                 ind[n-1] += 1
                 ind[n] = 0
                 n -= 1
-            i.put(ind,indlist)
+            i.put(indlist,ind)
             res = func1d(arr[tuple(i.tolist())],*args)
             outarr[ind] = res
             k += 1
@@ -63,7 +63,7 @@
                 ind[n-1] += 1
                 ind[n] = 0
                 n -= 1
-            i.put(ind, indlist)
+            i.put(indlist, ind)
             res = func1d(arr[tuple(i.tolist())],*args)
             outarr[tuple(i.tolist())] = res
             k += 1

Modified: trunk/numpy/oldnumeric/misc.py
===================================================================
--- trunk/numpy/oldnumeric/misc.py	2006-09-22 08:02:11 UTC (rev 3206)
+++ trunk/numpy/oldnumeric/misc.py	2006-09-22 19:42:43 UTC (rev 3207)
@@ -1,12 +1,12 @@
 # Functions that already have the correct syntax or miscellaneous functions
 
 
-__all__ = ['load', 'sort', 'copy_reg', 'clip', 'putmask', 'Unpickler', 'rank',
+__all__ = ['load', 'sort', 'copy_reg', 'clip', 'Unpickler', 'rank',
            'sign', 'shape', 'types', 'allclose', 'size',
            'choose', 'swapaxes', 'array_str',
-           'pi', 'math', 'concatenate',
+           'pi', 'math', 'concatenate', 'putmask', 'put',
            'around', 'vdot', 'transpose', 'array2string', 'diagonal',
-           'searchsorted', 'put', 'fromfunction', 'copy', 'resize',
+           'searchsorted', 'fromfunction', 'copy', 'resize',
            'array_repr', 'e', 'StringIO', 'pickle',
            'argsort', 'convolve', 'loads', 'cross_correlate',
            'Pickler', 'dot', 'outerproduct', 'innerproduct', 'insert']
@@ -19,10 +19,10 @@
 import copy_reg
 from pickle import load, loads
 
-from numpy import sort, clip, putmask, rank, sign, shape, allclose, size,\
-     choose, swapaxes, array_str, array_repr, e, pi, \
+from numpy import sort, clip, rank, sign, shape, putmask, allclose, size,\
+     choose, swapaxes, array_str, array_repr, e, pi, put, \
      fromfunction, resize, around, concatenate, vdot, transpose, \
-     diagonal, searchsorted, put, argsort, convolve, dot, \
+     diagonal, searchsorted, argsort, convolve, dot, \
      outer as outerproduct, inner as innerproduct, correlate as cross_correlate, \
      place as insert
 



More information about the Numpy-svn mailing list