Skip to content

Commit 42137b1

Browse files
authored
Improve docs (#72)
1 parent d351c0f commit 42137b1

File tree

15 files changed

+190
-90
lines changed

15 files changed

+190
-90
lines changed

docs/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"sphinx.ext.intersphinx",
3737
"sphinx.ext.autodoc",
3838
"sphinx.ext.autosummary",
39+
"sphinx.ext.napoleon",
40+
# "scanpydoc.definition_list_typed_field",
3941
"scanpydoc.elegant_typehints",
4042
"sphinx_autofixture",
4143
]
@@ -59,6 +61,7 @@
5961
cupy=("https://docs.cupy.dev/en/stable/", None),
6062
dask=("https://docs.dask.org/en/stable/", None),
6163
h5py=("https://docs.h5py.org/en/stable/", None),
64+
numba=("https://numba.readthedocs.io/en/stable/", None),
6265
numpy=("https://numpy.org/doc/stable/", None),
6366
python=("https://docs.python.org/3", None),
6467
scipy=("https://docs.scipy.org/doc/scipy/", None),

docs/conv.rst

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
``fast_array_utils.conv``
2+
=========================
3+
4+
.. automodule:: fast_array_utils.conv
5+
:members:
6+
7+
``fast_array_utils.conv.scipy``
8+
-------------------------------
9+
10+
.. automodule:: fast_array_utils.conv.scipy
11+
:members:

docs/index.rst

+3-25
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,10 @@
55
:hidden:
66

77
fast-array-utils <self>
8+
conv
9+
stats
10+
typing
811
testing
912

1013
.. automodule:: fast_array_utils
1114
:members:
12-
13-
``fast_array_utils.types``
14-
--------------------------
15-
16-
.. automodule:: fast_array_utils.types
17-
:members: CSBase, CSDataset
18-
19-
``fast_array_utils.typing``
20-
---------------------------
21-
22-
.. automodule:: fast_array_utils.typing
23-
:members:
24-
25-
``fast_array_utils.conv``
26-
-------------------------
27-
28-
.. automodule:: fast_array_utils.conv
29-
:members:
30-
31-
32-
``fast_array_utils.stats``
33-
--------------------------
34-
35-
.. automodule:: fast_array_utils.stats
36-
:members:

docs/stats.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``fast_array_utils.stats``
2+
==========================
3+
4+
.. automodule:: fast_array_utils.stats
5+
:members:

docs/typing.rst

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
typing
2+
======
3+
4+
The two submodules differ depending on their runtime properties:
5+
6+
``fast_array_utils.types``
7+
--------------------------
8+
9+
.. automodule:: fast_array_utils.types
10+
:members: CSBase, CSDataset
11+
12+
``fast_array_utils.typing``
13+
---------------------------
14+
15+
.. automodule:: fast_array_utils.typing
16+
:members:

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ installer = "uv"
6767
features = [ "doc" ]
6868
scripts.build = "sphinx-build -M html docs docs/_build"
6969
scripts.clean = "git clean -fdX docs"
70+
scripts.open = "python -m webbrowser -t docs/_build/html/index.html"
7071

