Skip to content

Commit 6f7c059

Browse files
authored
Merge pull request #2032 from stan-dev/feature/plus-cleanup-tests
Add missing unary plus and cleanup tests
2 parents 3001a22 + a74a277 commit 6f7c059

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+79
-401
lines changed

makefile

-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ help:
4747
@echo ' * rev -> prim'
4848
@echo ' * fwd -> prim'
4949
@echo ' * mix -> {rev, fwd, prim}'
50-
@echo ' * within {prim, rev, fwd, mix}: mat -> arr -> scal'
51-
@echo ' * only include {prim, rev, fwd, mix}/meta.hpp from the meta subfolders'
5250
@echo ''
5351
@echo ' Cpplint'
5452
@echo ' - cpplint : runs cpplint.py on source files. requires python 2.7.'

stan/math/prim/fun.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
#include <stan/math/prim/fun/owens_t.hpp>
232232
#include <stan/math/prim/fun/Phi.hpp>
233233
#include <stan/math/prim/fun/Phi_approx.hpp>
234+
#include <stan/math/prim/fun/plus.hpp>
234235
#include <stan/math/prim/fun/poisson_binomial_log_probs.hpp>
235236
#include <stan/math/prim/fun/polar.hpp>
236237
#include <stan/math/prim/fun/positive_constrain.hpp>

stan/math/prim/fun/plus.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef STAN_MATH_PRIM_FUN_PLUS_HPP
2+
#define STAN_MATH_PRIM_FUN_PLUS_HPP
3+
4+
#include <stan/math/prim/meta.hpp>
5+
6+
namespace stan {
7+
namespace math {
8+
9+
/**
10+
* Returns the unary plus of the input.
11+
*
12+
* @tparam T Type of input.
13+
* @param x input.
14+
* @return result of unary plus of the input.
15+
*/
16+
template <typename T>
17+
inline T plus(T&& x) {
18+
return std::forward<T>(x);
19+
}
20+
21+
} // namespace math
22+
} // namespace stan
23+
24+
#endif

test/expressions/stan_math_sigs_exceptions.expected

-3
Original file line numberDiff line numberDiff line change
@@ -8460,9 +8460,6 @@ real[] pareto_type_2_rng(real[], int[], vector)
84608460
real[] pareto_type_2_rng(real[], int[], row_vector)
84618461
real[] pareto_type_2_rng(real[], real[], vector)
84628462
real[] pareto_type_2_rng(real[], real[], row_vector)
8463-
vector plus(vector)
8464-
row_vector plus(row_vector)
8465-
matrix plus(matrix)
84668463
real poisson_ccdf_log(int, vector)
84678464
real poisson_ccdf_log(int, row_vector)
84688465
real poisson_ccdf_log(int[], vector)

test/unit/math/mix/fun/plus_test.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <test/unit/math/test_ad.hpp>
2+
#include <vector>
3+
4+
TEST(MathMixMatFun, plus) {
5+
auto f = [](const auto& x) { return stan::math::plus(x); };
6+
7+
double x = 10;
8+
stan::test::expect_ad(f, x);
9+
10+
Eigen::VectorXd y0(0);
11+
Eigen::VectorXd y1(1);
12+
y1 << -100;
13+
Eigen::VectorXd y2(2);
14+
y2 << -100, 0;
15+
Eigen::VectorXd y3(3);
16+
y3 << -100, 0, 1;
17+
for (const auto& y : std::vector<Eigen::VectorXd>{y0, y1, y2, y3}) {
18+
stan::test::expect_ad(f, y);
19+
}
20+
21+
Eigen::RowVectorXd z0(0);
22+
Eigen::RowVectorXd z1(1);
23+
z1 << -100;
24+
Eigen::RowVectorXd z2(2);
25+
z2 << -100, 0;
26+
Eigen::RowVectorXd z3(3);
27+
z3 << -100, 0, 1;
28+
for (const auto& y : std::vector<Eigen::RowVectorXd>{z0, z1, z2, z3}) {
29+
stan::test::expect_ad(f, y);
30+
}
31+
32+
Eigen::MatrixXd u00(0, 0);
33+
Eigen::MatrixXd u11(1, 1);
34+
u11 << 1;
35+
Eigen::MatrixXd u22(2, 2);
36+
u22 << 1, 2, 3, 4;
37+
Eigen::MatrixXd u23(2, 3);
38+
u23 << -100, 0, 1, 20, -40, 2;
39+
for (const auto& y : std::vector<Eigen::MatrixXd>{u00, u11, u22, u23}) {
40+
stan::test::expect_ad(f, y);
41+
}
42+
}

