5 #ifndef GKO_PUBLIC_CORE_BASE_DIM_HPP_
6 #define GKO_PUBLIC_CORE_BASE_DIM_HPP_
11 #include <ginkgo/core/base/types.hpp>
25 template <
size_type Dimensionality,
typename DimensionType =
size_type>
27 static constexpr
size_type dimensionality = Dimensionality;
28 friend struct dim<dimensionality + 1>;
30 using dimension_type = DimensionType;
35 constexpr GKO_ATTRIBUTES
dim() :
dim{dimension_type{}} {}
42 explicit constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size)
43 : first_{size}, rest_{size}
59 template <
typename... Rest, std::enable_if_t<
sizeof...(Rest) ==
60 Dimensionality - 1>* =
nullptr>
61 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& first,
63 : first_{first}, rest_{static_cast<dimension_type>(rest)...}
77 constexpr GKO_ATTRIBUTES
const dimension_type&
operator[](
78 const size_type& dimension)
const noexcept
80 return GKO_ASSERT(dimension < dimensionality),
81 dimension == 0 ? first_ : rest_[dimension - 1];
90 return GKO_ASSERT(dimension < dimensionality),
91 dimension == 0 ? first_ : rest_[dimension - 1];
105 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
107 return static_cast<bool>(first_) && static_cast<bool>(rest_);
120 return x.first_ == y.first_ && x.rest_ == y.rest_;
146 return dim(x.first_ * y.first_, x.rest_ * y.rest_);
166 void inline print_to(std::ostream& os)
const
168 os << first_ <<
", ";
173 constexpr GKO_ATTRIBUTES
dim(
const dimension_type first,
174 dim<dimensionality - 1> rest)
175 : first_{first}, rest_{rest}
178 dimension_type first_;
179 dim<dimensionality - 1, dimension_type> rest_;
184 template <
typename DimensionType>
186 static constexpr
size_type dimensionality = 1u;
189 using dimension_type = DimensionType;
191 constexpr GKO_ATTRIBUTES
dim(
const dimension_type& size = dimension_type{})
195 constexpr GKO_ATTRIBUTES
const dimension_type& operator[](
196 const size_type& dimension)
const noexcept
198 return GKO_ASSERT(dimension == 0), first_;
201 GKO_ATTRIBUTES dimension_type& operator[](
const size_type& dimension)
203 return GKO_ASSERT(dimension == 0), first_;
206 explicit constexpr GKO_ATTRIBUTES
operator bool()
const
208 return static_cast<bool>(first_);
211 friend constexpr GKO_ATTRIBUTES
bool operator==(
const dim& x,
const dim& y)
213 return x.first_ == y.first_;
216 friend constexpr GKO_ATTRIBUTES
bool operator!=(
const dim& x,
const dim& y)
221 friend constexpr GKO_ATTRIBUTES
dim operator*(
const dim& x,
const dim& y)
223 return dim(x.first_ * y.first_);
226 friend std::ostream& operator<<(std::ostream& os,
const dim& x)
235 void inline print_to(std::ostream& os)
const { os << first_; }
237 dimension_type first_;
250 template <
typename DimensionType>
254 return {dimensions[1], dimensions[0]};
261 #endif // GKO_PUBLIC_CORE_BASE_DIM_HPP_