-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added nan
to the DaCe math
namespace
#1437
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20c6295
It is now possible to wite `math.nan` in a (Python) tasklet.
philip-paul-mueller 93e86e6
Fixed some bugs with the `typeless_nan`.
philip-paul-mueller a07eede
Removed the exception in the `int` convertion of the `typeless_nan`.
philip-paul-mueller 8a9cb2c
Modified how the function hijacking for `typeless_nan` behaves.
philip-paul-mueller 724a4d1
Merge remote-tracking branch 'spcl/master' into nan_in_math
philip-paul-mueller d4a656e
Merge branch 'master' into nan_in_math
philip-paul-mueller fb35b70
Switched to `std::numeric_limits::quiet_NaN()`.
philip-paul-mueller f00c841
Merge branch 'master' into nan_in_math
philip-paul-mueller adfaab2
Merge branch 'master' into nan_in_math
philip-paul-mueller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,112 @@ | ||
// Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved. | ||
#ifndef __DACE_NAN_H | ||
#define __DACE_NAN_H | ||
|
||
// Class to define a stateless NAN and related operators. | ||
|
||
namespace dace | ||
{ | ||
namespace math | ||
{ | ||
////////////////////////////////////////////////////// | ||
// Defines a typeless Pi | ||
struct typeless_nan | ||
{ | ||
operator int() const = delete; | ||
operator float() const | ||
{ | ||
return std::nanf(""); | ||
} | ||
operator double() const | ||
{ | ||
return std::nan(""); | ||
} | ||
operator long double() const | ||
{ | ||
return std::nanl(""); | ||
} | ||
typeless_nan operator+() const | ||
{ | ||
return typeless_nan{}; | ||
} | ||
typeless_nan operator-() const | ||
{ | ||
return typeless_nan{}; | ||
} | ||
}; | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator*(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator*(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator*(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator+(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator+(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator+(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator-(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator-(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator-(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator/(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator/(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator/(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator%(const T&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
template<typename T> | ||
DACE_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, typeless_nan>::type | ||
operator%(const typeless_nan&, const T&) { return typeless_nan{}; } | ||
|
||
inline typeless_nan | ||
operator%(const typeless_nan&, const typeless_nan&) { return typeless_nan{}; } | ||
|
||
} | ||
} | ||
|
||
//These functions allows to perfrom operations with `typeless_nan` instances. | ||
# define FADAPT(F) DACE_CONSTEXPR ::dace::math::typeless_nan F (::dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; } | ||
# define FADAPT2(F) template<typename T1> DACE_CONSTEXPR dace::math::typeless_nan F (T1&&, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; }; \ | ||
template<typename T2> DACE_CONSTEXPR dace::math::typeless_nan F (dace::math::typeless_nan, T2&&) { return ::dace::math::typeless_nan{}; }; \ | ||
DACE_CONSTEXPR ::dace::math::typeless_nan F (dace::math::typeless_nan, dace::math::typeless_nan) { return ::dace::math::typeless_nan{}; } | ||
FADAPT(tanh); FADAPT(cos); FADAPT(sin); FADAPT(sqrt); FADAPT(tan); | ||
FADAPT(acos); FADAPT(asin); FADAPT(atan); FADAPT(log); FADAPT(exp); | ||
FADAPT(floor); FADAPT(ceil); FADAPT(round); FADAPT(abs); | ||
FADAPT2(max); FADAPT2(min); | ||
# undef FADAPT2 | ||
# undef FADAPT | ||
|
||
#endif // __DACE_NAN_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::nan*
usestrto*
, which will be slow. Please use numeric_limits' NaN: https://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaNThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reminding me about that thing.