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

Remove recursion from Base.:^ #618

Merged
merged 9 commits into from
Jan 16, 2025
Merged

Remove recursion from Base.:^ #618

merged 9 commits into from
Jan 16, 2025

Conversation

wheeheee
Copy link
Member

Prevents stack overflow, in the admittedly unlikely case that -e == e, for e == typemin(Int8) etc.
Also moves some definitions around for readability.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.97%. Comparing base (1f70965) to head (0276bc6).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #618   +/-   ##
=======================================
  Coverage   97.96%   97.97%           
=======================================
  Files          19       19           
  Lines        3251     3254    +3     
=======================================
+ Hits         3185     3188    +3     
  Misses         66       66           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wheeheee
Copy link
Member Author

wheeheee commented Jan 9, 2025

Using Int8 in the tests, otherwise with Int these might trigger OutOfMemoryError, or in the case of PolynomialRatio, we get ArgumentError: filter must have non-zero leading denominator coefficient because it rounds to zero.

Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't verified the code movement in detail, but the rest LGTM. Maybe the one additional test. Apart from that, good to go from my side.

test/filter_conversion.jl Outdated Show resolved Hide resolved
Co-authored-by: Martin Holters <[email protected]>
@wheeheee
Copy link
Member Author

Another unfortunate case of arithmetic overflow, as inv(3)^128 != inv(3^128). Should we try to convert g to typeof(inv(g)) first before exponentiation or just change the test?

Comment on lines 51 to 52
res = ZeroPoleGain{D}(repeat(f.z, ae), repeat(f.p, ae), f.k^ae)
return e < 0 ? inv(res) : res
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fix the overflow in computing k in the test?

Suggested change
res = ZeroPoleGain{D}(repeat(f.z, ae), repeat(f.p, ae), f.k^ae)
return e < 0 ? inv(res) : res
if e < 0
return ZeroPoleGain{D}(repeat(f.p, ae), repeat(f.z, ae), inv(f.k)^ae)
else
return ZeroPoleGain{D}(repeat(f.z, ae), repeat(f.p, ae), f.k^ae)
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works too.

@martinholters martinholters merged commit 1b76b87 into master Jan 16, 2025
11 checks passed
@martinholters martinholters deleted the no_recurse_pow branch January 16, 2025 09:30
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

Successfully merging this pull request may close these issues.

2 participants