5 #ifndef GKO_PUBLIC_CORE_BASE_DIM_HPP_
6 #define GKO_PUBLIC_CORE_BASE_DIM_HPP_
11 #include <ginkgo/core/base/types.hpp>
24 template <
size_type Dimensionality,
typename DimensionType =
size_type>
26 static constexpr
size_type dimensionality = Dimensionality;
27 friend struct dim<dimensionality + 1>;
29 using dimension_type = DimensionType;
34 constexpr GKO_ATTRIBUTES
dim() :
dim{dimension_type{}} {}
41 explicit constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size)
42 : first_{size}, rest_{size}
58 template <
typename... Rest, std::enable_if_t<
sizeof...(Rest) ==
59 Dimensionality - 1>* =
nullptr>
60 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& first,
62 : first_{first}, rest_{static_cast<dimension_type>(rest)...}
76 constexpr GKO_ATTRIBUTES
const dimension_type&
operator[](
77 const size_type& dimension)
const noexcept
79 return GKO_ASSERT(dimension < dimensionality),
80 dimension == 0 ? first_ : rest_[dimension - 1];
89 return GKO_ASSERT(dimension < dimensionality),
90 dimension == 0 ? first_ : rest_[dimension - 1];
104 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
106 return static_cast<bool>(first_) && static_cast<bool>(rest_);
119 return x.first_ == y.first_ && x.rest_ == y.rest_;
145 return dim(x.first_ * y.first_, x.rest_ * y.rest_);
165 void inline print_to(std::ostream& os)
const
167 os << first_ <<
", ";
172 constexpr GKO_ATTRIBUTES
dim(
const dimension_type first,
173 dim<dimensionality - 1> rest)
174 : first_{first}, rest_{rest}
177 dimension_type first_;
178 dim<dimensionality - 1, dimension_type> rest_;
183 template <
typename DimensionType>
185 static constexpr
size_type dimensionality = 1u;
188 using dimension_type = DimensionType;
190 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size = dimension_type{})
194 constexpr GKO_ATTRIBUTES
const dimension_type& operator[](
195 const size_type& dimension)
const noexcept
197 return GKO_ASSERT(dimension == 0), first_;
200 GKO_ATTRIBUTES dimension_type& operator[](
const size_type& dimension)
202 return GKO_ASSERT(dimension == 0), first_;
205 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
207 return static_cast<bool>(first_);
210 friend constexpr GKO_ATTRIBUTES
bool operator==(
const dim& x,
const dim& y)
212 return x.first_ == y.first_;
215 friend constexpr GKO_ATTRIBUTES
bool operator!=(
const dim& x,
const dim& y)
220 friend constexpr GKO_ATTRIBUTES
dim operator*(
const dim& x,
const dim& y)
222 return dim(x.first_ * y.first_);
225 friend std::ostream& operator<<(std::ostream& os,
const dim& x)
234 void inline print_to(std::ostream& os)
const { os << first_; }
236 dimension_type first_;
249 template <
typename DimensionType>
253 return {dimensions[1], dimensions[0]};
260 #endif // GKO_PUBLIC_CORE_BASE_DIM_HPP_