Skip to content

Commit

Permalink
Merge pull request #3080 from stan-dev/add_namespace_to_pow
Browse files Browse the repository at this point in the history
add std:: in tests to avoid ambiguity
  • Loading branch information
rok-cesnovar authored Nov 9, 2021
2 parents 02aff49 + a77b216 commit 233d9bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
21 changes: 12 additions & 9 deletions src/test/unit/variational/advi_univar_no_constraint_test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <test/test-models/good/variational/univariate_no_constraint.hpp>
#include <stan/variational/advi.hpp>
#include <stan/callbacks/stream_logger.hpp>
#include <gtest/gtest.h>
#include <test/unit/util.hpp>
#include <vector>
#include <string>
#include <boost/random/additive_combine.hpp> // L'Ecuyer RNG
#include <gtest/gtest.h>
#include <cmath>
#include <string>
#include <vector>

typedef boost::ecuyer1988 rng_t;
typedef univariate_no_constraint_model_namespace::univariate_no_constraint_model
Expand Down Expand Up @@ -57,14 +58,15 @@ TEST(advi_test, univar_no_constraint_fullrank) {

double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0))
* exp(-0.5
* (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2)
- pow(mu_j, 2) / sigma_j_sq));
* (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2)
- std::pow(mu_j, 2) / sigma_j_sq));

double elbo_true = 0.0;

elbo_true += log(S_j);
elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi())));
elbo_true += -0.5 * (pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq);
elbo_true
+= -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq);
elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi()));

double const EPSILON = 0.1;
Expand Down Expand Up @@ -182,14 +184,15 @@ TEST(advi_test, univar_no_constraint_meanfield) {

double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0))
* exp(-0.5
* (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2)
- pow(mu_j, 2) / sigma_j_sq));
* (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2)
- std::pow(mu_j, 2) / sigma_j_sq));

double elbo_true = 0.0;

elbo_true += log(S_j);
elbo_true += log(1.0 / (sqrt(sigma_j_sq * 2.0 * stan::math::pi())));
elbo_true += -0.5 * (pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq);
elbo_true
+= -0.5 * (std::pow(mu_j - 1.88, 2) / sigma_j_sq + 1.0 / sigma_j_sq);
elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi()));

double const EPSILON = 0.1;
Expand Down
19 changes: 10 additions & 9 deletions src/test/unit/variational/advi_univar_with_constraint_test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <test/test-models/good/variational/univariate_with_constraint.hpp>
#include <stan/variational/advi.hpp>
#include <stan/callbacks/stream_logger.hpp>
#include <gtest/gtest.h>
#include <test/unit/util.hpp>
#include <vector>
#include <string>
#include <boost/random/additive_combine.hpp> // L'Ecuyer RNG
#include <gtest/gtest.h>
#include <cmath>
#include <string>
#include <vector>

typedef boost::ecuyer1988 rng_t;
typedef univariate_with_constraint_model_namespace::
Expand Down Expand Up @@ -58,8 +59,8 @@ TEST(advi_test, univar_with_constraint_fullrank) {

double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0))
* exp(-0.5
* (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2)
- pow(mu_j, 2) / sigma_j_sq));
* (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2)
- std::pow(mu_j, 2) / sigma_j_sq));

double elbo_true = 0.0;

Expand All @@ -69,7 +70,7 @@ TEST(advi_test, univar_with_constraint_fullrank) {
+= -0.5 * one_over_sigma_j_sq * (exp(2.0 * log(1.88)) * exp(2.0 * 1.0));
elbo_true += -0.5 * one_over_sigma_j_sq
* (-2.0 * mu_j * exp(log(1.88)) * exp(0.5 * 1.0));
elbo_true += -0.5 * one_over_sigma_j_sq * (pow(mu_j, 2.0));
elbo_true += -0.5 * one_over_sigma_j_sq * (std::pow(mu_j, 2.0));
elbo_true += log(1.88);
elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi()));

Expand Down Expand Up @@ -189,8 +190,8 @@ TEST(advi_test, univar_with_constraint_meanfield) {

double S_j = 1.0 / (2.0 * stan::math::pi()) * sqrt(sigma_j_sq / (1.0))
* exp(-0.5
* (pow(1.5, 2) + pow(1.4, 2) + pow(1.6, 2)
- pow(mu_j, 2) / sigma_j_sq));
* (std::pow(1.5, 2) + std::pow(1.4, 2) + std::pow(1.6, 2)
- std::pow(mu_j, 2) / sigma_j_sq));

double elbo_true = 0.0;

Expand All @@ -200,7 +201,7 @@ TEST(advi_test, univar_with_constraint_meanfield) {
+= -0.5 * one_over_sigma_j_sq * (exp(2.0 * log(1.88)) * exp(2.0 * 1.0));
elbo_true += -0.5 * one_over_sigma_j_sq
* (-2.0 * mu_j * exp(log(1.88)) * exp(0.5 * 1.0));
elbo_true += -0.5 * one_over_sigma_j_sq * (pow(mu_j, 2.0));
elbo_true += -0.5 * one_over_sigma_j_sq * (std::pow(mu_j, 2.0));
elbo_true += log(1.88);
elbo_true += 0.5 * (1 + log(2.0 * stan::math::pi()));

Expand Down

0 comments on commit 233d9bf

Please sign in to comment.