Skip to content

Commit

Permalink
fix deep_copy return types
Browse files Browse the repository at this point in the history
  • Loading branch information
t4c1 committed Feb 19, 2020
1 parent 5d7fd44 commit 4de2ae7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
22 changes: 12 additions & 10 deletions stan/math/opencl/kernel_generator/binary_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ class binary_operation : public operation_cl<Derived, T_res, T_a, T_b> {
public: \
class_name(T_a&& a, T_b&& b) /* NOLINT */ \
: base(std::forward<T_a>(a), std::forward<T_b>(b), operation) {} \
inline class_name<std::remove_reference_t<T_a>, \
std::remove_reference_t<T_b>> \
deep_copy() { \
return {std::get<0>(arguments_).deep_copy(), \
std::get<1>(arguments_).deep_copy()}; \
inline auto deep_copy() { \
auto&& a_copy = std::get<0>(arguments_).deep_copy(); \
auto&& b_copy = std::get<1>(arguments_).deep_copy(); \
return class_name<std::remove_reference_t<decltype(a_copy)>, \
std::remove_reference_t<decltype(b_copy)>>( \
std::move(a_copy), std::move(b_copy)); \
} \
}; \
\
Expand Down Expand Up @@ -162,11 +163,12 @@ class binary_operation : public operation_cl<Derived, T_res, T_a, T_b> {
public: \
class_name(T_a&& a, T_b&& b) /* NOLINT */ \
: base(std::forward<T_a>(a), std::forward<T_b>(b), operation) {} \
inline class_name<std::remove_reference_t<T_a>, \
std::remove_reference_t<T_b>> \
deep_copy() { \
return {std::get<0>(arguments_).deep_copy(), \
std::get<1>(arguments_).deep_copy()}; \
inline auto deep_copy() { \
auto&& a_copy = std::get<0>(arguments_).deep_copy(); \
auto&& b_copy = std::get<1>(arguments_).deep_copy(); \
return class_name<std::remove_reference_t<decltype(a_copy)>, \
std::remove_reference_t<decltype(b_copy)>>( \
std::move(a_copy), std::move(b_copy)); \
} \
inline matrix_cl_view view() const { __VA_ARGS__; } \
}; \
Expand Down
7 changes: 4 additions & 3 deletions stan/math/opencl/kernel_generator/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ class block_
* Creates a deep copy of this expression.
* @return copy of \c *this
*/
inline block_<std::remove_reference_t<T>> deep_copy() {
return {std::get<0>(arguments_).deep_copy(), start_row_, start_col_, rows_,
cols_};
inline auto deep_copy() {
auto&& arg_copy = std::get<0>(arguments_).deep_copy();
return block_<std::remove_reference_t<decltype(arg_copy)>>{
std::move(arg_copy), start_row_, start_col_, rows_, cols_};
}

/**
Expand Down
16 changes: 11 additions & 5 deletions stan/math/opencl/kernel_generator/rowwise_reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class rowwise_sum_
* @return copy of \c *this
*/
inline rowwise_sum_<std::remove_reference_t<T>> deep_copy() {
return rowwise_sum_<std::remove_reference_t<T>>{std::get<0>(arguments_)};
auto&& arg_copy = std::get<0>(arguments_).deep_copy();
return rowwise_sum_<std::remove_reference_t<decltype(arg_copy)>>(
std::move(arg_copy));
}
};

Expand Down Expand Up @@ -224,8 +226,10 @@ class rowwise_max_
* Creates a deep copy of this expression.
* @return copy of \c *this
*/
inline rowwise_max_<std::remove_reference_t<T>> deep_copy() {
return rowwise_max_<std::remove_reference_t<T>>{std::get<0>(arguments_)};
inline auto deep_copy() {
auto&& arg_copy = std::get<0>(arguments_).deep_copy();
return rowwise_max_<std::remove_reference_t<decltype(arg_copy)>>(
std::move(arg_copy));
}
};

Expand Down Expand Up @@ -289,8 +293,10 @@ class rowwise_min_
* Creates a deep copy of this expression.
* @return copy of \c *this
*/
inline rowwise_min_<std::remove_reference_t<T>> deep_copy() {
return rowwise_min_<std::remove_reference_t<T>>{std::get<0>(arguments_)};
inline auto deep_copy() {
auto&& arg_copy = std::get<0>(arguments_).deep_copy();
return rowwise_min_<std::remove_reference_t<decltype(arg_copy)>>(
std::move(arg_copy));
}
};

Expand Down
15 changes: 8 additions & 7 deletions stan/math/opencl/kernel_generator/select.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ class select_ : public operation_cl<select_<T_condition, T_then, T_else>,
* Creates a deep copy of this expression.
* @return copy of \c *this
*/
inline select_<std::remove_reference_t<T_condition>,
std::remove_reference_t<T_then>,
std::remove_reference_t<T_else>>
deep_copy() {
return {std::get<0>(arguments_).deep_copy(),
std::get<1>(arguments_).deep_copy(),
std::get<2>(arguments_).deep_copy()};
inline auto deep_copy() {
auto&& condition_copy = std::get<0>(arguments_).deep_copy();
auto&& then_copy = std::get<0>(arguments_).deep_copy();
auto&& else_copy = std::get<0>(arguments_).deep_copy();
return select_<std::remove_reference_t<decltype(condition_copy)>,
std::remove_reference_t<decltype(then_copy)>,
std::remove_reference_t<decltype(else_copy)>>(
std::move(condition_copy), std::move(then_copy), std::move(else_copy));
}

/**
Expand Down
14 changes: 8 additions & 6 deletions stan/math/opencl/kernel_generator/unary_function_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ class unary_function_cl
\
public: \
explicit fun##_(T&& a) : base(std::forward<T>(a), #fun) {} \
inline fun##_<std::remove_reference_t<T>> deep_copy() { \
return fun##_<std::remove_reference_t<T>>{ \
std::get<0>(arguments_).deep_copy()}; \
inline auto deep_copy() { \
auto&& arg_copy = std::get<0>(arguments_).deep_copy(); \
return fun##_<std::remove_reference_t<decltype(arg_copy)>>{ \
std::move(arg_copy)}; \
} \
inline matrix_cl_view view() const { return matrix_cl_view::Entire; } \
}; \
Expand All @@ -110,9 +111,10 @@ class unary_function_cl
\
public: \
explicit fun##_(T&& a) : base(std::forward<T>(a), #fun) {} \
inline fun##_<std::remove_reference_t<T>> deep_copy() { \
return fun##_<std::remove_reference_t<T>>{ \
std::get<0>(arguments_).deep_copy()}; \
inline auto deep_copy() { \
auto&& arg_copy = std::get<0>(arguments_).deep_copy(); \
return fun##_<std::remove_reference_t<decltype(arg_copy)>>{ \
std::move(arg_copy)}; \
} \
}; \
\
Expand Down

0 comments on commit 4de2ae7

Please sign in to comment.