Skip to content

Commit a786585

Browse files
author
Yuuichi Asahi
committed
improve assertion
1 parent f46df0e commit a786585

4 files changed

+25
-26
lines changed

common/src/KokkosFFT_Helpers.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ auto get_shift(const ViewType& inout, axis_type<DIM> _axes, int direction = 1) {
2424
// Assert if the elements are overlapped
2525
constexpr int rank = ViewType::rank();
2626
KOKKOSFFT_EXPECTS(!KokkosFFT::Impl::has_duplicate_values(axes),
27-
"axes are overlapped");
27+
"Axes overlap");
2828
KOKKOSFFT_EXPECTS(
2929
!KokkosFFT::Impl::is_out_of_range_value_included(axes, rank),
30-
"axes include out of range index."
31-
"axes should be in the range of [-rank, rank-1].");
30+
"Axes include an out-of-range index."
31+
"Axes must be in the range of [-rank, rank-1].");
3232

3333
axis_type<rank> shift = {0};
3434
for (int i = 0; i < static_cast<int>(DIM); i++) {

common/src/KokkosFFT_layouts.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ auto get_extents(const InViewType& in, const OutViewType& out,
7070
KOKKOSFFT_EXPECTS(
7171
_out_extents.at(inner_most_axis) ==
7272
_in_extents.at(inner_most_axis) / 2 + 1,
73-
"For R2C, the output extent of transform should be input extent / "
74-
"2 + 1");
73+
"For R2C, the 'output extent' of transform must be equal to "
74+
"'input extent'/2 + 1");
7575
} else {
7676
throw std::runtime_error(
7777
"If the input type is real, the output type should be complex");
@@ -84,8 +84,8 @@ auto get_extents(const InViewType& in, const OutViewType& out,
8484
KOKKOSFFT_EXPECTS(
8585
_in_extents.at(inner_most_axis) ==
8686
_out_extents.at(inner_most_axis) / 2 + 1,
87-
"For C2R, the input extent of transform should be output extent / "
88-
"2 + 1");
87+
"For C2R, the 'input extent' of transform must be equal to "
88+
"'output extent' / 2 + 1");
8989
} else {
9090
throw std::runtime_error(
9191
"If the output type is real, the input type should be complex");

common/src/KokkosFFT_padding.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ auto get_modified_shape(const InViewType in, const OutViewType /* out */,
5252

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

6161
using full_shape_type = shape_type<rank>;
6262
full_shape_type modified_shape;

common/src/KokkosFFT_utils.hpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,53 @@
1313
#include <numeric>
1414
#include "KokkosFFT_traits.hpp"
1515

16-
#ifndef KOKKOS_ENABLE_CXX17
17-
#include <source_location>
18-
#define KOKKOSFFT_EXPECTS(expression, msg) \
19-
KokkosFFT::Impl::check_precondition((expression), msg, \
20-
std::source_location::current())
21-
#else
16+
#if defined(KOKKOS_ENABLE_CXX17)
2217
#include <cstdlib>
2318
#define KOKKOSFFT_EXPECTS(expression, msg) \
2419
KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \
2520
__FUNCTION__)
21+
#else
22+
#include <source_location>
23+
#define KOKKOSFFT_EXPECTS(expression, msg) \
24+
KokkosFFT::Impl::check_precondition((expression), msg, \
25+
std::source_location::current())
2626
#endif
2727

2828
namespace KokkosFFT {
2929
namespace Impl {
3030

31-
#ifndef KOKKOS_ENABLE_CXX17
31+
#if defined(KOKKOS_ENABLE_CXX17)
3232
inline void check_precondition(const bool expression, const std::string& msg,
33-
std::source_location location) {
33+
const char* file_name, int line,
34+
const char* function_name) {
3435
std::stringstream ss("file: ");
35-
ss << location.file_name() << '(' << location.line() << ':'
36-
<< location.column() << ") `" << location.function_name() << "`: " << msg
36+
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
3737
<< '\n';
38-
3938
if (!expression) {
4039
throw std::runtime_error(ss.str());
4140
}
4241
}
4342
#else
4443
inline void check_precondition(const bool expression, const std::string& msg,
45-
const char* file_name, int line,
46-
const char* function_name) {
44+
std::source_location location) {
4745
std::stringstream ss("file: ");
48-
ss << file_name << '(' << line << ") `" << function_name << "`: " << msg
46+
ss << location.file_name() << '(' << location.line() << ':'
47+
<< location.column() << ") `" << location.function_name() << "`: " << msg
4948
<< '\n';
49+
5050
if (!expression) {
5151
throw std::runtime_error(ss.str());
5252
}
5353
}
5454
#endif
55-
5655
template <typename ViewType>
5756
auto convert_negative_axis(ViewType, int _axis = -1) {
5857
static_assert(Kokkos::is_view<ViewType>::value,
5958
"convert_negative_axis: ViewType is not a Kokkos::View.");
6059
int rank = static_cast<int>(ViewType::rank());
6160

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

6564
int axis = _axis < 0 ? rank + _axis : _axis;
6665
return axis;

0 commit comments

Comments
 (0)