test/unit/math/prim/fun/Phi_approx_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ TEST(MathFunctions, Phi_approx_nan) {
1414

1515
EXPECT_TRUE(std::isnan(stan::math::Phi_approx(nan)));
1616
}
17-
18-
TEST(MathFunctions, Phi_approx__works_with_other_functions) {
19-
Eigen::VectorXd a(5);
20-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
21-
Eigen::RowVectorXd b(5);
22-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
23-
stan::math::multiply(a, stan::math::Phi_approx(b));
24-
}

test/unit/math/prim/fun/Phi_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,3 @@ TEST(MathFunctions, Phi_nan) {
118118
double nan = std::numeric_limits<double>::quiet_NaN();
119119
EXPECT_THROW(stan::math::Phi(nan), std::domain_error);
120120
}
121-
122-
TEST(MathFunctions, Phi_works_with_other_functions) {
123-
Eigen::VectorXd a(5);
124-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
125-
Eigen::RowVectorXd b(5);
126-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
127-
stan::math::multiply(a, stan::math::Phi(b));
128-
}

test/unit/math/prim/fun/acos_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ TEST(primScalFun, acos) {
55
stan::test::expect_common_prim([](auto x) { return std::acos(x); },
66
[](auto x) { return stan::math::acos(x); });
77
}
8-
9-
TEST(MathFunctions, acos_works_with_other_functions) {
10-
Eigen::VectorXd a(5);
11-
a << 0.1, 0.2, 0.3, 0.4, 0.5;
12-
Eigen::RowVectorXd b(5);
13-
b << 0.1, 0.2, 0.3, 0.4, 0.5;
14-
stan::math::multiply(a, stan::math::acos(b));
15-
}

test/unit/math/prim/fun/acosh_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,3 @@ TEST(MathFunctions, acosh_nan) {
2626
double nan = std::numeric_limits<double>::quiet_NaN();
2727
EXPECT_TRUE(std::isnan(stan::math::acosh(nan)));
2828
}
29-
30-
TEST(MathFunctions, acosh_works_with_other_functions) {
31-
Eigen::VectorXd a(5);
32-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
33-
Eigen::RowVectorXd b(5);
34-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
35-
stan::math::multiply(a, stan::math::acosh(b));
36-
}

test/unit/math/prim/fun/asin_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ TEST(primScalFun, asin) {
55
stan::test::expect_common_prim([](auto x) { return std::asin(x); },
66
[](auto x) { return stan::math::asin(x); });
77
}
8-
9-
TEST(MathFunctions, asin_works_with_other_functions) {
10-
Eigen::VectorXd a(5);
11-
a << 0.1, 0.2, 0.3, 0.4, 0.5;
12-
Eigen::RowVectorXd b(5);
13-
b << 0.1, 0.2, 0.3, 0.4, 0.5;
14-
stan::math::multiply(a, stan::math::asin(b));
15-
}

test/unit/math/prim/fun/asinh_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ TEST(MathFunctions, asinh_nan) {
2222
double nan = std::numeric_limits<double>::quiet_NaN();
2323
EXPECT_TRUE(std::isnan(stan::math::asinh(nan)));
2424
}
25-
26-
TEST(MathFunctions, asinh_works_with_other_functions) {
27-
Eigen::VectorXd a(5);
28-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
29-
Eigen::RowVectorXd b(5);
30-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
31-
stan::math::multiply(a, stan::math::asinh(b));
32-
}

test/unit/math/prim/fun/atan_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ TEST(primScalFun, atan) {
55
stan::test::expect_common_prim([](auto x) { return std::atan(x); },
66
[](auto x) { return stan::math::atan(x); });
77
}
8-
9-
TEST(MathFunctions, atan_works_with_other_functions) {
10-
Eigen::VectorXd a(5);
11-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
12-
Eigen::RowVectorXd b(5);
13-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
14-
stan::math::multiply(a, stan::math::atan(b));
15-
}

test/unit/math/prim/fun/atanh_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,3 @@ TEST(MathFunctions, atanh_nan) {
2727
double nan = std::numeric_limits<double>::quiet_NaN();
2828
EXPECT_TRUE(std::isnan(stan::math::atanh(nan)));
2929
}
30-
31-
TEST(MathFunctions, atanh_works_with_other_functions) {
32-
Eigen::VectorXd a(5);
33-
a << 0.1, 0.2, 0.3, 0.4, 0.5;
34-
Eigen::RowVectorXd b(5);
35-
b << 0.1, 0.2, 0.3, 0.4, 0.5;
36-
stan::math::multiply(a, stan::math::atanh(b));
37-
}

