On Tue, Sep 29, 2009 at 10:10, Neal Becker wrote:
> I could force an additional conversion using np.array (xxx, dtype=float).
> Seems wasteful.
np.asarray() will not be wasteful.
> The bigger question I have is, if I've subclassed an array, how can I get at
> the underlying array type?
x.view(
josef.p...@gmail.com wrote:
> On Tue, Sep 29, 2009 at 10:22 AM, Neal Becker wrote:
>> This doesn't work either:
>>
>> def as_double (self):
>> import math
>> def _as_double_1 (x):
>> return math.ldexp (x, -self.frac_bits)
>> vecfunc = np.vectorize (_as_double_1, otypes=[np.float])
>> return vecfu
On Tue, Sep 29, 2009 at 10:22 AM, Neal Becker wrote:
> This doesn't work either:
>
> def as_double (self):
> import math
> def _as_double_1 (x):
> return math.ldexp (x, -self.frac_bits)
> vecfunc = np.vectorize (_as_double_1, otypes=[np.float])
> return ve
This doesn't work either:
def as_double (self):
import math
def _as_double_1 (x):
return math.ldexp (x, -self.frac_bits)
vecfunc = np.vectorize (_as_double_1, otypes=[np.float])
return vecfunc (self)
In [49]: obj.as_double()
Out[49]: fixed_pt_array(
I'm starting with a pure python implementation and have some progress.
AFAICT, the only approach is to subclass ndarray and add the properties and
behaviors I need.
I ran into one issue though.
In my function 'as_double', I need to get to the underlying 'int' array to
pass to ldexp. I tried