Skip to content

Commit 6c9fea5

Browse files
author
Andrew Johnson
committed
Expand std::vector<int> testing
1 parent f463d39 commit 6c9fea5

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

test/unit/math/prim/fun/binary_scalar_tester.hpp

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,72 @@ void binary_scalar_tester(const F& f, const T1& x, const T2& y) {
290290
std::vector<typename T2::Scalar>(y.data(), y.data() + y.size()));
291291
}
292292

293+
/**
294+
* Testing framework for checking that the vectorisation of binary
295+
* functions returns the same results as the binary function with
296+
* scalar inputs. This specialization takes an Eigen matrix and a
297+
* two-dimensional std::vector of integers.
298+
*
299+
* @tparam F Type of functor to apply.
300+
* @tparam T1 Type of first input.
301+
* @tparam T2 Type of second input.
302+
* @param x First std::vector input to which operation is applied.
303+
* @param y Second Eigen input to which operation is applied.
304+
* @param f functor to apply to inputs.
305+
*/
306+
template <typename F, typename T1, typename T2,
307+
require_any_std_vector_vt<is_std_vector, T1, T2>* = nullptr,
308+
require_any_std_vector_st<std::is_integral, T1, T2>* = nullptr,
309+
require_any_eigen_matrix_t<T1, T2>* = nullptr>
310+
void binary_scalar_tester(const F& f, const T1& x, const T2& y) {
311+
binary_scalar_tester_impl(f, x, y);
312+
}
313+
314+
/**
315+
* Testing framework for checking that the vectorisation of binary
316+
* functions returns the same results as the binary function with
317+
* scalar inputs. This specialization takes an std::vector of integers
318+
* and an Eigen vector. The Eigen vector is then transformed to a row-vector
319+
* and an Eigen Array to also be tested.
320+
*
321+
* @tparam F Type of functor to apply.
322+
* @tparam T1 Type of std::vector.
323+
* @tparam T2 Type of Eigen vector.
324+
* @param x First std::vector input to which operation is applied.
325+
* @param y Second Eigen input to which operation is applied.
326+
* @param f functor to apply to inputs.
327+
*/
328+
template <typename F, typename T1, typename T2,
329+
require_std_vector_t<T1>* = nullptr,
330+
require_eigen_vector_t<T2>* = nullptr>
331+
void binary_scalar_tester(const F& f, const T1& x, const T2& y) {
332+
binary_scalar_tester_impl(f, x, y);
333+
binary_scalar_tester_impl(f, x, y.transpose());
334+
binary_scalar_tester_impl(f, x, y.array());
335+
}
336+
337+
/**
338+
* Testing framework for checking that the vectorisation of binary
339+
* functions returns the same results as the binary function with
340+
* scalar inputs. This specialization takes an Eigen vector
341+
* and an std::vector of integers. The Eigen vector is then transformed
342+
* to a row-vector and an Eigen Array to also be tested.
343+
*
344+
* @tparam F Type of functor to apply.
345+
* @tparam T1 Type of std::vector.
346+
* @tparam T2 Type of Eigen vector.
347+
* @param x First std::vector input to which operation is applied.
348+
* @param y Second Eigen input to which operation is applied.
349+
* @param f functor to apply to inputs.
350+
*/
293351
template <typename F, typename T1, typename T2,
294-
require_any_std_vector_t<T1, T2>* = nullptr>
352+
require_eigen_vector_t<T1>* = nullptr,
353+
require_std_vector_t<T2>* = nullptr>
295354
void binary_scalar_tester(const F& f, const T1& x, const T2& y) {
296355
binary_scalar_tester_impl(f, x, y);
356+
binary_scalar_tester_impl(f, x.transpose(), y);
357+
binary_scalar_tester_impl(f, x.array(), y);
297358
}
359+
298360
} // namespace test
299361
} // namespace stan

0 commit comments

Comments
 (0)