test/unit/math/prim/fun/cbrt_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,3 @@ TEST(MathFunctions, cbrt_nan) {
2424
double nan = std::numeric_limits<double>::quiet_NaN();
2525
EXPECT_TRUE(std::isnan(stan::math::cbrt(nan)));
2626
}
27-
28-
TEST(MathFunctions, cbrt_works_with_other_functions) {
29-
Eigen::VectorXd a(5);
30-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
31-
Eigen::RowVectorXd b(5);
32-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
33-
stan::math::multiply(a, stan::math::cbrt(b));
34-
}

test/unit/math/prim/fun/ceil_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ TEST(primScalFun, ceil) {
44
stan::test::expect_common_prim([](auto x) { return std::ceil(x); },
55
[](auto x) { return stan::math::ceil(x); });
66
}
7-
8-
TEST(MathFunctions, ceil_works_with_other_functions) {
9-
Eigen::VectorXd a(5);
10-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
11-
Eigen::RowVectorXd b(5);
12-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
13-
stan::math::multiply(a, stan::math::ceil(b));
14-
}

test/unit/math/prim/fun/cos_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ TEST(primScalFun, cos) {
55
stan::test::expect_common_prim([](auto x) { return std::cos(x); },
66
[](auto x) { return stan::math::cos(x); });
77
}
8-
9-
TEST(MathFunctions, cos_works_with_other_functions) {
10-
Eigen::VectorXd a(5);
11-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
12-
Eigen::RowVectorXd b(5);
13-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
14-
stan::math::multiply(a, stan::math::cos(b));
15-
}

test/unit/math/prim/fun/cosh_test.cpp

-10
This file was deleted.

test/unit/math/prim/fun/digamma_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,3 @@ TEST(MathFunctions, digamma_nan) {
1818

1919
EXPECT_TRUE(std::isnormal(stan::math::digamma(1.0E50)));
2020
}
21-
22-
TEST(MathFunctions, digamma_works_with_other_functions) {
23-
Eigen::VectorXd a(5);
24-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
25-
Eigen::RowVectorXd b(5);
26-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
27-
stan::math::multiply(a, stan::math::digamma(b));
28-
}

test/unit/math/prim/fun/erf_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,3 @@ TEST(MathFunctions, erfNan) {
2020
double nan = std::numeric_limits<double>::quiet_NaN();
2121
EXPECT_TRUE(std::isnan(stan::math::erf(nan)));
2222
}
23-
24-
TEST(MathFunctions, erf_works_with_other_functions) {
25-
Eigen::VectorXd a(5);
26-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
27-
Eigen::RowVectorXd b(5);
28-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
29-
stan::math::multiply(a, stan::math::erf(b));
30-
}

test/unit/math/prim/fun/erfc_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,3 @@ TEST(MathFunctions, erfcNan) {
2121
double nan = std::numeric_limits<double>::quiet_NaN();
2222
EXPECT_TRUE(std::isnan(stan::math::erfc(nan)));
2323
}
24-
25-
TEST(MathFunctions, erfc_works_with_other_functions) {
26-
Eigen::VectorXd a(5);
27-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
28-
Eigen::RowVectorXd b(5);
29-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
30-
stan::math::multiply(a, stan::math::erfc(b));
31-
}

test/unit/math/prim/fun/exp2_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,3 @@ TEST(MathFunctions, exp2_nan) {
3535

3636
EXPECT_TRUE(std::isnan(stan::math::exp2(nan)));
3737
}
38-
39-
TEST(MathFunctions, exp2_works_with_other_functions) {
40-
Eigen::VectorXd a(5);
41-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
42-
Eigen::RowVectorXd b(5);
43-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
44-
stan::math::multiply(a, stan::math::exp2(b));
45-
}

test/unit/math/prim/fun/exp_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ TEST(MathFunctions, expInt) {
77
EXPECT_FLOAT_EQ(std::exp(3.1), exp(3.1));
88
EXPECT_FLOAT_EQ(std::exp(3.0), exp(3.0));
99
}
10-
11-
TEST(MathFunctions, exp_works_with_other_functions) {
12-
Eigen::VectorXd a(5);
13-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
14-
Eigen::RowVectorXd b(5);
15-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
16-
stan::math::multiply(a, stan::math::exp(b));
17-
}

