builtin.hpp 1.66 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>
8
#include <migraph/config.hpp>
Paul's avatar
Paul committed
9

10
namespace migraph { inline namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
11
12
13

namespace builtin {

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

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

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

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

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

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

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

Paul's avatar
Paul committed
65
} // namespace builtin
66
} // inline namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
67
} // namespace migraph
Paul's avatar
Paul committed
68
69

#endif