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
[GSoC] Implemented convolution operation of two formal power series #17017
Conversation
✅ Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
sympy/series/formal.py
Outdated
========== | ||
|
||
order : Number, optional | ||
Specifies the order of the term upto which the polynomial should |
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.
Specifies the order of the term upto which the polynomial should | |
Specifies the order of the term up to which the polynomial should |
sympy/series/formal.py
Outdated
@@ -1143,6 +1143,66 @@ def integrate(self, x=None, **kwargs): | |||
|
|||
return self.func(f, self.x, self.x0, self.dir, (ak, self.xk, ind)) | |||
|
|||
def convolve(self, other, x=None, order=4): | |||
""" Convolute two Formal Power Series and return the truncated terms upto specified order. |
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.
Should this return the product of two power series? If so, then I think that the method should be renamed.
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.
Yes currently it does that. But if we implement other types of convolution like dyadic
or cyclic
convolution, then they are no longer product
of two power series. So I think, we should keep it convolute
. I will try to extend the code to integrate cyclic, dyadic and other types of convolution into it.
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.
Hi @ArighnaIITG ,
How do you plan to add new types of convolution in the future?
If they will be separate methods, I believe renaming it to product is good like @jksuom suggested.
or one way will be to allow a method
kwarg, eg. f1.convolve(f2, method='linear')
.
ping @leosartaj |
General comments on the way checks have been organized, if isinstance(other, FormalPowerSeries):
if self.dir != other.dir:
raise ValueError("Both series should be calculated from the"
" same direction.")
elif self.x0 != other.x0:
raise ValueError("Both series should be calculated about the"
" same point.")
<your-code>
else:
raise ValueError("Both series should be an instance of FormalPowerSeries"
" class.") can be reorganized for easy reading and better performance, if not isinstance(other, FormalPowerSeries): # rejected at the first place, no futher processing needed. easy debugging and reading.
raise ValueError("Both series should be an instance of FormalPowerSeries"
" class.")
if self.dir != other.dir:
raise ValueError("Both series should be calculated from the"
" same direction.")
elif self.x0 != other.x0:
raise ValueError("Both series should be calculated about the"
" same point.")
<your-code> As far as I have observed all the checks are kept at the entry point of the method/function, in the decreasing order of priority. |
sympy/series/formal.py
Outdated
@@ -1143,6 +1143,66 @@ def integrate(self, x=None, **kwargs): | |||
|
|||
return self.func(f, self.x, self.x0, self.dir, (ak, self.xk, ind)) | |||
|
|||
def convolve(self, other, x=None, order=4): | |||
""" Convolute two Formal Power Series and return the truncated terms upto specified order. |
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.
Hi @ArighnaIITG ,
How do you plan to add new types of convolution in the future?
If they will be separate methods, I believe renaming it to product is good like @jksuom suggested.
or one way will be to allow a method
kwarg, eg. f1.convolve(f2, method='linear')
.
sympy/series/formal.py
Outdated
|
||
sympy.discrete.convolutions | ||
""" | ||
from sympy.discrete.convolutions import convolution |
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.
Can this be top level import?
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.
Just asking, can you please clarify on when the import should be top level and when not? Some conditions for this?
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.
Just asking, can you please clarify on when the import should be top level and when not? Some conditions for this?
We try to follow the convention of imports at top-level only. It's easier to debug and read since you can see a list of everything up-top.
The only time I have ever added these imports inside of functions is when there are errors due to cyclic imports.
@ArighnaIITG , please add what is left to be done in the PR (mark it as TODO). |
Codecov Report
@@ Coverage Diff @@
## master #17017 +/- ##
=============================================
+ Coverage 74.411% 74.498% +0.086%
=============================================
Files 622 623 +1
Lines 160785 161362 +577
Branches 37738 37868 +130
=============================================
+ Hits 119643 120212 +569
- Misses 35818 35823 +5
- Partials 5324 5327 +3 |
I think there has been an issue with the branch. Several commits have been pushed here. @leosartaj can you guide me on this? |
You need to update your branch. Can you update your branch and then try to push. Or also you can just get rid of merge commit and do a force commit. |
ping @ArighnaIITG |
36c977f
to
1a2b0a7
Compare
The branch has been correctly restored. I actually went on the wrong path, and my branch got messed up. You can review now. @leosartaj |
ping @leosartaj |
@leosartaj , can you check what Travis build error this is and kindly notify me? I am unable to understand. |
It appears you're docstring for convolve is not correct. This is the error from the log You can try building the docs locally, to fix this. |
I would try making the "second level parameters" 'dyadic', etc. look different from the actual parameters by, for example, writing |
Can you explain @jksuom? I couldn't catch you. |
It seems that the combination |
@leosartaj I think this is ready for merging now. |
Looks good to me. Will merge in a day if no objection. |
The name |
Thanks @jksuom for the review. I feel that might be more appropriate for it. We should have operations only that make sense when dealing with power series. Does it make sense, to have overloading for
@ArighnaIITG what are your thoughts on this? |
I think that overloading |
@leosartaj @jksuom I believe that all the various forms of |
Let's rename the function for now to
For overloading let's wait until we have a class for this operation. It will be difficult to compute for minimum orders since by nature |
Ping @ArighnaIITG |
Ping @leosartaj |
This looks good to me. Merging. Thanks @ArighnaIITG for the work. |
References to other Issues or PRs
Brief description of what is fixed or changed
Convolution of two
FormalPowerSeries
objects have been implemented. Presently, it takes in aorder
term, and prints all the terms in the convoluted resultantfps
uptoorder
. NoFormalPowerSeries
object is being returned as of now.For example --
I have only implemented
linear convolution
as of now. Whether other forms of convolution is required has to be discussed.Other comments
Release Notes
sympy.series.formal