-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply check functions to fft functions (#130)
* Improve assertions in fft functions * format * use is_complex_v * fix: typo * using string_view and remove maybe_unused from assertion helper --------- Co-authored-by: Yuuichi Asahi <[email protected]>
- Loading branch information
1 parent
0dfbae8
commit be5919c
Showing
11 changed files
with
189 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-FileCopyrightText: (C) The Kokkos-FFT development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception | ||
|
||
#ifndef KOKKOSFFT_ASSERTS_HPP | ||
#define KOKKOSFFT_ASSERTS_HPP | ||
|
||
#include <stdexcept> | ||
#include <sstream> | ||
#include <string_view> | ||
|
||
#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L | ||
#include <source_location> | ||
#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()) | ||
#else | ||
#include <cstdlib> | ||
#define KOKKOSFFT_EXPECTS(expression, msg) \ | ||
KokkosFFT::Impl::check_precondition((expression), msg, __FILE__, __LINE__, \ | ||
__FUNCTION__) | ||
#endif | ||
|
||
namespace KokkosFFT { | ||
namespace Impl { | ||
|
||
inline void check_precondition(const bool expression, | ||
const std::string_view& msg, | ||
const char* file_name, int line, | ||
const char* function_name, | ||
const int column = -1) { | ||
// Quick return if possible | ||
if (expression) return; | ||
|
||
std::stringstream ss("file: "); | ||
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()); | ||
} | ||
|
||
} // namespace Impl | ||
} // namespace KokkosFFT | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.