-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with wrapping #20
Comments
Mello @MaenMallah Yes, you're right. When I tested it I didn't cover range with several wraps around limits. Thank you for the time you invest in this! Your solution seems to work well, but it has problems with performance. All of this show me that the original implementation also have this kind of problem (beside it is not working as it should) and use twos complement could be a bad idea. I have been thinking about an alternative and reach to this: def wrap(x, signed, n_word):
m = (1 << n_word)
if signed:
x = np.array(x).astype(int) & (m - 1)
x = np.where(x < (1 << (n_word-1)), x, x | (-m))
else:
x = np.array(x).astype(int) & (m - 1)
return x I tested it and work well! About performance (
So, now we have an even better wrap function :) Thanks again! As you could be noted, the arguments # val = utils.wrap(new_val, val_min, val_max, self.signed, self.n_word)
val = utils.wrap(new_val, self.signed, self.n_word) It would be great if you can test it and confirm is working well. |
Hello @francof2a , I have tested the new implementation on the git and the use-case I had works fine now. All seems to be working well. Thanks for your quick replies and fixes. |
Hello again,
As I spent some time debugging an issue and finally found the reason, I thought I can let you know with my potential solution for it.
Wrapping is not working when values are negative.
How to replicate:
x = Fxp(0, signed=True, n_word = 4, n_frac = 0)
x.equal(-30) ==> -14 which is not possible as we can only represent the range [-8,7]
This happens because the value I gave should wrap twice but the functions don't account for this. The positive case is correct.
To solve this I changed the wrap function inside utils.py
However, I am not sure if I broke something else.
The text was updated successfully, but these errors were encountered: