#ifndef MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP #define MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP #include #include #include #include #include namespace migraph { inline namespace MIGRAPH_INLINE_NS { template {})> constexpr T normalize(unsigned long z) { if(z == 0) return T(0); const auto max = 32; const double range = max / 2; // NOLINT double result = (z % max) / range; result -= 1; return T(result); } template {} and not is_floating_point{})> constexpr T normalize(unsigned long z) { const auto max = std::numeric_limits::max(); const auto half_max = max / 2; return half_max - (z % max); } template {} and std::is_integral{})> constexpr T normalize(unsigned long z) { const auto max = std::numeric_limits::max(); return z % max; } template struct xorshf96_generator { unsigned long x = 123456789; unsigned long y = 362436069; unsigned long z; xorshf96_generator(unsigned long seed = 0) : z(521288629ULL ^ seed) {} constexpr T operator()() noexcept { x ^= x << 16U; x ^= x >> 5U; x ^= x << 1U; unsigned long t = x; x = y; y = z; z = t ^ x ^ y; return normalize(z); } }; template struct xorshift_generator { unsigned long x; xorshift_generator(unsigned long seed = 0) : x(521288629ULL ^ seed) {} constexpr T operator()() noexcept { x ^= x >> 12U; x ^= x << 25U; x ^= x >> 27U; return normalize(x * 0x2545F4914F6CDD1D); } }; template std::vector generate_tensor_data(const migraph::shape& s, unsigned long seed = 0) { std::vector result(s.elements()); std::generate(result.begin(), result.end(), xorshf96_generator{seed}); // std::generate(result.begin(), result.end(), [&]{ return seed % 7; }); // std::generate(result.begin(), result.end(), []{ return 1; }); return result; } argument generate_argument(shape s, unsigned long seed = 0); literal generate_literal(shape s, unsigned long seed = 0); literal abs(literal l); } // namespace MIGRAPH_INLINE_NS } // namespace migraph #endif