Skip to content

Commit

Permalink
modify reshape method behavior to match numpy behavior.
Browse files Browse the repository at this point in the history
Now, this method not modify self object, only returned  a reshaped Fxp.

Fix issue #90
  • Loading branch information
francof2a committed Feb 10, 2024
1 parent 2bb9e93 commit bf94a97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fxpmath/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,9 @@ def reshape(self, shape, order='C'):
"""

self.val = self.val.reshape(shape=shape, order=order)
return self
x = self.copy()
x.val = x.val.reshape(shape, order=order)
return x

def flatten(self, order='C'):
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,21 @@ def test_issue_85_v0_4_8():

x = Fxp(0.0, dtype=dt, overflow='wrap') # EXCEPTION
assert x() == 0.0

def test_issue_90_v0_4_9():
# Built-in Fxp.reshape() method passes the wrong number of arguments to underlying numpy reshape() function
x = Fxp([1,2,3,4], False, 8, 0)
y = x.reshape((2,2))

assert np.all(x.val.shape == np.array((4,)))
assert np.all(y.val.shape == np.array((2,2)))

z = np.reshape(x, (2,2))

assert np.all(x.val.shape == np.array((4,)))
assert np.all(z.val.shape == np.array((2,2)))

zz = fxp.reshape(x, (2,2))

assert np.all(x.val.shape == np.array((4,)))
assert np.all(zz.val.shape == np.array((2,2)))

0 comments on commit bf94a97

Please sign in to comment.