[Numpy-discussion] Re: numarray questions

Todd Miller jmiller at stsci.edu
Mon Dec 16 14:22:03 CST 2002


Mika Illouz wrote:

>Hi Todd,
>
>  
>
>>Thanks for the encouragement!   numarray-0.4 is coming out today...
>>    
>>
>
>Finally got around to playing with version 0.4 and the new NA_New (code
>attached).  Wnen I ran the test, I got the following trace:
>
>  
>
>>>>import _test_numarray
>>>>z = _test_numarray.t1()
>>>>        
>>>>
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "/usr/lib/python2.2/site-packages/numarray/numarray.py", line 432, in __init__
>    bytestride=bytestride)
>  File "/usr/lib/python2.2/site-packages/numarray/ndarray.py", line 173, in __init__
>    self._data = memory.new_memory(size)
>OverflowError: long int too large to convert to int
>
>What am I doing wrong?
>
The parameter order in the call in t1() should be:

NA_New(a, tInt32, 1, length)

Because it is:

NA_New(a, tInt32, length, 1)

numarray thinks you're declaring a 5 dimensional array with some bizarre 
dimensions from "undefined values" on the stack.  One of these 
dimensions appears to be > MAX_INT.

>Thanks again,
>Mika
>  
>
Regards,
Todd

>  
>
>------------------------------------------------------------------------
>
>#include <Python.h>
>#include <libnumarray.h>
>
>static PyObject* t1( PyObject* self, PyObject* args )
>{
>  int length = 5;
>  int* a = new int[ length ];
>  for ( int i = 0 ; i < length ; i++ ) {
>    a[i] = i;
>  }
>
>  PyArrayObject* vec = NA_New( a, tInt32, length, 1 );
>  return (PyObject*)vec;
>  // return NA_ReturnOutput( NULL, vec );
>
>}
>
>static PyMethodDef TestNumarrayMethods[] = {
>  {"t1",  
>   t1, 
>   METH_VARARGS, 
>   "first test"
>  },
>  { NULL, NULL, 0, NULL}
>};
>
>extern "C" void init_test_numarray()
>{
>  Py_InitModule( "_test_numarray", TestNumarrayMethods );
>  import_libnumarray();
>}
>  
>







More information about the Numpy-discussion mailing list