|
14 | 14 |
|
15 | 15 | #if defined(KOKKOS_ENABLE_CXX17)
|
16 | 16 | #include <cstdlib>
|
| 17 | +#define KOKKOSFFT_EXPECTS(expression, msg) \ |
| 18 | + KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \ |
| 19 | + __FUNCTION__) |
17 | 20 | #else
|
18 | 21 | #include <source_location>
|
| 22 | +#define KOKKOSFFT_EXPECTS(expression, msg) \ |
| 23 | + KokkosFFT::Impl::check_precondition( \ |
| 24 | + (expression), msg, std::source_location::current().file_name(), \ |
| 25 | + std::source_location::current().line(), \ |
| 26 | + std::source_location::current().function_name(), \ |
| 27 | + std::source_location::current().column()) |
19 | 28 | #endif
|
20 | 29 |
|
21 | 30 | namespace KokkosFFT {
|
22 | 31 | namespace Impl {
|
23 | 32 |
|
| 33 | +inline void check_precondition(const bool expression, |
| 34 | + [[maybe_unused]] const std::string& msg, |
| 35 | + [[maybe_unused]] const char* file_name, int line, |
| 36 | + [[maybe_unused]] const char* function_name, |
| 37 | + [[maybe_unused]] const int column = -1) { |
| 38 | + // Quick return if possible |
| 39 | + if (expression) return; |
| 40 | + |
| 41 | + std::stringstream ss("file: "); |
| 42 | + if (column == -1) { |
| 43 | + // For C++ 17 |
| 44 | + ss << file_name << '(' << line << ") `" << function_name << "`: " << msg |
| 45 | + << '\n'; |
| 46 | + } else { |
| 47 | + // For C++ 20 and later |
| 48 | + ss << file_name << '(' << line << ':' << column << ") `" << function_name |
| 49 | + << "`: " << msg << '\n'; |
| 50 | + } |
| 51 | + throw std::runtime_error(ss.str()); |
| 52 | +} |
| 53 | +inline void check_precondition(const bool expression, const std::string& msg, |
| 54 | + const char* file_name, int line, |
| 55 | + const char* function_name) { |
| 56 | + std::stringstream ss("file: "); |
| 57 | + ss << file_name << '(' << line << ") `" << function_name << "`: " << msg |
| 58 | + << '\n'; |
| 59 | + if (!expression) { |
| 60 | + throw std::runtime_error(ss.str()); |
| 61 | + } |
| 62 | +} |
| 63 | +#endif |
| 64 | + |
24 | 65 | template <typename ViewType>
|
25 | 66 | auto convert_negative_axis(ViewType, int _axis = -1) {
|
26 | 67 | static_assert(Kokkos::is_view<ViewType>::value,
|
|
0 commit comments