-
-
Notifications
You must be signed in to change notification settings - Fork 45
feat: add polynomial odd-even coefficient sum and degree functions #217
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates introduce essential functions for polynomial operations within the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- poly/README.md (1 hunks)
- poly/poly.v (1 hunks)
- poly/poly_test.v (1 hunks)
Additional comments not posted (8)
poly/poly_test.v (3)
57-61: Comprehensive test coverage fordegree.The test cases effectively cover typical scenarios and edge cases for the
degreefunction.
63-67: Comprehensive test coverage forsum_odd_coeffs.The test cases effectively cover typical scenarios and edge cases for the
sum_odd_coeffsfunction.
69-72: Comprehensive test coverage forsum_even_coeffs.The test cases effectively cover typical scenarios and edge cases for the
sum_even_coeffsfunction.poly/README.md (3)
159-170: Clear documentation fordegree.The documentation clearly describes the purpose and expected output of the
degreefunction.
172-183: Clear documentation forsum_odd_coeffs.The documentation clearly describes the purpose and expected output of the
sum_odd_coeffsfunction.
185-196: Clear documentation forsum_even_coeffs.The documentation clearly describes the purpose and expected output of the
sum_even_coeffsfunction.poly/poly.v (2)
324-330: Efficient implementation ofsum_odd_coeffs.The function is correctly implemented and efficiently calculates the sum of coefficients at odd indices.
335-341: Efficient implementation ofsum_even_coeffs.The function is correctly implemented and efficiently calculates the sum of coefficients at even indices.
| pub fn degree(c []f64) int { | ||
| return c.len - 1 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle zero-coefficient case in degree.
The function should handle the case where all coefficients are zero, returning -1 as the degree.
Apply this diff to handle the zero-coefficient case:
pub fn degree(c []f64) int {
- return c.len - 1
+ for i := c.len - 1; i >= 0; i-- {
+ if c[i] != 0.0 {
+ return i
+ }
+ }
+ return -1
}Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| pub fn degree(c []f64) int { | |
| return c.len - 1 | |
| } | |
| pub fn degree(c []f64) int { | |
| for i := c.len - 1; i >= 0; i-- { | |
| if c[i] != 0.0 { | |
| return i | |
| } | |
| } | |
| return -1 | |
| } |
This PR introduces three new functions to the
polymodule:sum_odd_coeffs,sum_even_coeffs, anddegree. These functions compute specific properties of polynomials based on their coefficients.sum_odd_coeffs:
c = [a_0, a_1, ..., a_n]sum_even_coeffs:
c = [a_0, a_1, ..., a_n]degree:
c = [a_0, a_1, ..., a_n]The corresponding tests have been added to
poly_test.vto verify the functionality of these new functions.Changes:
poly.v:pub fn sum_odd_coeffs(c []f64) f64pub fn sum_even_coeffs(c []f64) f64pub fn degree(c []f64) intpoly_test.vto include tests for the new functions.Testing:
sum_odd_coeffs,sum_even_coeffs, anddegreeinpoly_test.v.Summary by CodeRabbit
New Features
degree,sum_odd_coeffs, andsum_even_coeffs.Tests