Skip to content
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

Infinite loop on exponent somehow #89

Closed
jrmoserbaltimore opened this issue Dec 3, 2023 · 4 comments
Closed

Infinite loop on exponent somehow #89

jrmoserbaltimore opened this issue Dec 3, 2023 · 4 comments

Comments

@jrmoserbaltimore
Copy link

I don't know what particularly causes this, but it hangs forever.

from fxpmath import Fxp
x = Fxp(0,dtype='UQ0.64')
x**4
@francof2a
Copy link
Owner

That is because when you use a constant as is, in this case the number 4, as operator of a Fxp object, this constant is converted to an Fxp object with same dtype. Then, the power operation are using a huge raw number as exponent.

You can solve this being explicit about dtype of the exponent:

x**Fxp(4)
# or
x**Fxp(4, dtype='some fixed-point dtype')

@jrmoserbaltimore
Copy link
Author

Interesting. Should this produce a warning or raise an exception (probably the best route) or be a different behavior, or is that just impossible? It's not obvious what's happening and an infinite loop is probably not the programmer's intent.

@francof2a
Copy link
Owner

Yes, it could be! I think a good change can be modify the op_input_size default value from 'same' to 'best'. In the first case the number 4 is converted to UQ0.64 before to perform the power operation. In the second case, using 'best' the number for is converted to Q4.0. This behavior will prevent long calculation time and intensive memory usage.

But the idea of the warning is really important in order be aware of this automatic sizing. Definitely I'll include this in next release.

francof2a added a commit that referenced this issue Dec 22, 2023
…nstant operator.

Add warning message.
issue #89
@francof2a francof2a mentioned this issue Feb 7, 2024
@francof2a
Copy link
Owner

solved in v0.4.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants