forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInlineReductions.cpp
More file actions
97 lines (72 loc) · 3.01 KB
/
Copy pathInlineReductions.cpp
File metadata and controls
97 lines (72 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "InlineReductions.h"
// to avoid compiler confusion, python.hpp must be include before Halide headers
#include <boost/python.hpp>
#include "../../src/InlineReductions.h"
#include "Expr.h"
#include <string>
namespace h = Halide;
namespace p = boost::python;
h::Expr sum0(h::Expr e, const std::string name) {
return h::sum(e, name);
}
h::Expr sum1(h::RDom r, h::Expr e, const std::string name) {
return h::sum(r, e, name);
}
h::Expr product0(h::Expr e, const std::string name) {
return h::product(e, name);
}
h::Expr product1(h::RDom r, h::Expr e, const std::string name) {
return h::product(r, e, name);
}
h::Expr maximum0(h::Expr e, const std::string name) {
return h::maximum(e, name);
}
h::Expr maximum1(h::RDom r, h::Expr e, const std::string name) {
return h::maximum(r, e, name);
}
h::Expr minimum0(h::Expr e, const std::string name) {
return h::minimum(e, name);
}
h::Expr minimum1(h::RDom r, h::Expr e, const std::string name) {
return h::minimum(r, e, name);
}
p::object argmin0(h::Expr e, const std::string name) {
return expr_vector_to_python_tuple(h::argmin(e, name).as_vector());
}
p::object argmin1(h::RDom r, h::Expr e, const std::string name) {
return expr_vector_to_python_tuple(h::argmin(r, e, name).as_vector());
}
p::object argmax0(h::Expr e, const std::string name) {
return expr_vector_to_python_tuple(h::argmin(e, name).as_vector());
}
p::object argmax1(h::RDom r, h::Expr e, const std::string name) {
return expr_vector_to_python_tuple(h::argmax(r, e, name).as_vector());
}
void defineInlineReductions() {
// Defines some inline reductions: sum, product, minimum, maximum.
p::def("sum", &sum0, (p::arg("e"), p::arg("name") = "sum"),
"An inline reduction.");
p::def("sum", &sum1, (p::arg("r"), p::arg("e"), p::arg("name") = "sum"),
"An inline reduction.");
p::def("product", &product0, (p::arg("e"), p::arg("name") = "product"),
"An inline reduction.");
p::def("product", &product1, (p::arg("r"), p::arg("e"), p::arg("name") = "product"),
"An inline reduction.");
p::def("maximum", &maximum0, (p::arg("e"), p::arg("name") = "maximum"),
"An inline reduction.");
p::def("maximum", &maximum1, (p::arg("r"), p::arg("e"), p::arg("name") = "maximum"),
"An inline reduction.");
p::def("minimum", &minimum0, (p::arg("e"), p::arg("name") = "minimum"),
"An inline reduction.");
p::def("minimum", &minimum1, (p::arg("r"), p::arg("e"), p::arg("name") = "minimum"),
"An inline reduction.");
p::def("argmin", &argmin0, (p::arg("e"), p::arg("name") = "argmin"),
"An inline reduction.");
p::def("argmin", &argmin1, (p::arg("r"), p::arg("e"), p::arg("name") = "argmin"),
"An inline reduction.");
p::def("argmax", &argmax0, (p::arg("e"), p::arg("name") = "argmax"),
"An inline reduction.");
p::def("argmax", &argmax1, (p::arg("r"), p::arg("e"), p::arg("name") = "argmax"),
"An inline reduction.");
return;
}