<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2017-2021, University of Tennessee. All rights reserved.
5// Copyright (c) 2025, University of Colorado Denver. All rights reserved.
6//
7// This file is part of <T>LAPACK.
8// <T>LAPACK is free software: you can redistribute it and/or modify it under
9// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
10
11#ifndef TLAPACK_TYPES_HH
12#define TLAPACK_TYPES_HH
13
14#include <vector>
15
16// blfoat16 and float16 are supported by the C++23 standard
17#if __has_include(<stdfloat>) && __cplusplus > 202002L
18 #include <stdfloat>
19#endif
20
23
24namespace tlapack {
25
26// -----------------------------------------------------------------------------
27// Layouts
28
29enum class Layout : char {
30 Strided = 'S',
32 ColMajor = 'C',
34 RowMajor = 'R',
36 Unspecified = 0
37};
38inline std::ostream& operator<<(std::ostream& out, const Layout v)
39{
40 if (v == Layout::Unspecified) return out << "Unspecified";
41 if (v == Layout::ColMajor) return out << "ColMajor";
42 if (v == Layout::RowMajor) return out << "RowMajor";
43 if (v == Layout::Strided) return out << "Strided";
44 return out << "<Invalid>";
45}
46
47// -----------------------------------------------------------------------------
48// Upper or Lower access
49
50enum class Uplo : char {
51 General = 'G',
52 Upper = 'U',
53 Lower = 'L',
54 UpperHessenberg = 'H',
55 LowerHessenberg = 4,
56 StrictUpper = 'S',
57 StrictLower = 6,
58};
59inline std::ostream& operator<<(std::ostream& out, const Uplo v)
60{
61 if (v == Uplo::Upper) return out << "Upper";
62 if (v == Uplo::Lower) return out << "Lower";
63 if (v == Uplo::General) return out << "General";
64 if (v == Uplo::UpperHessenberg) return out << "UpperHessenberg";
65 if (v == Uplo::LowerHessenberg) return out << "LowerHessenberg";
66 if (v == Uplo::StrictUpper) return out << "StrictUpper";
67 if (v == Uplo::StrictLower) return out << "StrictLower";
68 return out << "<Invalid>";
69}
70
71namespace internal {
83 constexpr operator Uplo() const noexcept { return Uplo::General; }
84 };
85
97 constexpr operator Uplo() const noexcept { return Uplo::Upper; }
98 };
99
111 constexpr operator Uplo() const noexcept { return Uplo::Lower; }
112 };
113
125 constexpr operator Uplo() const noexcept
126 {
128 }
129 };
130
142 constexpr operator Uplo() const noexcept
143 {
145 }
146 };
147
158 struct StrictUpper {
159 constexpr operator Uplo() const noexcept { return Uplo::StrictUpper; }
160 };
161
172 struct StrictLower {
173 constexpr operator Uplo() const noexcept { return Uplo::StrictLower; }
174 };
175} // namespace internal
176
177// constant expressions for upper/lower access
178
193
194// -----------------------------------------------------------------------------
195// Information about the main diagonal
196
197enum class Diag : char {
198 NonUnit = 'N',
199 Unit = 'U'
200};
201inline std::ostream& operator<<(std::ostream& out, const Diag v)
202{
203 if (v == Diag::NonUnit) return out << "NonUnit";
204 if (v == Diag::Unit) return out << "Unit";
205 return out << "<Invalid>";
206}
207
208namespace internal {
210 constexpr operator Diag() const noexcept { return Diag::NonUnit; }
211 };
213 constexpr operator Diag() const noexcept { return Diag::Unit; }
214 };
215} // namespace internal
216
217// constant expressions about the main diagonal
218
223
224// -----------------------------------------------------------------------------
225// Operations over data
226
227enum class Op : char {
228 NoTrans = 'N',
229 Trans = 'T',
230 ConjTrans = 'C',
231 Conj = 3
232};
233inline std::ostream& operator<<(std::ostream& out, const Op v)
234{
235 if (v == Op::NoTrans) return out << "NoTrans";
236 if (v == Op::Trans) return out << "Trans";
237 if (v == Op::ConjTrans) return out << "ConjTrans";
238 if (v == Op::Conj) return out << "Conj";
239 return out << "<Invalid>";
240}
241
242namespace internal {
243 struct NoTranspose {
244 constexpr operator Op() const noexcept { return Op::NoTrans; }
245 };
246 struct Transpose {
247 constexpr operator Op() const noexcept { return Op::Trans; }
248 };
250 constexpr operator Op() const noexcept { return Op::ConjTrans; }
251 };
252 struct Conjugate {
253 constexpr operator Op() const noexcept { return Op::Conj; }
254 };
255} // namespace internal
256
257// Constant expressions for operations over data
258
267
268// -----------------------------------------------------------------------------
269// Sides
270
271enum class Side : char {
272 Left = 'L',
273 Right = 'R',
274 Both = 'B'
275};
276inline std::ostream& operator<<(std::ostream& out, const Side v)
277{
278 if (v == Side::Left) return out << "Left";
279 if (v == Side::Right) return out << "Right";
280 if (v == Side::Both) return out << "Both";
281 return out << "<Invalid>";
282}
283
284namespace internal {
285 struct LeftSide {
286 constexpr operator Side() const noexcept { return Side::Left; }
287 };
288 struct RightSide {
289 constexpr operator Side() const noexcept { return Side::Right; }
290 };
291 struct BothSides {
292 constexpr operator Side() const noexcept { return Side::Both; }
293 };
294} // namespace internal
295
296// Constant expressions for sides
297
304
305// -----------------------------------------------------------------------------
306// Norm types
307
308enum class Norm : char {
309 One = '1',
310 Two = '2',
311 Inf = 'I',
312 Fro = 'F',
313 Max = 'M',
314};
315inline std::ostream& operator<<(std::ostream& out, const Norm v)
316{
317 if (v == Norm::One) return out << "One";
318 if (v == Norm::Two) return out << "Two";
319 if (v == Norm::Inf) return out << "Inf";
320 if (v == Norm::Fro) return out << "Fro";
321 if (v == Norm::Max) return out << "Max";
322 return out << "<Invalid>";
323}
324
325namespace internal {
326 struct MaxNorm {
327 constexpr operator Norm() const noexcept { return Norm::Max; }
328 };
329 struct OneNorm {
330 constexpr operator Norm() const noexcept { return Norm::One; }
331 };
332 struct TwoNorm {
333 constexpr operator Norm() const noexcept { return Norm::Two; }
334 };
335 struct InfNorm {
336 constexpr operator Norm() const noexcept { return Norm::Inf; }
337 };
338 struct FrobNorm {
339 constexpr operator Norm() const noexcept { return Norm::Fro; }
340 };
341} // namespace internal
342
343// Constant expressions for norm types
344
355
356// -----------------------------------------------------------------------------
357// Directions
358
359enum class Direction : char {
360 Forward = 'F',
361 Backward = 'B',
362};
363inline std::ostream& operator<<(std::ostream& out, const Direction v)
364{
365 if (v == Direction::Forward) return out << "Forward";
366 if (v == Direction::Backward) return out << "Backward";
367 return out << "<Invalid>";
368}
369
370namespace internal {
371 struct Forward {
372 constexpr operator Direction() const noexcept
373 {
374 return Direction::Forward;
375 }
376 };
377 struct Backward {
378 constexpr operator Direction() const noexcept
379 {
380 return Direction::Backward;
381 }
382 };
383} // namespace internal
384
385// Constant expressions for directions
386
391
392// -----------------------------------------------------------------------------
393// Storage types
394
395enum class StoreV : char {
396 Columnwise = 'C',
397 Rowwise = 'R',
398};
399inline std::ostream& operator<<(std::ostream& out, const StoreV v)
400{
401 if (v == StoreV::Columnwise) return out << "Columnwise";
402 if (v == StoreV::Rowwise) return out << "Rowwise";
403 return out << "<Invalid>";
404}
405
406namespace internal {
408 constexpr operator StoreV() const noexcept
409 {
410 return StoreV::Columnwise;
411 }
412 };
414 constexpr operator StoreV() const noexcept { return StoreV::Rowwise; }
415 };
416} // namespace internal
417
418// Constant expressions for storage types
419
424
425// -----------------------------------------------------------------------------
426// Band access
427
440 std::size_t lower_bandwidth;
441 std::size_t upper_bandwidth;
442};
443
444// -----------------------------------------------------------------------------
445// Legacy matrix and vector structures
446
447namespace legacy {
454 template <class T, class idx_t>
455 struct Matrix {
456 Layout layout;
457 idx_t m;
458 idx_t n;
459 T* ptr;
460 idx_t ldim;
461 };
462
469 template <class T, class idx_t>
470 struct Vector {
471 idx_t n;
472 T* ptr;
473 idx_t inc;
474 };
475} // namespace legacy
476} // namespace tlapack
477
478#endif // TLAPACK_TYPES_HH
Concept for types that represent tlapack::Diag.
Concept for types that represent tlapack::Direction.
Concept for types that represent tlapack::Norm.
Concept for types that represent tlapack::Op.
Concept for types that represent tlapack::Side.
Concept for types that represent tlapack::StoreV.
Concept for types that represent tlapack::Uplo.
Sort the numbers in D in increasing order (if ID = 'I') or in decreasing order (if ID = 'D' ).
Definition arrayTraits.hpp:15
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
constexpr internal::MaxNorm MAX_NORM
max norm
Definition types.hpp:346
constexpr internal::UpperHessenberg UPPER_HESSENBERG
Upper Hessenberg access.
Definition types.hpp:182
constexpr internal::FrobNorm FROB_NORM
Frobenius norm of matrices.
Definition types.hpp:354
constexpr internal::LowerTriangle LOWER_TRIANGLE
Lower Triangle access.
Definition types.hpp:188
constexpr internal::UpperTriangle UPPER_TRIANGLE
Upper Triangle access.
Definition types.hpp:186
Diag
Definition types.hpp:197
@ Unit
The main diagonal is assumed to consist of 1's.
@ NonUnit
The main diagonal is not assumed to consist of 1's.
constexpr internal::OneNorm ONE_NORM
one norm
Definition types.hpp:348
Side
Definition types.hpp:271
@ Both
both sides
@ Right
right side
@ Left
left side
constexpr internal::Backward BACKWARD
Backward direction.
Definition types.hpp:390
constexpr internal::RightSide RIGHT_SIDE
right side
Definition types.hpp:301
constexpr internal::TwoNorm TWO_NORM
two norm
Definition types.hpp:350
constexpr internal::RowwiseStorage ROWWISE_STORAGE
Rowwise storage.
Definition types.hpp:423
constexpr internal::StrictUpper STRICT_UPPER
Strict Upper Triangle access.
Definition types.hpp:190
constexpr internal::Forward FORWARD
Forward direction.
Definition types.hpp:388
constexpr internal::Transpose TRANSPOSE
transpose
Definition types.hpp:262
constexpr internal::UnitDiagonal UNIT_DIAG
The main diagonal is assumed to consist of 1's.
Definition types.hpp:222
constexpr internal::StrictLower STRICT_LOWER
Strict Lower Triangle access.
Definition types.hpp:192
constexpr internal::GeneralAccess GENERAL
General access.
Definition types.hpp:180
constexpr internal::NonUnitDiagonal NON_UNIT_DIAG
The main diagonal is not assumed to consist of 1's.
Definition types.hpp:220
constexpr internal::Conjugate CONJUGATE
non-transpose conjugate
Definition types.hpp:266
Direction
Definition types.hpp:359
@ Forward
Forward direction.
@ Backward
Backward direction.
Op
Definition types.hpp:227
@ Trans
transpose
@ NoTrans
no transpose
@ Conj
non-transpose conjugate
@ ConjTrans
conjugate transpose
constexpr internal::ConjTranspose CONJ_TRANS
conjugate transpose
Definition types.hpp:264
constexpr internal::ColumnwiseStorage COLUMNWISE_STORAGE
Columnwise storage.
Definition types.hpp:421
StoreV
Definition types.hpp:395
@ Rowwise
Rowwise storage.
@ Columnwise
Columnwise storage.
constexpr internal::BothSides BOTH_SIDES
both sides
Definition types.hpp:303
constexpr internal::LowerHessenberg LOWER_HESSENBERG
Lower Hessenberg access.
Definition types.hpp:184
Uplo
Definition types.hpp:50
@ General
0 <= i <= m, 0 <= j <= n.
@ Upper
0 <= i <= j, 0 <= j <= n.
@ StrictLower
0 <= i <= m, 0 <= j <= i-1.
@ Lower
0 <= i <= m, 0 <= j <= i.
@ StrictUpper
0 <= i <= j-1, 0 <= j <= n.
@ UpperHessenberg
0 <= i <= j+1, 0 <= j <= n.
@ LowerHessenberg
0 <= i <= m, 0 <= j <= i+1.
constexpr internal::NoTranspose NO_TRANS
no transpose
Definition types.hpp:260
constexpr internal::InfNorm INF_NORM
infinity norm of matrices
Definition types.hpp:352
Norm
Definition types.hpp:308
@ Inf
infinity norm of matrices
@ One
one norm
@ Max
max norm
@ Two
two norm
@ Fro
Frobenius norm of matrices.
constexpr internal::LeftSide LEFT_SIDE
left side
Definition types.hpp:299
Layout
Definition types.hpp:29
@ Unspecified
Used on all other data structures.
@ ColMajor
Column-major layout.
@ Strided
Strided layout.
@ RowMajor
Row-major layout.
Band access.
Definition types.hpp:439
std::size_t lower_bandwidth
Number of subdiagonals.
Definition types.hpp:440
std::size_t upper_bandwidth
Number of superdiagonals.
Definition types.hpp:441
Definition types.hpp:377
Definition types.hpp:291
Definition types.hpp:407
Definition types.hpp:249
Definition types.hpp:252
Definition types.hpp:371
Definition types.hpp:338
General access.
Definition types.hpp:82
Definition types.hpp:335
Definition types.hpp:285
Lower Hessenberg access.
Definition types.hpp:141
Lower Triangle access.
Definition types.hpp:110
Definition types.hpp:326
Definition types.hpp:243
Definition types.hpp:209
Definition types.hpp:329
Definition types.hpp:288
Definition types.hpp:413
Strict Lower Triangle access.
Definition types.hpp:172
Strict Upper Triangle access.
Definition types.hpp:158
Definition types.hpp:246
Definition types.hpp:332
Definition types.hpp:212
Upper Hessenberg access.
Definition types.hpp:124
Upper Triangle access.
Definition types.hpp:96
Describes a row- or column-major matrix.
Definition types.hpp:455
Describes a strided vector.
Definition types.hpp:470