Skip to content

Commit

Permalink
autodiff: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarpent committed Jun 15, 2020
1 parent c577f63 commit 853824c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions unittest/cppad-basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
ad_X.resize(2);
ad_Y.resize(2);

Eigen::Matrix2d x_test(-1,1);
Eigen::Matrix2d y_test = x_test.array().min(Scalar(0.));
Eigen::Vector2d x_test(-1,1);
Eigen::Vector2d y_test = x_test.array().min(Scalar(0.));

CppAD::Independent(ad_X);
//Function
ad_Y = ad_X.array().min(Scalar(0.));
CppAD::ADFun<Scalar> ad_fun(ad_X,ad_Y);

CPPAD_TESTVECTOR(Scalar) x((size_t)2);
Eigen::Map<Eigen::Matrix2d>(x.data(),2,1) = x_test;
Eigen::Map<Eigen::Vector2d>(x.data(),2,1) = x_test;

CPPAD_TESTVECTOR(Scalar) y = ad_fun.Forward(0,x);

BOOST_CHECK(Eigen::Map<Eigen::Matrix2d>(y.data(),2,1).isApprox(y_test));
BOOST_CHECK(Eigen::Map<Eigen::Vector2d>(y.data(),2,1).isApprox(y_test));
}

BOOST_AUTO_TEST_CASE(test_eigen_max)
Expand All @@ -209,20 +209,20 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
ad_X.resize(2);
ad_Y.resize(2);

Eigen::Matrix2d x_test(-1,1);
Eigen::Matrix2d y_test = x_test.array().max(Scalar(0.));
Eigen::Vector2d x_test(-1,1);
Eigen::Vector2d y_test = x_test.array().max(Scalar(0.));

CppAD::Independent(ad_X);
//Function
ad_Y = ad_X.array().max(Scalar(0.));
CppAD::ADFun<Scalar> ad_fun(ad_X,ad_Y);

CPPAD_TESTVECTOR(Scalar) x((size_t)2);
Eigen::Map<Eigen::Matrix2d>(x.data(),2,1) = x_test;
Eigen::Map<Eigen::Vector2d>(x.data(),2,1) = x_test;

CPPAD_TESTVECTOR(Scalar) y = ad_fun.Forward(0,x);

BOOST_CHECK(Eigen::Map<Eigen::Matrix2d>(y.data(),2,1).isApprox(y_test));
BOOST_CHECK(Eigen::Map<Eigen::Vector2d>(y.data(),2,1).isApprox(y_test));
}


Expand Down

0 comments on commit 853824c

Please sign in to comment.