From: Andrew M. <And...@AB...> - 2006-10-17 17:28:21
|
I would like to use the built-in array_repr in numpy, because I need a fast repr that does not contain new line characters. I see no way of doing this without editing the code in numeric.py, and I hate to edit other people's libraries. from numpy import array causes numeric.py to be executed, which includes a call to multiarray.set_string_function(array_repr, 1) If I want to "undo" this, there is no way of doing it. I would like to unset the repr with: numpy.set_string_function(None, 1) but this raises a TypeError because None is not callable. This behavior was the same in Numeric, and in that case I edited the code in Numeric.py but it would be nice if I didn't have to do that. Should I submit a patch for this? Andrew MacKeith |
From: Travis O. <oli...@ee...> - 2006-10-17 17:46:24
|
Andrew MacKeith wrote: >I would like to use the built-in array_repr in numpy, because >I need a fast repr that does not contain new line characters. >I see no way of doing this without editing the code in numeric.py, >and I hate to edit other people's libraries. > >from numpy import array >causes numeric.py to be executed, which includes a call to >multiarray.set_string_function(array_repr, 1) > >If I want to "undo" this, there is no way of doing it. > > Why do want to "undo" this? >I would like to unset the repr with: >numpy.set_string_function(None, 1) > > I don't understand what you are trying to do. Why don't you just set the string function to an actual callable. What edits do you propose to make? -Travis |
From: Andrew M. <And...@AB...> - 2006-10-17 18:15:45
|
Travis Oliphant wrote: >Andrew MacKeith wrote: > > > >>I would like to use the built-in array_repr in numpy, because >>I need a fast repr that does not contain new line characters. >>I see no way of doing this without editing the code in numeric.py, >>and I hate to edit other people's libraries. >> >> >> >>from numpy import array > > >>causes numeric.py to be executed, which includes a call to >>multiarray.set_string_function(array_repr, 1) >> >>If I want to "undo" this, there is no way of doing it. >> >> >> >> >Why do want to "undo" this? > > > >>I would like to unset the repr with: >>numpy.set_string_function(None, 1) >> >> >> >> >I don't understand what you are trying to do. Why don't you just set >the string function to an actual callable. > Since arrayobject.c contains a fast repr function, I would like to use that. Why reinvent the wheel. >What edits do you propose to >make? > > If you mean how would I propose to change the code, I would have array_set_string_function recognise None as an acceptable argument and PyArray_SetStringFunction would recognise this to set PyArray_ReprFunction = array_repr; These is the (untested) code. multiarraymodule.c: static PyObject * array_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) { PyObject *op; int repr=1; static char *kwlist[] = {"f", "repr", NULL}; if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &op, &repr)) return NULL; if (!PyCallable_Check(op) and op != Py_None) { PyErr_SetString(PyExc_TypeError, "Argument must be callable."); return NULL; } PyArray_SetStringFunction(op, repr); Py_INCREF(Py_None); return Py_None; } arrayobject.c: static void PyArray_SetStringFunction(PyObject *op, int repr) { if (repr) { /* Dispose of previous callback */ Py_XDECREF(PyArray_ReprFunction); if (op == Py_None) { PyArray_ReprFunction = array_repr; } else { /* Add a reference to new callback */ Py_XINCREF(op); /* Remember new callback */ PyArray_ReprFunction = op; } } else { /* Dispose of previous callback */ Py_XDECREF(PyArray_StrFunction); if (op == Py_None) { PyArray_StrFunction = array_str; } else { /* Add a reference to new callback */ Py_XINCREF(op); /* Remember new callback */ PyArray_StrFunction = op; } } } >-Travis > > > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job easier >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >_______________________________________________ >Numpy-discussion mailing list >Num...@li... >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > > |
From: Andrew M. <And...@AB...> - 2006-10-17 19:33:51
|
Travis Oliphant wrote: >Ah!, I get it. You want to be able to reset to the C-defined >array_repr function. The one that gets over-written on import. That >makes sense. And is definitely do-able. > >Please file a ticket. > > Can you point me to how to file a ticket. Thanks Andrew > > >-Travis > > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job easier >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >_______________________________________________ >Numpy-discussion mailing list >Num...@li... >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > > |
From: Travis O. <oli...@ee...> - 2006-10-17 19:21:39
|
Ah!, I get it. You want to be able to reset to the C-defined array_repr function. The one that gets over-written on import. That makes sense. And is definitely do-able. Please file a ticket. -Travis |
From: Charles R H. <cha...@gm...> - 2006-10-17 19:51:09
|
On 10/17/06, Andrew MacKeith <And...@ab...> wrote: > > Travis Oliphant wrote: > > >Ah!, I get it. You want to be able to reset to the C-defined > >array_repr function. The one that gets over-written on import. That > >makes sense. And is definitely do-able. > > > >Please file a ticket. > > > >** > Can you point me to how to file a ticket. > Thanks Go to http://projects.scipy.org/scipy/numpy/report, login or register (required), then choose new ticket from the menu at the top. BTW, I wish all this was more transparent to the casual visitor to the scipy site. There should be a link on the front page (numpy bugs or something) and a short explanation about needing to register to file a new ticket. Maybe something in the Cookbook would help. Chuck |
From: Andrew.MacKeith <And...@AB...> - 2006-10-18 01:05:36
|
Charles R Harris wrote: > > > On 10/17/06, Andrew MacKeith <And...@ab... > <mailto:And...@ab...>> wrote: > > Travis Oliphant wrote: > > >Ah!, I get it. You want to be able to reset to the C-defined > >array_repr function. The one that gets over-written on > import. That > >makes sense. And is definitely do-able. > > > >Please file a ticket. > > > > > Can you point me to how to file a ticket. > Thanks > > > Go to http://projects.scipy.org/scipy/numpy/report > <http://projects.scipy.org/scipy/numpy/report>, login or register > (required), then choose new ticket from the menu at the top. > > BTW, I wish all this was more transparent to the casual visitor to the > scipy site. There should be a link on the front page (numpy bugs or > something) and a short explanation about needing to register to file a > new ticket. Maybe something in the Cookbook would help. > > Chuck Thanks for the info. I filed a ticket. Andrew > > >------------------------------------------------------------------------ > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job easier >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > >------------------------------------------------------------------------ > >_______________________________________________ >Numpy-discussion mailing list >Num...@li... >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > |