[Numpy-discussion] fixed-point arithmetic
Mon Sep 21 10:03:46 CDT 2009
On Mon, Sep 21, 2009 at 9:00 PM, Neal Becker <firstname.lastname@example.org> wrote:
> numpy arrays of fpi should support all numeric operations. Also mixed
> fpi/integer operations.
> I'm not sure how to go about implementing this. At first, I was thinking to
> just subclass numpy array. But, I don't think this provides fpi scalars,
> and their associated operations.
Using dtype seems more straightforward. I would first try to see how
far you could go using a pure python object as a dtype. For example
(on python 2.6):
from decimal import Decimal
import numpy as np
a = np.array([1, 2, 3], Decimal)
b = np.array([2, 3, 4], Decimal)
a + b
works as expected. A lot of things won't work (e.g. most transcendent
functions, which would require a specific implementation anyway), but
arithmetic, etc... would work.
Then, you could think about implementing the class in cython. If speed
is an issue, then implementing your own dtype seems the way to go - I
don't know exactly what kind of speed increase you could hope from
going the object -> dtype, though.
More information about the NumPy-Discussion