@@ -46,7 +46,7 @@ class rowwise_reduction
46
46
* @param a the expression to reduce
47
47
* @param init OpenCL source code of initialization value for reduction
48
48
*/
49
- rowwise_reduction (T&& a, const std::string& init)
49
+ explicit rowwise_reduction (T&& a, const std::string& init)
50
50
: base(std::forward<T>(a)), init_(init) {}
51
51
52
52
/* *
@@ -121,7 +121,7 @@ class rowwise_reduction
121
121
122
122
/* *
123
123
* Determine index of top diagonal written.
124
- * @return number of columns
124
+ * @return top diagonal
125
125
*/
126
126
inline int top_diagonal () const { return 1 ; }
127
127
};
@@ -149,10 +149,21 @@ struct sum_op {
149
149
template <typename T>
150
150
class rowwise_sum_
151
151
: public rowwise_reduction<rowwise_sum_<T>, T, sum_op, true > {
152
+ using base = rowwise_reduction<rowwise_sum_<T>, T, sum_op, true >;
153
+ using base::arguments_;
154
+
152
155
public:
153
- explicit rowwise_sum_ (T&& a)
154
- : rowwise_reduction<rowwise_sum_<T>, T, sum_op, true>(std::forward<T>(a),
155
- "0") {}
156
+ explicit rowwise_sum_ (T&& a) : base(std::forward<T>(a), "0") {}
157
+
158
+ /* *
159
+ * Creates a deep copy of this expression.
160
+ * @return copy of \c *this
161
+ */
162
+ inline rowwise_sum_<std::remove_reference_t <T>> deep_copy () {
163
+ auto && arg_copy = std::get<0 >(arguments_).deep_copy ();
164
+ return rowwise_sum_<std::remove_reference_t <decltype (arg_copy)>>(
165
+ std::move (arg_copy));
166
+ }
156
167
};
157
168
158
169
/* *
@@ -163,9 +174,10 @@ class rowwise_sum_
163
174
*/
164
175
template <typename T,
165
176
typename = require_all_valid_expressions_and_none_scalar_t <T>>
166
- inline rowwise_sum_<as_operation_cl_t <T>> rowwise_sum (T&& a) {
167
- return rowwise_sum_<as_operation_cl_t <T>>(
168
- as_operation_cl (std::forward<T>(a)));
177
+ inline auto rowwise_sum (T&& a) {
178
+ auto && arg_copy = as_operation_cl (std::forward<T>(a)).deep_copy ();
179
+ return rowwise_sum_<std::remove_reference_t <decltype (arg_copy)>>(
180
+ std::move (arg_copy));
169
181
}
170
182
171
183
/* *
@@ -205,11 +217,21 @@ class rowwise_max_
205
217
: public rowwise_reduction<
206
218
rowwise_max_<T>, T,
207
219
max_op<typename std::remove_reference_t <T>::Scalar>, false > {
208
- public:
209
220
using op = max_op<typename std::remove_reference_t <T>::Scalar>;
210
- explicit rowwise_max_ (T&& a)
211
- : rowwise_reduction<rowwise_max_<T>, T, op, false>(std::forward<T>(a),
212
- op::init()) {}
221
+ using base = rowwise_reduction<rowwise_max_<T>, T, op, false >;
222
+ using base::arguments_;
223
+
224
+ public:
225
+ explicit rowwise_max_ (T&& a) : base(std::forward<T>(a), op::init()) {}
226
+ /* *
227
+ * Creates a deep copy of this expression.
228
+ * @return copy of \c *this
229
+ */
230
+ inline auto deep_copy () {
231
+ auto && arg_copy = std::get<0 >(arguments_).deep_copy ();
232
+ return rowwise_max_<std::remove_reference_t <decltype (arg_copy)>>(
233
+ std::move (arg_copy));
234
+ }
213
235
};
214
236
215
237
/* *
@@ -220,11 +242,11 @@ class rowwise_max_
220
242
*/
221
243
template <typename T,
222
244
typename = require_all_valid_expressions_and_none_scalar_t <T>>
223
- inline rowwise_max_<as_operation_cl_t <T>> rowwise_max (T&& a) {
224
- return rowwise_max_<as_operation_cl_t <T>>(
225
- as_operation_cl (std::forward<T>(a)));
245
+ inline auto rowwise_max (T&& a) {
246
+ auto && arg_copy = as_operation_cl (std::forward<T>(a)).deep_copy ();
247
+ return rowwise_max_<std::remove_reference_t <decltype (arg_copy)>>(
248
+ std::move (arg_copy));
226
249
}
227
-
228
250
/* *
229
251
* Operation for min reduction.
230
252
* @tparam T type to reduce
@@ -262,11 +284,21 @@ class rowwise_min_
262
284
: public rowwise_reduction<
263
285
rowwise_min_<T>, T,
264
286
min_op<typename std::remove_reference_t <T>::Scalar>, false > {
265
- public:
266
287
using op = min_op<typename std::remove_reference_t <T>::Scalar>;
267
- explicit rowwise_min_ (T&& a)
268
- : rowwise_reduction<rowwise_min_<T>, T, op, false>(std::forward<T>(a),
269
- op::init()) {}
288
+ using base = rowwise_reduction<rowwise_min_<T>, T, op, false >;
289
+ using base::arguments_;
290
+
291
+ public:
292
+ explicit rowwise_min_ (T&& a) : base(std::forward<T>(a), op::init()) {}
293
+ /* *
294
+ * Creates a deep copy of this expression.
295
+ * @return copy of \c *this
296
+ */
297
+ inline auto deep_copy () {
298
+ auto && arg_copy = std::get<0 >(arguments_).deep_copy ();
299
+ return rowwise_min_<std::remove_reference_t <decltype (arg_copy)>>(
300
+ std::move (arg_copy));
301
+ }
270
302
};
271
303
272
304
/* *
@@ -277,9 +309,10 @@ class rowwise_min_
277
309
*/
278
310
template <typename T,
279
311
typename = require_all_valid_expressions_and_none_scalar_t <T>>
280
- inline rowwise_min_<as_operation_cl_t <T>> rowwise_min (T&& a) {
281
- return rowwise_min_<as_operation_cl_t <T>>(
282
- as_operation_cl (std::forward<T>(a)));
312
+ inline auto rowwise_min (T&& a) {
313
+ auto && arg_copy = as_operation_cl (std::forward<T>(a)).deep_copy ();
314
+ return rowwise_min_<std::remove_reference_t <decltype (arg_copy)>>(
315
+ std::move (arg_copy));
283
316
}
284
317
285
318
} // namespace math
0 commit comments