builtin.hpp 1.56 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_BUILTIN_HPP
#define MIGRAPH_GUARD_BUILTIN_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
5
#include <migraph/context.hpp>
#include <migraph/errors.hpp>
Paul's avatar
Paul committed
6
#include <migraph/argument.hpp>
Paul's avatar
Paul committed
7
#include <migraph/reflect.hpp>
Paul's avatar
Paul committed
8

Paul's avatar
Paul committed
9
namespace migraph {
Paul's avatar
Paul committed
10
11
12

namespace builtin {

Paul's avatar
Paul committed
13
14
struct literal
{
Paul's avatar
Paul committed
15
    std::string name() const { return "@literal"; }
Paul's avatar
Paul committed
16
    shape compute_shape(const std::vector<shape>&) const { MIGRAPH_THROW("builtin"); }
Paul's avatar
Paul committed
17
18
19
20
    argument compute(context&, const shape&, const std::vector<argument>&) const
    {
        MIGRAPH_THROW("builtin");
    }
Paul's avatar
Paul committed
21
22
};

Paul's avatar
Paul committed
23
24
25
struct outline
{
    shape s;
Paul's avatar
Paul committed
26
27
28
29
30
31
32

    template <class Self, class F>
    static auto reflect(Self& self, F f)
    {
        return pack(f(self.s, "shape"));
    }

Paul's avatar
Paul committed
33
    std::string name() const { return "@outline"; }
Paul's avatar
Paul committed
34
    shape compute_shape(const std::vector<shape>&) const { return s; }
Paul's avatar
Paul committed
35
36
37
38
    argument compute(context&, const shape&, const std::vector<argument>&) const
    {
        MIGRAPH_THROW("builtin");
    }
Paul's avatar
Paul committed
39
40
};

Paul's avatar
Paul committed
41
42
43
struct param
{
    std::string parameter;
Paul's avatar
Paul committed
44
45
46
47
48
49
50

    template <class Self, class F>
    static auto reflect(Self& self, F f)
    {
        return pack(f(self.parameter, "parameter"));
    }

Paul's avatar
Paul committed
51
    std::string name() const { return "@param"; }
Paul's avatar
Paul committed
52
    shape compute_shape(const std::vector<shape>&) const { MIGRAPH_THROW("builtin"); }
Paul's avatar
Paul committed
53
54
55
56
    argument compute(context&, const shape&, const std::vector<argument>&) const
    {
        MIGRAPH_THROW("builtin");
    }
Paul's avatar
Paul committed
57
    friend std::ostream& operator<<(std::ostream& os, const param& op)
Paul's avatar
Paul committed
58
    {
Paul's avatar
Paul committed
59
        os << op.name() << ":" << op.parameter;
Paul's avatar
Paul committed
60
61
        return os;
    }
Paul's avatar
Paul committed
62
};
Paul's avatar
Paul committed
63

Paul's avatar
Paul committed
64
} // namespace builtin
Paul's avatar
Paul committed
65

Paul's avatar
Paul committed
66
} // namespace migraph
Paul's avatar
Paul committed
67
68

#endif