Skip to content

Commit ff5ea66

Browse files
authored
Merge pull request #575 from Blosc/optimise_cumsum
Optimise cumsum
2 parents 114719e + 8f5cdff commit ff5ea66

13 files changed

Lines changed: 1030 additions & 459 deletions

File tree

doc/conf.py

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77

88
import blosc2
9+
from blosc2.utils import constructors, elementwise_funcs, reducers
910

1011

1112
def genbody(f, func_list, lib="blosc2"):
@@ -99,7 +100,7 @@ def genbody(f, func_list, lib="blosc2"):
99100
100101
Their result is always a :ref:`LazyExpr` instance, which can be evaluated (with ``compute`` or ``__getitem__``) to get the actual values of the computation.
101102
102-
Note: The functions ``conj``, ``real``, ``imag``, ``contains``, ``where`` are not technically ufuncs.
103+
Note: The functions ``real``, ``imag``, ``contains``, ``where`` are not technically ufuncs.
103104
104105
.. currentmodule:: blosc2
105106
@@ -110,7 +111,7 @@ def genbody(f, func_list, lib="blosc2"):
110111
genbody(f, blosc2_ufuncs)
111112

112113
# GENERATE additional_funcs.rst
113-
blosc2_addfuncs = sorted(["conj", "real", "imag", "contains", "where", "clip", "round"])
114+
blosc2_addfuncs = sorted(set(elementwise_funcs) - set(blosc2_ufuncs))
114115
blosc2_dtypefuncs = sorted(["astype", "can_cast", "result_type", "isdtype"])
115116

116117
with open("reference/additional_funcs.rst", "w") as f:
@@ -133,7 +134,9 @@ def genbody(f, func_list, lib="blosc2"):
133134
)
134135
genbody(f, blosc2_addfuncs)
135136
f.write(
136-
"""Type Utilities
137+
"""
138+
139+
Type Utilities
137140
--------------
138141
139142
The following functions are useful for working with datatypes.
@@ -158,12 +161,14 @@ def genbody(f, func_list, lib="blosc2"):
158161
"broadcast_to",
159162
"meshgrid",
160163
"indices",
164+
"concat",
165+
"stack",
161166
]
162167
)
163168

