#ifndef MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP #define MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP #include #include #include namespace migraph { template {})> constexpr T normalize(unsigned long z) { if(z == 0) return 0; return (2.0 / z) - 1.0; } template {} and not std::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 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}); 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 #endif