Skip to content

Commit

Permalink
Merge pull request #584 from stan-dev/feature/issue-460-const-char-star
Browse files Browse the repository at this point in the history
Replacing const char* arguments with std::string in error functions
  • Loading branch information
syclik committed Aug 3, 2017
2 parents 5ed2d69 + 0571a4d commit 6fc8e2a
Show file tree
Hide file tree
Showing 303 changed files with 1,178 additions and 999 deletions.
7 changes: 4 additions & 3 deletions stan/math/prim/arr/err/check_matching_sizes.hpp
Expand Up @@ -3,6 +3,7 @@

#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -25,10 +26,10 @@ namespace stan {
* @throw <code>std::invalid_argument</code> if the sizes do not match
*/
template <typename T_y1, typename T_y2>
inline void check_matching_sizes(const char* function,
const char* name1,
inline void check_matching_sizes(const std::string& function,
const std::string& name1,
const T_y1& y1,
const char* name2,
const std::string& name2,
const T_y2& y2) {
check_size_match(function,
"size of ", name1, y1.size(),
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/arr/err/check_nonzero_size.hpp
Expand Up @@ -24,8 +24,8 @@ namespace stan {
* has zero size
*/
template <typename T_y>
inline void check_nonzero_size(const char* function,
const char* name,
inline void check_nonzero_size(const std::string& function,
const std::string& name,
const T_y& y) {
if (y.size() > 0)
return;
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/arr/err/check_ordered.hpp
Expand Up @@ -26,8 +26,8 @@ namespace stan {
* values, or if any element is <code>NaN</code>.
*/
template <typename T_y>
void check_ordered(const char* function,
const char* name,
void check_ordered(const std::string& function,
const std::string& name,
const std::vector<T_y>& y) {
for (size_t n = 1; n < y.size(); n++) {
if (!(y[n] > y[n-1])) {
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_cholesky_factor.hpp
Expand Up @@ -5,6 +5,7 @@
#include <stan/math/prim/scal/err/check_positive.hpp>
#include <stan/math/prim/scal/err/check_less_or_equal.hpp>
#include <stan/math/prim/mat/err/check_lower_triangular.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -29,8 +30,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_cholesky_factor(const char* function,
const char* name,
check_cholesky_factor(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
check_less_or_equal(function, "columns and rows of Cholesky factor",
y.cols(), y.rows());
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_cholesky_factor_corr.hpp
Expand Up @@ -7,6 +7,7 @@
#include <stan/math/prim/mat/err/check_square.hpp>
#include <stan/math/prim/mat/err/constraint_tolerance.hpp>
#include <stan/math/prim/mat/err/check_unit_vector.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -32,8 +33,8 @@ namespace stan {
*/
template <typename T_y>
void
check_cholesky_factor_corr(const char* function,
const char* name,
check_cholesky_factor_corr(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
using Eigen::Dynamic;
check_square(function, name, y);
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_column_index.hpp
Expand Up @@ -32,8 +32,8 @@ namespace stan {
* @throw std::out_of_range if index is an invalid column index
*/
template <typename T_y, int R, int C>
inline void check_column_index(const char* function,
const char* name,
inline void check_column_index(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, R, C>& y,
size_t i) {
if (i >= stan::error_index::value
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_corr_matrix.hpp
Expand Up @@ -41,8 +41,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_corr_matrix(const char* function,
const char* name,
check_corr_matrix(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
using Eigen::Matrix;

Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_cov_matrix.hpp
Expand Up @@ -3,6 +3,7 @@

#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/err/check_pos_definite.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -27,8 +28,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_cov_matrix(const char* function,
const char* name,
check_cov_matrix(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
check_pos_definite(function, name, y);
}
Expand Down
3 changes: 2 additions & 1 deletion stan/math/prim/mat/err/check_ldlt_factor.hpp
Expand Up @@ -26,7 +26,8 @@ namespace stan {
* invalid.
*/
template <typename T, int R, int C>
inline void check_ldlt_factor(const char* function, const char* name,
inline void check_ldlt_factor(const std::string& function,
const std::string& name,
LDLT_factor<T, R, C>& A) {
if (!A.success()) {
std::ostringstream msg;
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_lower_triangular.hpp
Expand Up @@ -29,8 +29,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_lower_triangular(const char* function,
const char* name,
check_lower_triangular(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
for (int n = 1; n < y.cols(); ++n) {
for (int m = 0; m < n && m < y.rows(); ++m) {
Expand Down
7 changes: 4 additions & 3 deletions stan/math/prim/mat/err/check_matching_dims.hpp
Expand Up @@ -5,6 +5,7 @@
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <sstream>
#include <string>

namespace stan {
namespace math {
Expand Down Expand Up @@ -33,10 +34,10 @@ namespace stan {
* do not match
*/
template <typename T1, typename T2, int R1, int C1, int R2, int C2>
inline void check_matching_dims(const char* function,
const char* name1,
inline void check_matching_dims(const std::string& function,
const std::string& name1,
const Eigen::Matrix<T1, R1, C1>& y1,
const char* name2,
const std::string& name2,
const Eigen::Matrix<T2, R2, C2>& y2) {
check_size_match(function,
"Rows of ", name1, y1.rows(),
Expand Down
7 changes: 4 additions & 3 deletions stan/math/prim/mat/err/check_multiplicable.hpp
Expand Up @@ -4,6 +4,7 @@
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <stan/math/prim/scal/err/check_positive_size.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -28,10 +29,10 @@ namespace stan {
* multiplicable or if either matrix is size 0 for either rows or columns
*/
template <typename T1, typename T2>
inline void check_multiplicable(const char* function,
const char* name1,
inline void check_multiplicable(const std::string& function,
const std::string& name1,
const T1& y1,
const char* name2,
const std::string& name2,
const T2& y2) {
check_positive_size(function, name1, "rows()", y1.rows());
check_positive_size(function, name2, "cols()", y2.cols());
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_ordered.hpp
Expand Up @@ -27,8 +27,8 @@ namespace stan {
* values, or if any element is <code>NaN</code>.
*/
template <typename T_y>
void check_ordered(const char* function,
const char* name,
void check_ordered(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down
16 changes: 10 additions & 6 deletions stan/math/prim/mat/err/check_pos_definite.hpp
Expand Up @@ -12,6 +12,7 @@
#include <stan/math/prim/scal/err/check_positive_size.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/fun/value_of_rec.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -30,7 +31,8 @@ namespace stan {
* if it is not positive definite, or if any element is <code>NaN</code>.
*/
template <typename T_y>
inline void check_pos_definite(const char* function, const char* name,
inline void check_pos_definite(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, -1, -1>& y) {
check_symmetric(function, name, y);
check_positive_size(function, name, "rows", y.rows());
Expand All @@ -52,13 +54,14 @@ namespace stan {
* @tparam Derived Derived type of the Eigen::LDLT transform.
* @param function Function name (for error messages)
* @param name Variable name (for error messages)
* @param cholesky Eigen::LDLT to test, whose progenitor
* @param cholesky Eigen::LDLT to test, whose progenitor
* must not have any NaN elements
* @throw <code>std::domain_error</code> if the matrix is not
* positive definite.
*/
template <typename Derived>
inline void check_pos_definite(const char* function, const char* name,
inline void check_pos_definite(const std::string& function,
const std::string& name,
const Eigen::LDLT<Derived>& cholesky) {
if (cholesky.info() != Eigen::Success
|| !cholesky.isPositive()
Expand All @@ -67,21 +70,22 @@ namespace stan {
}

/**
* Check if the specified LLT decomposition
* Check if the specified LLT decomposition
* transform resulted in <code>Eigen::Success</code>
*
* @tparam Derived Derived type of the Eigen::LLT transform.
*
* @param function Function name (for error messages)
* @param name Variable name (for error messages)
* @param cholesky Eigen::LLT to test, whose progenitor
* @param cholesky Eigen::LLT to test, whose progenitor
* must not have any NaN elements
*
* @throw <code>std::domain_error</code> if the diagonal of the
* L matrix is not positive.
*/
template <typename Derived>
inline void check_pos_definite(const char* function, const char* name,
inline void check_pos_definite(const std::string& function,
const std::string& name,
const Eigen::LLT<Derived>& cholesky) {
if (cholesky.info() != Eigen::Success
|| !(cholesky.matrixLLT().diagonal().array() > 0.0).all())
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_pos_semidefinite.hpp
Expand Up @@ -10,6 +10,7 @@
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/mat/fun/value_of_rec.hpp>
#include <sstream>
#include <string>

namespace stan {
namespace math {
Expand All @@ -31,8 +32,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_pos_semidefinite(const char* function,
const char* name,
check_pos_semidefinite(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
check_symmetric(function, name, y);
check_positive_size(function, name, "rows", y.rows());
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_positive_ordered.hpp
Expand Up @@ -26,8 +26,8 @@ namespace stan {
*/
template <typename T_y>
void
check_positive_ordered(const char* function,
const char* name,
check_positive_ordered(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down
16 changes: 8 additions & 8 deletions stan/math/prim/mat/err/check_range.hpp
Expand Up @@ -25,12 +25,12 @@ namespace stan {
*
* @throw <code>std::out_of_range</code> if the index is not in range
*/
inline void check_range(const char* function,
const char* name,
inline void check_range(const std::string& function,
const std::string& name,
int max,
int index,
int nested_level,
const char* error_msg) {
const std::string& error_msg) {
if ((index >= stan::error_index::value)
&& (index < max + stan::error_index::value))
return;
Expand All @@ -56,11 +56,11 @@ namespace stan {
*
* @throw <code>std::out_of_range</code> if the index is not in range
*/
inline void check_range(const char* function,
const char* name,
inline void check_range(const std::string& function,
const std::string& name,
int max,
int index,
const char* error_msg) {
const std::string& error_msg) {
if ((index >= stan::error_index::value)
&& (index < max + stan::error_index::value))
return;
Expand All @@ -81,8 +81,8 @@ namespace stan {
*
* @throw <code>std::out_of_range</code> if the index is not in range
*/
inline void check_range(const char* function,
const char* name,
inline void check_range(const std::string& function,
const std::string& name,
int max,
int index) {
if ((index >= stan::error_index::value)
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_row_index.hpp
Expand Up @@ -27,8 +27,8 @@ namespace stan {
* @throw <code>std::out_of_range</code> if the index is out of range.
*/
template <typename T_y, int R, int C>
inline void check_row_index(const char* function,
const char* name,
inline void check_row_index(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, R, C>& y,
size_t i) {
if (i >= stan::error_index::value
Expand Down
4 changes: 2 additions & 2 deletions stan/math/prim/mat/err/check_simplex.hpp
Expand Up @@ -36,8 +36,8 @@ namespace stan {
* simplex or if any element is <code>NaN</code>.
*/
template <typename T_prob>
void check_simplex(const char* function,
const char* name,
void check_simplex(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>& theta) {
using Eigen::Dynamic;
using Eigen::Matrix;
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_spsd_matrix.hpp
Expand Up @@ -6,6 +6,7 @@
#include <stan/math/prim/mat/err/check_pos_semidefinite.hpp>
#include <stan/math/prim/mat/err/check_symmetric.hpp>
#include <stan/math/prim/mat/err/check_square.hpp>
#include <string>

namespace stan {
namespace math {
Expand All @@ -26,8 +27,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_spsd_matrix(const char* function,
const char* name,
check_spsd_matrix(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
check_square(function, name, y);
check_positive_size(function, name, "rows()", y.rows());
Expand Down
5 changes: 3 additions & 2 deletions stan/math/prim/mat/err/check_square.hpp
Expand Up @@ -4,6 +4,7 @@
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <sstream>
#include <string>

namespace stan {
namespace math {
Expand All @@ -24,8 +25,8 @@ namespace stan {
*/
template <typename T_y>
inline void
check_square(const char* function,
const char* name,
check_square(const std::string& function,
const std::string& name,
const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
check_size_match(function,
"Expecting a square matrix; rows of ", name, y.rows(),
Expand Down

0 comments on commit 6fc8e2a

Please sign in to comment.