Skip to content

Commit

Permalink
adds test framework to all mix functions to cleanup memory after they…
Browse files Browse the repository at this point in the history
… finish
  • Loading branch information
SteveBronder committed Sep 14, 2023
1 parent 9230fbf commit 59792ee
Show file tree
Hide file tree
Showing 389 changed files with 1,526 additions and 1,150 deletions.
25 changes: 3 additions & 22 deletions runTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,13 @@
]

jumbo_folders = [
"test/unit/math/prim/core",
"test/unit/math/prim/err",
"test/unit/math/prim/fun",
"test/unit/math/prim/functor",
"test/unit/math/prim/meta",
"test/unit/math/prim/prob",
"test/unit/math/rev/core",
"test/unit/math/rev/err",
"test/unit/math/rev/fun",
"test/unit/math/rev/functor",
"test/unit/math/rev/meta",
"test/unit/math/rev/prob",
"test/unit/math/fwd/core",
"test/unit/math/fwd/fun",
"test/unit/math/fwd/functor",
"test/unit/math/fwd/meta",
"test/unit/math/fwd/prob",

"test/unit/math/mix/core",
"test/unit/math/mix/fun",
"test/unit/math/mix/functor",
"test/unit/math/mix/meta",
"test/unit/math/mix/prob",
"test/unit/math/opencl/device_functions",
"test/unit/math/opencl/kernel_generator",
"test/unit/math/opencl/prim",
"test/unit/math/opencl/rev",
"test/unit/math/mix/prob"

]


