<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
exceptionHandling.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_EXCEPTION_HH
11#define TLAPACK_EXCEPTION_HH
12
13#include <iostream>
14#include <stdexcept>
15#include <string>
16
23#ifndef TLAPACK_DEFAULT_INFCHECK
24 #define TLAPACK_DEFAULT_INFCHECK true
25#endif
26
34#ifndef TLAPACK_DEFAULT_NANCHECK
35 #define TLAPACK_DEFAULT_NANCHECK true
36#endif
37
38namespace tlapack {
39namespace internal {
40
50 inline std::string error_msg(int info, const std::string& detailedInfo)
51 {
52 return std::string("[") + std::to_string(info) + "] " + detailedInfo;
53 }
54} // namespace internal
55
65
70constexpr ErrorCheck NO_ERROR_CHECK = {false, false, false};
71
76struct EcOpts {
77 ErrorCheck ec = {};
78
79 constexpr EcOpts(const ErrorCheck& ec_ = {}) : ec(ec_) {}
80};
81} // namespace tlapack
82
83// -----------------------------------------------------------------------------
84// Macros to handle error in the input
85
86#if defined(TLAPACK_CHECK_INPUT) && !defined(TLAPACK_NDEBUG)
87
98 #define tlapack_check(cond) \
99 do { \
100 if (!static_cast<bool>(cond)) throw std::domain_error(#cond); \
101 } while (false)
102
113 #define tlapack_check_false(cond) \
114 do { \
115 if (static_cast<bool>(cond)) throw std::domain_error(#cond); \
116 } while (false)
117
118#else // !defined(TLAPACK_CHECK_INPUT) || defined(TLAPACK_NDEBUG)
119
120 // <T>LAPACK does not check input parameters
121
122 #define tlapack_check_false(cond) ((void)0)
123 #define tlapack_check(cond) ((void)0)
124
125#endif
126
127// -----------------------------------------------------------------------------
128// Macros to handle internal errors and warnings
129
130#ifndef TLAPACK_NDEBUG
131
142 #define tlapack_error(info, detailedInfo) \
143 throw std::runtime_error( \
144 tlapack::internal::error_msg(info, detailedInfo))
145
156 #define tlapack_warning(info, detailedInfo) \
157 std::cerr << tlapack::internal::error_msg(info, detailedInfo) \
158 << std::endl;
159
171 #define tlapack_error_if(cond, info, detailedInfo) \
172 do { \
173 if (static_cast<bool>(cond)) tlapack_error(info, detailedInfo); \
174 } while (false)
175
176#else
177
178 // <T>LAPACK does not throw errors or display warnings
179
180 #define tlapack_error(info, detailedInfo) ((void)0)
181 #define tlapack_warning(info, detailedInfo) ((void)0)
182 #define tlapack_error_if(cond, info, detailedInfo) ((void)0)
183
184#endif
185
186#endif // TLAPACK_EXCEPTION_HH
constexpr ErrorCheck NO_ERROR_CHECK
Options to disable error checking.
Definition exceptionHandling.hpp:70
#define TLAPACK_DEFAULT_INFCHECK
Default behavior of checks for Infs.
Definition exceptionHandling.hpp:24
std::string error_msg(int info, const std::string &detailedInfo)
Create a string with the error message.
Definition exceptionHandling.hpp:50
#define TLAPACK_DEFAULT_NANCHECK
Default behavior of checks for NaNs.
Definition exceptionHandling.hpp:35
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
Options for error checking.
Definition exceptionHandling.hpp:76
Descriptor for Exception Handling.
Definition exceptionHandling.hpp:60
bool nan
Default behavior of nan check.
Definition exceptionHandling.hpp:62
bool internal
Used to enable / disable internal checks.
Definition exceptionHandling.hpp:63
bool inf
Default behavior of inf check.
Definition exceptionHandling.hpp:61