6
6
7
7
#define ARMA_DONT_USE_WRAPPER
8
8
#include < armadillo>
9
- #include " operon/interpreter/backend/backend .hpp"
9
+ #include " operon/core/dispatch .hpp"
10
10
11
11
namespace Operon ::Backend {
12
12
template <typename T, std::size_t S>
@@ -32,173 +32,173 @@ namespace Operon::Backend {
32
32
33
33
// utility
34
34
template <typename T, std::size_t S>
35
- auto Fill (T* res, T value) {
35
+ auto Fill (T* res, T weight, T value) {
36
36
Map<T, S>(res).fill (value);
37
37
}
38
38
39
39
// n-ary functions
40
40
template <typename T, std::size_t S>
41
- auto Add (T* res, auto const *... args) {
42
- Map<T, S>(res) = (Map<T const , S>(args) + ...);
41
+ auto Add (T* res, T weight, auto const *... args) {
42
+ Map<T, S>(res) = weight * (Map<T const , S>(args) + ...);
43
43
}
44
44
45
45
template <typename T, std::size_t S>
46
- auto Mul (T* res, auto const *... args) {
47
- Map<T, S>(res) = (Map<T const , S>(args) % ...);
46
+ auto Mul (T* res, T weight, auto const *... args) {
47
+ Map<T, S>(res) = weight * (Map<T const , S>(args) % ...);
48
48
}
49
49
50
50
template <typename T, std::size_t S>
51
- auto Sub (T* res, auto * first, auto const *... rest) {
51
+ auto Sub (T* res, T weight, auto * first, auto const *... rest) {
52
52
static_assert (sizeof ...(rest) > 0 );
53
- Map<T, S>(res) = Map<T const , S>(first) - (Map<T const , S>(rest) + ...);
53
+ Map<T, S>(res) = weight * Map<T const , S>(first) - (Map<T const , S>(rest) + ...);
54
54
}
55
55
56
56
template <typename T, std::size_t S>
57
- auto Div (T* res, auto const * first, auto const *... rest) {
57
+ auto Div (T* res, T weight, auto const * first, auto const *... rest) {
58
58
static_assert (sizeof ...(rest) > 0 );
59
- Map<T, S>(res) = Map<T const , S>(first) / (Map<T const , S>(rest) * ...);
59
+ Map<T, S>(res) = weight * Map<T const , S>(first) / (Map<T const , S>(rest) * ...);
60
60
}
61
61
62
62
template <typename T, std::size_t S>
63
- auto Min (T* res, auto const * first, auto const *... args) {
63
+ auto Min (T* res, T weight, auto const * first, auto const *... args) {
64
64
static_assert (sizeof ...(args) > 0 );
65
65
for (auto i = 0UL ; i < S; ++i) {
66
- res[i] = std::min ({first[i], args[i]...});
66
+ res[i] = weight * std::min ({first[i], args[i]...});
67
67
}
68
68
}
69
69
70
70
template <typename T, std::size_t S>
71
- auto Max (T* res, auto * first, auto const *... args) {
71
+ auto Max (T* res, T weight, auto * first, auto const *... args) {
72
72
for (auto i = 0UL ; i < S; ++i) {
73
- res[i] = std::max ({first[i], args[i]...});
73
+ res[i] = weight * std::max ({first[i], args[i]...});
74
74
}
75
75
}
76
76
77
77
// binary functions
78
78
template <typename T, std::size_t S>
79
- auto Aq (T* res, T const * a, T const * b) {
80
- Map<T, S>(res) = Map<T const , S>(a) / arma::sqrt ((T{1 } + arma::square (Map<T const , S>(b))));
79
+ auto Aq (T* res, T weight, T const * a, T const * b) {
80
+ Map<T, S>(res) = weight * Map<T const , S>(a) / arma::sqrt ((T{1 } + arma::square (Map<T const , S>(b))));
81
81
}
82
82
83
83
template <typename T, std::size_t S>
84
- auto Pow (T* res, T const * a, T const * b) {
85
- Map<T, S>(res) = arma::pow (Map<T const , S>(a), Map<T const , S>(b));
84
+ auto Pow (T* res, T weight, T const * a, T const * b) {
85
+ Map<T, S>(res) = weight * arma::pow (Map<T const , S>(a), Map<T const , S>(b));
86
86
}
87
87
88
88
// unary functions
89
89
template <typename T, std::size_t S>
90
- auto Cpy (T* res, T const * arg) {
91
- Map<T, S>(res) = Map<T const , S>(arg);
90
+ auto Cpy (T* res, T weight, T const * arg) {
91
+ Map<T, S>(res) = weight * Map<T const , S>(arg);
92
92
}
93
93
94
94
template <typename T, std::size_t S>
95
- auto Neg (T* res, T const * arg) {
96
- Map<T, S>(res) = -Map<T const , S>(arg);
95
+ auto Neg (T* res, T weight, T const * arg) {
96
+ Map<T, S>(res) = weight * -Map<T const , S>(arg);
97
97
}
98
98
99
99
template <typename T, std::size_t S>
100
- auto Inv (T* res, T const * arg) {
101
- Map<T, S>(res) = T{ 1 } / Map<T const , S>(arg);
100
+ auto Inv (T* res, T weight, T const * arg) {
101
+ Map<T, S>(res) = weight / Map<T const , S>(arg);
102
102
}
103
103
104
104
template <typename T, std::size_t S>
105
- auto Abs (T* res, T const * arg) {
106
- Map<T, S>(res) = arma::abs (Map<T const , S>(arg));
105
+ auto Abs (T* res, T weight, T const * arg) {
106
+ Map<T, S>(res) = weight * arma::abs (Map<T const , S>(arg));
107
107
}
108
108
109
109
template <typename T, std::size_t S>
110
- auto Ceil (T* res, T const * arg) {
111
- Map<T, S>(res) = arma::ceil (Map<T const , S>(arg));
110
+ auto Ceil (T* res, T weight, T const * arg) {
111
+ Map<T, S>(res) = weight * arma::ceil (Map<T const , S>(arg));
112
112
}
113
113
114
114
template <typename T, std::size_t S>
115
- auto Floor (T* res, T const * arg) {
116
- Map<T, S>(res) = arma::floor (Map<T const , S>(arg));
115
+ auto Floor (T* res, T weight, T const * arg) {
116
+ Map<T, S>(res) = weight * arma::floor (Map<T const , S>(arg));
117
117
}
118
118
119
119
template <typename T, std::size_t S>
120
- auto Square (T* res, T const * arg) {
121
- Map<T, S>(res) = arma::square (Map<T const , S>(arg));
120
+ auto Square (T* res, T weight, T const * arg) {
121
+ Map<T, S>(res) = weight * arma::square (Map<T const , S>(arg));
122
122
}
123
123
124
124
template <typename T, std::size_t S>
125
- auto Exp (T* res, T const * arg) {
126
- Map<T, S>(res) = arma::exp (Map<T const , S>(arg));
125
+ auto Exp (T* res, T weight, T const * arg) {
126
+ Map<T, S>(res) = weight * arma::exp (Map<T const , S>(arg));
127
127
}
128
128
129
129
template <typename T, std::size_t S>
130
- auto Log (T* res, T const * arg) {
131
- Map<T, S>(res) = arma::log (Map<T const , S>(arg));
130
+ auto Log (T* res, T weight, T const * arg) {
131
+ Map<T, S>(res) = weight * arma::log (Map<T const , S>(arg));
132
132
}
133
133
134
134
template <typename T, std::size_t S>
135
- auto Log1p (T* res, T const * arg) {
136
- Map<T, S>(res) = arma::log1p (Map<T const , S>(arg));
135
+ auto Log1p (T* res, T weight, T const * arg) {
136
+ Map<T, S>(res) = weight * arma::log1p (Map<T const , S>(arg));
137
137
}
138
138
139
139
template <typename T, std::size_t S>
140
- auto Logabs (T* res, T const * arg) {
141
- Map<T, S>(res) = arma::log (arma::abs (Map<T const , S>(arg)));
140
+ auto Logabs (T* res, T weight, T const * arg) {
141
+ Map<T, S>(res) = weight * arma::log (arma::abs (Map<T const , S>(arg)));
142
142
}
143
143
144
144
template <typename T, std::size_t S>
145
- auto Sin (T* res, T const * arg) {
146
- Map<T, S>(res) = arma::sin (Map<T const , S>(arg));
145
+ auto Sin (T* res, T weight, T const * arg) {
146
+ Map<T, S>(res) = weight * arma::sin (Map<T const , S>(arg));
147
147
}
148
148
149
149
template <typename T, std::size_t S>
150
- auto Cos (T* res, T const * arg) {
151
- Map<T, S>(res) = arma::cos (Map<T const , S>(arg));
150
+ auto Cos (T* res, T weight, T const * arg) {
151
+ Map<T, S>(res) = weight * arma::cos (Map<T const , S>(arg));
152
152
}
153
153
154
154
template <typename T, std::size_t S>
155
- auto Tan (T* res, T const * arg) {
156
- Map<T, S>(res) = arma::tan (Map<T const , S>(arg));
155
+ auto Tan (T* res, T weight, T const * arg) {
156
+ Map<T, S>(res) = weight * arma::tan (Map<T const , S>(arg));
157
157
}
158
158
159
159
template <typename T, std::size_t S>
160
- auto Asin (T* res, T const * arg) {
161
- Map<T, S>(res) = arma::asin (Map<T const , S>(arg));
160
+ auto Asin (T* res, T weight, T const * arg) {
161
+ Map<T, S>(res) = weight * arma::asin (Map<T const , S>(arg));
162
162
}
163
163
164
164
template <typename T, std::size_t S>
165
- auto Acos (T* res, T const * arg) {
166
- Map<T, S>(res) = arma::acos (Map<T const , S>(arg));
165
+ auto Acos (T* res, T weight, T const * arg) {
166
+ Map<T, S>(res) = weight * arma::acos (Map<T const , S>(arg));
167
167
}
168
168
169
169
template <typename T, std::size_t S>
170
- auto Atan (T* res, T const * arg) {
171
- Map<T, S>(res) = arma::atan (Map<T const , S>(arg));
170
+ auto Atan (T* res, T weight, T const * arg) {
171
+ Map<T, S>(res) = weight * arma::atan (Map<T const , S>(arg));
172
172
}
173
173
174
174
template <typename T, std::size_t S>
175
- auto Sinh (T* res, T const * arg) {
176
- Map<T, S>(res) = arma::sinh (Map<T const , S>(arg));
175
+ auto Sinh (T* res, T weight, T const * arg) {
176
+ Map<T, S>(res) = weight * arma::sinh (Map<T const , S>(arg));
177
177
}
178
178
179
179
template <typename T, std::size_t S>
180
- auto Cosh (T* res, T const * arg) {
181
- Map<T, S>(res) = arma::cosh (Map<T const , S>(arg));
180
+ auto Cosh (T* res, T weight, T const * arg) {
181
+ Map<T, S>(res) = weight * arma::cosh (Map<T const , S>(arg));
182
182
}
183
183
184
184
template <typename T, std::size_t S>
185
- auto Tanh (T* res, T const * arg) {
186
- Map<T, S>(res) = arma::tanh (Map<T const , S>(arg));
185
+ auto Tanh (T* res, T weight, T const * arg) {
186
+ Map<T, S>(res) = weight * arma::tanh (Map<T const , S>(arg));
187
187
}
188
188
189
189
template <typename T, std::size_t S>
190
- auto Sqrt (T* res, T const * arg) {
191
- Map<T, S>(res) = arma::sqrt (Map<T const , S>(arg));
190
+ auto Sqrt (T* res, T weight, T const * arg) {
191
+ Map<T, S>(res) = weight * arma::sqrt (Map<T const , S>(arg));
192
192
}
193
193
194
194
template <typename T, std::size_t S>
195
- auto Sqrtabs (T* res, T const * arg) {
196
- Map<T, S>(res) = arma::sqrt (arma::abs (Map<T const , S>(arg)));
195
+ auto Sqrtabs (T* res, T weight, T const * arg) {
196
+ Map<T, S>(res) = weight * arma::sqrt (arma::abs (Map<T const , S>(arg)));
197
197
}
198
198
199
199
template <typename T, std::size_t S>
200
- auto Cbrt (T* res, T const * arg) {
201
- Map<T, S>(res) = arma::cbrt (Map<T const , S>(arg));
200
+ auto Cbrt (T* res, T weight, T const * arg) {
201
+ Map<T, S>(res) = weight * arma::cbrt (Map<T const , S>(arg));
202
202
}
203
203
} // namespace Operon::Backend
204
204
#endif
0 commit comments