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

Commit

Permalink
#15673: Minor changes from Martin Rubey's coments
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhansen committed Jan 17, 2014
1 parent f4157f7 commit 927ff83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions src/sage/combinat/species/new_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def __init__(self, **kwds):
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc, ListCachedStream
sage: from sage.combinat.species.new_stream import StreamFromFunction, ListCachedStream
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: isinstance(s, ListCachedStream)
True
sage: s[5]
Expand All @@ -241,9 +241,9 @@ def __setitem__(self, n, value):
"""
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc, ListCachedStream
sage: from sage.combinat.species.new_stream import StreamFromFunction, ListCachedStream
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: isinstance(s, ListCachedStream)
True
sage: s[1]
Expand All @@ -263,26 +263,26 @@ def __setitem__(self, n, value):
pos += 1
self._cache[n] = value

def number_computed(self):
def length_of_cache(self):
"""
Returns the number of coefficients that have been computed so
far.
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc, ListCachedStream
sage: from sage.combinat.species.new_stream import StreamFromFunction, ListCachedStream
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: isinstance(s, ListCachedStream)
True
sage: s[5]
8
sage: s.number_computed()
sage: s.length_of_cache()
6
"""
return len(self._cache)

__len__ = number_computed
__len__ = length_of_cache

@check_constant_decorator
def __getitem__(self, n):
Expand All @@ -294,9 +294,9 @@ def __getitem__(self, n):
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc, ListCachedStream
sage: from sage.combinat.species.new_stream import StreamFromFunction, ListCachedStream
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: isinstance(s, ListCachedStream)
True
sage: s[5]
Expand Down Expand Up @@ -364,14 +364,14 @@ def compute(self, n):
return value


class StreamFromFunc(ListCachedStream):
class StreamFromFunction(ListCachedStream):
def __init__(self, func=None, **kwds):
"""
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc
sage: from sage.combinat.species.new_stream import StreamFromFunction
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: s[0]
1
sage: s[1]
Expand All @@ -382,7 +382,7 @@ def __init__(self, func=None, **kwds):
89
"""
self._func = func
super(StreamFromFunc, self).__init__(**kwds)
super(StreamFromFunction, self).__init__(**kwds)

def compute(self, n):
"""
Expand All @@ -393,9 +393,9 @@ def compute(self, n):
EXAMPLES::
sage: from sage.combinat.species.new_stream import StreamFromFunc
sage: from sage.combinat.species.new_stream import StreamFromFunction
sage: h = lambda l: 1 if len(l) < 2 else l[-1] + l[-2]
sage: s = StreamFromFunc(h)
sage: s = StreamFromFunction(h)
sage: s.compute(0)
1
sage: s.compute(2)
Expand Down Expand Up @@ -466,6 +466,6 @@ def OldStreamBehavior(x=None, const=None):
elif hasattr(x, '__iter__'):
return StreamFromIterator(iter(x))
elif isinstance(x, (types.FunctionType, types.LambdaType)):
return StreamFromFunc(x)
return StreamFromFunction(x)
else:
return StreamFromIterator(iter([x,0]))
6 changes: 3 additions & 3 deletions src/sage/combinat/species/series_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def refine_aorder(self):
self.compute_aorder()
else:
#Try to improve the approximate order
n = self.number_computed()
n = self.length_of_cache()

if self.aorder < n:
while self.aorder < n:
Expand Down Expand Up @@ -1006,7 +1006,7 @@ class IntegralStream(SeriesStream):
def __init__(self, stream, integration_constant=0, **kwds):
"""
A class for a stream whose coefficients represent the
derivative of a power series.
integral of a power series.
EXAMPLES::
Expand Down Expand Up @@ -1649,7 +1649,7 @@ def compute(self, n):
"""
s = self._series_stream
r = s[n][n]
for i in range(min(n, s.number_computed() - 1)):
for i in range(min(n, s.length_of_cache() - 1)):
r += s[i][n]
return r

Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/species/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def __len__(self):
"""
return len(self._list)

number_computed = __len__
length_of_cache = __len__

def data(self):
"""
Expand Down

0 comments on commit 927ff83

Please sign in to comment.