Skip to content

Commit c19fef6

Browse files
authored
Merge pull request #467 from Blosc/arrayapi
Array-api 2
2 parents 6d34487 + ea3090f commit c19fef6

25 files changed

+6389
-2996
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ else()
5050
include(FetchContent)
5151
FetchContent_Declare(blosc2
5252
GIT_REPOSITORY https://github.com/Blosc/c-blosc2
53-
GIT_TAG 82a85f9d285d7ae6d141c73e84c7574bfc24a134 # v2.21.2
53+
GIT_TAG 0c853a639ba97997e33e29db9eed202459ebc6f0 # v2.21.3
5454
)
5555
FetchContent_MakeAvailable(blosc2)
5656
include_directories("${blosc2_SOURCE_DIR}/include")

doc/conf.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
# -- Path setup --------------------------------------------------------------
2+
import inspect
23
import os
34
import sys
45

6+
import numpy as np
7+
58
import blosc2
69

10+
11+
def genbody(f, func_list, lib="blosc2"):
12+
for func in func_list:
13+
f.write(f" {func}\n")
14+
15+
f.write("\n\n\n")
16+
for func in func_list:
17+
f.write(f".. autofunction:: {lib}.{func}\n\n")
18+
19+
720
sys.path.insert(0, os.path.abspath(os.path.dirname(blosc2.__file__)))
821

922
project = "Python-Blosc2"
@@ -69,6 +82,120 @@
6982
html_show_sourcelink = False
7083

7184
autosummary_generate_overwrite = False
85+
autosummary_generate = True
86+
87+
# GENERATE ufuncs.rst
88+
blosc2_ufuncs = []
89+
for name, obj in vars(np).items():
90+
if isinstance(obj, np.ufunc) and hasattr(blosc2, name):
91+
blosc2_ufuncs.append(name)
92+
93+
with open("reference/ufuncs.rst", "w") as f:
94+
f.write(
95+
"""Universal Functions (`ufuncs`)
96+
------------------------------
97+
98+
The following elementwise functions can be used for computing with any of :ref:`NDArray <NDArray>`, :ref:`C2Array <C2Array>`, :ref:`NDField <NDField>` and :ref:`LazyExpr <LazyExpr>`.
99+
100+
Their result is always a :ref:`LazyExpr` instance, which can be evaluated (with ``compute`` or ``__getitem__``) to get the actual values of the computation.
101+
102+
Note: The functions ``conj``, ``real``, ``imag``, ``contains``, ``where`` are not technically ufuncs.
103+
104+
.. currentmodule:: blosc2
105+
106+
.. autosummary::
107+
108+
"""
109+
)
110+
genbody(f, blosc2_ufuncs)
111+
112+
# GENERATE additional_funcs.rst
113+
blosc2_addfuncs = sorted(["conj", "real", "imag", "contains", "where", "clip", "round"])
114+
blosc2_dtypefuncs = sorted(["astype", "can_cast", "result_type", "isdtype"])
115+
116+
with open("reference/additional_funcs.rst", "w") as f:
117+
f.write(
118+
"""Additional Functions and Type Utilities
119+
=======================================
120+
121+
Functions
122+
---------
123+
124+
The following functions can also be used for computing with any of :ref:`NDArray <NDArray>`, :ref:`C2Array <C2Array>`, :ref:`NDField <NDField>` and :ref:`LazyExpr <LazyExpr>`.
125+
126+
Their result is typically a :ref:`LazyExpr` instance, which can be evaluated (with ``compute`` or ``__getitem__``) to get the actual values of the computation.
127+
128+
.. currentmodule:: blosc2
129+
130+
.. autosummary::
131+
132+
"""
133+
)
134+
genbody(f, blosc2_addfuncs)
135+
f.write(
136+
"""Type Utilities
137+
--------------
138+
139+
The following functions are useful for working with datatypes.
140+
141+
.. currentmodule:: blosc2
142+
143+
.. autosummary::
144+
145+
"""
146+
)
147+
genbody(f, blosc2_dtypefuncs)
148+
149+
# GENERATE index_funcs.rst
150+
blosc2_indexfuncs = sorted(
151+
[
152+
"count_nonzero",
153+
"squeeze",
154+
"expand_dims",
155+
"sort",
156+
"take",
157+
"take_along_axis",
158+
"broadcast_to",
159+
"meshgrid",
160+
"indices",
161+
]
162+
)
163+
164+
with open("reference/index_funcs.rst", "w") as f:
165+
f.write(
166+
"""Indexing Functions and Utilities
167+
=======================================
168+
169+
The following functions are useful for performing indexing and oter associated operations.
170+
171+
.. currentmodule:: blosc2
172+
173+
.. autosummary::
174+
175+
"""
176+
)
177+
genbody(f, blosc2_indexfuncs)
178+
179+
# GENERATE linear_algebra.rst
180+
linalg_funcs = [
181+
name
182+
for name, obj in vars(blosc2.linalg).items()
183+
if (inspect.isfunction(obj) and getattr(obj, "__doc__", None))
184+
]
185+
186+
with open("reference/linalg.rst", "w") as f:
187+
f.write(
188+
"""Linear Algebra
189+
-----------------
190+
The following functions can be used for computing linear algebra operations with :ref:`NDArray <NDArray>`.
191+
192+
.. currentmodule:: blosc2.linalg
193+
194+
.. autosummary::
195+
196+
"""
197+
)
198+
genbody(f, linalg_funcs, "blosc2.linalg")
72199

