Compute :meth:`toolz.accumulate` with caching. Caching is by the identify of `seq` rather than the value. It is thus important that `seq` is a tuple of immutable objects, and this function is intended for use where `seq` is a value that will persist (generally block sizes). Par
(seq, initial_zero=False)
| 2123 | |
| 2124 | |
| 2125 | def cached_cumsum(seq, initial_zero=False): |
| 2126 | """Compute :meth:`toolz.accumulate` with caching. |
| 2127 | |
| 2128 | Caching is by the identify of `seq` rather than the value. It is thus |
| 2129 | important that `seq` is a tuple of immutable objects, and this function |
| 2130 | is intended for use where `seq` is a value that will persist (generally |
| 2131 | block sizes). |
| 2132 | |
| 2133 | Parameters |
| 2134 | ---------- |
| 2135 | seq : tuple |
| 2136 | Values to cumulatively sum. |
| 2137 | initial_zero : bool, optional |
| 2138 | If true, the return value is prefixed with a zero. |
| 2139 | |
| 2140 | Returns |
| 2141 | ------- |
| 2142 | tuple |
| 2143 | """ |
| 2144 | if isinstance(seq, tuple): |
| 2145 | # Look up by identity first, to avoid a linear-time __hash__ |
| 2146 | # if we've seen this tuple object before. |
| 2147 | result = _cumsum(_HashIdWrapper(seq), initial_zero) |
| 2148 | else: |
| 2149 | # Construct a temporary tuple, and look up by value. |
| 2150 | result = _cumsum(tuple(seq), initial_zero) |
| 2151 | return result |
| 2152 | |
| 2153 | |
| 2154 | def show_versions() -> None: |
searching dependent graphs…