7172
[tool.hatch.envs.hatch-test]
73+
default-args = [ ]
7274
features = [ "test-min" ]
7375
extra-dependencies = [ "ipykernel", "ipycytoscape" ]
7476
env-vars.CODSPEED_PROFILE_FOLDER = "test-data/codspeed"
@@ -87,6 +89,8 @@ extras = [ "full", "default", "min" ]
8789
[tool.ruff]
8890
line-length = 100
8991
namespace-packages = [ "src/testing" ]
92+
format.preview = true
93+
format.docstring-code-format = true
9094
lint.select = [ "ALL" ]
9195
lint.ignore = [
9296
"A005", # submodules never shadow builtins.
@@ -113,7 +117,6 @@ lint.per-file-ignores."tests/**/*.py" = [
113117
lint.per-file-ignores."typings/**/*.pyi" = [ "A002", "F403", "F405", "N801" ] # Stubs don’t follow name conventions
114118
lint.allowed-confusables = [ "×", "" ]
115119
lint.flake8-bugbear.extend-immutable-calls = [ "testing.fast_array_utils.Flags" ]
116-
117120
lint.flake8-copyright.notice-rgx = "SPDX-License-Identifier: MPL-2\\.0"
118121
lint.flake8-type-checking.exempt-modules = [ ]
119122
lint.flake8-type-checking.strict = true

src/fast_array_utils/__init__.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# SPDX-License-Identifier: MPL-2.0
2-
"""Fast array utils."""
2+
"""Fast array utilities with minimal dependencies.
3+
4+
:mod:`fast_array_utils.conv`
5+
This submodule is always available and contains conversion utilities.
6+
7+
:mod:`fast_array_utils.stats`
8+
This submodule requires :doc:`numba <numba:index>` to be installed
9+
and contains statistics utilities.
10+
11+
:mod:`fast_array_utils.typing` and :mod:`fast_array_utils.types`
12+
These submodules contain types for annotations and checks, respectively.
13+
Stubs for these types are available even if the respective packages are not installed.
14+
"""
315

416
from __future__ import annotations
517

src/fast_array_utils/conv/__init__.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ def to_dense(
2525
x: CpuArray | DiskArray | types.sparray | types.spmatrix | types.CSDataset,
2626
/,
2727
*,
28-
to_memory: bool = False,
28+
to_cpu_memory: bool = False,
2929
) -> NDArray[Any]: ...
3030

3131

3232
@overload
33-
def to_dense(x: types.DaskArray, /, *, to_memory: Literal[False] = False) -> types.DaskArray: ...
33+
def to_dense(
34+
x: types.DaskArray, /, *, to_cpu_memory: Literal[False] = False
35+
) -> types.DaskArray: ...
3436
@overload
35-
def to_dense(x: types.DaskArray, /, *, to_memory: Literal[True]) -> NDArray[Any]: ...
37+
def to_dense(x: types.DaskArray, /, *, to_cpu_memory: Literal[True]) -> NDArray[Any]: ...
3638

3739

3840
@overload
3941
def to_dense(
40-
x: GpuArray | types.CupySpMatrix, /, *, to_memory: Literal[False] = False
42+
x: GpuArray | types.CupySpMatrix, /, *, to_cpu_memory: Literal[False] = False
4143
) -> types.CupyArray: ...
4244
@overload
43-
def to_dense(x: GpuArray | types.CupySpMatrix, /, *, to_memory: Literal[True]) -> NDArray[Any]: ...
45+
def to_dense(
46+
x: GpuArray | types.CupySpMatrix, /, *, to_cpu_memory: Literal[True]
47+
) -> NDArray[Any]: ...
4448

4549

4650
def to_dense(
@@ -54,20 +58,24 @@ def to_dense(
5458
| types.CupySpMatrix,
5559
/,
5660
*,
57-
to_memory: bool = False,
61+
to_cpu_memory: bool = False,
5862
) -> NDArray[Any] | types.DaskArray | types.CupyArray:
59-
"""Convert x to a dense array.
63+
r"""Convert x to a dense array.
64+
65+
If ``to_cpu_memory`` is :data:`False`, :class:`dask.array.Array`\ s and
66+
:class:`cupy.ndarray`\ s/:class:`cupyx.scipy.sparse.spmatrix` instances
67+
stay out-of-core and in GPU memory, respecively.
6068
6169
Parameters
6270
----------
6371
x
6472
Input object to be converted.
65-
to_memory
73+
to_cpu_memory
6674
Also load data into memory (resulting in a :class:`numpy.ndarray`).
6775
6876
Returns
6977
-------
7078
Dense form of ``x``
7179
7280
"""
73-
return to_dense_(x, to_memory=to_memory)
81+
return to_dense_(x, to_cpu_memory=to_cpu_memory)

src/fast_array_utils/conv/_to_dense.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: MPL-2.0
22
from __future__ import annotations
33

4-
from functools import singledispatch
4+
from functools import partial, singledispatch
55
from typing import TYPE_CHECKING, cast
66

77
import numpy as np
@@ -28,42 +28,46 @@ def to_dense_(
2828
| types.CupySpMatrix,
2929
/,
3030
*,
31-
to_memory: bool = False,
31+
to_cpu_memory: bool = False,
3232
) -> NDArray[Any] | types.CupyArray | types.DaskArray:
33-
del to_memory # it already is
33+
del to_cpu_memory # it already is
3434
return np.asarray(x)
3535

3636

3737
@to_dense_.register(types.spmatrix | types.sparray) # type: ignore[call-overload,misc]
38-
def _to_dense_cs(x: types.spmatrix | types.sparray, /, *, to_memory: bool = False) -> NDArray[Any]:
38+
def _to_dense_cs(
39+
x: types.spmatrix | types.sparray, /, *, to_cpu_memory: bool = False
40+
) -> NDArray[Any]:
3941
from . import scipy
4042

41-
del to_memory # it already is
43+
del to_cpu_memory # it already is
4244
return scipy.to_dense(x)
4345

4446

4547
@to_dense_.register(types.DaskArray)
4648
def _to_dense_dask(
47-
x: types.DaskArray, /, *, to_memory: bool = False
49+
x: types.DaskArray, /, *, to_cpu_memory: bool = False
4850
) -> NDArray[Any] | types.DaskArray:
4951
from . import to_dense
5052

51-
x = x.map_blocks(lambda x: to_dense(x, to_memory=to_memory))
52-
return x.compute() if to_memory else x # type: ignore[return-value]
53+
x = x.map_blocks(partial(to_dense, to_cpu_memory=to_cpu_memory))
54+
return x.compute() if to_cpu_memory else x # type: ignore[return-value]
5355

5456

5557
@to_dense_.register(types.CSDataset)
56-
def _to_dense_ooc(x: types.CSDataset, /, *, to_memory: bool = False) -> NDArray[Any]:
58+
def _to_dense_ooc(x: types.CSDataset, /, *, to_cpu_memory: bool = False) -> NDArray[Any]:
5759
from . import to_dense
5860

59-
if not to_memory:
60-
msg = "to_memory must be True if x is an CS{R,C}Dataset"
61+
if not to_cpu_memory:
62+
msg = "to_cpu_memory must be True if x is an CS{R,C}Dataset"
6163
raise ValueError(msg)
6264
# TODO(flying-sheep): why is to_memory of type Any? # noqa: TD003
6365
return to_dense(cast("types.CSBase", x.to_memory()))
6466

6567

6668
@to_dense_.register(types.CupyArray | types.CupySpMatrix) # type: ignore[call-overload,misc]
67-
def _to_dense_cupy(x: GpuArray, /, *, to_memory: bool = False) -> NDArray[Any] | types.CupyArray:
69+
def _to_dense_cupy(
70+
x: GpuArray, /, *, to_cpu_memory: bool = False
71+
) -> NDArray[Any] | types.CupyArray:
6872
x = x.toarray() if isinstance(x, types.CupySpMatrix) else x
69-
return x.get() if to_memory else x
73+
return x.get() if to_cpu_memory else x

0 commit comments

Comments
 (0)