73200
hidden = "_ignore_multiple_size"
74201

doc/reference/additional_funcs.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Additional Functions and Type Utilities
2+
=======================================
3+
4+
Functions
5+
---------
6+
7+
The following functions can also be used for computing with any of :ref:`NDArray <NDArray>`, :ref:`C2Array <C2Array>`, :ref:`NDField <NDField>` and :ref:`LazyExpr <LazyExpr>`.
8+
9+
Their result is typically a :ref:`LazyExpr` instance, which can be evaluated (with ``compute`` or ``__getitem__``) to get the actual values of the computation.
10+
11+
.. currentmodule:: blosc2
12+
13+
.. autosummary::
14+
15+
clip
16+
conj
17+
contains
18+
imag
19+
real
20+
round
21+
where
22+
23+
24+
25+
.. autofunction:: blosc2.clip
26+
27+
.. autofunction:: blosc2.conj
28+
29+
.. autofunction:: blosc2.contains
30+
31+
.. autofunction:: blosc2.imag
32+
33+
.. autofunction:: blosc2.real
34+
35+
.. autofunction:: blosc2.round
36+
37+
.. autofunction:: blosc2.where
38+
39+
Type Utilities
40+
--------------
41+
42+
The following functions are useful for working with datatypes.
43+
44+
.. currentmodule:: blosc2
45+
46+
.. autosummary::
47+
48+
astype
49+
can_cast
50+
isdtype
51+
result_type
52+
53+
54+
55+
.. autofunction:: blosc2.astype
56+
57+
.. autofunction:: blosc2.can_cast
58+
59+
.. autofunction:: blosc2.isdtype
60+
61+
.. autofunction:: blosc2.result_type

doc/reference/array_operations.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Operations with arrays
44
.. toctree::
55
:maxdepth: 1
66

7-
lazy_functions
7+
ufuncs
88
reduction_functions
9-
linear_algebra
9+
linalg
10+
additional_funcs
11+
index_funcs

doc/reference/index_funcs.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Indexing Functions and Utilities
2+
=======================================
3+
4+
The following functions are useful for performing indexing and oter associated operations.
5+
6+
.. currentmodule:: blosc2
7+
8+
.. autosummary::
9+
10+
broadcast_to
11+
count_nonzero
12+
expand_dims
13+
indices
14+
meshgrid
15+
sort
16+
squeeze
17+
take
18+
take_along_axis
19+
20+
21+
22+
.. autofunction:: blosc2.broadcast_to
23+
24+
.. autofunction:: blosc2.count_nonzero
25+
26+
.. autofunction:: blosc2.expand_dims
27+
28+
.. autofunction:: blosc2.indices
29+
30+
.. autofunction:: blosc2.meshgrid
31+
32+
.. autofunction:: blosc2.sort
33+
34+
.. autofunction:: blosc2.squeeze
35+
36+
.. autofunction:: blosc2.take
37+
38+
.. autofunction:: blosc2.take_along_axis

doc/reference/lazy_functions.rst

Lines changed: 0 additions & 63 deletions
This file was deleted.

doc/reference/linalg.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Linear Algebra
2+
-----------------
3+
The following functions can be used for computing linear algebra operations with :ref:`NDArray <NDArray>`.
4+
5+
.. currentmodule:: blosc2.linalg
6+
7+
.. autosummary::
8+
9+
matmul
10+
tensordot
11+
vecdot
12+
permute_dims
13+
transpose
14+
matrix_transpose
15+
diagonal
16+
outer
17+
18+
19+
20+
.. autofunction:: blosc2.linalg.matmul
21+
22+
.. autofunction:: blosc2.linalg.tensordot
23+
24+
.. autofunction:: blosc2.linalg.vecdot
25+
26+
.. autofunction:: blosc2.linalg.permute_dims
27+
28+
.. autofunction:: blosc2.linalg.transpose
29+
30+
.. autofunction:: blosc2.linalg.matrix_transpose
31+
32+
.. autofunction:: blosc2.linalg.diagonal
33+
34+
.. autofunction:: blosc2.linalg.outer

doc/reference/linear_algebra.rst

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)