Skip to content

Commit 72c34c0

Browse files
committed
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
1 parent 3f4a904 commit 72c34c0

4 files changed

Lines changed: 125 additions & 84 deletions

File tree

stan/math/prim/err/check_stochastic_column.hpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ namespace stan {
1616
namespace math {
1717

1818
/**
19-
* Throw an exception if the specified matrix is not a column stochastic matrix. To be a
20-
* column stochastic matrix, all the values in each column must be greater than or equal to 0 and the values must sum to 1. A
21-
* valid column stochastic matrix is one where the sum of the elements by column is equal to 1. This
22-
* function tests that the sum is within the tolerance specified by
19+
* Throw an exception if the specified matrix is not a column stochastic matrix.
20+
* To be a column stochastic matrix, all the values in each column must be
21+
* greater than or equal to 0 and the values must sum to 1. A valid column
22+
* stochastic matrix is one where the sum of the elements by column is equal
23+
* to 1. This function tests that the sum is within the tolerance specified by
2324
* `CONSTRAINT_TOLERANCE`. This function only accepts Eigen matrices, statically
2425
* typed vectors, not general matrices with 1 column.
2526
* @tparam T A type inheriting from `Eigen::EigenBase`
2627
* @param function Function name (for error messages)
2728
* @param name Variable name (for error messages)
2829
* @param theta Matrix to test
2930
* @throw `std::invalid_argument` if `theta` is a 0-vector
30-
* @throw `std::domain_error` if the vector is not a column stochastic matrix or if any element
31-
* is `NaN`
31+
* @throw `std::domain_error` if the vector is not a column stochastic matrix or
32+
* if any element is `NaN`
3233
*/
3334
template <typename T, require_matrix_t<T>* = nullptr>
34-
void check_stochastic_column(const char* function, const char* name, const T& theta) {
35+
void check_stochastic_column(const char* function, const char* name,
36+
const T& theta) {
3537
using std::fabs;
3638
check_nonzero_size(function, name, theta);
3739
auto&& theta_ref = to_ref(value_of_rec(theta));
@@ -42,12 +44,13 @@ void check_stochastic_column(const char* function, const char* name, const T& th
4244
[&]() STAN_COLD_PATH {
4345
std::ostringstream msg;
4446
msg << "is not a valid column stochastic matrix. " << name << "["
45-
<< std::to_string(i + stan::error_index::value) <<
46-
", " << std::to_string(i + stan::error_index::value) << "]"
47+
<< std::to_string(i + stan::error_index::value) << ", "
48+
<< std::to_string(i + stan::error_index::value) << "]"
4749
<< " = ";
4850
std::string msg_str(msg.str());
49-
throw_domain_error(function, name, theta_ref.coeff(i, j), msg_str.c_str(),
50-
", but should be greater than or equal to 0");
51+
throw_domain_error(function, name, theta_ref.coeff(i, j),
52+
msg_str.c_str(),
53+
", but should be greater than or equal to 0");
5154
}();
5255
}
5356
vec_sum += theta_ref.coeff(i, j);
@@ -57,7 +60,8 @@ void check_stochastic_column(const char* function, const char* name, const T& th
5760
std::stringstream msg;
5861
msg << "is not a valid column stochastic matrix.";
5962
msg.precision(10);
60-
msg << " sum(" << name << "[:, "<< std::to_string(j + 1) << "]) = " << vec_sum << ", but should be ";
63+
msg << " sum(" << name << "[:, " << std::to_string(j + 1)
64+
<< "]) = " << vec_sum << ", but should be ";
6165
std::string msg_str(msg.str());
6266
throw_domain_error(function, name, 1.0, msg_str.c_str());
6367
}();
@@ -66,25 +70,27 @@ void check_stochastic_column(const char* function, const char* name, const T& th
6670
}
6771

6872
/**
69-
* Throw an exception if the specified matrices in a standard vector are not a column stochastic matrix. To be a
70-
* column stochastic matrix, all the values in each column must be greater than or equal to 0 and the values must sum to 1. A
71-
* valid column stochastic matrix is one where the sum of the elements by column is equal to 1. This
72-
* function tests that the sum is within the tolerance specified by
73-
* `CONSTRAINT_TOLERANCE`. This function only accepts Eigen matrices, statically
74-
* typed vectors, not general matrices with 1 column.
73+
* Throw an exception if the specified matrices in a standard vector are not a
74+
* column stochastic matrix. To be a column stochastic matrix, all the values in
75+
* each column must be greater than or equal to 0 and the values must sum to 1.
76+
* A valid column stochastic matrix is one where the sum of the elements by
77+
* column is equal to 1. This function tests that the sum is within the
78+
* tolerance specified by `CONSTRAINT_TOLERANCE`. This function only accepts
79+
* Eigen matrices, statically typed vectors, not general matrices with 1 column.
7580
* @tparam T A type inheriting from `Eigen::EigenBase`
7681
* @param function Function name (for error messages)
7782
* @param name Variable name (for error messages)
7883
* @param theta Matrix to test
7984
* @throw `std::invalid_argument` if `theta` is a 0-vector
80-
* @throw `std::domain_error` if the vector's matrices are not column stochastic matrices or if any element
81-
* is `NaN`
85+
* @throw `std::domain_error` if the vector's matrices are not column stochastic
86+
* matrices or if any element is `NaN`
8287
*/
8388
template <typename T, require_std_vector_t<T>* = nullptr>
84-
void check_stochastic_column(const char* function, const char* name, const T& theta) {
89+
void check_stochastic_column(const char* function, const char* name,
90+
const T& theta) {
8591
for (size_t i = 0; i < theta.size(); ++i) {
8692
check_stochastic_column(function, internal::make_iter_name(name, i).c_str(),
87-
theta[i]);
93+
theta[i]);
8894
}
8995
}
9096

stan/math/prim/err/check_stochastic_row.hpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ namespace stan {
1616
namespace math {
1717

1818
/**
19-
* Throw an exception if the specified matrix is not a row stochastic matrix. To be a
20-
* row stochastic matrix, all the values in each row must be greater than or equal to 0 and the values must sum to 1. A
21-
* valid row stochastic matrix is one where the sum of the elements by row is equal to 1. This
22-
* function tests that the sum is within the tolerance specified by
23-
* `CONSTRAINT_TOLERANCE`. This function only accepts Eigen matrices, statically
24-
* typed vectors, not general matrices with 1 column.
19+
* Throw an exception if the specified matrix is not a row stochastic matrix. To
20+
* be a row stochastic matrix, all the values in each row must be greater than
21+
* or equal to 0 and the values must sum to 1. A valid row stochastic matrix is
22+
* one where the sum of the elements by row is equal to 1. This function tests
23+
* that the sum is within the tolerance specified by `CONSTRAINT_TOLERANCE`.
24+
* This function only accepts Eigen matrices, statically typed vectors, not
25+
* general matrices with 1 column.
2526
* @tparam T A type inheriting from `Eigen::EigenBase`
2627
* @param function Function name (for error messages)
2728
* @param name Variable name (for error messages)
2829
* @param theta Matrix to test
2930
* @throw `std::invalid_argument` if `theta` is a 0-vector
30-
* @throw `std::domain_error` if the vector is not a row stochastic matrix or if any element
31-
* is `NaN`
31+
* @throw `std::domain_error` if the vector is not a row stochastic matrix or if
32+
* any element is `NaN`
3233
*/
3334
template <typename T, require_matrix_t<T>* = nullptr>
34-
void check_stochastic_row(const char* function, const char* name, const T& theta) {
35+
void check_stochastic_row(const char* function, const char* name,
36+
const T& theta) {
3537
using std::fabs;
3638
check_nonzero_size(function, name, theta);
3739
auto&& theta_ref = to_ref(value_of_rec(theta));
@@ -42,12 +44,13 @@ void check_stochastic_row(const char* function, const char* name, const T& theta
4244
[&]() STAN_COLD_PATH {
4345
std::ostringstream msg;
4446
msg << "is not a valid row stochastic matrix. " << name << "["
45-
<< std::to_string(i + stan::error_index::value) <<
46-
", " << std::to_string(i + stan::error_index::value) << "]"
47+
<< std::to_string(i + stan::error_index::value) << ", "
48+
<< std::to_string(i + stan::error_index::value) << "]"
4749
<< " = ";
4850
std::string msg_str(msg.str());
49-
throw_domain_error(function, name, theta_ref.coeff(i, j), msg_str.c_str(),
50-
", but should be greater than or equal to 0");
51+
throw_domain_error(function, name, theta_ref.coeff(i, j),
52+
msg_str.c_str(),
53+
", but should be greater than or equal to 0");
5154
}();
5255
}
5356
vec_sum += theta_ref.coeff(i, j);
@@ -57,7 +60,8 @@ void check_stochastic_row(const char* function, const char* name, const T& theta
5760
std::stringstream msg;
5861
msg << "is not a valid row stochastic matrix.";
5962
msg.precision(10);
60-
msg << " sum(" << name << "[" << std::to_string(i + 1) << ",:]) = " << vec_sum << ", but should be ";
63+
msg << " sum(" << name << "[" << std::to_string(i + 1)
64+
<< ",:]) = " << vec_sum << ", but should be ";
6165
std::string msg_str(msg.str());
6266
throw_domain_error(function, name, 1.0, msg_str.c_str());
6367
}();
@@ -66,25 +70,27 @@ void check_stochastic_row(const char* function, const char* name, const T& theta
6670
}
6771

6872
/**
69-
* Throw an exception if the specified matrices in a standard vector are not a row stochastic matrix. To be a
70-
* row stochastic matrix, all the values in each row must be greater than or equal to 0 and the values must sum to 1. A
71-
* valid row stochastic matrix is one where the sum of the elements by row is equal to 1. This
72-
* function tests that the sum is within the tolerance specified by
73+
* Throw an exception if the specified matrices in a standard vector are not a
74+
* row stochastic matrix. To be a row stochastic matrix, all the values in each
75+
* row must be greater than or equal to 0 and the values must sum to 1. A valid
76+
* row stochastic matrix is one where the sum of the elements by row is equal
77+
* to 1. This function tests that the sum is within the tolerance specified by
7378
* `CONSTRAINT_TOLERANCE`. This function only accepts Eigen matrices, statically
7479
* typed vectors, not general matrices with 1 column.
7580
* @tparam T A type inheriting from `Eigen::EigenBase`
7681
* @param function Function name (for error messages)
7782
* @param name Variable name (for error messages)
7883
* @param theta Matrix to test
7984
* @throw `std::invalid_argument` if `theta` is a 0-vector
80-
* @throw `std::domain_error` if the standard vector's matrices are not row stochastic matrix or if any element
81-
* is `NaN`
85+
* @throw `std::domain_error` if the standard vector's matrices are not row
86+
* stochastic matrix or if any element is `NaN`
8287
*/
8388
template <typename T, require_std_vector_t<T>* = nullptr>
84-
void check_stochastic_row(const char* function, const char* name, const T& theta) {
89+
void check_stochastic_row(const char* function, const char* name,
90+
const T& theta) {
8591
for (size_t i = 0; i < theta.size(); ++i) {
8692
check_stochastic_row(function, internal::make_iter_name(name, i).c_str(),
87-
theta[i]);
93+
theta[i]);
8894
}
8995
}
9096

test/unit/math/prim/err/check_stochastic_column_test.cpp

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,29 @@
66

77
TEST(ErrorHandlingMatrix, checkStochasticColumn) {
88
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> y_vec(2, 2);
9-
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{y_vec, y_vec, y_vec};
9+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{
10+
y_vec, y_vec, y_vec};
1011
for (auto& y_i : y) {
1112
y_i << 0.5, 0.5, 0.5, 0.5;
1213
}
1314

14-
EXPECT_NO_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y));
15+
EXPECT_NO_THROW(
16+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y));
1517

1618
for (auto& y_i : y) {
1719
y_i(0, 1) = 0.55;
1820
}
19-
EXPECT_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
20-
std::domain_error);
21+
EXPECT_THROW(
22+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
23+
std::domain_error);
2124
}
2225

2326
TEST(ErrorHandlingMatrix, checkStochasticColumn_message_negative_value) {
2427
std::string message;
2528
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> y_vec(3, 3);
2629
y_vec.setZero();
27-
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{y_vec, y_vec, y_vec};
30+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{
31+
y_vec, y_vec, y_vec};
2832
for (auto& y_i : y) {
2933
y_i(0, 0) = -0.1;
3034
y_i(1, 0) = 1.1;
@@ -41,10 +45,12 @@ TEST(ErrorHandlingMatrix, checkStochasticColumn_message_negative_value) {
4145
FAIL() << "threw the wrong error";
4246
}
4347

44-
EXPECT_TRUE(std::string::npos != message.find(" y[1] is not a valid column stochastic matrix"))
48+
EXPECT_TRUE(std::string::npos
49+
!= message.find(" y[1] is not a valid column stochastic matrix"))
4550
<< "Found: " << message;
4651

47-
EXPECT_TRUE(std::string::npos != message.find("y[1][1, 1] = -0.1")) << "Found: " << message;
52+
EXPECT_TRUE(std::string::npos != message.find("y[1][1, 1] = -0.1"))
53+
<< "Found: " << message;
4854

4955
for (auto& y_i : y) {
5056
y_i.setZero();
@@ -61,17 +67,20 @@ TEST(ErrorHandlingMatrix, checkStochasticColumn_message_negative_value) {
6167
FAIL() << "threw the wrong error";
6268
}
6369

64-
EXPECT_TRUE(std::string::npos != message.find(" y[1] is not a valid column stochastic matrix"))
65-
<< "Found: " << message;
70+
EXPECT_TRUE(std::string::npos
71+
!= message.find(" y[1] is not a valid column stochastic matrix"))
72+
<< "Found: " << message;
6673

67-
EXPECT_TRUE(std::string::npos != message.find("sum(y[1][:, 1]) = 1.2")) << "Found: " << message;
74+
EXPECT_TRUE(std::string::npos != message.find("sum(y[1][:, 1]) = 1.2"))
75+
<< "Found: " << message;
6876
}
6977

7078
TEST(ErrorHandlingMatrix, checkStochasticColumn_message_sum) {
7179
std::string message;
7280
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> y_vec(10, 10);
7381
y_vec.setZero();
74-
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{y_vec, y_vec, y_vec};
82+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{
83+
y_vec, y_vec, y_vec};
7584
for (auto& y_i : y) {
7685
y_i(3, 0) = 0.9;
7786
}
@@ -85,50 +94,58 @@ TEST(ErrorHandlingMatrix, checkStochasticColumn_message_sum) {
8594
FAIL() << "threw the wrong error";
8695
}
8796

88-
EXPECT_TRUE(std::string::npos != message.find(" y[1] is not a valid column stochastic matrix"))
97+
EXPECT_TRUE(std::string::npos
98+
!= message.find(" y[1] is not a valid column stochastic matrix"))
8999
<< message;
90100

91-
EXPECT_TRUE(std::string::npos != message.find("sum(y[1][:, 1]) = 0.9")) << message;
101+
EXPECT_TRUE(std::string::npos != message.find("sum(y[1][:, 1]) = 0.9"))
102+
<< message;
92103
}
93104

94105
TEST(ErrorHandlingMatrix, checkStochasticColumn_message_length) {
95106
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> y_vec(0, 0);
96-
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{y_vec, y_vec, y_vec};
107+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{
108+
y_vec, y_vec, y_vec};
97109

98110
using stan::math::check_stochastic_column;
99111

100-
EXPECT_THROW_MSG(check_stochastic_column("checkStochasticColumn", "y", y), std::invalid_argument,
112+
EXPECT_THROW_MSG(check_stochastic_column("checkStochasticColumn", "y", y),
113+
std::invalid_argument,
101114
"y[1] has size 0, but must have a non-zero size");
102115
}
103116

104117
TEST(ErrorHandlingMatrix, checkStochasticColumn_nan) {
105118
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> y_vec(2, 2);
106-
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{y_vec, y_vec, y_vec};
119+
std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>> y{
120+
y_vec, y_vec, y_vec};
107121
constexpr double nan = std::numeric_limits<double>::quiet_NaN();
108122
for (auto& y_i : y) {
109123
y_i << nan, 0.5, nan, 0.5;
110124
}
111125

112-
EXPECT_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
113-
std::domain_error);
126+
EXPECT_THROW(
127+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
128+
std::domain_error);
114129

115130
for (auto& y_i : y) {
116131
y_i(0, 1) = 0.55;
117132
}
118-
EXPECT_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
119-
std::domain_error);
133+
EXPECT_THROW(
134+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
135+
std::domain_error);
120136

121137
for (auto& y_i : y) {
122138
y_i(0, 0) = 0.5;
123139
y_i(0, 1) = nan;
124140
}
125-
EXPECT_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
126-
std::domain_error);
141+
EXPECT_THROW(
142+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
143+
std::domain_error);
127144

128145
for (auto& y_i : y) {
129146
y_i(0, 0) = nan;
130147
}
131-
EXPECT_THROW(stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
132-
std::domain_error);
148+
EXPECT_THROW(
149+
stan::math::check_stochastic_column("checkStochasticColumn", "y", y),
150+
std::domain_error);
133151
}
134-

0 commit comments

Comments
 (0)