Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zzzzzzzzac/numfi
a subclass of numpy.ndarray that does fixed-point arithmetic
https://github.com/zzzzzzzzac/numfi
dsp fixed-point fpga numpy numpy-arrays simulation
Last synced: 13 days ago
JSON representation
a subclass of numpy.ndarray that does fixed-point arithmetic
- Host: GitHub
- URL: https://github.com/zzzzzzzzac/numfi
- Owner: ZZZZzzzzac
- License: mit
- Created: 2021-04-26T01:48:17.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T09:32:35.000Z (over 1 year ago)
- Last Synced: 2024-04-29T08:21:27.971Z (9 months ago)
- Topics: dsp, fixed-point, fpga, numpy, numpy-arrays, simulation
- Language: Jupyter Notebook
- Homepage:
- Size: 633 KB
- Stars: 10
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [numfi](https://github.com/ZZZZzzzzac/numfi)
numfi is a numpy.ndarray subclass that does fixed-point arithmetic.
Feature:
- Automatically perform fixed-point arithmetic through overloaded operators
- Maximum compatibility with numpy and other library, just like a normal numpy.ndarray
- Optimized calculation speed by minimizing quantization as much as possible
## Install
**Prerequisite**: python3 and numpy
```bash
pip install numfi
```or you can just copy [numfi.py](https://github.com/ZZZZzzzzac/numfi/blob/master/numfi/numfi.py) and do whatever you want, after all it's only 200+ lines of code
## Quick start
```python
import numfi
import numpy as np# numfi(array=[], signed=1, bits_word=16, bits_frac=None, RoundingMethod='Nearest', OverflowAction='Saturate')
x = numfi(np.random.rand(3),1,16,8)
# numfi.__repr__() return brief description of numfi object: x => s16/8-N/S
# s for 'signed', followed by word bits and fraction bits, N/S for 'Nearest' and 'Saturate` for rounding/overflow method# any arithmetic operation with numfi will return a numfi object with proper precision and value
# By overloading operators, numfi object can do fixed-point arithmetic easily:# normal arithmetic operation work with float form of x
y = x + 1
y = [1] - x
y = x * np.random.rand(3)
y = numfi([1,0,0.1234],1,21,15) / x
y = -x
y = x ** 0.5
y = x % 3
# comparison return np.array of bool, just like normal np.array
y = x > 0.5
y = x >= numfi([1,0,0.1234],1,21,15)
y = x == x
y = x <= np.ones(3)
y = x < [1,1,1]
# bitwise operation work with integer form of x
y = x & 0b101
y = 0b100 | x # order of operands doesn't matter
y = x ^ x # two numfi object can also be used in bitwise operations
y = x << 4
y = x >> 2
...# By inheriting from numpy.ndarray, numfi object can be used just like normal numpy array, and return same numfi object back
y = np.sin(x)
y = x[x>1]
y = x.sum()
y = x.reshape(3,1)
plt.plot(x)
pandas.DataFrame(x)
np.convolve(x,np.ones(4))
np.fft.fft(x,n=512)
for i in x:
print(i)
...
```## Document
Details can be found here: [https://numfi.readthedocs.io/en/latest/?](https://numfi.readthedocs.io/en/latest/?)
## License
The project is licensed under the MIT license.