Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
only get coefficient if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Aug 11, 2021
1 parent 4723f6b commit 651c3ed
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/sage/data_structures/coefficient_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,9 @@ def get_coefficient(self, n):
return self._ainv
c = self._zero
for k in range(v, n):
c += self[k] * self._series[n - v - k]
l = self[k]
if l:
c += l * self._series[n - v - k]
return -c * self._ainv

def iterate_coefficients(self):
Expand All @@ -1515,9 +1517,13 @@ def iterate_coefficients(self):
c = self._zero
m = min(len(self._cache), n)
for k in range(m):
c += self._cache[k] * self._series[n - v - k]
l = self._cache[k]
if l:
c += l * self._series[n - v - k]
for k in range(v+m, v+n):
c += self[k] * self._series[n - k]
l = self[k]
if l:
c += l * self._series[n - k]
yield -c * self._ainv


Expand Down Expand Up @@ -1579,6 +1585,7 @@ def get_coefficient(self, n):
sage: [g.get_coefficient(i) for i in range(-1, 3)]
[1, 0, 1, 1]
"""
return self._function(self._ring(self._series[n])) if self._series[n] else self._series[n]


c = self._series[n]
if c:
return self._function(self._ring(c))
return c

0 comments on commit 651c3ed

Please sign in to comment.