-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1641 from stan-dev/feature/parameter-pack-odes
Clicked my button for the day
- Loading branch information
Showing
71 changed files
with
8,902 additions
and
2,534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef STAN_MATH_PRIM_ERR_CHECK_SORTED_HPP | ||
#define STAN_MATH_PRIM_ERR_CHECK_SORTED_HPP | ||
|
||
#include <stan/math/prim/err/throw_domain_error.hpp> | ||
#include <stan/math/prim/fun/Eigen.hpp> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace stan { | ||
namespace math { | ||
|
||
/** | ||
* Check if the specified vector is sorted into increasing order (repeated | ||
* values are okay). | ||
* @tparam T_y Type of scalar | ||
* @param function Function name (for error messages) | ||
* @param name Variable name (for error messages) | ||
* @param y Vector to test | ||
* @throw <code>std::domain_error</code> if the vector elements are | ||
* not sorted, or if any element is <code>NaN</code>. | ||
*/ | ||
template <typename T_y> | ||
void check_sorted(const char* function, const char* name, | ||
const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y) { | ||
using size_type = index_type_t<Eigen::Matrix<T_y, Eigen::Dynamic, 1>>; | ||
|
||
for (size_type n = 1; n < y.size(); n++) { | ||
if (!(y[n] >= y[n - 1])) { | ||
std::ostringstream msg1; | ||
msg1 << "is not a valid sorted vector." | ||
<< " The element at " << stan::error_index::value + n << " is "; | ||
std::string msg1_str(msg1.str()); | ||
std::ostringstream msg2; | ||
msg2 << ", but should be greater than or equal to the previous element, " | ||
<< y[n - 1]; | ||
std::string msg2_str(msg2.str()); | ||
throw_domain_error(function, name, y[n], msg1_str.c_str(), | ||
msg2_str.c_str()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Check if the specified vector is sorted into increasing order (repeated | ||
* values are okay). | ||
* @tparam T_y Type of scalar | ||
* @param function Function name (for error messages) | ||
* @param name Variable name (for error messages) | ||
* @param y <code>std::vector</code> to test | ||
* @throw <code>std::domain_error</code> if the vector elements are | ||
* not sorted, or if any element | ||
* is <code>NaN</code>. | ||
*/ | ||
template <typename T_y> | ||
void check_sorted(const char* function, const char* name, | ||
const std::vector<T_y>& y) { | ||
for (size_t n = 1; n < y.size(); n++) { | ||
if (!(y[n] >= y[n - 1])) { | ||
std::ostringstream msg1; | ||
msg1 << "is not a valid sorted vector." | ||
<< " The element at " << stan::error_index::value + n << " is "; | ||
std::string msg1_str(msg1.str()); | ||
std::ostringstream msg2; | ||
msg2 << ", but should be greater than or equal to the previous element, " | ||
<< y[n - 1]; | ||
std::string msg2_str(msg2.str()); | ||
throw_domain_error(function, name, y[n], msg1_str.c_str(), | ||
msg2_str.c_str()); | ||
} | ||
} | ||
} | ||
|
||
} // namespace math | ||
} // namespace stan | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef STAN_MATH_PRIM_FUN_EVAL_HPP | ||
#define STAN_MATH_PRIM_FUN_EVAL_HPP | ||
|
||
#include <stan/math/prim/meta.hpp> | ||
#include <stan/math/prim/fun/Eigen.hpp> | ||
|
||
namespace stan { | ||
namespace math { | ||
|
||
/** | ||
* Inputs which have a plain_type equal to the own time are forwarded | ||
* unmodified (for Eigen expressions these types are different) | ||
* | ||
* @tparam T Input type | ||
* @param[in] arg Input argument | ||
* @return Forwarded input argument | ||
**/ | ||
template <typename T, | ||
require_same_t<std::decay_t<T>, plain_type_t<T>>* = nullptr> | ||
inline decltype(auto) eval(T&& arg) { | ||
return std::forward<T>(arg); | ||
} | ||
|
||
/** | ||
* Inputs which have a plain_type different from their own type are | ||
* Eval'd (this catches Eigen expressions) | ||
* | ||
* @tparam T Input type | ||
* @param[in] arg Input argument | ||
* @return Eval'd argument | ||
**/ | ||
template <typename T, | ||
require_not_same_t<std::decay_t<T>, plain_type_t<T>>* = nullptr> | ||
inline decltype(auto) eval(const T& arg) { | ||
return arg.eval(); | ||
} | ||
|
||
} // namespace math | ||
} // namespace stan | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.