Skip to content

Commit

Permalink
simplify check_precondition
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jul 29, 2024
1 parent a786585 commit 2a1d1d9
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions common/src/KokkosFFT_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <Kokkos_Core.hpp>
#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include "KokkosFFT_traits.hpp"
Expand All @@ -20,38 +20,38 @@
__FUNCTION__)
#else
#include <source_location>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition((expression), msg, \
std::source_location::current())
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition( \
(expression), msg, std::source_location::current().file_name(), \
std::source_location::current().line(), \
std::source_location::current().function_name(), \
std::source_location::current().column())
#endif

namespace KokkosFFT {
namespace Impl {

#if defined(KOKKOS_ENABLE_CXX17)
inline void check_precondition(const bool expression, const std::string& msg,
const char* file_name, int line,
const char* function_name) {
inline void check_precondition(const bool expression,
[[maybe_unused]] const std::string& msg,
[[maybe_unused]] const char* file_name, int line,
[[maybe_unused]] const char* function_name,
[[maybe_unused]] const int column = -1) {
// Quick return if possible
if (expression) return;

std::stringstream ss("file: ");
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
<< '\n';
if (!expression) {
throw std::runtime_error(ss.str());
if (column == -1) {
// For C++ 17
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
<< '\n';
} else {
// For C++ 20 and later
ss << file_name << '(' << line << ':' << column << ") `" << function_name
<< "`: " << msg << '\n';
}
throw std::runtime_error(ss.str());
}
#else
inline void check_precondition(const bool expression, const std::string& msg,
std::source_location location) {
std::stringstream ss("file: ");
ss << location.file_name() << '(' << location.line() << ':'
<< location.column() << ") `" << location.function_name() << "`: " << msg
<< '\n';

if (!expression) {
throw std::runtime_error(ss.str());
}
}
#endif
template <typename ViewType>
auto convert_negative_axis(ViewType, int _axis = -1) {
static_assert(Kokkos::is_view<ViewType>::value,
Expand Down

0 comments on commit 2a1d1d9

Please sign in to comment.