Skip to content

Add missing unary plus and cleanup tests #2032

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

Merged
merged 6 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ help:
@echo ' * rev -> prim'
@echo ' * fwd -> prim'
@echo ' * mix -> {rev, fwd, prim}'
@echo ' * within {prim, rev, fwd, mix}: mat -> arr -> scal'
@echo ' * only include {prim, rev, fwd, mix}/meta.hpp from the meta subfolders'
@echo ''
@echo ' Cpplint'
@echo ' - cpplint : runs cpplint.py on source files. requires python 2.7.'
Expand Down
1 change: 1 addition & 0 deletions stan/math/prim/fun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
#include <stan/math/prim/fun/owens_t.hpp>
#include <stan/math/prim/fun/Phi.hpp>
#include <stan/math/prim/fun/Phi_approx.hpp>
#include <stan/math/prim/fun/plus.hpp>
#include <stan/math/prim/fun/poisson_binomial_log_probs.hpp>
#include <stan/math/prim/fun/polar.hpp>
#include <stan/math/prim/fun/positive_constrain.hpp>
Expand Down
24 changes: 24 additions & 0 deletions stan/math/prim/fun/plus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef STAN_MATH_PRIM_FUN_PLUS_HPP
#define STAN_MATH_PRIM_FUN_PLUS_HPP

#include <stan/math/prim/meta.hpp>

namespace stan {
namespace math {

/**
* Returns the unary plus of the input.
*
* @tparam T Type of input.
* @param x input.
* @return result of unary plus of the input.
*/
template <typename T>
inline T plus(T&& x) {
return std::forward<T>(x);
}

} // namespace math
} // namespace stan

#endif
3 changes: 0 additions & 3 deletions test/expressions/stan_math_sigs_exceptions.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8877,9 +8877,6 @@ real[] pareto_type_2_rng(real[], int[], vector)
real[] pareto_type_2_rng(real[], int[], row_vector)
real[] pareto_type_2_rng(real[], real[], vector)
real[] pareto_type_2_rng(real[], real[], row_vector)
vector plus(vector)
row_vector plus(row_vector)
matrix plus(matrix)
real poisson_ccdf_log(int, vector)
real poisson_ccdf_log(int, row_vector)
real poisson_ccdf_log(int[], vector)
Expand Down
42 changes: 42 additions & 0 deletions test/unit/math/mix/fun/plus_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <test/unit/math/test_ad.hpp>
#include <vector>

