<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
LegacyVector.hpp
Go to the documentation of this file.
1
4//
5// Copyright (c) 2021-2023, 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_LEGACY_VECTOR_HH
12#define TLAPACK_LEGACY_VECTOR_HH
13
14#include <cassert>
15
18
19namespace tlapack {
20
21namespace internal {
23 struct StrongOne {
24 constexpr operator int() const { return 1; }
25 constexpr StrongOne(int i = 1) { assert(i == 1); }
26 };
27} // namespace internal
28
35template <
36 typename T,
37 class idx_t = std::size_t,
38 typename int_t = internal::StrongOne,
39 Direction D = Direction::Forward,
40 std::enable_if_t<(D == Direction::Forward) || (D == Direction::Backward),
41 int> = 0>
43 idx_t n;
44 T* ptr;
45 int_t inc;
46
47 static constexpr Direction direction = D;
48
49 constexpr const T& operator[](idx_t i) const noexcept
50 {
51 assert(i >= 0);
52 assert(i < n);
53 return (direction == Direction::Forward) ? *(ptr + (i * inc))
54 : *(ptr + ((n - 1) - i) * inc);
55 }
56
57 constexpr T& operator[](idx_t i) noexcept
58 {
59 assert(i >= 0);
60 assert(i < n);
61 return (direction == Direction::Forward) ? *(ptr + (i * inc))
62 : *(ptr + ((n - 1) - i) * inc);
63 }
64
65 constexpr LegacyVector(idx_t n, T* ptr, int_t inc = 1)
66 : n(n), ptr(ptr), inc(inc)
67 {
69 }
70};
71
72} // namespace tlapack
73
74#endif // TLAPACK_LEGACY_MATRIX_HH
Direction
Definition types.hpp:347
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
Concept for vectors that can be converted to a legacy vector.
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
Legacy vector.
Definition LegacyVector.hpp:42
T * ptr
Pointer to array in memory.
Definition LegacyVector.hpp:44
int_t inc
Memory increment.
Definition LegacyVector.hpp:45
idx_t n
Size.
Definition LegacyVector.hpp:43
Auxiliary data type to vector increments.
Definition LegacyVector.hpp:23