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

Commit

Permalink
remove _target
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Oct 14, 2022
1 parent 5020b9d commit 8396a91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
24 changes: 3 additions & 21 deletions src/sage/data_structures/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,32 +1011,14 @@ def __init__(self, approximate_order, true_order=False):
sage: C = Stream_uninitialized(0)
sage: TestSuite(C).run(skip="_test_pickling")
"""
self._target = None
if approximate_order is None:
raise ValueError("the valuation must be specified for undefined series")
super().__init__(False, true_order)
self._iter = None
self._approximate_order = approximate_order

def iterate_coefficients(self):
"""
A generator for the coefficients of ``self``.
EXAMPLES::
sage: from sage.data_structures.stream import Stream_uninitialized
sage: from sage.data_structures.stream import Stream_exact
sage: z = Stream_exact([1], order=1)
sage: C = Stream_uninitialized(0)
sage: C._target
sage: C._target = z
sage: n = C.iterate_coefficients()
sage: [next(n) for _ in range(10)]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
"""
n = self._approximate_order
while True:
yield self._target[n]
n += 1
def define(self, coeff_stream):
self._iter = coeff_stream.iterate_coefficients()


class Stream_unary(Stream_inexact):
Expand Down
21 changes: 8 additions & 13 deletions src/sage/rings/lazy_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,12 +938,7 @@ def __bool__(self):
if isinstance(self._coeff_stream, Stream_exact):
return True
if isinstance(self._coeff_stream, Stream_uninitialized):
if self._coeff_stream._target is None:
return True
if isinstance(self._coeff_stream._target, Stream_zero):
return False
if isinstance(self._coeff_stream._target, Stream_exact):
return True
return True
if self._coeff_stream._is_sparse:
cache = self._coeff_stream._cache
if any(cache[a] for a in cache):
Expand Down Expand Up @@ -1207,7 +1202,7 @@ def define(self, s):
O^7
"""
if not isinstance(self._coeff_stream, Stream_uninitialized) or self._coeff_stream._target is not None:
if not isinstance(self._coeff_stream, Stream_uninitialized) or self._coeff_stream._iter is not None:
raise ValueError("series already defined")

if not isinstance(s, LazyModuleElement):
Expand All @@ -1219,7 +1214,7 @@ def define(self, s):
self._coeff_stream = coeff_stream
return

self._coeff_stream._target = coeff_stream
self._coeff_stream.define(coeff_stream)

# an alias for compatibility with padics
set = define
Expand Down Expand Up @@ -1266,7 +1261,7 @@ def _repr_(self):
"""
if isinstance(self._coeff_stream, Stream_zero):
return '0'
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._target is None:
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._iter is None:
return 'Uninitialized Lazy Laurent Series'
return self._format_series(repr)

Expand Down Expand Up @@ -1316,7 +1311,7 @@ def _latex_(self):
from sage.misc.latex import latex
if isinstance(self._coeff_stream, Stream_zero):
return latex('0')
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._target is None:
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._iter is None:
return latex("Undef")
return self._format_series(latex)

Expand All @@ -1336,7 +1331,7 @@ def _ascii_art_(self):
from sage.typeset.ascii_art import ascii_art, AsciiArt
if isinstance(self._coeff_stream, Stream_zero):
return AsciiArt('0')
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._target is None:
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._iter is None:
return AsciiArt('Uninitialized Lazy Laurent Series')
return self._format_series(ascii_art, True)

Expand All @@ -1356,7 +1351,7 @@ def _unicode_art_(self):
from sage.typeset.unicode_art import unicode_art, UnicodeArt
if isinstance(self._coeff_stream, Stream_zero):
return UnicodeArt('0')
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._target is None:
if isinstance(self._coeff_stream, Stream_uninitialized) and self._coeff_stream._iter is None:
return UnicodeArt('Uninitialized Lazy Laurent Series')
return self._format_series(unicode_art, True)

Expand Down Expand Up @@ -3145,7 +3140,7 @@ def exp(self):
d_self_f = Stream_cauchy_mul(d_self, f._coeff_stream, False)
int_d_self_f = Stream_function(lambda n: d_self_f[n-1] / R(n) if n else R.one(),
False, 0)
f._coeff_stream._target = int_d_self_f
f._coeff_stream.define(int_d_self_f)
return f

def log(self):
Expand Down

0 comments on commit 8396a91

Please sign in to comment.