TEST(MathMixMatFun, plus) {
auto f = [](const auto& x) { return stan::math::plus(x); };

double x = 10;
stan::test::expect_ad(f, x);

Eigen::VectorXd y0(0);
Eigen::VectorXd y1(1);
y1 << -100;
Eigen::VectorXd y2(2);
y2 << -100, 0;
Eigen::VectorXd y3(3);
y3 << -100, 0, 1;
for (const auto& y : std::vector<Eigen::VectorXd>{y0, y1, y2, y3}) {
stan::test::expect_ad(f, y);
}

Eigen::RowVectorXd z0(0);
Eigen::RowVectorXd z1(1);
z1 << -100;
Eigen::RowVectorXd z2(2);
z2 << -100, 0;
Eigen::RowVectorXd z3(3);
z3 << -100, 0, 1;
for (const auto& y : std::vector<Eigen::RowVectorXd>{z0, z1, z2, z3}) {
stan::test::expect_ad(f, y);
}

Eigen::MatrixXd u00(0, 0);
Eigen::MatrixXd u11(1, 1);
u11 << 1;
Eigen::MatrixXd u22(2, 2);
u22 << 1, 2, 3, 4;
Eigen::MatrixXd u23(2, 3);
u23 << -100, 0, 1, 20, -40, 2;
for (const auto& y : std::vector<Eigen::MatrixXd>{u00, u11, u22, u23}) {
stan::test::expect_ad(f, y);
}
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/Phi_approx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ TEST(MathFunctions, Phi_approx_nan) {

EXPECT_TRUE(std::isnan(stan::math::Phi_approx(nan)));
}

TEST(MathFunctions, Phi_approx__works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::Phi_approx(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/Phi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,3 @@ TEST(MathFunctions, Phi_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_THROW(stan::math::Phi(nan), std::domain_error);
}

TEST(MathFunctions, Phi_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::Phi(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/acos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ TEST(primScalFun, acos) {
stan::test::expect_common_prim([](auto x) { return std::acos(x); },
[](auto x) { return stan::math::acos(x); });
}

TEST(MathFunctions, acos_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 0.1, 0.2, 0.3, 0.4, 0.5;
Eigen::RowVectorXd b(5);
b << 0.1, 0.2, 0.3, 0.4, 0.5;
stan::math::multiply(a, stan::math::acos(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/acosh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ TEST(MathFunctions, acosh_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::acosh(nan)));
}

TEST(MathFunctions, acosh_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::acosh(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/asin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ TEST(primScalFun, asin) {
stan::test::expect_common_prim([](auto x) { return std::asin(x); },
[](auto x) { return stan::math::asin(x); });
}

TEST(MathFunctions, asin_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 0.1, 0.2, 0.3, 0.4, 0.5;
Eigen::RowVectorXd b(5);
b << 0.1, 0.2, 0.3, 0.4, 0.5;
stan::math::multiply(a, stan::math::asin(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/asinh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ TEST(MathFunctions, asinh_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::asinh(nan)));
}

TEST(MathFunctions, asinh_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::asinh(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/atan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ TEST(primScalFun, atan) {
stan::test::expect_common_prim([](auto x) { return std::atan(x); },
[](auto x) { return stan::math::atan(x); });
}

TEST(MathFunctions, atan_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::atan(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/atanh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ TEST(MathFunctions, atanh_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::atanh(nan)));
}

TEST(MathFunctions, atanh_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 0.1, 0.2, 0.3, 0.4, 0.5;
Eigen::RowVectorXd b(5);
b << 0.1, 0.2, 0.3, 0.4, 0.5;
stan::math::multiply(a, stan::math::atanh(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/cbrt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,3 @@ TEST(MathFunctions, cbrt_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::cbrt(nan)));
}

TEST(MathFunctions, cbrt_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::cbrt(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/ceil_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ TEST(primScalFun, ceil) {
stan::test::expect_common_prim([](auto x) { return std::ceil(x); },
[](auto x) { return stan::math::ceil(x); });
}

TEST(MathFunctions, ceil_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::ceil(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/cos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ TEST(primScalFun, cos) {
stan::test::expect_common_prim([](auto x) { return std::cos(x); },
[](auto x) { return stan::math::cos(x); });
}

TEST(MathFunctions, cos_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::cos(b));
}
10 changes: 0 additions & 10 deletions test/unit/math/prim/fun/cosh_test.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/digamma_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ TEST(MathFunctions, digamma_nan) {

EXPECT_TRUE(std::isnormal(stan::math::digamma(1.0E50)));
}

TEST(MathFunctions, digamma_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::digamma(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/erf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@ TEST(MathFunctions, erfNan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::erf(nan)));
}

TEST(MathFunctions, erf_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::erf(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/erfc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,3 @@ TEST(MathFunctions, erfcNan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::erfc(nan)));
}

TEST(MathFunctions, erfc_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::erfc(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/exp2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,3 @@ TEST(MathFunctions, exp2_nan) {

EXPECT_TRUE(std::isnan(stan::math::exp2(nan)));
}

TEST(MathFunctions, exp2_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::exp2(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/exp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,3 @@ TEST(MathFunctions, expInt) {
EXPECT_FLOAT_EQ(std::exp(3.1), exp(3.1));
EXPECT_FLOAT_EQ(std::exp(3.0), exp(3.0));
}

TEST(MathFunctions, exp_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::exp(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/expm1_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ TEST(MathFunctions, expm1_nan) {
double nan = std::numeric_limits<double>::quiet_NaN();
EXPECT_TRUE(std::isnan(stan::math::expm1(nan)));
}

TEST(MathFunctions, expm1_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::expm1(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/fabs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ TEST(primScalFun, fabs) {
stan::test::expect_common_prim([](auto x) { return std::fabs(x); },
[](auto x) { return stan::math::fabs(x); });
}

TEST(MathFunctions, fabs_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::fabs(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/floor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ TEST(primScalFun, floor) {
stan::test::expect_common_prim([](auto x) { return std::floor(x); },
[](auto x) { return stan::math::floor(x); });
}

TEST(MathFunctions, floor_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::floor(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/inv_Phi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,3 @@ TEST(MathFunctions, inv_Phi_nan) {
EXPECT_THROW(inv_Phi(-2.0), std::domain_error);
EXPECT_THROW(inv_Phi(2.0), std::domain_error);
}

TEST(MathFunctions, inv_Phi_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 0.1, 0.2, 0.3, 0.4, 0.5;
Eigen::RowVectorXd b(5);
b << 0.1, 0.2, 0.3, 0.4, 0.5;
stan::math::multiply(a, stan::math::inv_Phi(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/inv_cloglog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ TEST(MathFunctions, inv_cloglog_nan) {

EXPECT_TRUE(std::isnan(stan::math::inv_cloglog(nan)));
}

TEST(MathFunctions, inv_cloglog_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::inv_cloglog(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/inv_logit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@ TEST(MathFunctions, inv_logit_nan) {

EXPECT_TRUE(std::isnan(stan::math::inv_logit(nan)));
}

TEST(MathFunctions, inv_logit_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::inv_logit(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/inv_sqrt_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ TEST(MathFunctions, inv_sqrt_nan) {

EXPECT_TRUE(std::isnan(stan::math::inv_sqrt(nan)));
}

TEST(MathFunctions, inv_sqrt_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::inv_sqrt(b));
}
8 changes: 0 additions & 8 deletions test/unit/math/prim/fun/inv_square_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,3 @@ TEST(MathFunctions, inv_square_nan) {

EXPECT_TRUE(std::isnan(stan::math::inv_square(nan)));
}

TEST(MathFunctions, inv_square_works_with_other_functions) {
Eigen::VectorXd a(5);
a << 1.1, 1.2, 1.3, 1.4, 1.5;
Eigen::RowVectorXd b(5);
b << 1.1, 1.2, 1.3, 1.4, 1.5;
stan::math::multiply(a, stan::math::inv_square(b));
}
Loading