@@ -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