test/unit/math/prim/fun/expm1_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,3 @@ TEST(MathFunctions, expm1_nan) {
2323
double nan = std::numeric_limits<double>::quiet_NaN();
2424
EXPECT_TRUE(std::isnan(stan::math::expm1(nan)));
2525
}
26-
27-
TEST(MathFunctions, expm1_works_with_other_functions) {
28-
Eigen::VectorXd a(5);
29-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
30-
Eigen::RowVectorXd b(5);
31-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
32-
stan::math::multiply(a, stan::math::expm1(b));
33-
}

test/unit/math/prim/fun/fabs_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ TEST(primScalFun, fabs) {
55
stan::test::expect_common_prim([](auto x) { return std::fabs(x); },
66
[](auto x) { return stan::math::fabs(x); });
77
}
8-
9-
TEST(MathFunctions, fabs_works_with_other_functions) {
10-
Eigen::VectorXd a(5);
11-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
12-
Eigen::RowVectorXd b(5);
13-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
14-
stan::math::multiply(a, stan::math::fabs(b));
15-
}

test/unit/math/prim/fun/floor_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ TEST(primScalFun, floor) {
44
stan::test::expect_common_prim([](auto x) { return std::floor(x); },
55
[](auto x) { return stan::math::floor(x); });
66
}
7-
8-
TEST(MathFunctions, floor_works_with_other_functions) {
9-
Eigen::VectorXd a(5);
10-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
11-
Eigen::RowVectorXd b(5);
12-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
13-
stan::math::multiply(a, stan::math::floor(b));
14-
}

test/unit/math/prim/fun/inv_Phi_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,3 @@ TEST(MathFunctions, inv_Phi_nan) {
3434
EXPECT_THROW(inv_Phi(-2.0), std::domain_error);
3535
EXPECT_THROW(inv_Phi(2.0), std::domain_error);
3636
}
37-
38-
TEST(MathFunctions, inv_Phi_works_with_other_functions) {
39-
Eigen::VectorXd a(5);
40-
a << 0.1, 0.2, 0.3, 0.4, 0.5;
41-
Eigen::RowVectorXd b(5);
42-
b << 0.1, 0.2, 0.3, 0.4, 0.5;
43-
stan::math::multiply(a, stan::math::inv_Phi(b));
44-
}

test/unit/math/prim/fun/inv_cloglog_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ TEST(MathFunctions, inv_cloglog_nan) {
1414

1515
EXPECT_TRUE(std::isnan(stan::math::inv_cloglog(nan)));
1616
}
17-
18-
TEST(MathFunctions, inv_cloglog_works_with_other_functions) {
19-
Eigen::VectorXd a(5);
20-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
21-
Eigen::RowVectorXd b(5);
22-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
23-
stan::math::multiply(a, stan::math::inv_cloglog(b));
24-
}

test/unit/math/prim/fun/inv_logit_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ TEST(MathFunctions, inv_logit_nan) {
1414

1515
EXPECT_TRUE(std::isnan(stan::math::inv_logit(nan)));
1616
}
17-
18-
TEST(MathFunctions, inv_logit_works_with_other_functions) {
19-
Eigen::VectorXd a(5);
20-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
21-
Eigen::RowVectorXd b(5);
22-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
23-
stan::math::multiply(a, stan::math::inv_logit(b));
24-
}

test/unit/math/prim/fun/inv_sqrt_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,3 @@ TEST(MathFunctions, inv_sqrt_nan) {
2222

2323
EXPECT_TRUE(std::isnan(stan::math::inv_sqrt(nan)));
2424
}
25-
26-
TEST(MathFunctions, inv_sqrt_works_with_other_functions) {
27-
Eigen::VectorXd a(5);
28-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
29-
Eigen::RowVectorXd b(5);
30-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
31-
stan::math::multiply(a, stan::math::inv_sqrt(b));
32-
}

test/unit/math/prim/fun/inv_square_test.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,3 @@ TEST(MathFunctions, inv_square_nan) {
1919

2020
EXPECT_TRUE(std::isnan(stan::math::inv_square(nan)));
2121
}
22-
23-
TEST(MathFunctions, inv_square_works_with_other_functions) {
24-
Eigen::VectorXd a(5);
25-
a << 1.1, 1.2, 1.3, 1.4, 1.5;
26-
Eigen::RowVectorXd b(5);
27-
b << 1.1, 1.2, 1.3, 1.4, 1.5;
28-
stan::math::multiply(a, stan::math::inv_square(b));
29-
}

0 commit comments

Comments
 (0)