Skip to content

Commit

Permalink
Update due to changes in sagemath#35265.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Mar 22, 2023
1 parent 3019636 commit 79da410
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/sage/data_structures/stream.py
Expand Up @@ -2880,33 +2880,6 @@ def __init__(self, series, shift, minimal_valuation):
self._minimal_valuation = minimal_valuation
self._approximate_order = minimal_valuation

@lazy_attribute
def _offset(self):
"""
Return the offset of a stream with a dense cache.
EXAMPLES::
sage: from sage.data_structures.stream import Stream_function, Stream_truncated
sage: def fun(n): return 1 if ZZ(n).is_power_of(2) else 0
sage: f = Stream_function(fun, False, 0)
sage: [f[i] for i in range(8)]
[0, 1, 1, 0, 1, 0, 0, 0]
sage: f._cache
[0, 1, 1, 0, 1, 0, 0, 0]
sage: s = Stream_truncated(f, -5, 0)
sage: s._offset
-5
sage: [s[i] for i in range(10)]
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
sage: s._cache
[0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
"""
# self[n] = self._cache[n-self._offset]
if self._is_sparse:
raise ValueError("_offset is only for dense streams")
return self._series._offset + self._shift

def __getitem__(self, n):
"""
Return the ``n``-th coefficient of ``self``.
Expand Down Expand Up @@ -2997,14 +2970,15 @@ def order(self):
n = self._approximate_order
cache = self._series._cache
while True:
if n-self._shift in cache:
if n - self._shift in cache:
if cache[n-self._shift]:
self._approximate_order = n
self._true_order = True
return n
elif self[n]:
return n
n += 1
# dense case
return super().order()

def is_nonzero(self):
Expand All @@ -3020,7 +2994,7 @@ def is_nonzero(self):
sage: [f[i] for i in range(0, 4)]
[0, 1, 1, 0]
sage: f._cache
[0, 1, 1, 0]
[1, 1, 0]
sage: s = Stream_truncated(f, -5, 0)
sage: s.is_nonzero()
False
Expand All @@ -3033,7 +3007,7 @@ def is_nonzero(self):
sage: [f[i] for i in range(0, 4)]
[0, 1, 1, 0]
sage: f._cache
{0: 0, 1: 1, 2: 1, 3: 0}
{1: 1, 2: 1, 3: 0}
sage: s = Stream_truncated(f, -5, 0)
sage: s.is_nonzero()
False
Expand All @@ -3044,7 +3018,8 @@ def is_nonzero(self):
"""
if self._is_sparse:
return any(c for n, c in self._series._cache.items() if n + self._shift >= self._minimal_valuation)
start = self._approximate_order - self._offset
offset = self._series._approximate_order + self._shift
start = self._approximate_order - offset
return any(self._series._cache[start:])


Expand Down

0 comments on commit 79da410

Please sign in to comment.