[Numpy-discussion] Subclassing NumArray: _PROTOTYPE flag issue

Nadav Horesh nadavh at visionsense.com
Wed Jun 16 08:43:14 EDT 2004


OK it is my mistake, I did not implement the buffer argument in the constructor of my derived class. Still I have some minor problems, but nothing to bother about for the time being.

It is very compelling to subclass NumArray, I wish that it will be documented when version 1.0 will be released.

  Nadav


-----Original Message-----
From:	Perry Greenfield [mailto:perry at stsci.edu]
Sent:	Mon 14-Jun-04 21:27
To:	Nadav Horesh; numpy
Cc:	
Subject:	RE: [Numpy-discussion] Subclassing NumArray: _PROTOTYPE flag issue
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
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>








More information about the NumPy-Discussion mailing list