Skip to content

Commit e44074f

Browse files
authored
Merge pull request #29 from jhlegarreta/FixbvalIteratorsTypeAnnotations
DOC: Revision of docstrings in the iterators' module
2 parents f82305c + 8ceaf57 commit e44074f

File tree

1 file changed

+52
-30
lines changed

1 file changed

+52
-30
lines changed

src/nifreeze/utils/iterators.py

+52-30
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ def linear_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
3333
3434
Parameters
3535
----------
36-
size : :obj:`int`
37-
Number of volumes in the dataset
38-
(for instance, the number of orientations in a DWI)
39-
40-
Returns
41-
-------
42-
:obj:`~typing.Iterator`
43-
The sorted index order.
36+
size : :obj:`int` or ``None``, optional
37+
Number of volumes in the dataset.
38+
If ``None``, ``size`` will be inferred from the ``bvalues``
39+
keyword argument.
40+
bvalues : :obj:`list`, optional (keyword argument)
41+
List of b-values corresponding to all orientations of a DWI dataset.
42+
If ``size`` is provided, this argument will be ignored.
43+
Otherwise, ``size`` will be inferred from the length of ``bvalues``.
44+
45+
Yields
46+
------
47+
:obj:`int`
48+
The next index.
4449
4550
Examples
4651
--------
@@ -53,28 +58,38 @@ def linear_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
5358
if size is None:
5459
raise TypeError("Cannot build iterator without size")
5560

56-
return iter(range(size))
61+
return (s for s in range(size))
5762

5863

5964
def random_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
6065
"""
6166
Traverse the dataset volumes randomly.
6267
68+
If the ``seed`` key is present in the keyword arguments, initializes the seed
69+
of Python's ``random`` pseudo-random number generator library with the given
70+
value. Specifically, if ``False``, ``None`` is used as the seed; if ``True``, a
71+
default seed value is used.
72+
6373
Parameters
6474
----------
65-
size : :obj:`int`
66-
Number of volumes in the dataset
67-
(for instance, the number of orientations in a DWI)
68-
seed : :obj:`int` or :obj:`bool` or :obj:`bool` or ``None``
75+
size : :obj:`int` or ``None``, optional
76+
Number of volumes in the dataset.
77+
If ``None``, ``size`` will be inferred from the ``bvalues``
78+
keyword argument.
79+
bvalues : :obj:`list`, optional (keyword argument)
80+
List of b-values corresponding to all orientations of a DWI dataset.
81+
If ``size`` is provided, this argument will be ignored.
82+
Otherwise, ``size`` will be inferred from the length of ``bvalues``.
83+
seed : :obj:`int`, :obj:`bool`, :obj:`str`, or ``None``, optional (keyword argument)
6984
If :obj:`int` or :obj:`str` or ``None``, initializes the seed of Python's random generator
7085
with the given value.
7186
If ``False``, the random generator is passed ``None``.
7287
If ``True``, a default seed value is set.
7388
74-
Returns
75-
-------
76-
:obj:`~typing.Iterator`
77-
The sorted index order.
89+
Yields
90+
------
91+
:obj:`int`
92+
The next index.
7893
7994
Examples
8095
--------
@@ -105,19 +120,21 @@ def random_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
105120
return (x for x in index_order)
106121

107122

108-
def bvalue_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
123+
def bvalue_iterator(*_, **kwargs) -> Iterator[int]:
109124
"""
110125
Traverse the volumes in a DWI dataset by growing b-value.
111126
112127
Parameters
113128
----------
114129
bvalues : :obj:`list`
115130
List of b-values corresponding to all orientations of the dataset.
131+
Please note that ``bvalues`` is a keyword argument and MUST be provided
132+
to generate the volume sequence.
116133
117-
Returns
118-
-------
119-
:obj:`~typing.Iterator`
120-
The sorted index order.
134+
Yields
135+
------
136+
:obj:`int`
137+
The next index.
121138
122139
Examples
123140
--------
@@ -138,14 +155,19 @@ def centralsym_iterator(size: int | None = None, **kwargs) -> Iterator[int]:
138155
139156
Parameters
140157
----------
141-
size : :obj:`int`
142-
Number of volumes in the dataset
143-
(for instance, the number of orientations in a DWI)
144-
145-
Returns
146-
-------
147-
:obj:`~typing.Iterator`
148-
The sorted index order.
158+
size : :obj:`int` or ``None``, optional
159+
Number of volumes in the dataset.
160+
If ``None``, ``size`` will be inferred from the ``bvalues``
161+
keyword argument.
162+
bvalues : :obj:`list`, optional (keyword argument)
163+
List of b-values corresponding to all orientations of the dataset.
164+
If ``size`` is provided, this argument will be ignored.
165+
Otherwise, ``size`` will be inferred from the length of ``bvalues``.
166+
167+
Yields
168+
------
169+
:obj:`~int`
170+
The next index.
149171
150172
Examples
151173
--------

0 commit comments

Comments
 (0)