<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
TestUploMatrix.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_TEST_TESTUPLOMATRIX_HH
12#define TLAPACK_TEST_TESTUPLOMATRIX_HH
13
15
16namespace tlapack {
17
32template <class T,
33 class idx_t = std::size_t,
34 Uplo uplo = Uplo::Upper,
35 Layout L = Layout::ColMajor>
36struct TestUploMatrix : public LegacyMatrix<T, idx_t, L> {
38 0;
39
41 : LegacyMatrix<T, idx_t, L>(A)
42 {}
43
44 // Overload of the access operator
45 constexpr const T& operator()(idx_t i, idx_t j) const noexcept
46 {
47 if (uplo == Uplo::Upper)
48 assert((int)i <= (int)j + modifier);
49 else if (uplo == Uplo::Lower)
50 assert((int)i >= (int)j + modifier);
51
53 };
54
55 // Overload of the access operator
56 constexpr T& operator()(idx_t i, idx_t j) noexcept
57 {
58 if (uplo == Uplo::Upper)
59 assert((int)i <= (int)j + modifier);
60 else if (uplo == Uplo::Lower)
61 assert((int)i >= (int)j + modifier);
62
64 };
65};
66
67// -----------------------------------------------------------------------------
68// Data traits
69
70namespace traits {
71 template <typename T, class idx_t, Uplo uplo, Layout L>
72 struct layout_trait<TestUploMatrix<T, idx_t, uplo, L>, int>
73 : layout_trait<LegacyMatrix<T, idx_t, L>, int> {};
74
75 template <typename T, class idx_t, Uplo uplo, Layout L>
76 struct real_type_traits<TestUploMatrix<T, idx_t, uplo, L>, int>
77 : real_type_traits<LegacyMatrix<T, idx_t, L>, int> {};
78
79 template <typename T, class idx_t, Uplo uplo, Layout L>
81 : complex_type_traits<LegacyMatrix<T, idx_t, L>, int> {};
82
83 template <class T, class idx_t, Uplo uplo, Layout L>
84 struct CreateFunctor<TestUploMatrix<T, idx_t, uplo, L>, int>
85 : CreateFunctor<LegacyMatrix<T, idx_t, L>, int> {};
86} // namespace traits
87
88// Block access specialization for TestUploMatrix
89
90#define isSlice(SliceSpec) !std::is_convertible<SliceSpec, idx_t>::value
91
92template <
93 typename T,
94 class idx_t,
95 Uplo uplo,
97 class SliceSpecRow,
98 class SliceSpecCol,
99 typename std::enable_if<isSlice(SliceSpecRow) && isSlice(SliceSpecCol),
100 int>::type = 0>
101constexpr auto slice(const TestUploMatrix<T, idx_t, uplo, layout>& A,
102 SliceSpecRow&& rows,
103 SliceSpecCol&& cols) noexcept
104{
106 slice((const LegacyMatrix<T, idx_t, layout>&)A, rows, cols));
107 B.modifier = A.modifier + cols.first - rows.first;
108 return B;
109}
110
111#undef isSlice
112
113template <typename T, class idx_t, Uplo uplo, Layout layout, class SliceSpec>
114constexpr auto rows(const TestUploMatrix<T, idx_t, uplo, layout>& A,
115 SliceSpec&& slice) noexcept
116{
117 TestUploMatrix<const T, idx_t, uplo, layout> B(
118 rows((const LegacyMatrix<T, idx_t, layout>&)A, slice));
119 B.modifier = A.modifier - slice.first;
120 return B;
121}
122
123template <typename T, class idx_t, Uplo uplo, Layout layout, class SliceSpec>
124constexpr auto cols(const TestUploMatrix<T, idx_t, uplo, layout>& A,
125 SliceSpec&& slice) noexcept
126{
127 TestUploMatrix<const T, idx_t, uplo, layout> B(
128 cols((const LegacyMatrix<T, idx_t, layout>&)A, slice));
129 B.modifier = A.modifier + slice.first;
130 return B;
131}
132
133#define isSlice(SliceSpec) !std::is_convertible<SliceSpec, idx_t>::value
134
135template <
136 typename T,
137 class idx_t,
138 Uplo uplo,
140 class SliceSpecRow,
141 class SliceSpecCol,
142 typename std::enable_if<isSlice(SliceSpecRow) && isSlice(SliceSpecCol),
143 int>::type = 0>
144constexpr auto slice(TestUploMatrix<T, idx_t, uplo, layout>& A,
145 SliceSpecRow&& rows,
146 SliceSpecCol&& cols) noexcept
147{
148 TestUploMatrix<T, idx_t, uplo, layout> B(
149 slice((LegacyMatrix<T, idx_t, layout>&)A, rows, cols));
150 B.modifier = A.modifier + cols.first - rows.first;
151 return B;
152}
153
154#undef isSlice
155
156template <typename T, class idx_t, Uplo uplo, Layout layout, class SliceSpec>
157constexpr auto rows(TestUploMatrix<T, idx_t, uplo, layout>& A,
158 SliceSpec&& slice) noexcept
159{
160 TestUploMatrix<T, idx_t, uplo, layout> B(
161 rows((LegacyMatrix<T, idx_t, layout>&)A, slice));
162 B.modifier = A.modifier - slice.first;
163 return B;
164}
165
166template <typename T, class idx_t, Uplo uplo, Layout layout, class SliceSpec>
167constexpr auto cols(TestUploMatrix<T, idx_t, uplo, layout>& A,
168 SliceSpec&& slice) noexcept
169{
170 TestUploMatrix<T, idx_t, uplo, layout> B(
171 cols((LegacyMatrix<T, idx_t, layout>&)A, slice));
172 B.modifier = A.modifier + slice.first;
173 return B;
174}
175
176} // namespace tlapack
177
178#endif // TLAPACK_TEST_TESTUPLOMATRIX_HH
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
Uplo
Definition types.hpp:45
Layout
Definition types.hpp:24
Concept for matrices that can be converted to a legacy matrix.
Concept for types that represent tlapack::Uplo.
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 matrix.
Definition LegacyMatrix.hpp:34
TestUploMatrix class.
Definition TestUploMatrix.hpp:36
int modifier
Modifier to the access region. Enables slicing of the matrix.
Definition TestUploMatrix.hpp:37
Functor for data creation.
Definition arrayTraits.hpp:89
Complex type traits for the list of types Types.
Definition scalar_type_traits.hpp:145
Trait to determine the layout of a given data structure.
Definition arrayTraits.hpp:75
Real type traits for the list of types Types.
Definition scalar_type_traits.hpp:71