2424
2525namespace xt
2626{
27+ /* *
28+ * @defgroup xt_xadapt Adaptors of STL-like containers
29+ */
30+
2731 namespace detail
2832 {
2933 template <class >
@@ -66,6 +70,8 @@ namespace xt
6670 /* *
6771 * Constructs an xarray_adaptor of the given stl-like container,
6872 * with the specified shape and layout.
73+ *
74+ * @ingroup xt_xadapt
6975 * @param container the container to adapt
7076 * @param shape the shape of the xarray_adaptor
7177 * @param l the layout_type of the xarray_adaptor
@@ -85,6 +91,8 @@ namespace xt
8591
8692 /* *
8793 * Constructs an non-owning xarray_adaptor from a pointer with the specified shape and layout.
94+ *
95+ * @ingroup xt_xadapt
8896 * @param pointer the container to adapt
8997 * @param shape the shape of the xarray_adaptor
9098 * @param l the layout_type of the xarray_adaptor
@@ -106,6 +114,8 @@ namespace xt
106114 /* *
107115 * Constructs an xarray_adaptor of the given stl-like container,
108116 * with the specified shape and strides.
117+ *
118+ * @ingroup xt_xadapt
109119 * @param container the container to adapt
110120 * @param shape the shape of the xarray_adaptor
111121 * @param strides the strides of the xarray_adaptor
@@ -130,6 +140,8 @@ namespace xt
130140 /* *
131141 * Constructs an xarray_adaptor of the given dynamically allocated C array,
132142 * with the specified shape and layout.
143+ *
144+ * @ingroup xt_xadapt
133145 * @param pointer the pointer to the beginning of the dynamic array
134146 * @param size the size of the dynamic array
135147 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -165,6 +177,8 @@ namespace xt
165177 /* *
166178 * Constructs an xarray_adaptor of the given dynamically allocated C array,
167179 * with the specified shape and strides.
180+ *
181+ * @ingroup xt_xadapt
168182 * @param pointer the pointer to the beginning of the dynamic array
169183 * @param size the size of the dynamic array
170184 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -196,8 +210,10 @@ namespace xt
196210 }
197211
198212 /* *
199- * Contructs an xarray_adaptor of the given C array allocated on the stack, with the
213+ * Constructs an xarray_adaptor of the given C array allocated on the stack, with the
200214 * specified shape and layout.
215+ *
216+ * @ingroup xt_xadapt
201217 * @param c_array the C array allocated on the stack
202218 * @param shape the shape of the xarray_adaptor
203219 * @param l the layout_type of the xarray_adaptor
@@ -214,8 +230,10 @@ namespace xt
214230 }
215231
216232 /* *
217- * Contructs an xarray_adaptor of the given C array allocated on the stack, with the
233+ * Constructs an xarray_adaptor of the given C array allocated on the stack, with the
218234 * specified shape and stirdes.
235+ *
236+ * @ingroup xt_xadapt
219237 * @param c_array the C array allocated on the stack
220238 * @param shape the shape of the xarray_adaptor
221239 * @param strides the strides of the xarray_adaptor
@@ -238,6 +256,8 @@ namespace xt
238256 /* *
239257 * Constructs a 1-D xtensor_adaptor of the given stl-like container,
240258 * with the specified layout_type.
259+ *
260+ * @ingroup xt_xadapt
241261 * @param container the container to adapt
242262 * @param l the layout_type of the xtensor_adaptor
243263 */
@@ -252,6 +272,8 @@ namespace xt
252272 /* *
253273 * Constructs an xtensor_adaptor of the given stl-like container,
254274 * with the specified shape and layout_type.
275+ *
276+ * @ingroup xt_xadapt
255277 * @param container the container to adapt
256278 * @param shape the shape of the xtensor_adaptor
257279 * @param l the layout_type of the xtensor_adaptor
@@ -272,6 +294,8 @@ namespace xt
272294
273295 /* *
274296 * Constructs an non-owning xtensor_adaptor from a pointer with the specified shape and layout.
297+ *
298+ * @ingroup xt_xadapt
275299 * @param pointer the pointer to adapt
276300 * @param shape the shape of the xtensor_adaptor
277301 * @param l the layout_type of the xtensor_adaptor
@@ -293,6 +317,8 @@ namespace xt
293317 /* *
294318 * Constructs an xtensor_adaptor of the given stl-like container,
295319 * with the specified shape and strides.
320+ *
321+ * @ingroup xt_xadapt
296322 * @param container the container to adapt
297323 * @param shape the shape of the xtensor_adaptor
298324 * @param strides the strides of the xtensor_adaptor
@@ -318,6 +344,8 @@ namespace xt
318344 /* *
319345 * Constructs a 1-D xtensor_adaptor of the given dynamically allocated C array,
320346 * with the specified layout.
347+ *
348+ * @ingroup xt_xadapt
321349 * @param pointer the pointer to the beginning of the dynamic array
322350 * @param size the size of the dynamic array
323351 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -340,6 +368,8 @@ namespace xt
340368 /* *
341369 * Constructs an xtensor_adaptor of the given dynamically allocated C array,
342370 * with the specified shape and layout.
371+ *
372+ * @ingroup xt_xadapt
343373 * @param pointer the pointer to the beginning of the dynamic array
344374 * @param size the size of the dynamic array
345375 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -377,6 +407,8 @@ namespace xt
377407 /* *
378408 * Constructs an xtensor_adaptor of the given dynamically allocated C array,
379409 * with the specified shape and strides.
410+ *
411+ * @ingroup xt_xadapt
380412 * @param pointer the pointer to the beginning of the dynamic array
381413 * @param size the size of the dynamic array
382414 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -409,8 +441,10 @@ namespace xt
409441 }
410442
411443 /* *
412- * Contructs an xtensor_adaptor of the given C array allocated on the stack, with the
444+ * Constructs an xtensor_adaptor of the given C array allocated on the stack, with the
413445 * specified shape and layout.
446+ *
447+ * @ingroup xt_xadapt
414448 * @param c_array the C array allocated on the stack
415449 * @param shape the shape of the xarray_adaptor
416450 * @param l the layout_type of the xarray_adaptor
@@ -427,8 +461,10 @@ namespace xt
427461 }
428462
429463 /* *
430- * Contructs an xtensor_adaptor of the given C array allocated on the stack, with the
431- * specified shape and stirdes.
464+ * Constructs an xtensor_adaptor of the given C array allocated on the stack, with the
465+ * specified shape and strides.
466+ *
467+ * @ingroup xt_xadapt
432468 * @param c_array the C array allocated on the stack
433469 * @param shape the shape of the xarray_adaptor
434470 * @param strides the strides of the xarray_adaptor
@@ -447,6 +483,8 @@ namespace xt
447483 /* *
448484 * Constructs an non-owning xtensor_fixed_adaptor from a pointer with the
449485 * specified shape and layout.
486+ *
487+ * @ingroup xt_xadapt
450488 * @param pointer the pointer to adapt
451489 * @param shape the shape of the xtensor_fixed_adaptor
452490 */
@@ -478,6 +516,8 @@ namespace xt
478516 *
479517 * from the given stl-like container or pointer, with the specified shape and layout.
480518 * If the adaptor is built from a pointer, it does not take its ownership.
519+ *
520+ * @ingroup xt_xadapt
481521 * @param container the container or pointer to adapt
482522 * @param shape the shape of the adaptor
483523 * @param l the layout_type of the adaptor
@@ -491,6 +531,8 @@ namespace xt
491531 * - an xtensor_adaptor if SC is an array type
492532 *
493533 * from the given stl-like container with the specified shape and strides.
534+ *
535+ * @ingroup xt_xadapt
494536 * @param container the container to adapt
495537 * @param shape the shape of the adaptor
496538 * @param strides the strides of the adaptor
@@ -504,6 +546,8 @@ namespace xt
504546 * - an xtensor_adaptor if SC is an array type
505547 *
506548 * of the given dynamically allocated C array, with the specified shape and layout.
549+ *
550+ * @ingroup xt_xadapt
507551 * @param pointer the pointer to the beginning of the dynamic array
508552 * @param size the size of the dynamic array
509553 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -528,6 +572,8 @@ namespace xt
528572 * - an xtensor_adaptor if SC is an array type
529573 *
530574 * of the given dynamically allocated C array, with the specified shape and strides.
575+ *
576+ * @ingroup xt_xadapt
531577 * @param pointer the pointer to the beginning of the dynamic array
532578 * @param size the size of the dynamic array
533579 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -541,11 +587,13 @@ namespace xt
541587 adapt (P&& pointer, typename A::size_type size, O ownership, SC&& shape, SS&& strides, const A& alloc = A());
542588
543589 /* *
544- * Contructs :
590+ * Constructs :
545591 * - an xarray_adaptor if SC is not an array type
546592 * - an xtensor_adaptor if SC is an array type
547593 *
548594 * of the given C array allocated on the stack, with the specified shape and layout.
595+ *
596+ * @ingroup xt_xadapt
549597 * @param c_array the C array allocated on the stack
550598 * @param shape the shape of the adaptor
551599 * @param l the layout_type of the adaptor
@@ -554,12 +602,14 @@ namespace xt
554602 inline auto adapt (T (&c_array)[N], const SC& shape, layout_type l = L);
555603
556604 /* *
557- * Contructs :
605+ * Constructs :
558606 * - an xarray_adaptor if SC is not an array type
559607 * - an xtensor_adaptor if SC is an array type
560608 *
561609 * of the given C array allocated on the stack, with the
562610 * specified shape and strides.
611+ *
612+ * @ingroup xt_xadapt
563613 * @param c_array the C array allocated on the stack
564614 * @param shape the shape of the adaptor
565615 * @param strides the strides of the adaptor
@@ -570,6 +620,8 @@ namespace xt
570620 /* *
571621 * Constructs an non-owning xtensor_fixed_adaptor from a pointer with the
572622 * specified shape and layout.
623+ *
624+ * @ingroup xt_xadapt
573625 * @param pointer the pointer to adapt
574626 * @param shape the shape of the xtensor_fixed_adaptor
575627 */
@@ -579,6 +631,8 @@ namespace xt
579631 /* *
580632 * Constructs a 1-D xtensor_adaptor of the given stl-like container,
581633 * with the specified layout_type.
634+ *
635+ * @ingroup xt_xadapt
582636 * @param container the container to adapt
583637 * @param l the layout_type of the xtensor_adaptor
584638 */
@@ -588,6 +642,8 @@ namespace xt
588642 /* *
589643 * Constructs a 1-D xtensor_adaptor of the given dynamically allocated C array,
590644 * with the specified layout.
645+ *
646+ * @ingroup xt_xadapt
591647 * @param pointer the pointer to the beginning of the dynamic array
592648 * @param size the size of the dynamic array
593649 * @param ownership indicates whether the adaptor takes ownership of the array.
@@ -620,6 +676,7 @@ namespace xt
620676 * std::cout << xptr;
621677 * \endcode
622678 *
679+ * @ingroup xt_xadapt
623680 * @param smart_ptr a smart pointer to a memory block of T[]
624681 * @param shape The desired shape
625682 * @param l The desired memory layout
@@ -678,6 +735,7 @@ namespace xt
678735 * }
679736 * \endcode
680737 *
738+ * @ingroup xt_xadapt
681739 * @param data_ptr A pointer to a typed data block (e.g. double*)
682740 * @param shape The desired shape
683741 * @param smart_ptr A smart pointer to move or copy, in order to manage memory
@@ -716,6 +774,7 @@ namespace xt
716774 * std::cout << xptr;
717775 * \endcode
718776 *
777+ * @ingroup xt_xadapt
719778 * @param smart_ptr a smart pointer to a memory block of T[]
720779 * @param shape The desired shape
721780 * @param l The desired memory layout
@@ -775,6 +834,7 @@ namespace xt
775834 * }
776835 * \endcode
777836 *
837+ * @ingroup xt_xadapt
778838 * @param data_ptr A pointer to a typed data block (e.g. double*)
779839 * @param shape The desired shape
780840 * @param smart_ptr A smart pointer to move or copy, in order to manage memory
@@ -802,6 +862,60 @@ namespace xt
802862 l
803863 );
804864 }
865+
866+ /* *
867+ * @brief xtensor adaptor for a pointer.
868+ *
869+ * Construct for example with:
870+ *
871+ * \code{.cpp}
872+ * #include <xtensor/xadapt.hpp>
873+ *
874+ * std::array<size_t, 2> shape = {2, 2};
875+ * std::vector<double> data = {1, 2, 3, 4};
876+ *
877+ * xt::xtensor_pointer<double, 2> a = xt::adapt(data.data(), 4, xt::no_ownership(), shape);
878+ * \endcode
879+ *
880+ * @ingroup xt_xadapt
881+ * @tparam T The data type (e.g. ``double``).
882+ * @tparam N The number of dimensions.
883+ * @tparam L The xt::layout_type() of the xtensor.
884+ */
885+ template <class T , std::size_t N, layout_type L = XTENSOR_DEFAULT_LAYOUT>
886+ using xtensor_pointer = xtensor_adaptor<
887+ xbuffer_adaptor<xtl::closure_type_t <T*>, xt::no_ownership, detail::default_allocator_for_ptr_t <T>>,
888+ N,
889+ L>;
890+
891+ /* *
892+ * @brief xarray adaptor for a pointer.
893+ *
894+ * Construct for example with:
895+ *
896+ * \code{.cpp}
897+ * #include <xtensor/xadapt.hpp>
898+ *
899+ * std::vector<int> data(4, 0);
900+ * xt::svector<size_t> shape({2, 2});
901+ *
902+ * xt::xarray_pointer<int> a = xt::adapt(data.data(), data.size(), xt::no_ownership(), shape);
903+ * \endcode
904+ *
905+ * @ingroup xt_xadapt
906+ * @tparam T The data type (e.g. ``double``).
907+ * @tparam L The xt::layout_type() of the xarray.
908+ * @tparam SC The shape container type (e.g. ``xt::svector<size_t>``). Default matches
909+ * xt::adapt(P&&, typename A::size_type, O, const SC&, layout_type, const A& alloc)
910+ */
911+ template <
912+ class T ,
913+ layout_type L = XTENSOR_DEFAULT_LAYOUT,
914+ class SC = XTENSOR_DEFAULT_SHAPE_CONTAINER(T, std::allocator<std::size_t >, std::allocator<std::size_t >)>
915+ using xarray_pointer = xarray_adaptor<
916+ xbuffer_adaptor<xtl::closure_type_t<T*>, xt::no_ownership, detail::default_allocator_for_ptr_t<T>>,
917+ L,
918+ SC>;
805919}
806920
807921#endif
0 commit comments