Skip to content

Commit fffc14f

Browse files
committed
includes
1 parent 9d9d58c commit fffc14f

2 files changed

Lines changed: 40 additions & 37 deletions

File tree

stan/math/prim/fun/serializer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define STAN_MATH_PRIM_FUN_SERIALIZER_HPP
33

44
#include <stan/math/prim/fun/to_vector.hpp>
5+
#include <stan/math/prim/fun/to_array_1d.hpp>
56
#include <complex>
67
#include <string>
78
#include <vector>

test/unit/math/test_ad.hpp

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void expect_all_throw(const F& f, const Eigen::VectorXd& x) {
402402
*/
403403
template <typename F>
404404
void expect_all_throw(const F& f, double x1) {
405-
auto h = [&](auto v) { return serialize_return(eval(f(v(0)))); };
405+
auto h = [&](auto v) { return stan::math::serialize_return(eval(f(v(0)))); };
406406
Eigen::VectorXd x(1);
407407
x << x1;
408408
expect_all_throw(h, x);
@@ -419,7 +419,8 @@ void expect_all_throw(const F& f, double x1) {
419419
*/
420420
template <typename F>
421421
void expect_all_throw(const F& f, double x1, double x2) {
422-
auto h = [&](auto v) { return serialize_return(eval(f(v(0), v(1)))); };
422+
auto h = [&](auto v) {
423+
return stan::math::serialize_return(eval(f(v(0), v(1)))); };
423424
Eigen::VectorXd x(2);
424425
x << x1, x2;
425426
expect_all_throw(h, x);
@@ -437,7 +438,8 @@ void expect_all_throw(const F& f, double x1, double x2) {
437438
*/
438439
template <typename F>
439440
void expect_all_throw(const F& f, double x1, double x2, double x3) {
440-
auto h = [&](auto v) { return serialize_return(eval(f(v(0), v(1), v(2)))); };
441+
auto h = [&](auto v) {
442+
return stan::math::serialize_return(eval(f(v(0), v(1), v(2)))); };
441443
Eigen::VectorXd x(3);
442444
x << x1, x2, x3;
443445
expect_all_throw(h, x);
@@ -473,7 +475,7 @@ void expect_ad_helper(const ad_tolerances& tols, const F& f, const G& g,
473475
try {
474476
auto y1 = eval(f(xs...)); // original types, including int
475477
auto y2 = eval(g(x)); // all int cast to double
476-
auto y1_serial = serialize<double>(y1);
478+
auto y1_serial = stan::math::serialize<double>(y1);
477479
expect_near_rel("expect_ad_helper", y1_serial, y2, 1e-10);
478480
result_size = y1_serial.size();
479481
} catch (...) {
@@ -499,11 +501,11 @@ void expect_ad_helper(const ad_tolerances& tols, const F& f, const G& g,
499501
template <typename F, typename T>
500502
void expect_ad_v(const ad_tolerances& tols, const F& f, const T& x) {
501503
auto g = [&](const auto& v) {
502-
auto ds = to_deserializer(v);
504+
auto ds = stan::math::to_deserializer(v);
503505
auto xds = ds.read(x);
504-
return serialize_return(eval(f(xds)));
506+
return stan::math::serialize_return(eval(f(xds)));
505507
};
506-
internal::expect_ad_helper(tols, f, g, serialize_args(x), x);
508+
internal::expect_ad_helper(tols, f, g, stan::math::serialize_args(x), x);
507509
}
508510

509511
/**
@@ -561,28 +563,28 @@ void expect_ad_vv(const ad_tolerances& tols, const F& f, const T1& x1,
561563
const T2& x2) {
562564
// d.x1
563565
auto g1 = [&](const auto& v) {
564-
auto ds = to_deserializer(v);
566+
auto ds = stan::math::to_deserializer(v);
565567
auto x1ds = ds.read(x1);
566-
return serialize_return(eval(f(x1ds, x2)));
568+
return stan::math::serialize_return(eval(f(x1ds, x2)));
567569
};
568-
internal::expect_ad_helper(tols, f, g1, serialize_args(x1), x1, x2);
570+
internal::expect_ad_helper(tols, f, g1, stan::math::serialize_args(x1), x1, x2);
569571

570572
// d.x2
571573
auto g2 = [&](const auto& v) {
572-
auto ds = to_deserializer(v);
574+
auto ds = stan::math::to_deserializer(v);
573575
auto x2ds = ds.read(x2);
574-
return serialize_return(eval(f(x1, x2ds)));
576+
return stan::math::serialize_return(eval(f(x1, x2ds)));
575577
};
576-
internal::expect_ad_helper(tols, f, g2, serialize_args(x2), x1, x2);
578+
internal::expect_ad_helper(tols, f, g2, stan::math::serialize_args(x2), x1, x2);
577579

578580
// d.x1, d.x2
579581
auto g12 = [&](const auto& v) {
580-
auto ds = to_deserializer(v);
582+
auto ds = stan::math::to_deserializer(v);
581583
auto x1ds = ds.read(x1);
582584
auto x2ds = ds.read(x2);
583-
return serialize_return(eval(f(x1ds, x2ds)));
585+
return stan::math::serialize_return(eval(f(x1ds, x2ds)));
584586
};
585-
internal::expect_ad_helper(tols, f, g12, serialize_args(x1, x2), x1, x2);
587+
internal::expect_ad_helper(tols, f, g12, stan::math::serialize_args(x1, x2), x1, x2);
586588
}
587589

588590
template <typename F, typename T2>
@@ -673,64 +675,64 @@ void expect_ad_vvv(const ad_tolerances& tols, const F& f, const T1& x1,
673675
const T2& x2, const T3& x3) {
674676
// d.x1
675677
auto g1 = [&](const auto& v) {
676-
auto ds = to_deserializer(v);
678+
auto ds = stan::math::to_deserializer(v);
677679
auto x1ds = ds.read(x1);
678-
return serialize_return(eval(f(x1ds, x2, x3)));
680+
return stan::math::serialize_return(eval(f(x1ds, x2, x3)));
679681
};
680-
internal::expect_ad_helper(tols, f, g1, serialize_args(x1), x1, x2, x3);
682+
internal::expect_ad_helper(tols, f, g1, stan::math::serialize_args(x1), x1, x2, x3);
681683

682684
// d.x2
683685
auto g2 = [&](const auto& v) {
684-
auto ds = to_deserializer(v);
686+
auto ds = stan::math::to_deserializer(v);
685687
auto x2ds = ds.read(x2);
686-
return serialize_return(eval(f(x1, x2ds, x3)));
688+
return stan::math::serialize_return(eval(f(x1, x2ds, x3)));
687689
};
688-
internal::expect_ad_helper(tols, f, g2, serialize_args(x2), x1, x2, x3);
690+
internal::expect_ad_helper(tols, f, g2, stan::math::serialize_args(x2), x1, x2, x3);
689691

690692
// d.x3
691693
auto g3 = [&](const auto& v) {
692-
auto ds = to_deserializer(v);
694+
auto ds = stan::math::to_deserializer(v);
693695
auto x3ds = ds.read(x3);
694-
return serialize_return(eval(f(x1, x2, x3ds)));
696+
return stan::math::serialize_return(eval(f(x1, x2, x3ds)));
695697
};
696-
internal::expect_ad_helper(tols, f, g3, serialize_args(x3), x1, x2, x3);
698+
internal::expect_ad_helper(tols, f, g3, stan::math::serialize_args(x3), x1, x2, x3);
697699

698700
// d.x1 d.x2
699701
auto g12 = [&](const auto& v) {
700-
auto ds = to_deserializer(v);
702+
auto ds = stan::math::to_deserializer(v);
701703
auto x1ds = ds.read(x1);
702704
auto x2ds = ds.read(x2);
703-
return serialize_return(eval(f(x1ds, x2ds, x3)));
705+
return stan::math::serialize_return(eval(f(x1ds, x2ds, x3)));
704706
};
705-
internal::expect_ad_helper(tols, f, g12, serialize_args(x1, x2), x1, x2, x3);
707+
internal::expect_ad_helper(tols, f, g12, stan::math::serialize_args(x1, x2), x1, x2, x3);
706708

707709
// d.x1 d.x3
708710
auto g13 = [&](const auto& v) {
709-
auto ds = to_deserializer(v);
711+
auto ds = stan::math::to_deserializer(v);
710712
auto x1ds = ds.read(x1);
711713
auto x3ds = ds.read(x3);
712-
return serialize_return(eval(f(x1ds, x2, x3ds)));
714+
return stan::math::serialize_return(eval(f(x1ds, x2, x3ds)));
713715
};
714-
internal::expect_ad_helper(tols, f, g13, serialize_args(x1, x3), x1, x2, x3);
716+
internal::expect_ad_helper(tols, f, g13, stan::math::serialize_args(x1, x3), x1, x2, x3);
715717

716718
// d.x2 d.x3
717719
auto g23 = [&](const auto& v) {
718-
auto ds = to_deserializer(v);
720+
auto ds = stan::math::to_deserializer(v);
719721
auto x2ds = ds.read(x2);
720722
auto x3ds = ds.read(x3);
721-
return serialize_return(eval(f(x1, x2ds, x3ds)));
723+
return stan::math::serialize_return(eval(f(x1, x2ds, x3ds)));
722724
};
723-
internal::expect_ad_helper(tols, f, g23, serialize_args(x2, x3), x1, x2, x3);
725+
internal::expect_ad_helper(tols, f, g23, stan::math::serialize_args(x2, x3), x1, x2, x3);
724726

725727
// d.x1 d.x2 d.x3
726728
auto g123 = [&](const auto& v) {
727-
auto ds = to_deserializer(v);
729+
auto ds = stan::math::to_deserializer(v);
728730
auto x1ds = ds.read(x1);
729731
auto x2ds = ds.read(x2);
730732
auto x3ds = ds.read(x3);
731-
return serialize_return(eval(f(x1ds, x2ds, x3ds)));
733+
return stan::math::serialize_return(eval(f(x1ds, x2ds, x3ds)));
732734
};
733-
internal::expect_ad_helper(tols, f, g123, serialize_args(x1, x2, x3), x1, x2,
735+
internal::expect_ad_helper(tols, f, g123, stan::math::serialize_args(x1, x2, x3), x1, x2,
734736
x3);
735737
}
736738

0 commit comments

Comments
 (0)