Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion test/expressions/expression_test_helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <gtest/gtest.h>
#include <stan/math/prim.hpp>
#include <stan/math/prim/meta.hpp>
#include <stan/math/prim/functor/for_each.hpp>
#include <stan/math/rev.hpp>
#include <stan/math/fwd.hpp>
#include <vector>
Expand All @@ -18,7 +20,7 @@ struct counterOp {
}
};

template <typename T>
template <typename T, stan::math::require_not_tuple_t<T>* = nullptr>
auto recursive_sum(const T& a) {
return math::sum(a);
}
Expand All @@ -32,6 +34,13 @@ auto recursive_sum(const std::vector<T>& a) {
return res;
}

template <typename T, stan::math::require_tuple_t<T>* = nullptr>
auto recursive_sum(const T& t1) {
stan::value_type_t<decltype(std::get<0>(t1))> val = 0;
stan::math::for_each([&val](auto&& elt1) { val += recursive_sum(elt1); }, t1);
return val;
}

template <typename T, require_integral_t<T>* = nullptr>
T make_arg(double value = 0.4, int size = 1) {
return 1;
Expand Down Expand Up @@ -160,6 +169,12 @@ void expect_eq(const std::vector<T>& a, const std::vector<T>& b,
}
}

template <typename T, stan::math::require_tuple_t<T>* = nullptr>
void expect_eq(const T& t1, const T& t2, const char* msg) {
stan::math::for_each(
[&msg](auto&& elt1, auto&& elt2) { expect_eq(elt1, elt2, msg); }, t1, t2);
}

template <typename T, require_not_st_var<T>* = nullptr>
void expect_adj_eq(const T& a, const T& b, const char* msg = "expect_ad_eq") {}

Expand Down