Commit 5df808fc authored by Paul's avatar Paul
Browse files

Update generate to try to normalize the data

parent abb27ba0
......@@ -7,10 +7,31 @@
namespace migraph {
template<class T, MIGRAPH_REQUIRES(std::is_floating_point<T>{})>
T normalize(T z)
{
if(z == 0) return 0;
return (2.0 / z) - 1.0;
}
template<class T, MIGRAPH_REQUIRES(std::is_signed<T>{})>
T normalize(T z)
{
const auto max = std::numeric_limits<T>::max();
const auto half_max = max/2;
return half_max - (z % max);
}
template<class T, MIGRAPH_REQUIRES(not std::is_signed<T>{} and std::is_integral<T>{})>
T normalize(T z)
{
const auto max = std::numeric_limits<T>::max();
return z % max;
}
template <class T>
struct xorshf96_generator
{
long max = 16;
unsigned long x = 123456789;
unsigned long y = 362436069;
unsigned long z = 521288629;
......@@ -26,7 +47,8 @@ struct xorshf96_generator
y = z;
z = t ^ x ^ y;
return z % max - (max + 1);
return normalize(z);
}
};
......
......@@ -13,12 +13,30 @@ struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT
template <bool B>
using bool_c = std::integral_constant<bool, B>;
template<int N>
struct requires_enum
{
enum e
{
A = 0
};
};
#define MIGRAPH_REQUIRES_CAT(x, y) x ## y
#ifdef CPPCHECK
#define MIGRAPH_REQUIRES(...) class = void
#else
#if 0
// TODO: This current crashed on clang
#define MIGRAPH_REQUIRES(...) \
bool PrivateRequires##__LINE__ = true, \
class = typename std::enable_if<and_<__VA_ARGS__, PrivateRequires##__LINE__>{}>::type
typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
class = typename std::enable_if<and_<__VA_ARGS__, MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) == migraph::requires_enum<__LINE__>::A>{}>::type
#else
#define MIGRAPH_REQUIRES(...) \
typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
class = typename std::enable_if<and_<__VA_ARGS__>{}>::type
#endif
#endif
} // namespace migraph
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment