"projects/vscode:/vscode.git/clone" did not exist on "104273cc79ecc921020e962238014e2ce2dad9ba"
tensor_generator.hpp 1.21 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
2
3
4
5
6
7
#ifndef TENSOR_GENERATOR_HPP
#define TENSOR_GENERATOR_HPP

#include "config.hpp"

struct GeneratorTensor_1
{
Chao Liu's avatar
Chao Liu committed
8
9
    int value = 1;

Chao Liu's avatar
Chao Liu committed
10
11
12
    template <class... Is>
    double operator()(Is... is)
    {
Chao Liu's avatar
Chao Liu committed
13
        return value;
Chao Liu's avatar
Chao Liu committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    }
};

struct GeneratorTensor_2
{
    int min_value = 0;
    int max_value = 1;

    template <class... Is>
    double operator()(Is...)
    {
        return (std::rand() % (max_value - min_value)) + min_value;
    }
};

struct GeneratorTensor_3
{
    template <class... Is>
    double operator()(Is... is)
    {
        std::array<ck::index_t, sizeof...(Is)> dims = {{static_cast<ck::index_t>(is)...}};

        auto f_acc = [](auto a, auto b) { return 10 * a + b; };

        return std::accumulate(dims.begin(), dims.end(), ck::index_t(0), f_acc);
    }
};

struct GeneratorTensor_Checkboard
{
    template <class... Ts>
    double operator()(Ts... Xs) const
    {
        std::array<ck::index_t, sizeof...(Ts)> dims = {{Xs...}};
        return std::accumulate(dims.begin(),
                               dims.end(),
                               true,
                               [](bool init, ck::index_t x) -> int { return init != (x % 2); })
                   ? 1
                   : -1;
    }
};

#endif