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

Commit

Permalink
Improve speed of inv by using the cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Jul 26, 2021
1 parent 0e056f5 commit b136d70
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/sage/data_structures/coefficient_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,18 +587,19 @@ def iterate_coefficients(self):
"""
Return the generator for the coefficients of the multiplicative inverse of the ``series``.
"""
n = self._offset
v = self._approximate_valuation # shorthand name
n = 0 # Counts the number of places from the valuation
yield self._ainv
# Note that first entry of the cache will correspond to z^v
while True:
v = self._approximate_valuation
if n == v:
yield self._ainv
n += 1
continue
n += 1
c = self._zero
for k in range(v, n):
c += self[k] * self._series[n - v - k]
m = min(len(self._cache), n)
for k in range(m):
c += self._cache[k] * self._series[n - k]
for k in range(m, n):
c += self[v+k] * self._series[n - k]
yield -c * self._ainv
n += 1


class CoefficientStream_apply_coeff(LazyLaurentSeries_unary):
Expand Down

0 comments on commit b136d70

Please sign in to comment.