5 #ifndef GKO_PUBLIC_CORE_BASE_DIM_HPP_
6 #define GKO_PUBLIC_CORE_BASE_DIM_HPP_
12 #include <ginkgo/core/base/types.hpp>
26 template <
size_type Dimensionality,
typename DimensionType =
size_type>
28 static constexpr
size_type dimensionality = Dimensionality;
29 friend struct dim<dimensionality + 1>;
31 using dimension_type = DimensionType;
36 constexpr GKO_ATTRIBUTES
dim() :
dim{dimension_type{}} {}
43 explicit constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size)
44 : first_{size}, rest_{size}
60 template <
typename... Rest, std::enable_if_t<
sizeof...(Rest) ==
61 Dimensionality - 1>* =
nullptr>
62 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& first,
64 : first_{first}, rest_{static_cast<dimension_type>(rest)...}
78 constexpr GKO_ATTRIBUTES
const dimension_type&
operator[](
79 const size_type& dimension)
const noexcept
81 return GKO_ASSERT(dimension < dimensionality),
82 dimension == 0 ? first_ : rest_[dimension - 1];
91 return GKO_ASSERT(dimension < dimensionality),
92 dimension == 0 ? first_ : rest_[dimension - 1];
106 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
108 return static_cast<bool>(first_) && static_cast<bool>(rest_);
121 return x.first_ == y.first_ && x.rest_ == y.rest_;
147 return dim(x.first_ * y.first_, x.rest_ * y.rest_);
167 void inline print_to(std::ostream& os)
const
169 os << first_ <<
", ";
174 constexpr GKO_ATTRIBUTES
dim(
const dimension_type first,
175 dim<dimensionality - 1> rest)
176 : first_{first}, rest_{rest}
179 dimension_type first_;
180 dim<dimensionality - 1, dimension_type> rest_;
185 template <
typename DimensionType>
187 static constexpr
size_type dimensionality = 1u;
190 using dimension_type = DimensionType;
192 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size = dimension_type{})
196 constexpr GKO_ATTRIBUTES
const dimension_type& operator[](
197 const size_type& dimension)
const noexcept
199 return GKO_ASSERT(dimension == 0), first_;
202 GKO_ATTRIBUTES dimension_type& operator[](
const size_type& dimension)
204 return GKO_ASSERT(dimension == 0), first_;
207 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
209 return static_cast<bool>(first_);
212 friend constexpr GKO_ATTRIBUTES
bool operator==(
const dim& x,
const dim& y)
214 return x.first_ == y.first_;
217 friend constexpr GKO_ATTRIBUTES
bool operator!=(
const dim& x,
const dim& y)
222 friend constexpr GKO_ATTRIBUTES
dim operator*(
const dim& x,
const dim& y)
224 return dim(x.first_ * y.first_);
227 friend std::ostream& operator<<(std::ostream& os,
const dim& x)
236 void inline print_to(std::ostream& os)
const { os << first_; }
238 dimension_type first_;
251 template <
typename DimensionType>
255 return {dimensions[1], dimensions[0]};
262 #endif // GKO_PUBLIC_CORE_BASE_DIM_HPP_