Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve quadprog #1896

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
tests
  • Loading branch information
rok-cesnovar committed Apr 18, 2020
commit 04020e938a5bd308b52251b72352a806895945cc
41 changes: 38 additions & 3 deletions test/unit/math/rev/fun/solve_quadprog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ TEST(AgradRevMatrix, dddddd) {
Eigen::MatrixXd CI(3,4);
Eigen::VectorXd ci0(4);

G << 2.1, 1.5, 1.2,
1.5, 2.2, 1.3,
1.2, 1.3, 3.1;
G << 2.1, 0.0, 1.0,
1.5, 2.2, 0.0,
1.2, 1.3, 3.1;

g0 << 6, 1, 1;

Expand All @@ -29,6 +29,11 @@ TEST(AgradRevMatrix, dddddd) {


stan::math::vector_d x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i), 1e-8);
}
}

TEST(AgradRevMatrix, vddddd) {
Expand Down Expand Up @@ -57,6 +62,11 @@ TEST(AgradRevMatrix, vddddd) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}

TEST(AgradRevMatrix, vvdddd) {
Expand Down Expand Up @@ -85,6 +95,11 @@ TEST(AgradRevMatrix, vvdddd) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}

TEST(AgradRevMatrix, vvvddd) {
Expand Down Expand Up @@ -113,6 +128,11 @@ TEST(AgradRevMatrix, vvvddd) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}

TEST(AgradRevMatrix, vvvvdd) {
Expand Down Expand Up @@ -141,6 +161,11 @@ TEST(AgradRevMatrix, vvvvdd) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}

TEST(AgradRevMatrix, vvvvvd) {
Expand Down Expand Up @@ -169,6 +194,11 @@ TEST(AgradRevMatrix, vvvvvd) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}

TEST(AgradRevMatrix, vvvvvv) {
Expand Down Expand Up @@ -197,4 +227,9 @@ TEST(AgradRevMatrix, vvvvvv) {


stan::math::vector_v x = stan::math::solve_quadprog(G, g0, CE, ce0, CI, ci0);
stan::math::vector_d solution(3);
solution << -3e-16, 2, 0;
for(int i=0;i<x.size();i++) {
EXPECT_NEAR(solution(i), x(i).val(), 1e-8);
}
}