164169
with open("reference/index_funcs.rst", "w") as f:
165170
f.write(
166-
"""Indexing Functions and Utilities
171+
"""Indexing and Manipulation Functions and Utilities
167172
=======================================
168173
169174
The following functions are useful for performing indexing and other associated operations.
@@ -195,7 +200,68 @@ def genbody(f, func_list, lib="blosc2"):
195200
196201
"""
197202
)
198-
genbody(f, linalg_funcs, "blosc2.linalg")
203+
genbody(f, sorted(linalg_funcs), "blosc2.linalg")
204+
205+
with open("reference/reduction_functions.rst", "w") as f:
206+
f.write(
207+
"""Reduction Functions
208+
-------------------
209+
210+
Contrarily to lazy functions, reduction functions are evaluated eagerly, and the result is always a NumPy array (although this can be converted internally into an :ref:`NDArray <NDArray>` if you pass any :func:`blosc2.empty` arguments in ``kwargs``).
211+
212+
Reduction operations can be used with any of :ref:`NDArray <NDArray>`, :ref:`C2Array <C2Array>`, :ref:`NDField <NDField>` and :ref:`LazyExpr <LazyExpr>`. Again, although these can be part of a :ref:`LazyExpr <LazyExpr>`, you must be aware that they are not lazy, but will be evaluated eagerly during the construction of a LazyExpr instance (this might change in the future). When the input is a :ref:`LazyExpr`, reductions accept ``fp_accuracy`` to control floating-point accuracy, and it is forwarded to :func:`LazyExpr.compute`.
213+
214+
.. currentmodule:: blosc2
215+
216+
.. autosummary::
217+
218+
"""
219+
)
220+
genbody(f, sorted(reducers))
221+
222+
with open("reference/ndarray.rst", "w") as f:
223+
f.write(
224+
""".. _NDArray:
225+
226+
NDArray
227+
=======
228+
229+
The multidimensional data array class. Instances may be constructed using the constructor functions in the list below `NDArrayConstructors`_.
230+
In addition, all the functions from the :ref:`Lazy Functions <lazy_functions>` section can be used with NDArray instances.
231+
232+
.. currentmodule:: blosc2
233+
234+
.. autoclass:: NDArray
235+
:members:
236+
:inherited-members:
237+
:exclude-members: get_slice, set_slice, get_slice_numpy, get_oindex_numpy, set_oindex_numpy
238+
:member-order: groupwise
239+
240+
:Special Methods:
241+
242+
.. autosummary::
243+
244+
__iter__
245+
__len__
246+
__getitem__
247+
__setitem__
248+
249+
Utility Methods
250+
---------------
251+
252+
.. automethod:: __iter__
253+
.. automethod:: __len__
254+
.. automethod:: __getitem__
255+
.. automethod:: __setitem__
256+
257+
Constructors
258+
------------
259+
.. _NDArrayConstructors:
260+
.. autosummary::
261+
262+
"""
263+
)
264+
genbody(f, sorted(constructors))
199265

200266
hidden = "_ignore_multiple_size"
201267

doc/reference/additional_funcs.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Their result is typically a :ref:`LazyExpr` instance, which can be evaluated (wi
1212

1313
.. autosummary::
1414

15+
broadcast_to
1516
clip
16-
conj
1717
contains
1818
imag
1919
real
@@ -22,13 +22,15 @@ Their result is typically a :ref:`LazyExpr` instance, which can be evaluated (wi
2222

2323

2424

25+
.. autofunction:: blosc2.broadcast_to
2526
.. autofunction:: blosc2.clip
26-
.. autofunction:: blosc2.conj
2727
.. autofunction:: blosc2.contains
2828
.. autofunction:: blosc2.imag
2929
.. autofunction:: blosc2.real
3030
.. autofunction:: blosc2.round
3131
.. autofunction:: blosc2.where
32+
33+
3234
Type Utilities
3335
--------------
3436

doc/reference/index_funcs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Indexing Functions and Utilities
1+
Indexing and Manipulation Functions and Utilities
22
=======================================
33

44
The following functions are useful for performing indexing and other associated operations.

doc/reference/linalg.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ The following functions can be used for computing linear algebra operations with
66

77
.. autosummary::
88

9+
diagonal
910
matmul
10-
tensordot
11-
vecdot
12-
permute_dims
13-
transpose
1411
matrix_transpose
15-
diagonal
1612
outer
13+
permute_dims
14+
tensordot
15+
transpose
16+
vecdot
1717

1818

1919

20+
.. autofunction:: blosc2.linalg.diagonal
2021
.. autofunction:: blosc2.linalg.matmul
21-
.. autofunction:: blosc2.linalg.tensordot
22-
.. autofunction:: blosc2.linalg.vecdot
23-
.. autofunction:: blosc2.linalg.permute_dims
24-
.. autofunction:: blosc2.linalg.transpose
2522
.. autofunction:: blosc2.linalg.matrix_transpose
26-
.. autofunction:: blosc2.linalg.diagonal
2723
.. autofunction:: blosc2.linalg.outer
24+
.. autofunction:: blosc2.linalg.permute_dims
25+
.. autofunction:: blosc2.linalg.tensordot
26+
.. autofunction:: blosc2.linalg.transpose
27+
.. autofunction:: blosc2.linalg.vecdot

doc/reference/misc.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This page documents the miscellaneous members of the ``blosc2`` module that do n
77
:members:
88
:exclude-members: LazyArray,
99
LazyExpr,
10+
LazyUDF,
1011
lazyexpr,
1112
lazyudf,
1213
evaluate,
@@ -227,4 +228,6 @@ This page documents the miscellaneous members of the ``blosc2`` module that do n
227228
round,
228229
are_partitions_aligned,
229230
are_partitions_behaved,
230-
indices
231+
indices,
232+
cumulative_sum,
233+
cumulative_prod,

doc/reference/ndarray.rst

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ Constructors
3838

3939
arange
4040
asarray
41-
concat
4241
copy
4342
empty
4443
empty_like
45-
expand_dims
4644
eye
4745
frombuffer
4846
fromiter
47+
fromiter
4948
full
5049
full_like
5150
linspace
@@ -55,31 +54,30 @@ Constructors
5554
ones
5655
ones_like
5756
reshape
58-
stack
59-
squeeze
6057
uninit
6158
zeros
6259
zeros_like
6360

64-
.. autofunction:: arange
65-
.. autofunction:: asarray
66-
.. autofunction:: concat
67-
.. autofunction:: copy
68-
.. autofunction:: empty
69-
.. autofunction:: empty_like
70-
.. autofunction:: expand_dims
71-
.. autofunction:: eye
72-
.. autofunction:: frombuffer
73-
.. autofunction:: fromiter
74-
.. autofunction:: full
75-
.. autofunction:: full_like
76-
.. autofunction:: linspace
77-
.. autofunction:: nans
78-
.. autofunction:: ndarray_from_cframe
79-
.. autofunction:: ones
80-
.. autofunction:: ones_like
81-
.. autofunction:: reshape
82-
.. autofunction:: stack
83-
.. autofunction:: uninit
84-
.. autofunction:: zeros
85-
.. autofunction:: zeros_like
61+
62+
63+
.. autofunction:: blosc2.arange
64+
.. autofunction:: blosc2.asarray
65+
.. autofunction:: blosc2.copy
66+
.. autofunction:: blosc2.empty
67+
.. autofunction:: blosc2.empty_like
68+
.. autofunction:: blosc2.eye
69+
.. autofunction:: blosc2.frombuffer
70+
.. autofunction:: blosc2.fromiter
71+
.. autofunction:: blosc2.fromiter
72+
.. autofunction:: blosc2.full
73+
.. autofunction:: blosc2.full_like
74+
.. autofunction:: blosc2.linspace
75+
.. autofunction:: blosc2.meshgrid
76+
.. autofunction:: blosc2.nans
77+
.. autofunction:: blosc2.ndarray_from_cframe
78+
.. autofunction:: blosc2.ones
79+
.. autofunction:: blosc2.ones_like
80+
.. autofunction:: blosc2.reshape
81+
.. autofunction:: blosc2.uninit
82+
.. autofunction:: blosc2.zeros
83+
.. autofunction:: blosc2.zeros_like

doc/reference/reduction_functions.rst

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,32 @@ Reduction operations can be used with any of :ref:`NDArray <NDArray>`, :ref:`C2A
1111

1212
all
1313
any
14-
sum
15-
prod
14+
argmax
15+
argmin
16+
count_nonzero
17+
cumulative_prod
18+
cumulative_sum
19+
max
1620
mean
21+
min
22+
prod
1723
std
24+
sum
1825
var
19-
min
20-
max
21-
argmin
22-
argmax
2326

24-
.. autofunction:: all
25-
.. autofunction:: any
26-
.. autofunction:: sum
27-
.. autofunction:: prod
28-
.. autofunction:: mean
29-
.. autofunction:: std
30-
.. autofunction:: var
31-
.. autofunction:: min
32-
.. autofunction:: max
33-
.. autofunction:: argmin
34-
.. autofunction:: argmax
27+
28+
29+
.. autofunction:: blosc2.all
30+
.. autofunction:: blosc2.any
31+
.. autofunction:: blosc2.argmax
32+
.. autofunction:: blosc2.argmin
33+
.. autofunction:: blosc2.count_nonzero
34+
.. autofunction:: blosc2.cumulative_prod
35+
.. autofunction:: blosc2.cumulative_sum
36+
.. autofunction:: blosc2.max
37+
.. autofunction:: blosc2.mean
38+
.. autofunction:: blosc2.min
39+
.. autofunction:: blosc2.prod
40+
.. autofunction:: blosc2.std
41+
.. autofunction:: blosc2.sum
42+
.. autofunction:: blosc2.var

doc/reference/ufuncs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The following elementwise functions can be used for computing with any of :ref:`
55

66
Their result is always a :ref:`LazyExpr` instance, which can be evaluated (with ``compute`` or ``__getitem__``) to get the actual values of the computation.
77

8-
Note: The functions ``conj``, ``real``, ``imag``, ``contains``, ``where`` are not technically ufuncs.
8+
Note: The functions ``real``, ``imag``, ``contains``, ``where`` are not technically ufuncs.
99

1010
.. currentmodule:: blosc2
1111

src/blosc2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ def _raise(exc):
556556
cos,
557557
cosh,
558558
count_nonzero,
559+
cumulative_prod,
560+
cumulative_sum,
559561
divide,
560562
equal,
561563
exp,
@@ -719,6 +721,8 @@ def _raise(exc):
719721
"count_nonzero",
720722
"cparams_dflts",
721723
"cpu_info",
724+
"cumulative_prod",
725+
"cumulative_sum",
722726
"decompress",
723727
"decompress2",
724728
"detect_number_of_cores",

0 commit comments

Comments
 (0)