From: Nadav H. <na...@vi...> - 2004-06-14 10:40:25
|
For a simulation project I am working on I've subclasses ArrayType. I was able to do much of my intentions until in one place when I tried to make an array from a list of arrays I got an error message: . . . File "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line 325, in array return fromlist(sequence, type, shape) File "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line 212, in fromlist a = a.astype(type) File "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line 630, in astype retarr = self.__class__(buffer=None, shape=self._shape, type=type) TypeError: __init__() got an unexpected keyword argument 'buffer' The analysis of the code showed that: 1. The NumArray class method definitions depends on the _PROTOTYPE flag 2. The post-mortem debugging showed that when the error flagged, the value of the variable _PROTOTYPE was 0 In a stand alone script there was no problem to do the list-> array conversion: >>> import numarray as N >>> import NumImage as NI # My module with the derived class >>> a = N.arange(4) >>> ia = NI.Cimage(N.arange(4)) # CImage is a derivative of NumImage >>> a array([0, 1, 2, 3]) >>> ia Cimage([0, 1, 2, 3]) >>> N.array([a+i for i in range(3)]) array([[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]]) >>> N.array([ia+i for i in range(3)]) # OK here, but failed as a part of a complex script Cimage([[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]]) My questions are: 1. Is this flag is in use? If I set it to 0 will I be able to derive a class from the "C code"? 2. Any intelligent solution? Nadav. |
From: Perry G. <pe...@st...> - 2004-06-14 18:27:21
|
Unfortunately Todd is away this week. I can try to help if you can illustrate what is being tried in the more complex script that you are referring to that is failing. Offhand, I didn't believe that _PROTOTYPE should ever be set to 0 unless it was done so explicitly for testing or debugging purposes (but perhaps I misremember). Thanks, Perry Nadav Horesh wrote: > For a simulation project I am working on I've subclasses ArrayType. I > was able to do much of my intentions until in one place when I tried to > make an array from a list of arrays I got an error message: > > . > . > . > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 325, in array > return fromlist(sequence, type, shape) > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 212, in fromlist > a = a.astype(type) > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 630, in astype > retarr = self.__class__(buffer=None, shape=self._shape, type=type) > TypeError: __init__() got an unexpected keyword argument 'buffer' > > The analysis of the code showed that: > > 1. The NumArray class method definitions depends on the _PROTOTYPE flag > 2. The post-mortem debugging showed that when the error flagged, the > value of the variable _PROTOTYPE was 0 > > In a stand alone script there was no problem to do the list-> array > conversion: > > >>> import numarray as N > >>> import NumImage as NI # My module with the derived class > >>> a = N.arange(4) > >>> ia = NI.Cimage(N.arange(4)) # CImage is a derivative of NumImage > >>> a > array([0, 1, 2, 3]) > >>> ia > Cimage([0, 1, 2, 3]) > >>> N.array([a+i for i in range(3)]) > array([[0, 1, 2, 3], > [1, 2, 3, 4], > [2, 3, 4, 5]]) > >>> N.array([ia+i for i in range(3)]) # OK here, but failed as a part > of a complex script > Cimage([[0, 1, 2, 3], > [1, 2, 3, 4], > [2, 3, 4, 5]]) > > > My questions are: > > 1. Is this flag is in use? If I set it to 0 will I be able to derive > a class from the "C code"? > 2. Any intelligent solution? > > Nadav. > > > ------------------------------------------------------- > This SF.Net email is sponsored by the new InstallShield X. > From Windows to Linux, servers to mobile, InstallShield X is the > one installation-authoring solution that does it all. Learn more and > evaluate today! http://www.installshield.com/Dev2Dev/0504 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |
From: Todd M. <jm...@st...> - 2004-06-21 14:59:37
|
On Mon, 2004-06-14 at 06:39, Nadav Horesh wrote: > For a simulation project I am working on I've subclasses ArrayType. I > was able to do much of my intentions until in one place when I tried to > make an array from a list of arrays I got an error message: > > . > . > . > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 325, in array > return fromlist(sequence, type, shape) > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 212, in fromlist > a = a.astype(type) > File > "/usr/local/lib/python2.3/site-packages/numarray/numarraycore.py", line > 630, in astype > retarr = self.__class__(buffer=None, shape=self._shape, type=type) > TypeError: __init__() got an unexpected keyword argument 'buffer' > > The analysis of the code showed that: > > 1. The NumArray class method definitions depends on the _PROTOTYPE flag > 2. The post-mortem debugging showed that when the error flagged, the > value of the variable _PROTOTYPE was 0 > > In a stand alone script there was no problem to do the list-> array > conversion: > > >>> import numarray as N > >>> import NumImage as NI # My module with the derived class > >>> a = N.arange(4) > >>> ia = NI.Cimage(N.arange(4)) # CImage is a derivative of NumImage > >>> a > array([0, 1, 2, 3]) > >>> ia > Cimage([0, 1, 2, 3]) > >>> N.array([a+i for i in range(3)]) > array([[0, 1, 2, 3], > [1, 2, 3, 4], > [2, 3, 4, 5]]) > >>> N.array([ia+i for i in range(3)]) # OK here, but failed as a part > of a complex script > Cimage([[0, 1, 2, 3], > [1, 2, 3, 4], > [2, 3, 4, 5]]) > > > My questions are: > > 1. Is this flag is in use? Yes. > If I set it to 0 will I be able to derive > a class from the "C code"? Exactly. _PROTOTYPE hides the original Python implementations of things that have since been moved to C; it is a compile time flag. I keep the prototype Python code around because it is much easier to debug and very useful when modifying or extending numarray. Regards, Todd |