"vscode:/vscode.git/clone" did not exist on "5ab28fd107686e5cb5490a803bdc988bcbbd698f"
generate.hpp 1.05 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_GENERATE_HPP

#include <migraph/argument.hpp>
Paul's avatar
Paul committed
5
#include <migraph/literal.hpp>
Paul's avatar
Paul committed
6
7
8
9
#include <random>

namespace migraph {

Paul's avatar
Paul committed
10
template <class T>
11
12
struct xorshf96_generator
{
Paul's avatar
Paul committed
13
14
15
16
    long max        = 16;
    unsigned long x = 123456789;
    unsigned long y = 362436069;
    unsigned long z = 521288629;
17

18
    constexpr T operator()() noexcept
19
    {
20
21
22
        x ^= x << 16U;
        x ^= x >> 5U;
        x ^= x << 1U;
23

Paul's avatar
Paul committed
24
        unsigned long t = x;
Paul's avatar
Paul committed
25
26
27
        x               = y;
        y               = z;
        z               = t ^ x ^ y;
28

Paul's avatar
Paul committed
29
        return z % max - (max + 1);
30
31
32
    }
};

Paul's avatar
Paul committed
33
template <class T>
Paul's avatar
Paul committed
34
std::vector<T> generate_tensor_data(const migraph::shape& s, std::mt19937::result_type)
Paul's avatar
Paul committed
35
36
{
    std::vector<T> result(s.elements());
37
    std::generate(result.begin(), result.end(), xorshf96_generator<T>{});
Paul's avatar
Paul committed
38
39
40
    return result;
}

Paul's avatar
Paul committed
41
42
43
argument generate_argument(shape s, std::mt19937::result_type seed = 0);

literal generate_literal(shape s, std::mt19937::result_type seed = 0);
Paul's avatar
Paul committed
44
45
46
47

} // namespace migraph

#endif