-
Notifications
You must be signed in to change notification settings - Fork 77
New method for derivative of constant ImmutableDensePolynomial #615
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
Conversation
…` (N=1). The method returns the zero `ImmutableDensePolynomial. This is a possible fix of a bug, since previously derivative of an `ImmutablePolynomial` returned an unusable polynomial of type `ImmutablePolynomial{Union{},:x,0}`.
|
Thanks for the contribution. Let me see. I think your observations are good ones. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #615 +/- ##
==========================================
+ Coverage 76.64% 76.65% +0.01%
==========================================
Files 38 38
Lines 4068 4070 +2
==========================================
+ Hits 3118 3120 +2
Misses 950 950 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I am not happy with that solution, as I expect the derivative of a constant polynomial the the zero polynomial, and that would be more naturally of type |
|
The test |
…)` now returns `zero(p)`.
|
That is a very good point. I was not aware of the type of |
|
|
||
| function derivative(p::ImmutableDensePolynomial{B,T,X,N}) where {B<:StandardBasis,T,X,N} | ||
| N == 0 && return p | ||
| N == 1 && return zero(p) |
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.
It seems like rather than add a case, we can remove the N==0 case which is captured in the special case above.
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.
I think, both cases (N == 0 and N == 1) are covered by the more specific functions in lines 145 and 146, so could be both removed.
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.
Agreed
|
Thanks @KalusC for your points. There seems to be one change we can take in the other direction. |
|
As I mentioned before: there should be test cases. At least one, which fails before the fix and succeeds after the fix. |
|
Thanks for responding @KlausC , I added tests, but not to test the issue with display. I just added that. |
|
I'll merge yours, then mine. A bit easier that way. |
|
Thanks! That was my very first PR :). |
|
Thanks for taking the time to do it. It was very much appreciated. |
Currently
derivativedoes not work properly on a constantImmutablePolynomial.In the example
the returned
dpis of typeImmutablePolynomial{Union{},:x,0}, which is unusable (cannot be shown nor evaluated).This pull request fixes this issue by introducing a new method:
This returns the zero
ImmutablePolynomial, that works fine in all my tests: it evaluates to zero(T) for every input, it produces the zeroImmutablePolynomial(orPolynomial) when multiplied by any other polynomial and it integrates to itself.I think that there maybe some other issue in the other variants of
derivative. In particular, I fail to see the meaning ofImmutablePolynomial{T,X,N}whenN=0, which is treated in a specialderivativemethod but is also considered in the main one. As far as I understand the code, all references to the caseN=0should be removed, and thezeropolynomial should be interpreted as havingN=1, since it has one coefficient. I have not make any changes in this direction, however, just in case I am missing something.