[Numpy-discussion] Fixed-point arithemetic...any solution yet?
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Wed Dec 9 14:29:38 EST 2009
Ruben Salvador wrote:
> Hello everybody.
>
> I've seen this question arise sometimes on the list, but don't know if
> something has "happened" yet or not. I mean, any solution feasible to
> use more or less right out of the box?
>
> I'm just a hardware engineer, so it would be difficult for me to create
> my own class for this, since my knowledge of python/numpy is very
> limited, and, just don't have the time/knowledge to be more than a
> simple user of the language, not a developer.
>
> I have just come across this:
> http://www.dilloneng.com/documents/downloads/demodel/ but haven't used
> it yet. I'll give it a try and see how it works and come back to the
> list to report somehow. But, is there any "official" plans for this
> within the numpy developers? Is there any code around that may be used?
> I just need to test my code with fixed point arithmetic (I'm modelling
> hardware....)
>
> Thanks for the good work to all the Python/Numpy developers (and all the
> projects related, matplotlib and so on....) and for the possiblity of
> freeing from matlab!!! I'm determined to do research with as many free
> software design tools as possible....though this fixed-point arithmetic
> issue is still a chain!
I haven't heard of anything, but here's what I'd do:
- Use np.int64
- Multiply all inputs to my code with 10^6
- Divide all output from my code with 10^6
- If you need to debug-print and array, simply define something like
FIXED_POINT_FACTOR = 10**6
def printarr(x):
print x.astype(np.float) / FIXED_POINT_FACTOR
Or am I missing something?
--
Dag Sverre
More information about the NumPy-Discussion
mailing list