operation.hpp 1.17 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_OPERAND_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_OPERAND_HPP
Paul's avatar
Paul committed
3
4
5
6
7
8

#include <string>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
Paul's avatar
Paul committed
9
10
11
#include <migraph/shape.hpp>
#include <migraph/argument.hpp>
#include <migraph/context.hpp>
Paul's avatar
Paul committed
12
#include <migraph/auto_any_cast.hpp>
Paul's avatar
Paul committed
13

Paul's avatar
Paul committed
14
namespace migraph {
Paul's avatar
Paul committed
15

Paul's avatar
Paul committed
16
17
namespace operation_stream {

Paul's avatar
Paul committed
18
19
template <class T>
auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
Paul's avatar
Paul committed
20
{
Paul's avatar
Paul committed
21
    return os << x.name();
Paul's avatar
Paul committed
22
23
}

Paul's avatar
Paul committed
24
} // namespace operation_stream
Paul's avatar
Paul committed
25

Paul's avatar
Paul committed
26
template <class T>
Paul's avatar
Paul committed
27
28
29
30
31
argument compute_op(const T& x, context& ctx, shape output_shape, std::vector<argument> input)
{
    return x.compute(auto_any_cast(ctx), output_shape, input);
}

32
<%
Paul's avatar
Paul committed
33
34
35
interface('operation',
    virtual('name', returns='std::string', const=True),
    virtual('compute_shape', returns='shape', input='std::vector<shape>', const=True),
Paul's avatar
Paul committed
36
    virtual('compute', returns='argument', ctx='context&', output='shape', input='std::vector<argument>', const=True, default='compute_op'),
Paul's avatar
Paul committed
37
    friend('operator<<', returns='std::ostream &', os='std::ostream &', op='const operation &', using='migraph::operation_stream::operator<<')
Paul's avatar
Paul committed
38
)
39
%>
Paul's avatar
Paul committed
40

Paul's avatar
Paul committed
41
} // namespace migraph
Paul's avatar
Paul committed
42
43

#endif