<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
hasnan.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_HASNAN_HH
11#define TLAPACK_HASNAN_HH
12
14
15namespace tlapack {
16
41template <TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
43{
44 using idx_t = size_type<matrix_t>;
45
46 // constants
47 const idx_t m = nrows(A);
48 const idx_t n = ncols(A);
49
50 tlapack_check(uplo == Uplo::General || uplo == Uplo::UpperHessenberg ||
51 uplo == Uplo::LowerHessenberg || uplo == Uplo::Upper ||
52 uplo == Uplo::Lower || uplo == Uplo::StrictUpper ||
53 uplo == Uplo::StrictLower);
54
55 if (uplo == Uplo::UpperHessenberg) {
56 for (idx_t j = 0; j < n; ++j)
57 for (idx_t i = 0; i < ((j < m) ? j + 2 : m); ++i)
58 if (isnan(A(i, j))) return true;
59 return false;
60 }
61 else if (uplo == Uplo::Upper) {
62 for (idx_t j = 0; j < n; ++j)
63 for (idx_t i = 0; i < ((j < m) ? j + 1 : m); ++i)
64 if (isnan(A(i, j))) return true;
65 return false;
66 }
67 else if (uplo == Uplo::StrictUpper) {
68 for (idx_t j = 0; j < n; ++j)
69 for (idx_t i = 0; i < ((j < m) ? j : m); ++i)
70 if (isnan(A(i, j))) return true;
71 return false;
72 }
73 else if (uplo == Uplo::LowerHessenberg) {
74 for (idx_t j = 0; j < n; ++j)
75 for (idx_t i = ((j > 1) ? j - 1 : 0); i < m; ++i)
76 if (isnan(A(i, j))) return true;
77 return false;
78 }
79 else if (uplo == Uplo::Lower) {
80 for (idx_t j = 0; j < n; ++j)
81 for (idx_t i = j; i < m; ++i)
82 if (isnan(A(i, j))) return true;
83 return false;
84 }
85 else if (uplo == Uplo::StrictLower) {
86 for (idx_t j = 0; j < n; ++j)
87 for (idx_t i = j + 1; i < m; ++i)
88 if (isnan(A(i, j))) return true;
89 return false;
90 }
91 else // if ( (Uplo) uplo == Uplo::General )
92 {
93 for (idx_t j = 0; j < n; ++j)
94 for (idx_t i = 0; i < m; ++i)
95 if (isnan(A(i, j))) return true;
96 return false;
97 }
98}
99
108template <TLAPACK_MATRIX matrix_t>
109bool hasnan(BandAccess accessType, const matrix_t& A) noexcept
110{
111 using idx_t = size_type<matrix_t>;
112
113 // constants
114 const idx_t m = nrows(A);
115 const idx_t n = ncols(A);
116 const idx_t kl = accessType.lower_bandwidth;
117 const idx_t ku = accessType.upper_bandwidth;
118
119 for (idx_t j = 0; j < n; ++j)
120 for (idx_t i = ((j >= ku) ? (j - ku) : 0); i < min(m, j + kl + 1); ++i)
121 if (isnan(A(i, j))) return true;
122 return false;
123}
124
135template <TLAPACK_VECTOR vector_t>
136bool hasnan(const vector_t& x) noexcept
137{
138 using idx_t = size_type<vector_t>;
139
140 // constants
141 const idx_t n = size(x);
142
143 for (idx_t i = 0; i < n; ++i)
144 if (isnan(x[i])) return true;
145 return false;
146}
147
148} // namespace tlapack
149
150#endif // TLAPACK_HASNAN_HH
constexpr bool isnan(const T &x) noexcept
Extends std::isnan() to complex numbers.
Definition utils.hpp:125
#define tlapack_check(cond)
Throw an error if cond is false.
Definition exceptionHandling.hpp:98
bool hasnan(uplo_t uplo, const matrix_t &A)
Returns true if and only if A has an NaN entry.
Definition hasnan.hpp:42
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
Band access.
Definition types.hpp:427