Expand Down
13 changes: 7 additions & 6 deletions test/unit/math/mix/core/operator_addition_test.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <stan/math/mix.hpp>
#include <stan/math/prim/core/operator_addition.hpp>
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorAddition) {
TEST_F(mathMix, operatorAddition) {
auto f = [](const auto& x1, const auto& x2) { return x1 + x2; };
bool disable_lhs_int = true;
stan::test::expect_common_binary(f, disable_lhs_int);
stan::test::expect_complex_common_binary(f);
}

TEST(mathMixCore, operatorAdditionMatrixSmall) {
TEST_F(mathMix, operatorAdditionMatrixSmall) {
// This calls operator+ under the hood
auto f
= [](const auto& x1, const auto& x2) { return stan::math::add(x1, x2); };
Expand Down Expand Up @@ -48,7 +49,7 @@ TEST(mathMixCore, operatorAdditionMatrixSmall) {
stan::test::expect_ad_matvar(tols, f, matrix_m11, matrix_m11);
}

TEST(mathMixCore, operatorAdditionMatrixZeroSize) {
TEST_F(mathMix, operatorAdditionMatrixZeroSize) {
auto f
= [](const auto& x1, const auto& x2) { return stan::math::add(x1, x2); };
stan::test::ad_tolerances tols;
Expand Down Expand Up @@ -79,7 +80,7 @@ TEST(mathMixCore, operatorAdditionMatrixZeroSize) {
stan::test::expect_ad_matvar(f, matrix_m00, matrix_m00);
}

TEST(mathMixCore, operatorAdditionMatrixNormal) {
TEST_F(mathMix, operatorAdditionMatrixNormal) {
auto f
= [](const auto& x1, const auto& x2) { return stan::math::add(x1, x2); };
stan::test::ad_tolerances tols;
Expand Down Expand Up @@ -113,7 +114,7 @@ TEST(mathMixCore, operatorAdditionMatrixNormal) {
stan::test::expect_ad_matvar(tols, f, matrix_m, matrix_m);
}

TEST(mathMixCore, operatorAdditionMatrixFailures) {
TEST_F(mathMix, operatorAdditionMatrixFailures) {
auto f
= [](const auto& x1, const auto& x2) { return stan::math::add(x1, x2); };
stan::test::ad_tolerances tols;
Expand All @@ -139,7 +140,7 @@ TEST(mathMixCore, operatorAdditionMatrixFailures) {
stan::test::expect_ad_matvar(tols, f, u, vv);
stan::test::expect_ad_matvar(tols, f, rvv, u);
}
TEST(mathMixCore, operatorAdditionMatrixLinearAccess) {
TEST_F(mathMix, operatorAdditionMatrixLinearAccess) {
Eigen::MatrixXd matrix_m11(3, 3);
for (Eigen::Index i = 0; i < matrix_m11.size(); ++i) {
matrix_m11(i) = i;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_divide_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorDivideEqual) {
TEST_F(mathMix, operatorDivideEqual) {
auto f = [](const auto& x1, const auto& x2) {
// decltype instead of auto to make following statement legal
decltype(x1 + x2) y = x1;
Expand Down
5 changes: 3 additions & 2 deletions test/unit/math/mix/core/operator_division_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>
#include <vector>

TEST(mathMixCore, operatorDivision) {
TEST_F(mathMix, operatorDivision) {
auto f = [](const auto& x1, const auto& x2) { return x1 / x2; };
bool disable_lhs_int = true;
stan::test::expect_common_binary(f, disable_lhs_int);
Expand Down Expand Up @@ -54,7 +55,7 @@ struct operator_divide_tester {
} // namespace test
} // namespace stan

TEST(mathMixCore, operatorDivisionVarMat) {
TEST_F(mathMix, operatorDivisionVarMat) {
Eigen::MatrixXd mat1(2, 2);
mat1 << -2, -1, 0.5, 2.8;
Eigen::MatrixXd mat2 = mat1.reverse();
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorEqual) {
TEST_F(mathMix, operatorEqual) {
auto f = [](const auto& x1, const auto& x2) { return x1 == x2; };
stan::test::expect_common_comparison(f);
stan::test::expect_complex_common_comparison(f);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorGreaterThanOrEqual) {
TEST_F(mathMix, operatorGreaterThanOrEqual) {
auto f = [](const auto& x1, const auto& x2) { return x1 >= x2; };
stan::test::expect_common_comparison(f);
}
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_greater_than_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorGreaterThan) {
TEST_F(mathMix, operatorGreaterThan) {
auto f = [](const auto& x1, const auto& x2) { return x1 > x2; };
stan::test::expect_common_comparison(f);
}
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_less_than_or_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorLessThanOrEqual) {
TEST_F(mathMix, operatorLessThanOrEqual) {
auto f = [](const auto& x1, const auto& x2) { return x1 <= x2; };
stan::test::expect_common_comparison(f);
}
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_less_than_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorLessThan) {
TEST_F(mathMix, operatorLessThan) {
auto f = [](const auto& x1, const auto& x2) { return x1 < x2; };
stan::test::expect_common_comparison(f);
}
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_logical_and_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stan/math/mix.hpp>
#include <test/unit/math/mix/util.hpp>
#include <gtest/gtest.h>
#include <limits>
#include <vector>
Expand All @@ -24,7 +25,7 @@ void test_logical_and(double x, double y) {
EXPECT_EQ(x && y, x && fvar<fvar<var> >(y));
}

TEST(AgradMix, logical_and) {
TEST_F(mathMix, logical_and) {
std::vector<double> xs;
xs.push_back(6.1);
xs.push_back(6.1);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_logical_or_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stan/math/mix.hpp>
#include <test/unit/math/mix/util.hpp>
#include <gtest/gtest.h>
#include <vector>
#include <limits>
Expand All @@ -24,7 +25,7 @@ void test_logical_or(double x, double y) {
EXPECT_EQ(x || y, x || fvar<fvar<var> >(y));
}

TEST(AgradMix, logical_or) {
TEST_F(mathMix, logical_or) {
std::vector<double> xs;
xs.push_back(6.1);
xs.push_back(6.1);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_minus_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorMinusEqual) {
TEST_F(mathMix, operatorMinusEqual) {
auto f = [](const auto& x1, const auto& x2) {
decltype(x1 + x2) y = x1;
y -= x2;
Expand Down
9 changes: 5 additions & 4 deletions test/unit/math/mix/core/operator_minus_minus_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorMinusMinusPre1) {
TEST_F(mathMix, operatorMinusMinusPre1) {
// this functor tests that y is right value after operator
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -11,7 +12,7 @@ TEST(mathMixCore, operatorMinusMinusPre1) {
};
stan::test::expect_common_unary(f);
}
TEST(mathMixCore, operatorMinusMinusPre2) {
TEST_F(mathMix, operatorMinusMinusPre2) {
// this functor tests that value of expression has right value
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -21,7 +22,7 @@ TEST(mathMixCore, operatorMinusMinusPre2) {
stan::test::expect_common_unary(f);
}

TEST(mathMixCore, operatorMinusMinusPost1) {
TEST_F(mathMix, operatorMinusMinusPost1) {
// this functor tests that y is right value after operator
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -33,7 +34,7 @@ TEST(mathMixCore, operatorMinusMinusPost1) {
stan::test::expect_common_unary(f);
}

TEST(mathMixCore, operatorMinusMinusPost2) {
TEST_F(mathMix, operatorMinusMinusPost2) {
// this functor tests that value of expression has right value
auto f = [](const auto& x1) {
auto y = x1;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_multiplication_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorMultiplication) {
TEST_F(mathMix, operatorMultiplication) {
auto f = [](const auto& x1, const auto& x2) { return x1 * x2; };
bool disable_lhs_int = true;
stan::test::expect_common_binary(f, disable_lhs_int);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_multiply_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorMultiplyEqual) {
TEST_F(mathMix, operatorMultiplyEqual) {
auto f = [](const auto& x1, const auto& x2) {
decltype(x1 + x2) y = x1;
y *= x2;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_not_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorNotEqual) {
TEST_F(mathMix, operatorNotEqual) {
auto f = [](const auto& x1, const auto& x2) { return x1 != x2; };
stan::test::expect_common_comparison(f);
stan::test::expect_complex_common_comparison(f);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_plus_equal_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorPlusEqual) {
TEST_F(mathMix, operatorPlusEqual) {
auto f = [](const auto& x1, const auto& x2) {
decltype(x1 + x2) y = x1;
y += x2;
Expand Down
9 changes: 5 additions & 4 deletions test/unit/math/mix/core/operator_plus_plus_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorPlusPlusPre1) {
TEST_F(mathMix, operatorPlusPlusPre1) {
// this functor tests that y is right value after operator
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -11,7 +12,7 @@ TEST(mathMixCore, operatorPlusPlusPre1) {
};
stan::test::expect_common_unary(f);
}
TEST(mathMixCore, operatorPlusPlusPre2) {
TEST_F(mathMix, operatorPlusPlusPre2) {
// this functor tests that value of expression has right value
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -21,7 +22,7 @@ TEST(mathMixCore, operatorPlusPlusPre2) {
stan::test::expect_common_unary(f);
}

TEST(mathMixCore, operatorPlusPlusPost1) {
TEST_F(mathMix, operatorPlusPlusPost1) {
// this functor tests that y is right value after operator
auto f = [](const auto& x1) {
auto y = x1;
Expand All @@ -33,7 +34,7 @@ TEST(mathMixCore, operatorPlusPlusPost1) {
stan::test::expect_common_unary(f);
}

TEST(mathMixCore, operatorPlusPlusPost2) {
TEST_F(mathMix, operatorPlusPlusPost2) {
// this functor tests that value of expression has right value
auto f = [](const auto& x1) {
auto y = x1;
Expand Down
13 changes: 7 additions & 6 deletions test/unit/math/mix/core/operator_subtraction_test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorSubtraction) {
TEST_F(mathMix, operatorSubtraction) {
auto f = [](const auto& x1, const auto& x2) { return x1 - x2; };
bool disable_lhs_int = true;
stan::test::expect_common_binary(f, disable_lhs_int);
stan::test::expect_complex_common_binary(f);
}

TEST(mathMixCore, operatorSubtractionMatrixSmall) {
TEST_F(mathMix, operatorSubtractionMatrixSmall) {
// This calls operator- under the hood
auto f = [](const auto& x1, const auto& x2) {
return stan::math::subtract(x1, x2);
Expand Down Expand Up @@ -47,7 +48,7 @@ TEST(mathMixCore, operatorSubtractionMatrixSmall) {
stan::test::expect_ad_matvar(tols, f, matrix_m11, matrix_m11);
}

TEST(mathMixCore, operatorSubtractionMatrixZeroSize) {
TEST_F(mathMix, operatorSubtractionMatrixZeroSize) {
auto f = [](const auto& x1, const auto& x2) {
return stan::math::subtract(x1, x2);
};
Expand Down Expand Up @@ -80,7 +81,7 @@ TEST(mathMixCore, operatorSubtractionMatrixZeroSize) {
stan::test::expect_ad_matvar(f, matrix_m00, vector_v0);
}

TEST(mathMixCore, operatorSubtractionMatrixNormal) {
TEST_F(mathMix, operatorSubtractionMatrixNormal) {
auto f = [](const auto& x1, const auto& x2) {
return stan::math::subtract(x1, x2);
};
Expand Down Expand Up @@ -116,7 +117,7 @@ TEST(mathMixCore, operatorSubtractionMatrixNormal) {
stan::test::expect_ad_matvar(tols, f, rowvector_rv, matrix_m);
}

TEST(mathMixCore, operatorSubtractionMatrixFailures) {
TEST_F(mathMix, operatorSubtractionMatrixFailures) {
auto f = [](const auto& x1, const auto& x2) {
return stan::math::subtract(x1, x2);
};
Expand Down Expand Up @@ -144,7 +145,7 @@ TEST(mathMixCore, operatorSubtractionMatrixFailures) {
stan::test::expect_ad_matvar(tols, f, rvv, u);
}

TEST(mathMixCore, operatorSubtractionMatrixLinearAccess) {
TEST_F(mathMix, operatorSubtractionMatrixLinearAccess) {
Eigen::MatrixXd matrix_m11(3, 3);
for (Eigen::Index i = 0; i < matrix_m11.size(); ++i) {
matrix_m11(i) = i;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_unary_negative_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorUnaryNegative) {
TEST_F(mathMix, operatorUnaryNegative) {
auto f = [](const auto& x1) { return -x1; };
stan::test::expect_common_unary(f);
stan::test::expect_complex_common(f);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_unary_not_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stan/math/mix.hpp>
#include <test/unit/math/mix/util.hpp>
#include <gtest/gtest.h>
#include <limits>

Expand All @@ -12,7 +13,7 @@ void test_unary_not(double x) {
EXPECT_EQ(!x, !fvar<fvar<var> >(x));
}

TEST(AgradMix, unary_not) {
TEST_F(mathMix, unary_not) {
test_unary_not(6.1);
test_unary_not(0);
test_unary_not(-13.2);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/math/mix/core/operator_unary_plus_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <test/unit/math/test_ad.hpp>
#include <test/unit/math/mix/util.hpp>

TEST(mathMixCore, operatorUnaryPlus) {
TEST_F(mathMix, operatorUnaryPlus) {
auto f = [](const auto& x1) { return +x1; };
stan::test::expect_common_unary(f);
stan::test::expect_complex_common(f);
Expand Down
Loading

0 comments on commit 59792ee

Please sign in to comment.