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

Bases: object

A list of C int’s.

list()

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'>
max(index=False)

Return the largest value in this time series. If this series has length 0 we raise a ValueError

INPUT:

  • index – bool (default: False); if True, 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)
min(index=False)

Return the smallest value in this integer list. If this series has length 0 we raise a ValueError.

INPUT:

  • index – bool (default: False); if True, 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)
plot(*args, **kwds)

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()
Graphics object consisting of 1 graphics primitive
sage: stats.IntList([3,7,19,-2]).plot(color='red',pointsize=50,points=True)
Graphics object consisting of 1 graphics primitive
plot_histogram(*args, **kwds)

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()
Graphics object consisting of 50 graphics primitives
prod()

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

Note that there can be overflow:

sage: a = stats.IntList([2^30, 2]); a
[1073741824, 2]
sage: a.prod()
-2147483648
sum()

Return the sum of the entries of self.

EXAMPLES:

sage: stats.IntList([1..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
time_series()

Return TimeSeries version of self, 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.finance.time_series.TimeSeries'>
sage.stats.intlist.unpickle_intlist_v1(v, n)

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)
[]