Skip to content

Commit 00b1303

Browse files
committed
Namespaces
1 parent 24a9e71 commit 00b1303

1 file changed

Lines changed: 50 additions & 40 deletions

File tree

test/unit/math/test_ad.hpp

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <test/unit/math/ad_tolerances.hpp>
77
#include <test/unit/math/is_finite.hpp>
88
#include <test/unit/math/expect_near_rel.hpp>
9-
#include <stan/math/prim/fun/serializer.hpp>
109
#include <test/unit/math/test_ad_matvar.hpp>
1110
#include <test/unit/util.hpp>
1211
#include <gtest/gtest.h>
@@ -402,7 +401,8 @@ void expect_all_throw(const F& f, const Eigen::VectorXd& x) {
402401
*/
403402
template <typename F>
404403
void expect_all_throw(const F& f, double x1) {
405-
auto h = [&](auto v) { return stan::math::serialize_return(eval(f(v(0)))); };
404+
using stan::math::serialize_return;
405+
auto h = [&](auto v) { return serialize_return(eval(f(v(0)))); };
406406
Eigen::VectorXd x(1);
407407
x << x1;
408408
expect_all_throw(h, x);
@@ -419,8 +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) {
423-
return stan::math::serialize_return(eval(f(v(0), v(1)))); };
422+
using stan::math::serialize_return;
423+
auto h = [&](auto v) { return serialize_return(eval(f(v(0), v(1)))); };
424424
Eigen::VectorXd x(2);
425425
x << x1, x2;
426426
expect_all_throw(h, x);
@@ -438,8 +438,8 @@ void expect_all_throw(const F& f, double x1, double x2) {
438438
*/
439439
template <typename F>
440440
void expect_all_throw(const F& f, double x1, double x2, double x3) {
441-
auto h = [&](auto v) {
442-
return stan::math::serialize_return(eval(f(v(0), v(1), v(2)))); };
441+
using stan::math::serialize_return;
442+
auto h = [&](auto v) { return serialize_return(eval(f(v(0), v(1), v(2)))); };
443443
Eigen::VectorXd x(3);
444444
x << x1, x2, x3;
445445
expect_all_throw(h, x);
@@ -469,13 +469,14 @@ void expect_all_throw(const F& f, double x1, double x2, double x3) {
469469
template <typename F, typename G, typename... Ts>
470470
void expect_ad_helper(const ad_tolerances& tols, const F& f, const G& g,
471471
const Eigen::VectorXd& x, Ts... xs) {
472+
using stan::math::serialize;
472473
auto h
473474
= [&](const int i) { return [&g, i](const auto& v) { return g(v)[i]; }; };
474475
size_t result_size = 0;
475476
try {
476477
auto y1 = eval(f(xs...)); // original types, including int
477478
auto y2 = eval(g(x)); // all int cast to double
478-
auto y1_serial = stan::math::serialize<double>(y1);
479+
auto y1_serial = serialize<double>(y1);
479480
expect_near_rel("expect_ad_helper", y1_serial, y2, 1e-10);
480481
result_size = y1_serial.size();
481482
} catch (...) {
@@ -500,12 +501,15 @@ void expect_ad_helper(const ad_tolerances& tols, const F& f, const G& g,
500501
*/
501502
template <typename F, typename T>
502503
void expect_ad_v(const ad_tolerances& tols, const F& f, const T& x) {
504+
using stan::math::to_deserializer;
505+
using stan::math::serialize_return;
506+
using stan::math::serialize_args;
503507
auto g = [&](const auto& v) {
504-
auto ds = stan::math::to_deserializer(v);
508+
auto ds = to_deserializer(v);
505509
auto xds = ds.read(x);
506-
return stan::math::serialize_return(eval(f(xds)));
510+
return serialize_return(eval(f(xds)));
507511
};
508-
internal::expect_ad_helper(tols, f, g, stan::math::serialize_args(x), x);
512+
internal::expect_ad_helper(tols, f, g, serialize_args(x), x);
509513
}
510514

511515
/**
@@ -561,30 +565,33 @@ void expect_ad_v(const ad_tolerances& tols, const F& f, int x) {
561565
template <typename F, typename T1, typename T2>
562566
void expect_ad_vv(const ad_tolerances& tols, const F& f, const T1& x1,
563567
const T2& x2) {
568+
using stan::math::to_deserializer;
569+
using stan::math::serialize_return;
570+
using stan::math::serialize_args;
564571
// d.x1
565572
auto g1 = [&](const auto& v) {
566-
auto ds = stan::math::to_deserializer(v);
573+
auto ds = to_deserializer(v);
567574
auto x1ds = ds.read(x1);
568-
return stan::math::serialize_return(eval(f(x1ds, x2)));
575+
return serialize_return(eval(f(x1ds, x2)));
569576
};
570-
internal::expect_ad_helper(tols, f, g1, stan::math::serialize_args(x1), x1, x2);
577+
internal::expect_ad_helper(tols, f, g1, serialize_args(x1), x1, x2);
571578

572579
// d.x2
573580
auto g2 = [&](const auto& v) {
574-
auto ds = stan::math::to_deserializer(v);
581+
auto ds = to_deserializer(v);
575582
auto x2ds = ds.read(x2);
576-
return stan::math::serialize_return(eval(f(x1, x2ds)));
583+
return serialize_return(eval(f(x1, x2ds)));
577584
};
578-
internal::expect_ad_helper(tols, f, g2, stan::math::serialize_args(x2), x1, x2);
585+
internal::expect_ad_helper(tols, f, g2, serialize_args(x2), x1, x2);
579586

580587
// d.x1, d.x2
581588
auto g12 = [&](const auto& v) {
582-
auto ds = stan::math::to_deserializer(v);
589+
auto ds = to_deserializer(v);
583590
auto x1ds = ds.read(x1);
584591
auto x2ds = ds.read(x2);
585-
return stan::math::serialize_return(eval(f(x1ds, x2ds)));
592+
return serialize_return(eval(f(x1ds, x2ds)));
586593
};
587-
internal::expect_ad_helper(tols, f, g12, stan::math::serialize_args(x1, x2), x1, x2);
594+
internal::expect_ad_helper(tols, f, g12, serialize_args(x1, x2), x1, x2);
588595
}
589596

590597
template <typename F, typename T2>
@@ -673,66 +680,69 @@ void expect_ad_vv(const ad_tolerances& tols, const F& f, int x1, int x2) {
673680
template <typename F, typename T1, typename T2, typename T3>
674681
void expect_ad_vvv(const ad_tolerances& tols, const F& f, const T1& x1,
675682
const T2& x2, const T3& x3) {
683+
using stan::math::to_deserializer;
684+
using stan::math::serialize_return;
685+
using stan::math::serialize_args;
676686
// d.x1
677687
auto g1 = [&](const auto& v) {
678-
auto ds = stan::math::to_deserializer(v);
688+
auto ds = to_deserializer(v);
679689
auto x1ds = ds.read(x1);
680-
return stan::math::serialize_return(eval(f(x1ds, x2, x3)));
690+
return serialize_return(eval(f(x1ds, x2, x3)));
681691
};
682-
internal::expect_ad_helper(tols, f, g1, stan::math::serialize_args(x1), x1, x2, x3);
692+
internal::expect_ad_helper(tols, f, g1, serialize_args(x1), x1, x2, x3);
683693

684694
// d.x2
685695
auto g2 = [&](const auto& v) {
686-
auto ds = stan::math::to_deserializer(v);
696+
auto ds = to_deserializer(v);
687697
auto x2ds = ds.read(x2);
688-
return stan::math::serialize_return(eval(f(x1, x2ds, x3)));
698+
return serialize_return(eval(f(x1, x2ds, x3)));
689699
};
690-
internal::expect_ad_helper(tols, f, g2, stan::math::serialize_args(x2), x1, x2, x3);
700+
internal::expect_ad_helper(tols, f, g2, serialize_args(x2), x1, x2, x3);
691701

692702
// d.x3
693703
auto g3 = [&](const auto& v) {
694-
auto ds = stan::math::to_deserializer(v);
704+
auto ds = to_deserializer(v);
695705
auto x3ds = ds.read(x3);
696-
return stan::math::serialize_return(eval(f(x1, x2, x3ds)));
706+
return serialize_return(eval(f(x1, x2, x3ds)));
697707
};
698-
internal::expect_ad_helper(tols, f, g3, stan::math::serialize_args(x3), x1, x2, x3);
708+
internal::expect_ad_helper(tols, f, g3, serialize_args(x3), x1, x2, x3);
699709

700710
// d.x1 d.x2
701711
auto g12 = [&](const auto& v) {
702-
auto ds = stan::math::to_deserializer(v);
712+
auto ds = to_deserializer(v);
703713
auto x1ds = ds.read(x1);
704714
auto x2ds = ds.read(x2);
705-
return stan::math::serialize_return(eval(f(x1ds, x2ds, x3)));
715+
return serialize_return(eval(f(x1ds, x2ds, x3)));
706716
};
707-
internal::expect_ad_helper(tols, f, g12, stan::math::serialize_args(x1, x2), x1, x2, x3);
717+
internal::expect_ad_helper(tols, f, g12, serialize_args(x1, x2), x1, x2, x3);
708718

709719
// d.x1 d.x3
710720
auto g13 = [&](const auto& v) {
711-
auto ds = stan::math::to_deserializer(v);
721+
auto ds = to_deserializer(v);
712722
auto x1ds = ds.read(x1);
713723
auto x3ds = ds.read(x3);
714-
return stan::math::serialize_return(eval(f(x1ds, x2, x3ds)));
724+
return serialize_return(eval(f(x1ds, x2, x3ds)));
715725
};
716-
internal::expect_ad_helper(tols, f, g13, stan::math::serialize_args(x1, x3), x1, x2, x3);
726+
internal::expect_ad_helper(tols, f, g13, serialize_args(x1, x3), x1, x2, x3);
717727

718728
// d.x2 d.x3
719729
auto g23 = [&](const auto& v) {
720-
auto ds = stan::math::to_deserializer(v);
730+
auto ds = to_deserializer(v);
721731
auto x2ds = ds.read(x2);
722732
auto x3ds = ds.read(x3);
723-
return stan::math::serialize_return(eval(f(x1, x2ds, x3ds)));
733+
return serialize_return(eval(f(x1, x2ds, x3ds)));
724734
};
725-
internal::expect_ad_helper(tols, f, g23, stan::math::serialize_args(x2, x3), x1, x2, x3);
735+
internal::expect_ad_helper(tols, f, g23, serialize_args(x2, x3), x1, x2, x3);
726736

727737
// d.x1 d.x2 d.x3
728738
auto g123 = [&](const auto& v) {
729-
auto ds = stan::math::to_deserializer(v);
739+
auto ds = to_deserializer(v);
730740
auto x1ds = ds.read(x1);
731741
auto x2ds = ds.read(x2);
732742
auto x3ds = ds.read(x3);
733-
return stan::math::serialize_return(eval(f(x1ds, x2ds, x3ds)));
743+
return serialize_return(eval(f(x1ds, x2ds, x3ds)));
734744
};
735-
internal::expect_ad_helper(tols, f, g123, stan::math::serialize_args(x1, x2, x3), x1, x2,
745+
internal::expect_ad_helper(tols, f, g123, serialize_args(x1, x2, x3), x1, x2,
736746
x3);
737747
}
738748

0 commit comments

Comments
 (0)