diff --git a/changelog.txt b/changelog.txt index fe13fc9..a9adff8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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). diff --git a/fxpmath/__init__.py b/fxpmath/__init__.py index 2a54560..fbe5a84 100644 --- a/fxpmath/__init__.py +++ b/fxpmath/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.4.7' +__version__ = '0.4.8' import sys import os diff --git a/fxpmath/objects.py b/fxpmath/objects.py index 972e968..723955e 100644 --- a/fxpmath/objects.py +++ b/fxpmath/objects.py @@ -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 @@ -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) diff --git a/tests/test_issues.py b/tests/test_issues.py index 4e8c6d2..69ba000 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -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 @@ -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