Skip to content

Commit 1130436

Browse files
authored
Merge pull request #2664 from tdegeus/strides
[docs] Improving documentation `xstrides`
2 parents c51af85 + d19e508 commit 1130436

4 files changed

Lines changed: 79 additions & 16 deletions

File tree

docs/source/api/shape.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht
2+
3+
Distributed under the terms of the BSD 3-Clause License.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
Shape/index manipulation
8+
========================
9+
10+
.. toctree::
11+
12+
xshape
13+
xstrides

docs/source/api/xstrides.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
xshape
8-
======
7+
xstrides
8+
========
99

10-
Defined in ``xtensor/xstride.hpp``
10+
Defined in ``xtensor/xstrides.hpp``
1111

12-
.. doxygenfunction:: auto strides(const E& e, xt::stride_type type)
12+
.. cpp:namespace-push:: xt
1313

14-
.. doxygenfunction:: auto strides(const E& e, S axis, xt::stride_type type)
14+
.. doxygengroup:: xt_xstrides
15+
16+
.. cpp:namespace-pop::

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ for details.
9898
api/function_index
9999
api/io_index
100100
api/xmath
101-
api/xshape
101+
api/shape
102102

103103
.. toctree::
104104
:caption: DEVELOPER ZONE

include/xtensor/xstrides.hpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,40 @@ namespace xt
2828
template <class shape_type>
2929
std::size_t compute_size(const shape_type& shape) noexcept;
3030

31+
/**
32+
* @defgroup xt_xstrides Support functions swich between array indices and flat indices
33+
*/
34+
3135
/***************
3236
* data offset *
3337
***************/
3438

3539
template <class offset_type, class S>
3640
offset_type data_offset(const S& strides) noexcept;
3741

42+
/**
43+
* @brief Return the flat index for an array index.
44+
*
45+
* Given ``m`` arguments, and dimension ``n``of the array (``n == strides.size()``).
46+
*
47+
* - If ``m == n``, the index is
48+
* ``strides[0] * index[0] + ... + strides[n - 1] * index[n - 1]``.
49+
*
50+
* - If ``m < n`` and the last argument is ``xt::missing`` the indices are zero-padded at
51+
* the end to match the dimension of the array. The index is then
52+
* ``strides[0] * index[0] + ... + strides[m - 1] * index[m - 1]``.
53+
*
54+
* - If ``m < n`` (and the last argument is not ``xt::missing``), the index is
55+
* ``strides[n - m - 1] * index[0] + ... + strides[n - 1] * index[m - 1]``.
56+
*
57+
* - If ``m > n``, then the first ``m - n`` arguments are ignored. The index is then
58+
* ``strides[0] * index[m - n] + ... + strides[n - 1] * index[m - 1]``.
59+
*
60+
* @ingroup xt_xstrides
61+
* @param strides Strides of the array.
62+
* @param args Array index.
63+
* @return The flat index.
64+
*/
3865
template <class offset_type, class S, class Arg, class... Args>
3966
offset_type data_offset(const S& strides, Arg arg, Args... args) noexcept;
4067

@@ -48,6 +75,15 @@ namespace xt
4875
* strides builder *
4976
*******************/
5077

78+
/**
79+
* @brief Compute the strides given the shape and the layout of an array.
80+
*
81+
* @ingroup xt_xstrides
82+
* @param shape Shape of the array.
83+
* @param l Layout type, see xt::layout_type().
84+
* @param strides (output) Strides of the array.
85+
* @return The size: the product of the shape.
86+
*/
5187
template <layout_type L = layout_type::dynamic, class shape_type, class strides_type>
5288
std::size_t compute_strides(const shape_type& shape, layout_type l, strides_type& strides);
5389

@@ -100,13 +136,29 @@ namespace xt
100136
* check bounds, without throwing *
101137
**********************************/
102138

139+
/**
140+
* @brief Check if the index is within the bounds of the array.
141+
*
142+
* @param shape Shape of the array.
143+
* @param args Array index.
144+
* @return true If the index is within the bounds of the array.
145+
* @return false Otherwise.
146+
*/
103147
template <class S, class... Args>
104148
bool in_bounds(const S& shape, Args&... args);
105149

106150
/********************************
107151
* apply periodicity to indices *
108152
*******************************/
109153

154+
/**
155+
* @brief Normalise an index of a periodic array.
156+
* For example if the shape is ``(3, 4)`` and the index is ``(3, -4)`` the result is ``(0, 0)``.
157+
*
158+
* @ingroup xt_xstrides
159+
* @param shape Shape of the array.
160+
* @param args (input/output) Array index.
161+
*/
110162
template <class S, class... Args>
111163
void normalize_periodic(const S& shape, Args&... args);
112164

@@ -175,10 +227,8 @@ namespace xt
175227
}
176228

177229
/**
178-
* @ingroup strides
179-
* @brief strides_type
180-
*
181-
* Choose stride type
230+
* @brief Choose stride type
231+
* @ingroup xt_xstrides
182232
*/
183233
enum class stride_type
184234
{
@@ -188,10 +238,9 @@ namespace xt
188238
};
189239

190240
/**
191-
* @ingroup strides
192-
* @brief strides
241+
* @brief Get strides of an object.
193242
*
194-
* Get strides of an object.
243+
* @ingroup xt_xstrides
195244
* @param a an array
196245
* @return array
197246
*/
@@ -233,10 +282,9 @@ namespace xt
233282
}
234283

235284
/**
236-
* @ingroup strides
237-
* @brief strides
285+
* @brief Get stride of an object along an axis.
238286
*
239-
* Get stride of an object along an axis.
287+
* @ingroup xt_xstrides
240288
* @param a an array
241289
* @return integer
242290
*/

0 commit comments

Comments
 (0)