<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
infnorm_triangular_colmajor.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_INFNORM_TR_COLMAJOR_HH
11#define TLAPACK_INFNORM_TR_COLMAJOR_HH
12
14
15namespace tlapack {
16
34template <class T,
35 TLAPACK_UPLO uplo_t,
36 TLAPACK_DIAG diag_t,
37 TLAPACK_MATRIX matrix_t>
39 diag_t diag,
40 const matrix_t& A)
41{
42 return WorkInfo(nrows(A));
43}
44
53template <TLAPACK_UPLO uplo_t,
54 TLAPACK_DIAG diag_t,
55 TLAPACK_MATRIX matrix_t,
56 TLAPACK_WORKSPACE work_t>
58 diag_t diag,
59 const matrix_t& A,
60 work_t& work)
61{
62 using T = type_t<matrix_t>;
63 using real_t = real_type<T>;
64 using idx_t = size_type<matrix_t>;
66
67 // check arguments
68 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
69 tlapack_check_false(diag != Diag::NonUnit && diag != Diag::Unit);
70
71 // constants
72 const idx_t m = nrows(A);
73 const idx_t n = ncols(A);
74
75 // quick return
76 if (m == 0 || n == 0) return real_t(0);
77
78 // Vector w
79 auto [w, work1] = reshape(work, m);
80
81 // Norm value
82 real_t norm(0);
83
84 for (idx_t i = 0; i < n; ++i)
85 w[i] = T(0);
86
87 if (uplo == Uplo::Upper) {
88 if (diag == Diag::NonUnit) {
89 for (idx_t i = 0; i < m; ++i)
90 w[i] = real_t(0);
91
92 for (idx_t j = 0; j < n; ++j)
93 for (idx_t i = 0; i <= min(j, m - 1); ++i)
94 w[i] += abs(A(i, j));
95 }
96 else {
97 for (idx_t i = 0; i < m; ++i)
98 w[i] = real_t(1);
99
100 for (idx_t j = 1; j < n; ++j) {
101 for (idx_t i = 0; i < min(j, m); ++i)
102 w[i] += abs(A(i, j));
103 }
104 }
105 }
106 else {
107 if (diag == Diag::NonUnit) {
108 for (idx_t i = 0; i < m; ++i)
109 w[i] = real_t(0);
110
111 for (idx_t j = 0; j < n; ++j)
112 for (idx_t i = j; i < m; ++i)
113 w[i] += abs(A(i, j));
114 }
115 else {
116 for (idx_t i = 0; i < min(m, n); ++i)
117 w[i] = real_t(1);
118 for (idx_t i = n; i < m; ++i)
119 w[i] = real_t(0);
120
121 for (idx_t j = 1; j < n; ++j) {
122 for (idx_t i = j + 1; i < m; ++i)
123 w[i] += abs(A(i, j));
124 }
125 }
126 }
127
128 for (idx_t i = 0; i < m; ++i) {
129 real_t temp = w[i];
130
131 if (temp > norm)
132 norm = temp;
133 else {
134 if (isnan(temp)) return temp;
135 }
136 }
137
138 return norm;
139}
140
161template <TLAPACK_UPLO uplo_t, TLAPACK_DIAG diag_t, TLAPACK_MATRIX matrix_t>
163{
164 using T = type_t<matrix_t>;
165 using real_t = real_type<T>;
166 using idx_t = size_type<matrix_t>;
167
168 // check arguments
169 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
170 tlapack_check_false(diag != Diag::NonUnit && diag != Diag::Unit);
171
172 // constants
173 const idx_t m = nrows(A);
174 const idx_t n = ncols(A);
175
176 // quick return
177 if (m == 0 || n == 0) return real_t(0);
178
179 // Allocates workspace
181 std::vector<T> work_;
182 auto work = new_matrix(work_, workinfo.m, workinfo.n);
183
185}
186
187} // namespace tlapack
188
189#endif // TLAPACK_INFNORM_TR_COLMAJOR_HH
constexpr bool isnan(const T &x) noexcept
Extends std::isnan() to complex numbers.
Definition utils.hpp:125
#define TLAPACK_DIAG
Macro for tlapack::concepts::Diag compatible with C++17.
Definition concepts.hpp:945
#define TLAPACK_UPLO
Macro for tlapack::concepts::Uplo compatible with C++17.
Definition concepts.hpp:942
#define TLAPACK_WORKSPACE
Macro for tlapack::concepts::Workspace compatible with C++17.
Definition concepts.hpp:912
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
constexpr auto diag(T &A, int diagIdx=0) noexcept
Get the Diagonal of an Eigen Matrix.
Definition eigen.hpp:576
auto infnorm_triangular_colmajor(uplo_t uplo, diag_t diag, const matrix_t &A)
Calculates the infinity norm of a column-major triangular matrix.
Definition infnorm_triangular_colmajor.hpp:162
auto infnorm_triangular_colmajor_work(uplo_t uplo, diag_t diag, const matrix_t &A, work_t &work)
Calculates the infinity norm of a column-major triangular matrix. Workspace is provided as an argum...
Definition infnorm_triangular_colmajor.hpp:57
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
constexpr WorkInfo infnorm_triangular_colmajor_worksize(uplo_t uplo, diag_t diag, const matrix_t &A)
Worspace query of infnorm_triangular_colmajor()
Definition infnorm_triangular_colmajor.hpp:38
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
Output information in the workspace query.
Definition workspace.hpp:16