Skip to content

Commit

Permalink
improve assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuuichi Asahi committed Jul 29, 2024
1 parent f46df0e commit a786585
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions common/src/KokkosFFT_Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ auto get_shift(const ViewType& inout, axis_type<DIM> _axes, int direction = 1) {
// Assert if the elements are overlapped
constexpr int rank = ViewType::rank();
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(axes),
"axes are overlapped");
"Axes overlap");
KOKKOSFFT_EXPECTS(
!KokkosFFT::Impl::is_out_of_range_value_included(axes, rank),
"axes include out of range index."
"axes should be in the range of [-rank, rank-1].");
"Axes include an out-of-range index."
"Axes must be in the range of [-rank, rank-1].");

axis_type<rank> shift = {0};
for (int i = 0; i < static_cast<int>(DIM); i++) {
Expand Down
8 changes: 4 additions & 4 deletions common/src/KokkosFFT_layouts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ auto get_extents(const InViewType& in, const OutViewType& out,
KOKKOSFFT_EXPECTS(
_out_extents.at(inner_most_axis) ==
_in_extents.at(inner_most_axis) / 2 + 1,
"For R2C, the output extent of transform should be input extent / "
"2 + 1");
"For R2C, the 'output extent' of transform must be equal to "
"'input extent'/2 + 1");
} else {
throw std::runtime_error(
"If the input type is real, the output type should be complex");
Expand All @@ -84,8 +84,8 @@ auto get_extents(const InViewType& in, const OutViewType& out,
KOKKOSFFT_EXPECTS(
_in_extents.at(inner_most_axis) ==
_out_extents.at(inner_most_axis) / 2 + 1,
"For C2R, the input extent of transform should be output extent / "
"2 + 1");
"For C2R, the 'input extent' of transform must be equal to "
"'output extent' / 2 + 1");
} else {
throw std::runtime_error(
"If the output type is real, the input type should be complex");
Expand Down
6 changes: 3 additions & 3 deletions common/src/KokkosFFT_padding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ auto get_modified_shape(const InViewType in, const OutViewType /* out */,

// Assert if the elements are overlapped
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(positive_axes),
"axes are overlapped");
"Axes overlap");
KOKKOSFFT_EXPECTS(
!KokkosFFT::Impl::is_out_of_range_value_included(positive_axes, rank),
"axes include out of range index."
"axes should be in the range of [-rank, rank-1].");
"Axes include an out-of-range index."
"Axes must be in the range of [-rank, rank-1].");

using full_shape_type = shape_type<rank>;
full_shape_type modified_shape;
Expand Down
31 changes: 15 additions & 16 deletions common/src/KokkosFFT_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,53 @@
#include <numeric>
#include "KokkosFFT_traits.hpp"

#ifndef KOKKOS_ENABLE_CXX17
#include <source_location>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition((expression), msg, \
std::source_location::current())
#else
#if defined(KOKKOS_ENABLE_CXX17)
#include <cstdlib>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \
__FUNCTION__)
#else
#include <source_location>
#define KOKKOSFFT_EXPECTS(expression, msg) \
KokkosFFT::Impl::check_precondition((expression), msg, \
std::source_location::current())
#endif

namespace KokkosFFT {
namespace Impl {

#ifndef KOKKOS_ENABLE_CXX17
#if defined(KOKKOS_ENABLE_CXX17)
inline void check_precondition(const bool expression, const std::string& msg,
std::source_location location) {
const char* file_name, int line,
const char* function_name) {
std::stringstream ss("file: ");
ss << location.file_name() << '(' << location.line() << ':'
<< location.column() << ") `" << location.function_name() << "`: " << msg
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
<< '\n';

if (!expression) {
throw std::runtime_error(ss.str());
}
}
#else
inline void check_precondition(const bool expression, const std::string& msg,
const char* file_name, int line,
const char* function_name) {
std::source_location location) {
std::stringstream ss("file: ");
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
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,
"convert_negative_axis: ViewType is not a Kokkos::View.");
int rank = static_cast<int>(ViewType::rank());

KOKKOSFFT_EXPECTS(_axis >= -rank && _axis < rank,
"axis should be in [-rank, rank-1]");
"Axis must be in [-rank, rank-1]");

int axis = _axis < 0 ? rank + _axis : _axis;
return axis;
Expand Down

0 comments on commit a786585

Please sign in to comment.