<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
infnorm_symmetric_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_SY_COLMAJOR_HH
11#define TLAPACK_INFNORM_SY_COLMAJOR_HH
12
14
15namespace tlapack {
16
29template <class T, TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
31 const matrix_t& A)
32{
33 return WorkInfo(nrows(A));
34}
35
44template <TLAPACK_UPLO uplo_t,
45 TLAPACK_MATRIX matrix_t,
46 TLAPACK_WORKSPACE work_t>
48 const matrix_t& A,
49 work_t& work)
50{
51 using T = type_t<matrix_t>;
52 using real_t = real_type<T>;
53 using idx_t = size_type<matrix_t>;
55
56 // check arguments
57 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
58
59 // constants
60 const idx_t n = nrows(A);
61
62 // quick return
63 if (n <= 0) return real_t(0);
64
65 // Vector w
66 auto [w, work1] = reshape(work, n);
67
68 // Norm value
69 real_t norm(0);
70
71 for (idx_t i = 0; i < n; ++i)
72 w[i] = T(0);
73
74 if (uplo == Uplo::Upper) {
75 for (idx_t j = 0; j < n; ++j) {
76 real_t sum(0);
77 for (idx_t i = 0; i < j; ++i) {
78 const real_t absa = abs(A(i, j));
79 sum += absa;
80 w[i] += absa;
81 }
82 w[j] = sum + abs(A(j, j));
83 }
84 for (idx_t i = 0; i < n; ++i) {
85 real_t sum = w[i];
86 if (sum > norm)
87 norm = sum;
88 else {
89 if (isnan(sum)) return sum;
90 }
91 }
92 }
93 else {
94 for (idx_t j = 0; j < n; ++j) {
95 real_t sum = w[j] + abs(A(j, j));
96 for (idx_t i = j + 1; i < n; ++i) {
97 const real_t absa = abs(A(i, j));
98 sum += absa;
99 w[i] += absa;
100 }
101 if (sum > norm)
102 norm = sum;
103 else {
104 if (isnan(sum)) return sum;
105 }
106 }
107 }
108
109 return norm;
110}
111
127template <TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
129{
130 using T = type_t<matrix_t>;
131 using real_t = real_type<T>;
132 using idx_t = size_type<matrix_t>;
133
134 // check arguments
135 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
136
137 // constants
138 const idx_t n = nrows(A);
139
140 // quick return
141 if (n <= 0) return real_t(0);
142
143 // Allocates workspace
145 std::vector<T> work_;
146 auto work = new_matrix(work_, workinfo.m, workinfo.n);
147
149}
150
151} // namespace tlapack
152
153#endif // TLAPACK_INFNORM_SY_COLMAJOR_HH
constexpr bool isnan(const T &x) noexcept
Extends std::isnan() to complex numbers.
Definition utils.hpp:125
#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
auto infnorm_symmetric_colmajor_work(uplo_t uplo, const matrix_t &A, work_t &work)
Calculates the infinity norm of a column-major symmetric matrix. Workspace is provided as an argume...
Definition infnorm_symmetric_colmajor.hpp:47
auto infnorm_symmetric_colmajor(uplo_t uplo, const matrix_t &A)
Calculates the infinity norm of a column-major symmetric matrix.
Definition infnorm_symmetric_colmajor.hpp:128
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
constexpr WorkInfo infnorm_symmetric_colmajor_worksize(uplo_t uplo, const matrix_t &A)
Worspace query of infnorm_symmetric_colmajor()
Definition infnorm_symmetric_colmajor.hpp:30
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