Ginkgo  Generated from pipelines/2837190956 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
containers.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
6 #define GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
7 
8 
9 #include <array>
10 #include <type_traits>
11 
12 
13 namespace gko {
18 namespace syn {
19 
20 
27 template <typename T, T... Values>
28 struct value_list {};
29 
30 
36 template <typename... Types>
37 struct type_list {};
38 
39 
47 template <int Start, int End, int Step = 1>
48 struct range {};
49 
50 
51 namespace detail {
52 
53 
60 template <typename List1, typename List2>
61 struct concatenate_impl;
62 
70 template <typename T, T... Values1, T... Values2>
71 struct concatenate_impl<value_list<T, Values1...>, value_list<T, Values2...>> {
72  using type = value_list<T, Values1..., Values2...>;
73 };
74 
75 
76 } // namespace detail
77 
78 
85 template <typename List1, typename List2>
86 using concatenate = typename detail::concatenate_impl<List1, List2>::type;
87 
88 
89 namespace detail {
90 
91 
97 template <typename T, typename = void>
98 struct as_list_impl;
99 
106 template <typename T, T... Values>
107 struct as_list_impl<value_list<T, Values...>> {
108  using type = value_list<T, Values...>;
109 };
110 
116 template <typename... Types>
117 struct as_list_impl<type_list<Types...>> {
118  using type = type_list<Types...>;
119 };
120 
129 template <int Start, int End, int Step>
130 struct as_list_impl<range<Start, End, Step>, std::enable_if_t<(Start < End)>> {
131  using type = concatenate<
133  typename as_list_impl<range<Start + Step, End, Step>>::type>;
134 };
135 
143 template <int Start, int End, int Step>
144 struct as_list_impl<range<Start, End, Step>, std::enable_if_t<(Start >= End)>> {
145  using type = value_list<int>;
146 };
147 
148 
149 } // namespace detail
150 
151 
158 template <typename T>
159 using as_list = typename detail::as_list_impl<T>::type;
160 
161 
173 template <typename T, T... Value>
174 constexpr std::array<T, sizeof...(Value)> as_array(value_list<T, Value...> vl)
175 {
176  return std::array<T, sizeof...(Value)>{Value...};
177 }
178 
179 
180 } // namespace syn
181 } // namespace gko
182 
183 
184 #endif // GKO_PUBLIC_CORE_SYNTHESIZER_CONTAINERS_HPP_
gko::syn::as_list
typename detail::as_list_impl< T >::type as_list
as_list<T> gives the alias type of as_list_impl<T>::type.
Definition: containers.hpp:159
gko::syn::type_list
type_list records several types in template
Definition: containers.hpp:37
gko::layout_type::array
The matrix should be written as dense matrix in column-major order.
gko::syn::as_array
constexpr std::array< T, sizeof...(Value)> as_array(value_list< T, Value... > vl)
as_array<T> returns the array from value_list.
Definition: containers.hpp:174
gko::syn::value_list
value_list records several values with the same type in template.
Definition: containers.hpp:28
gko::syn::range
range records start, end, step in template
Definition: containers.hpp:48
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::syn::concatenate
typename detail::concatenate_impl< List1, List2 >::type concatenate
concatenate combines two value_list into one value_list.
Definition: containers.hpp:86