xtensor_forward.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /***************************************************************************
  2. * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
  3. * Copyright (c) QuantStack *
  4. * *
  5. * Distributed under the terms of the BSD 3-Clause License. *
  6. * *
  7. * The full license is in the file LICENSE, distributed with this software. *
  8. ****************************************************************************/
  9. #ifndef XTENSOR_FORWARD_HPP
  10. #define XTENSOR_FORWARD_HPP
  11. // This file contains forward declarations and
  12. // alias types to solve the problem of circular
  13. // includes. It should not contain anything else
  14. // and should not bring additional dependencies to
  15. // the files that include it. So:
  16. // - do NOT define classes of metafunctions here
  17. // - do NOT include other headers
  18. //
  19. // If you need to do so, something is probably
  20. // going wrong (either your change, or xtensor
  21. // needs to be refactored).
  22. #include <memory>
  23. #include <vector>
  24. #include <xtl/xoptional_sequence.hpp>
  25. #include "xlayout.hpp"
  26. #include "xtensor_config.hpp"
  27. namespace xt
  28. {
  29. struct xtensor_expression_tag;
  30. struct xoptional_expression_tag;
  31. template <class C>
  32. struct xcontainer_inner_types;
  33. template <class D>
  34. class xcontainer;
  35. template <class T, class A>
  36. class uvector;
  37. template <class T, std::size_t N, class A, bool Init>
  38. class svector;
  39. template <
  40. class EC,
  41. layout_type L = XTENSOR_DEFAULT_LAYOUT,
  42. class SC = XTENSOR_DEFAULT_SHAPE_CONTAINER(typename EC::value_type, typename EC::allocator_type, std::allocator<typename EC::size_type>),
  43. class Tag = xtensor_expression_tag>
  44. class xarray_container;
  45. /**
  46. * @typedef xarray
  47. * Alias template on xarray_container with default parameters for data container
  48. * type and shape / strides container type. This allows to write
  49. *
  50. * @code{.cpp}
  51. * xt::xarray<double> a = {{1., 2.}, {3., 4.}};
  52. * @endcode
  53. *
  54. * instead of the heavier syntax
  55. *
  56. * @code{.cpp}
  57. * xt::xarray_container<std::vector<double>, std::vector<std::size_t>> a = ...
  58. * @endcode
  59. *
  60. * @tparam T The value type of the elements.
  61. * @tparam L The layout_type of the xarray_container (default: XTENSOR_DEFAULT_LAYOUT).
  62. * @tparam A The allocator of the container holding the elements.
  63. * @tparam SA The allocator of the containers holding the shape and the strides.
  64. */
  65. template <
  66. class T,
  67. layout_type L = XTENSOR_DEFAULT_LAYOUT,
  68. class A = XTENSOR_DEFAULT_ALLOCATOR(T),
  69. class SA = std::allocator<typename std::vector<T, A>::size_type>>
  70. using xarray = xarray_container<XTENSOR_DEFAULT_DATA_CONTAINER(T, A), L, XTENSOR_DEFAULT_SHAPE_CONTAINER(T, A, SA)>;
  71. template <
  72. class EC,
  73. layout_type L = XTENSOR_DEFAULT_LAYOUT,
  74. class SC = XTENSOR_DEFAULT_SHAPE_CONTAINER(typename EC::value_type, std::allocator<typename EC::size_type>, std::allocator<typename EC::size_type>),
  75. class Tag = xtensor_expression_tag>
  76. class xarray_adaptor;
  77. /**
  78. * @typedef xarray_optional
  79. * Alias template on xarray_container for handling missing values
  80. *
  81. * @tparam T The value type of the elements.
  82. * @tparam L The layout_type of the container (default: XTENSOR_DEFAULT_LAYOUT).
  83. * @tparam A The allocator of the container holding the elements.
  84. * @tparam BA The allocator of the container holding the missing flags.
  85. * @tparam SA The allocator of the containers holding the shape and the strides.
  86. */
  87. template <
  88. class T,
  89. layout_type L = XTENSOR_DEFAULT_LAYOUT,
  90. class A = XTENSOR_DEFAULT_ALLOCATOR(T),
  91. class BC = xtl::xdynamic_bitset<std::size_t>,
  92. class SA = std::allocator<typename std::vector<T, A>::size_type>>
  93. using xarray_optional = xarray_container<
  94. xtl::xoptional_vector<T, A, BC>,
  95. L,
  96. XTENSOR_DEFAULT_SHAPE_CONTAINER(T, A, SA),
  97. xoptional_expression_tag>;
  98. template <class EC, std::size_t N, layout_type L = XTENSOR_DEFAULT_LAYOUT, class Tag = xtensor_expression_tag>
  99. class xtensor_container;
  100. /**
  101. * @typedef xtensor
  102. * Alias template on xtensor_container with default parameters for data container
  103. * type. This allows to write
  104. *
  105. * @code{.cpp}
  106. * xt::xtensor<double, 2> a = {{1., 2.}, {3., 4.}};
  107. * @endcode
  108. *
  109. * instead of the heavier syntax
  110. *
  111. * @code{.cpp}
  112. * xt::xtensor_container<std::vector<double>, 2> a = ...
  113. * @endcode
  114. *
  115. * @tparam T The value type of the elements.
  116. * @tparam N The dimension of the tensor.
  117. * @tparam L The layout_type of the tensor (default: XTENSOR_DEFAULT_LAYOUT).
  118. * @tparam A The allocator of the containers holding the elements.
  119. */
  120. template <class T, std::size_t N, layout_type L = XTENSOR_DEFAULT_LAYOUT, class A = XTENSOR_DEFAULT_ALLOCATOR(T)>
  121. using xtensor = xtensor_container<XTENSOR_DEFAULT_DATA_CONTAINER(T, A), N, L>;
  122. template <class EC, std::size_t N, layout_type L = XTENSOR_DEFAULT_LAYOUT, class Tag = xtensor_expression_tag>
  123. class xtensor_adaptor;
  124. template <class EC, std::size_t N, layout_type L = XTENSOR_DEFAULT_LAYOUT, class Tag = xtensor_expression_tag>
  125. class xtensor_view;
  126. template <std::size_t... N>
  127. class fixed_shape;
  128. /**
  129. * @typedef xshape
  130. * Alias template for ``fixed_shape`` allows for a shorter template shape definition in ``xtensor_fixed``.
  131. */
  132. template <std::size_t... N>
  133. using xshape = fixed_shape<N...>;
  134. template <class ET, class S, layout_type L = XTENSOR_DEFAULT_LAYOUT, bool Sharable = true, class Tag = xtensor_expression_tag>
  135. class xfixed_container;
  136. template <class ET, class S, layout_type L = XTENSOR_DEFAULT_LAYOUT, bool Sharable = true, class Tag = xtensor_expression_tag>
  137. class xfixed_adaptor;
  138. /**
  139. * @typedef xtensor_fixed
  140. * Alias template on xfixed_container with default parameters for layout
  141. * type. This allows to write
  142. *
  143. * @code{.cpp}
  144. * xt::xtensor_fixed<double, xt::xshape<2, 2>> a = {{1., 2.}, {3., 4.}};
  145. * @endcode
  146. *
  147. * instead of the syntax
  148. *
  149. * @code{.cpp}
  150. * xt::xfixed_container<double, xt::xshape<2, 2>, xt::layout_type::row_major> a = ...
  151. * @endcode
  152. *
  153. * @tparam T The value type of the elements.
  154. * @tparam FSH A xshape template shape.
  155. * @tparam L The layout_type of the tensor (default: XTENSOR_DEFAULT_LAYOUT).
  156. * @tparam Sharable Whether the tensor can be used in a shared expression.
  157. */
  158. template <class T, class FSH, layout_type L = XTENSOR_DEFAULT_LAYOUT, bool Sharable = true>
  159. using xtensor_fixed = xfixed_container<T, FSH, L, Sharable>;
  160. /**
  161. * @typedef xtensor_optional
  162. * Alias template on xtensor_container for handling missing values
  163. *
  164. * @tparam T The value type of the elements.
  165. * @tparam N The dimension of the tensor.
  166. * @tparam L The layout_type of the container (default: XTENSOR_DEFAULT_LAYOUT).
  167. * @tparam A The allocator of the containers holding the elements.
  168. * @tparam BA The allocator of the container holding the missing flags.
  169. */
  170. template <
  171. class T,
  172. std::size_t N,
  173. layout_type L = XTENSOR_DEFAULT_LAYOUT,
  174. class A = XTENSOR_DEFAULT_ALLOCATOR(T),
  175. class BC = xtl::xdynamic_bitset<std::size_t>>
  176. using xtensor_optional = xtensor_container<xtl::xoptional_vector<T, A, BC>, N, L, xoptional_expression_tag>;
  177. template <class CT, class... S>
  178. class xview;
  179. template <class F, class... CT>
  180. class xfunction;
  181. }
  182. #endif