[Numpy-svn] r3446 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Nov 17 15:17:32 EST 2006


Author: oliphant
Date: 2006-11-17 14:17:30 -0600 (Fri, 17 Nov 2006)
New Revision: 3446

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Allow data-type objects to be 'repeated' using '*' like ctypes.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-11-17 19:39:02 UTC (rev 3445)
+++ trunk/numpy/core/src/arrayobject.c	2006-11-17 20:17:30 UTC (rev 3446)
@@ -4027,7 +4027,7 @@
 #if PY_VERSION_HEX >= 0x02050000
         (lenfunc)array_length,          /*sq_length*/
         (binaryfunc)NULL,               /* sq_concat is handled by nb_add*/
-        (ssizeargfunc)NULL,
+        (ssizeargfunc)NULL,             
         (ssizeargfunc)array_item_nice,
         (ssizessizeargfunc)array_slice,
         (ssizeobjargproc)array_ass_item,               /*sq_ass_item*/
@@ -10976,7 +10976,6 @@
 }
 
 /* returns 1 if this data-type has an object portion
-
    used when setting the state because hasobject is not stored.
  */
 static int
@@ -11397,6 +11396,26 @@
 }
 
 static PyObject *
+descr_repeat(PyObject *self, Py_ssize_t length)
+{
+        PyObject *tup;
+        PyArray_Descr *new;
+        if (length < 0)
+                return PyErr_Format(PyExc_ValueError,
+#if (PY_VERSION_HEX < 0x02050000)
+                                    "Array length must be >= 0, not %d",
+#else
+                                    "Array length must be >= 0, not %zd",
+#endif
+                                    length);
+        tup = Py_BuildValue("O" NPY_SSIZE_T_PYFMT, self, length);
+        if (tup == NULL) return NULL;
+        PyArray_DescrConverter(tup, &new);
+        Py_DECREF(tup);
+        return (PyObject *)new;
+}
+
+static PyObject *
 descr_subscript(PyArray_Descr *self, PyObject *op)
 {
 
@@ -11449,6 +11468,12 @@
         return NULL;
 }
 
+static PySequenceMethods descr_as_sequence = {
+        descr_length,
+        (binaryfunc)NULL,
+        descr_repeat,
+};
+
 static PyMappingMethods descr_as_mapping = {
         descr_length,                       /*mp_length*/
         (binaryfunc)descr_subscript,        /*mp_subscript*/
@@ -11472,7 +11497,7 @@
         0,                                      /* tp_compare */
         (reprfunc)arraydescr_repr,              /* tp_repr */
         0,                                      /* tp_as_number */
-        0,                                      /* tp_as_sequence */
+        &descr_as_sequence,                     /* tp_as_sequence */
         &descr_as_mapping,                      /* tp_as_mapping */
         0,                                      /* tp_hash */
         0,                                      /* tp_call */




More information about the Numpy-svn mailing list