FPGARelated.com
Forums

fixed point modeling tools

Started by Unknown May 6, 2020
Hello,=20

For those of you who do DSP modeling in Python, I've recently released a pa=
ckage that supports fixed point arithmetic. The existing open source tools =
are lackluster and MATLAB doesn't nicely fit into our simulation/testing wo=
rkflow. Just trying to get the word out for a higher adoption rate!

Documentation is here:
https://fixedpoint.readthedocs.io

Gihub repo is here:
https://github.com/Schweitzer-Engineering-Laboratories/fixedpoint

Compatible with Python 3.8.0 and later. Install from PyPI with pip:
pip install fixedpoint
zack_sheffield@selinc.com writes:

> For those of you who do DSP modeling in Python, I've recently released > a package that supports fixed point arithmetic. The existing open > source tools are lackluster and MATLAB doesn't nicely fit into our > simulation/testing workflow. Just trying to get the word out for a > higher adoption rate!
Interesting. When I went looking some months ago I found spfpm (https://pypi.python.org/pypi/spfpm) which was fairly recently updated. So how does yours compare? At least compatibility seems tighter for yours as spfpm works with Python 3.3 and later. My need was mostly for conversion of floats to VHDL sfixed/ufixed formats for FPGA testing but in the end I didn't need it.
On Wednesday, May 6, 2020 at 11:57:04 PM UTC-7, Anssi Saari wrote:
> Zack Sheffield writes: >=20 > > For those of you who do DSP modeling in Python, I've recently released > > a package that supports fixed point arithmetic. The existing open > > source tools are lackluster and MATLAB doesn't nicely fit into our > > simulation/testing workflow. Just trying to get the word out for a > > higher adoption rate! >=20 > Interesting. When I went looking some months ago I found spfpm > (https://pypi.python.org/pypi/spfpm) which was fairly recently > updated. So how does yours compare? At least compatibility seems tighter > for yours as spfpm works with Python 3.3 and later. >=20 > My need was mostly for conversion of floats to VHDL sfixed/ufixed > formats for FPGA testing but in the end I didn't need it.
* spfpm has support for various transcendental functions (log, sqrt, sin, c= os, tan) whereas fixedpoint does not. As an RTL engineer frustrated with th= e lack of python tools to more closely model VHDL constructs, I opted to no= t include these, as ieee libraries do not support these operations for fixe= d point (ufixed, sfixed, signed, unsigned) types. * fixedpoint offers several methods/functions for resizing bits of an exist= ing object. It appears that to accomplish this with spfpm, a new object mus= t be created (which is expensive).=20 * fixedpoint is (at least currently) limited to python 3.8 whereas spfpm (a= s you mentioned) is compatible back to 3.3. Version 3.8 simplified the code= base greatly, so I opted to stick with it. * Unit tests for spfpm cover very few corner cases. Unit tests for fixedpoi= nt in most cases iterate over at least 1024 random values. Bit accuracy for= fixedpoint is validated against MATLAB's fixed point designer. * fixedpoint offers several different rounding schemes (convergent, nearest= , toward inf, toward -inf, toward 0, away from 0, floor, ceil) and overflow= handling schemes (clamp/saturate, wrap).=20 * fixedpoint has configurable alerts (error, warning, ignore) for overflow,= implicit cast errors, and property mismatches (e.g., adding 2 objects with= different rounding schemes). * I can't find any documentation on spfpm other than the docstring in the s= ource file. fixedpoint documents most (if not all) aspects at https://fixed= point.readthedocs.io.=20 * fixedpoint has rich string formatting support (using f-strings, format fu= nction, or the str.format method) * fixedpoint is typed (if you like that sort of thing). * Overall, fixedpoint more closely resembles VHDL constructs than spfpm. Hope this helps!
zack_sheffield@selinc.com writes:

> * fixedpoint is (at least currently) limited to python 3.8 whereas > spfpm (as you mentioned) is compatible back to 3.3. Version 3.8 > simplified the code base greatly, so I opted to stick with it.
Thanks for the answers! I also like your clear three clause BSD license, spfpm has a messy PSF license which basically consists of a bunch of license texts that were bundled with Python itself. Out of curiousity and as something of a Python enthusiast, what features in Python 3.8 were so useful for fixedpoint?
On Friday, May 8, 2020 at 2:10:23 AM UTC-7, Anssi Saari wrote:
> Out of curiousity and as something of a Python enthusiast, what features > in Python 3.8 were so useful for fixedpoint?
Three main things: * walrus operator (https://docs.python.org/3/whatsnew/3.8.html#assignment-e= xpressions) allowed combining of lines of code all over the place. * Positional-only parameters (https://docs.python.org/3/whatsnew/3.8.html#p= ositional-only-parameters) and keyword arguments allowed for built-in error= checking of keyword arguments. * logging calls got a stacklevel keyword argument (https://docs.python.org/= 3/library/logging.html#logging.Logger.debug), which basically allows me to = wrap logging calls in a single method but always point to the line (outside= of that method) where I wanted the log to originate from. These 3 things greatly enhanced readability and reduced SLOC.