<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
arrayTraits.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_ARRAY_TRAITS_HH
11#define TLAPACK_ARRAY_TRAITS_HH
12
14
15namespace tlapack {
16
17// C++ standard utils:
18using std::enable_if_t;
19using std::is_same_v;
20
21namespace traits {
22
39 template <class T, class = int>
41 using type = void;
42 };
43
60 template <class T, class = int>
62 using type = std::size_t;
63 };
64
74 template <class array_t, class = int>
75 struct layout_trait {
76 static constexpr Layout value = Layout::Unspecified;
77 };
78
88 template <class matrix_t, class = int>
90 static_assert(false && sizeof(matrix_t),
91 "Must use correct specialization");
92
104 template <class T, class idx_t>
105 constexpr auto operator()(std::vector<T>& v, idx_t m, idx_t n = 1) const
106 {
107 return matrix_t();
108 }
109
120 template <class T, class idx_t>
121 constexpr auto operator()(std::vector<T>& v, idx_t n) const
122 {
123 return matrix_t();
124 }
125 };
126
140 template <class matrix_t, int m, int n, class = int>
142 static_assert(false && sizeof(matrix_t),
143 "Must use correct specialization");
144 static_assert(m >= 0 && n >= -1);
145
156 template <typename T>
157 constexpr auto operator()(T* v) const
158 {
159 return matrix_t();
160 }
161 };
162
163 // Matrix and vector type deduction:
164
175 template <class... matrix_t>
177
178 // Matrix type deduction for one type
179 template <class matrix_t>
180 struct matrix_type_traits<matrix_t, int> {
182 };
183
184 // Matrix type deduction for three or more types
185 template <class matrixA_t, class matrixB_t, class... matrix_t>
186 struct matrix_type_traits<matrixA_t, matrixB_t, matrix_t...> {
187 using type = typename matrix_type_traits<
189 matrix_t...>::type;
190 };
191
202 template <class... vector_t>
204
205 // Vector type deduction for one type
206 template <class vector_t>
207 struct vector_type_traits<vector_t, int> {
209 };
210
211 // Vector type deduction for three or more types
212 template <class vectorA_t, class vectorB_t, class... vector_t>
213 struct vector_type_traits<vectorA_t, vectorB_t, vector_t...> {
214 using type = typename vector_type_traits<
216 vector_t...>::type;
217 };
218} // namespace traits
219
220// Aliases for the traits:
221
223template <class T>
224using type_t = typename traits::entry_type_trait<T, int>::type;
225
227template <class T>
228using size_type = typename traits::size_type_trait<T, int>::type;
229
231template <class array_t>
233
250template <class T>
252
272template <class T, int m, int n = -1>
274
276template <class... matrix_t>
277using matrix_type = typename traits::matrix_type_traits<matrix_t..., int>::type;
278
280template <class... vector_t>
281using vector_type = typename traits::vector_type_traits<vector_t..., int>::type;
282
283} // namespace tlapack
284
285#endif // TLAPACK_ARRAY_TRAITS_HH
typename traits::entry_type_trait< T, int >::type type_t
Entry type of a matrix or vector.
Definition arrayTraits.hpp:224
typename traits::vector_type_traits< vector_t..., int >::type vector_type
Common vector type deduced from the list of types.
Definition arrayTraits.hpp:281
typename traits::size_type_trait< T, int >::type size_type
Size type of a matrix or vector.
Definition arrayTraits.hpp:228
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
typename traits::matrix_type_traits< matrix_t..., int >::type matrix_type
Common matrix type deduced from the list of types.
Definition arrayTraits.hpp:277
Layout
Definition types.hpp:24
Functor for data creation.
Definition arrayTraits.hpp:89
constexpr auto operator()(std::vector< T > &v, idx_t n) const
Creates a vector of size n with entries of type T.
Definition arrayTraits.hpp:121
constexpr auto operator()(std::vector< T > &v, idx_t m, idx_t n=1) const
Creates a m-by-n matrix with entries of type T.
Definition arrayTraits.hpp:105
Functor for data creation with static size.
Definition arrayTraits.hpp:141
constexpr auto operator()(T *v) const
Creates a m-by-n matrix or, if n == -1, a vector of size m.
Definition arrayTraits.hpp:157
Entry type trait.
Definition arrayTraits.hpp:40
Trait to determine the layout of a given data structure.
Definition arrayTraits.hpp:75
Matrix type deduction.
Definition arrayTraits.hpp:176
Size type trait.
Definition arrayTraits.hpp:61
Vector type deduction.
Definition arrayTraits.hpp:203