C Int Lists#
This is a class for fast basic operations with lists of C ints. It is similar to the double precision TimeSeries class. It has all the standard C int semantics, of course, including overflow. It is also similar to the Python list class, except all elements are C ints, which makes some operations much, much faster. For example, concatenating two IntLists can be over 10 times faster than concatenating the corresponding Python lists of ints, and taking slices is also much faster.
AUTHOR:
William Stein, 2010-03
- class sage.stats.intlist.IntList[source]#
Bases:
object
A list of C int’s.
- list()[source]#
Return Python list version of
self
with Python ints as entries.EXAMPLES:
sage: a = stats.IntList([1..15]); a [1, 2, 3, 4, 5 ... 11, 12, 13, 14, 15] sage: a.list() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] sage: list(a) == a.list() True sage: type(a.list()[0]) <... 'int'>
>>> from sage.all import * >>> a = stats.IntList((ellipsis_range(Integer(1),Ellipsis,Integer(15)))); a [1, 2, 3, 4, 5 ... 11, 12, 13, 14, 15] >>> a.list() [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] >>> list(a) == a.list() True >>> type(a.list()[Integer(0)]) <... 'int'>
- max(index=False)[source]#
Return the largest value in this time series. If this series has length 0 we raise a
ValueError
INPUT:
index
– bool (default:False
); ifTrue
, also return index of maximum entry.
OUTPUT:
int – largest value
int – index of largest value; only returned if
index=True
EXAMPLES:
sage: v = stats.IntList([1,-4,3,-2,-4,3]) sage: v.max() 3 sage: v.max(index=True) (3, 2)
>>> from sage.all import * >>> v = stats.IntList([Integer(1),-Integer(4),Integer(3),-Integer(2),-Integer(4),Integer(3)]) >>> v.max() 3 >>> v.max(index=True) (3, 2)
- min(index=False)[source]#
Return the smallest value in this integer list. If this series has length 0 we raise a
ValueError
.INPUT:
index
– bool (default:False
); ifTrue
, also return index of minimal entry.
OUTPUT:
float – smallest value
integer – index of smallest value; only returned if
index=True
EXAMPLES:
sage: v = stats.IntList([1,-4,3,-2,-4]) sage: v.min() -4 sage: v.min(index=True) (-4, 1)
>>> from sage.all import * >>> v = stats.IntList([Integer(1),-Integer(4),Integer(3),-Integer(2),-Integer(4)]) >>> v.min() -4 >>> v.min(index=True) (-4, 1)
- plot(*args, **kwds)[source]#
Return a plot of this
IntList
.This just constructs the corresponding double-precision floating point
TimeSeries
object, passing on all arguments.EXAMPLES:
sage: stats.IntList([3,7,19,-2]).plot() # needs sage.plot Graphics object consisting of 1 graphics primitive sage: stats.IntList([3,7,19,-2]).plot(color='red', # needs sage.plot ....: pointsize=50, points=True) Graphics object consisting of 1 graphics primitive
>>> from sage.all import * >>> stats.IntList([Integer(3),Integer(7),Integer(19),-Integer(2)]).plot() # needs sage.plot Graphics object consisting of 1 graphics primitive >>> stats.IntList([Integer(3),Integer(7),Integer(19),-Integer(2)]).plot(color='red', # needs sage.plot ... pointsize=Integer(50), points=True) Graphics object consisting of 1 graphics primitive
- plot_histogram(*args, **kwds)[source]#
Return a histogram plot of this
IntList
.This just constructs the corresponding double-precision floating point
TimeSeries
object, and plots it, passing on all arguments.EXAMPLES:
sage: stats.IntList([1..15]).plot_histogram() # needs sage.plot Graphics object consisting of 50 graphics primitives
>>> from sage.all import * >>> stats.IntList((ellipsis_range(Integer(1),Ellipsis,Integer(15)))).plot_histogram() # needs sage.plot Graphics object consisting of 50 graphics primitives
- prod()[source]#
Return the product of the entries of
self
.EXAMPLES:
sage: a = stats.IntList([1..10]); a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] sage: a.prod() 3628800 sage: factorial(10) 3628800
>>> from sage.all import * >>> a = stats.IntList((ellipsis_range(Integer(1),Ellipsis,Integer(10)))); a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> a.prod() 3628800 >>> factorial(Integer(10)) 3628800
Note that there can be overflow:
sage: a = stats.IntList([2^30, 2]); a [1073741824, 2] sage: a.prod() -2147483648
>>> from sage.all import * >>> a = stats.IntList([Integer(2)**Integer(30), Integer(2)]); a [1073741824, 2] >>> a.prod() -2147483648
- sum()[source]#
Return the sum of the entries of
self
.EXAMPLES:
sage: stats.IntList([1..100]).sum() 5050
>>> from sage.all import * >>> stats.IntList((ellipsis_range(Integer(1),Ellipsis,Integer(100)))).sum() 5050
Note that there can be overflow, since the entries are C ints:
sage: a = stats.IntList([2^30,2^30]); a [1073741824, 1073741824] sage: a.sum() -2147483648
>>> from sage.all import * >>> a = stats.IntList([Integer(2)**Integer(30),Integer(2)**Integer(30)]); a [1073741824, 1073741824] >>> a.sum() -2147483648
- time_series()[source]#
Return
TimeSeries
version ofself
, which involves changing each entry to a double.EXAMPLES:
sage: T = stats.IntList([-2,3,5]).time_series(); T [-2.0000, 3.0000, 5.0000] sage: type(T) <... 'sage.stats.time_series.TimeSeries'>
>>> from sage.all import * >>> T = stats.IntList([-Integer(2),Integer(3),Integer(5)]).time_series(); T [-2.0000, 3.0000, 5.0000] >>> type(T) <... 'sage.stats.time_series.TimeSeries'>
- sage.stats.intlist.unpickle_intlist_v1(v, n)[source]#
Version 1 unpickle method.
INPUT:
v
– a raw char buffer
EXAMPLES:
sage: v = stats.IntList([1,2,3]) sage: s = v.__reduce__()[1][0] sage: type(s) == type(b'') True sage: sage.stats.intlist.unpickle_intlist_v1(s, 3) [1, 2, 3] sage: sage.stats.intlist.unpickle_intlist_v1(s+s,6) [1, 2, 3, 1, 2, 3] sage: sage.stats.intlist.unpickle_intlist_v1(b'',0) []
>>> from sage.all import * >>> v = stats.IntList([Integer(1),Integer(2),Integer(3)]) >>> s = v.__reduce__()[Integer(1)][Integer(0)] >>> type(s) == type(b'') True >>> sage.stats.intlist.unpickle_intlist_v1(s, Integer(3)) [1, 2, 3] >>> sage.stats.intlist.unpickle_intlist_v1(s+s,Integer(6)) [1, 2, 3, 1, 2, 3] >>> sage.stats.intlist.unpickle_intlist_v1(b'',Integer(0)) []