Skip to content

Commit

Permalink
Merge pull request #63 from francof2a/0.4.8-dev
Browse files Browse the repository at this point in the history
0.4.8 dev
  • Loading branch information
francof2a committed Apr 24, 2022
2 parents 3da49c9 + ec5cf96 commit 3ede955
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
version 0.4.8
--------------------------------------------------
* Fix value dtype handling for windows OS and uint as 32 bits.
* __getitem__ method return a Fxp with raw value as view (this solve issue #62).
* Add tests for issues #60 and #62.

version 0.4.7
--------------------------------------------------
* Keep val as original_vdtype and not as object when it is convenient (solve issue #60).
Expand Down
2 changes: 1 addition & 1 deletion fxpmath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.4.7'
__version__ = '0.4.8'

import sys
import os
Expand Down
6 changes: 5 additions & 1 deletion fxpmath/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ def set_val(self, val, raw=False, vdtype=None, index=None):
val_dtype = object
val = val.astype(object)
else:
val = val.astype(original_vdtype)
val_dtype = np.int64 if self.signed else np.uint64

# rounding and overflowing
Expand Down Expand Up @@ -1455,7 +1456,10 @@ def __ge__(self, x):

# indexation
def __getitem__(self, index):
return Fxp(self.val[index], like=self, raw=True)
# return Fxp(self.val[index], like=self, raw=True)
y = Fxp(like=self)
y.val = self.val[index]
return y

def __setitem__(self, index, value):
self.set_val(value, index=index)
Expand Down
31 changes: 30 additions & 1 deletion tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import fxpmath as fxp
from fxpmath.objects import Fxp
from fxpmath.objects import Fxp, Config

import numpy as np

Expand Down Expand Up @@ -226,3 +226,32 @@ def test_issue_58_v0_4_5():
assert np.all(filt_fxp() == filt_fxp1())
assert np.all(out() == out1())

def test_issue_60_v0_4_6():
cfg=Config(dtype_notation="Q",rounding="around")

t_fxp = Fxp(0.0,1,n_int=16,n_frac=15,config=cfg)
t_int = Fxp(0.0,1,n_int=13,n_frac=0,config=cfg)

arr = [-5,0,14.8,7961.625]
fullprec = Fxp(arr , like=t_fxp )
rounded_direct = Fxp(arr , like=t_int )
rounded = Fxp(fullprec , like=t_int )
assert np.all(rounded_direct == rounded)

scalar_full = Fxp(7961.625 , like=t_fxp )
scalar_round_direct = Fxp(7961.625 , like=t_int )
scalar_round = Fxp(scalar_full , like=t_int )

assert scalar_round_direct == scalar_round

def test_issue_62_v0_4_7():
y = Fxp(dtype='fxp-s6/2')
y([[1.0,0.25,0.5],[0.25,0.5,0.25]])

y[0][0] = -1.0

assert y[0][0]() == -1.0

y[0][0] = y[0][0] + 1.0

assert y[0][0]() == 0.0

0 comments on commit 3ede955

Please sign in to comment.