diff --git a/doxygen/contributor_help_pages/common_pitfalls.md b/doxygen/contributor_help_pages/common_pitfalls.md index f3e8fb817ad..b153f9b2084 100644 --- a/doxygen/contributor_help_pages/common_pitfalls.md +++ b/doxygen/contributor_help_pages/common_pitfalls.md @@ -26,7 +26,7 @@ template T norm(const Eigen::Matrix&); ``` -A typical problem with a function like this is that `norm` can similarly be defined for a row vector (and the implementation is the same). +A typical problem with a function like this is that `norm` can similarly be defined for a row vector (and the implementation is the same). In this case there are two signatures: ```cpp @@ -46,10 +46,10 @@ return_type_t norm(const T&); But what if we want different overloads to handle different types? The most common situation is when there is one template overload that works with any autodiff type, and then a second faster overload that only works with a specific autodiff type. -There can easily be ambiguities between the two function signatures. -The previous examples took advantage of simple overloads. -The more general solution is template metaprograms that additionally make use of C++ substitution failure -is not an error (SFINAE) semantics. +There can easily be ambiguities between the two function signatures. +The previous examples took advantage of simple overloads. +The more general solution are template metaprograms that additionally make use of C++ substitution failure +is not an error (SFINAE) semantics. For the norm function above, SFINAE could be used to limit one signature to work with reverse mode autodiff types and one to work with anything else: @@ -65,11 +65,11 @@ template norm(const T&); ``` -SFINAE should be thought of as a filter on what functions are visible to the compiler when it does a name lookup for a specific function. -The type trait `require_st_var` should be read "require the @ref stan::scalar_type of the argument to be a @ref stan::math::var". -The metaprogram `require_st_var` will evaluate to a valid type if the scalar type of `T` is a @ref stan::math::var. -If the scalar type of `T` is not a @ref stan::math::var, then `require_st_var` does not evaluate to a valid type and the compiler treats it as if the signature does not exist. -This is how SFINAE (substitution failure is not an error) works. +SFINAE should be thought of as filters on what functions are visible to the compiler when it does name lookup for a specific function. +The type trait `require_st_var` should be read "require the @ref stan::scalar_type of the argument to be a @ref stan::math::var". +The metaprogram `require_st_var` will evaluate to a valid type if the scalar type of `T` is a @ref stan::math::var. +If the scalar type of `T` is not a @ref stan::math::var, then `require_st_var` does not evaluate to a valid type and the compiler treats it as if the signature does not exist. +This is how SFINAE (substitution failure is not an error) works. Because the substitution does not work, the signature is ignored. This is all built based on C++'s [std::enable_if](https://en.cppreference.com/w/cpp/types/enable_if) template metaprogram. @@ -143,8 +143,8 @@ auto add_zero(T&& a) { } ``` -Returning expressions is an advanced feature, and it is easy to make mistakes. -In this regard, it is simplest to start development not returning expressions (in this case holders are unnecessary) and only add expression return types later. +Returning expressions is an advanced feature and it is easy to make mistakes. +In this regard, it is simplest to start development not returning expressions (in this case holders are unnecessary), and only add expression return types later. It is always possible to return a non-expression type by evaluating the Eigen expression. For convenience, there is an `eval` function in Math that will evaluate Eigen expressions and forward anything else. @@ -256,8 +256,8 @@ inline var cool_fun(const EigVec& v) { } ``` -we make a deep copy of the return whose inner `vari` will not be the same, but the `var` will produce a new copy of the pointer to the `vari`. -Now the user code above will be protected, and it is safe for them to assign to individual elements of the `auto` returned matrix. +we make a deep copy of the return whose inner `vari` will not be the same but the `var` will produce a new copy of the pointer to the `vari`. +Now the user code above will be protected and it is safe for them to assign to individual elements of the `auto` returned matrix. ### Const correctness, reverse mode autodiff, and arena types diff --git a/doxygen/contributor_help_pages/developer_doc.md b/doxygen/contributor_help_pages/developer_doc.md index 971026b908d..ea1a76b222c 100644 --- a/doxygen/contributor_help_pages/developer_doc.md +++ b/doxygen/contributor_help_pages/developer_doc.md @@ -43,7 +43,7 @@ We're committed to having a permissive open-source license. The Math library is # Contributing {#contribution} -Thanks for reading! We love contributions from everyone in the form of good discussion, issues, and pull requests. +Thanks for reading! We love contributions from everyone in the form of discussion, issues, and pull requests. ## Issues @@ -87,7 +87,7 @@ Pull requests are code reviewed after they pass our continuous integration tests It is the responsibility of the contributor submitting the pull request that the code meets these requirements. We're open-source. Once the code gets into the code base, the community of developers take ownership of it. -## Discussion +## Discussion {#discussion} For general questions, please ask on the forums with the ["Developers" tag](http://discourse.mc-stan.org/c/stan-dev). diff --git a/doxygen/contributor_help_pages/getting_started.md b/doxygen/contributor_help_pages/getting_started.md index 02c9caf28da..d9b7c5d8e48 100644 --- a/doxygen/contributor_help_pages/getting_started.md +++ b/doxygen/contributor_help_pages/getting_started.md @@ -150,7 +150,7 @@ for (Eigen::Index i = 0; i < x.size(); ++i) { } ``` -Using lazily evaluated expressions allows Eigen to avoid redundant copies, reads and writes to our data. +Using lazily evaluated expressions allows Eigen to avoid redundant copies, reads, and writes to our data. However, this comes at the cost of more complicated template traits and patterns as well as being careful around handling inputs to functions. In (3), when we access the coefficients of `x` in the loop, if its type is similar to the expression above we can get incorrect results as Eigen does not guarantee any safety of results when performing coefficient level access on an expression type that transforms its inputs. @@ -396,8 +396,8 @@ You can think of `.val()` and `.adj()` as returning an Eigen matrix of doubles s ### (4) Setting up the reverse pass -Once the forward pass is complete, and the data for the reverse pass is in the arena the adjoint calculation for the portion of the reverse pass for this function needs to be written. -The reverse pass consists of an adjoint calculation which is placed onto the callback stack. +Once the forward pass is complete and the data for the reverse pass is in the arena the adjoint calculation for the portion of the reverse pass for this function needs to be written. +The reverse pass consists of an adjoint calculation which is placed onto the callback stack. When a user calls @ref stan::math::grad this adjoint calculation will be called so that adjoints are accumulated from the final output to the starting inputs. The adjoint method for a self dot product is diff --git a/doxygen/docker/alpine/Dockerfile b/doxygen/docker/alpine/Dockerfile index e0d4a3911be..ab00cf60573 100644 --- a/doxygen/docker/alpine/Dockerfile +++ b/doxygen/docker/alpine/Dockerfile @@ -1,8 +1,16 @@ -FROM nnadeau/docker-doxygen +FROM alpine:3.16 + +ARG USER_ID +ARG GROUP_ID +ARG DEBIAN_FRONTEND=noninteractive RUN apk update && apk add \ - make execline + make execline doxygen graphviz bash g++ git + +#RUN addgroup -g $GROUP_ID user +#RUN adduser --disabled-password --gecos '' --uid $USER_ID user -RUN mkdir math -COPY . ./math -WORKDIR ./math +USER root +RUN mkdir /math +#RUN chown $USER_ID:$GROUP_ID /math +USER user diff --git a/doxygen/docker/ubuntu/Dockerfile b/doxygen/docker/ubuntu/Dockerfile new file mode 100644 index 00000000000..46800badf89 --- /dev/null +++ b/doxygen/docker/ubuntu/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:20.04 + +ARG USER_ID +ARG GROUP_ID +ARG DEBIAN_FRONTEND=noninteractive + +RUN apk update && apk add \ + make execline doxygen graphviz bash g++ git + +RUN addgroup --gid $GROUP_ID user +RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user + +USER root +RUN mkdir /math +RUN chown $USER_ID:$GROUP_ID /math +USER user diff --git a/doxygen/doxygen.cfg b/doxygen/doxygen.cfg index 41ea76ecfed..ab8edc88fe5 100644 --- a/doxygen/doxygen.cfg +++ b/doxygen/doxygen.cfg @@ -826,7 +826,7 @@ WARN_NO_PARAMDOC = NO # Possible values are: NO, YES and FAIL_ON_WARNINGS. # The default value is: NO. -WARN_AS_ERROR = NO +WARN_AS_ERROR = YES # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which diff --git a/doxygen/pretty_stuff/standoxy.css b/doxygen/pretty_stuff/standoxy.css index db435bfdbb3..5627d4832c7 100644 --- a/doxygen/pretty_stuff/standoxy.css +++ b/doxygen/pretty_stuff/standoxy.css @@ -1,4 +1,3 @@ - /******** Eigen specific CSS code ************/ /**** Styles removing elements ****/ @@ -152,8 +151,7 @@ h2 { border-width: 1px; border-color: #cccccc; } -a#details + h2.groupheader { display:none; } -div.textblock { border-bottom: 1px solid #879ECB; width: 100%; } + /**** Table of content in the side-nav ****/ @@ -161,9 +159,7 @@ div.toc { margin:0; padding: 0.3em 0 0 0; width:100%; - float:none; - position:absolute; - bottom:0; + float: none; border-radius:0px; border-style: solid none none none; max-height:50%; diff --git a/doxygen/pretty_stuff/zenodo_1101101.svg b/doxygen/pretty_stuff/zenodo_1101101.svg index a5a8efcb4fa..c93aa24229a 100644 --- a/doxygen/pretty_stuff/zenodo_1101101.svg +++ b/doxygen/pretty_stuff/zenodo_1101101.svg @@ -25,4 +25,4 @@ 10.5281/zenodo.1101101 - \ No newline at end of file + diff --git a/lib/eigen_3.3.9/Eigen/src/Core/Ref.h b/lib/eigen_3.3.9/Eigen/src/Core/Ref.h index 17a1496b842..80e3caae249 100644 --- a/lib/eigen_3.3.9/Eigen/src/Core/Ref.h +++ b/lib/eigen_3.3.9/Eigen/src/Core/Ref.h @@ -10,7 +10,7 @@ #ifndef EIGEN_REF_H #define EIGEN_REF_H -namespace Eigen { +namespace Eigen { namespace internal { @@ -48,7 +48,7 @@ struct traits > }; typedef typename internal::conditional::type type; }; - + }; template @@ -86,7 +86,7 @@ template class RefBase m_stride(StrideType::OuterStrideAtCompileTime==Dynamic?0:StrideType::OuterStrideAtCompileTime, StrideType::InnerStrideAtCompileTime==Dynamic?0:StrideType::InnerStrideAtCompileTime) {} - + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(RefBase) protected: @@ -110,12 +110,12 @@ template class RefBase } else ::new (static_cast(this)) Base(expr.data(), expr.rows(), expr.cols()); - + if(Expression::IsVectorAtCompileTime && (!PlainObjectType::IsVectorAtCompileTime) && ((Expression::Flags&RowMajorBit)!=(PlainObjectType::Flags&RowMajorBit))) ::new (&m_stride) StrideBase(expr.innerStride(), StrideType::InnerStrideAtCompileTime==0?0:1); else ::new (&m_stride) StrideBase(StrideType::OuterStrideAtCompileTime==0?0:expr.outerStride(), - StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride()); + StrideType::InnerStrideAtCompileTime==0?0:expr.innerStride()); } StrideBase m_stride; diff --git a/makefile b/makefile index f34da7b164b..67aba6f3ff1 100644 --- a/makefile +++ b/makefile @@ -89,6 +89,15 @@ doxygen: doxygen -v doxygen doxygen/doxygen.cfg cp ./doxygen/pretty_stuff/eigen_navtree_hacks.js ./doc/api/html + +MAKE_DIR = $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) + +.PHONY: docker-doxygen +docker-doxygen: + docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t math-doxygen ./doxygen/docker/alpine/ + docker run -it --rm --mount "type=bind,src=$(MAKE_DIR),dst=$(MAKE_DIR)" --user "$(id -u):$(id -g)" --workdir $(MAKE_DIR) math-doxygen make doxygen + + ## # Clean up. ## diff --git a/stan/math.hpp b/stan/math.hpp index 857e499b808..7676cfb0868 100644 --- a/stan/math.hpp +++ b/stan/math.hpp @@ -1,6 +1,9 @@ #ifndef STAN_MATH_HPP #define STAN_MATH_HPP +/** + * Test Stan math doc + */ /** * \defgroup prob_dists Probability Distributions */ diff --git a/stan/math/fwd/core/std_complex.hpp b/stan/math/fwd/core/std_complex.hpp index 19fadd85bbc..fc75252078b 100644 --- a/stan/math/fwd/core/std_complex.hpp +++ b/stan/math/fwd/core/std_complex.hpp @@ -29,7 +29,7 @@ class complex> * Construct a complex number with the specified real part and a zero * imaginary part. * - * @tparam Scalar real type (must be assignable to `value_type`) + * @tparam Scalar real type (must be assignable to \ref stan::value_type ) * @param[in] re real part */ template > diff --git a/stan/math/fwd/core/std_numeric_limits.hpp b/stan/math/fwd/core/std_numeric_limits.hpp index 0c437981739..82ca6ca3f44 100644 --- a/stan/math/fwd/core/std_numeric_limits.hpp +++ b/stan/math/fwd/core/std_numeric_limits.hpp @@ -7,20 +7,20 @@ namespace std { template -struct numeric_limits > { - static const bool is_specialized; +struct numeric_limits> { + static constexpr bool is_specialized{true}; static constexpr stan::math::fvar min() { return numeric_limits::min(); } static constexpr stan::math::fvar max() { return numeric_limits::max(); } - static const int digits; - static const int digits10; - static const bool is_signed; - static const bool is_integer; - static const bool is_exact; - static const int radix; + static constexpr int digits{numeric_limits::digits}; + static constexpr int digits10{numeric_limits::digits10}; + static constexpr bool is_signed{numeric_limits::is_signed}; + static constexpr bool is_integer{numeric_limits::is_integer}; + static constexpr bool is_exact{numeric_limits::is_exact}; + static constexpr int radix{numeric_limits::radix}; static constexpr stan::math::fvar epsilon() { return numeric_limits::epsilon(); } @@ -28,17 +28,17 @@ struct numeric_limits > { return numeric_limits::round_error(); } static constexpr int max_digits10{numeric_limits::max_digits10}; - static const int min_exponent; - static const int min_exponent10; - static const int max_exponent; - static const int max_exponent10; + static constexpr int min_exponent{numeric_limits::min_exponent}; + static constexpr int min_exponent10{numeric_limits::min_exponent10}; + static constexpr int max_exponent{numeric_limits::max_exponent}; + static constexpr int max_exponent10{numeric_limits::max_exponent10}; - static const bool has_infinity; - static const bool has_quiet_NaN; - static const bool has_signaling_NaN; + static constexpr bool has_infinity{numeric_limits::has_infinity}; + static constexpr bool has_quiet_NaN{numeric_limits::has_quiet_NaN}; + static constexpr bool has_signaling_NaN{numeric_limits::has_signaling_NaN}; - static const float_denorm_style has_denorm; - static const bool has_denorm_loss; + static constexpr float_denorm_style has_denorm{numeric_limits::has_denorm}; + static constexpr bool has_denorm_loss{numeric_limits::has_denorm_loss}; static constexpr stan::math::fvar infinity() { return numeric_limits::infinity(); } @@ -52,83 +52,15 @@ struct numeric_limits > { return numeric_limits::denorm_min(); } - static const bool is_iec559; - static const bool is_bounded; - static const bool is_modulo; + static constexpr bool is_iec559{numeric_limits::is_iec559}; + static constexpr bool is_bounded{numeric_limits::is_bounded}; + static constexpr bool is_modulo{numeric_limits::is_modulo}; - static const bool traps; - static const bool tinyness_before; - static const float_round_style round_style; + static constexpr bool traps{numeric_limits::traps}; + static constexpr bool tinyness_before{numeric_limits::tinyness_before}; + static constexpr float_round_style round_style{ + numeric_limits::round_style}; }; -template -const bool numeric_limits >::is_specialized = true; -template -const int numeric_limits >::digits - = numeric_limits::digits; -template -const int numeric_limits >::digits10 - = numeric_limits::digits10; -template -const bool numeric_limits >::is_signed - = numeric_limits::is_signed; -template -const bool numeric_limits >::is_integer - = numeric_limits::is_integer; -template -const bool numeric_limits >::is_exact - = numeric_limits::is_exact; -template -const int numeric_limits >::radix - = numeric_limits::radix; -template -const int numeric_limits >::min_exponent - = numeric_limits::min_exponent; -template -const int numeric_limits >::min_exponent10 - = numeric_limits::min_exponent10; -template -const int numeric_limits >::max_exponent - = numeric_limits::max_exponent; -template -const int numeric_limits >::max_exponent10 - = numeric_limits::max_exponent10; - -template -const bool numeric_limits >::has_infinity - = numeric_limits::has_infinity; -template -const bool numeric_limits >::has_quiet_NaN - = numeric_limits::has_quiet_NaN; -template -const bool numeric_limits >::has_signaling_NaN - = numeric_limits::has_signaling_NaN; -template -const float_denorm_style numeric_limits >::has_denorm - = numeric_limits::has_denorm; -template -const bool numeric_limits >::has_denorm_loss - = numeric_limits::has_denorm_loss; - -template -const bool numeric_limits >::is_iec559 - = numeric_limits::is_iec559; -template -const bool numeric_limits >::is_bounded - = numeric_limits::is_bounded; -template -const bool numeric_limits >::is_modulo - = numeric_limits::is_modulo; - -template -const bool numeric_limits >::traps - = numeric_limits::traps; -template -const bool numeric_limits >::tinyness_before - = numeric_limits::tinyness_before; -template -const float_round_style numeric_limits >::round_style - = numeric_limits::round_style; - } // namespace std #endif diff --git a/stan/math/fwd/fun/hypergeometric_pFq.hpp b/stan/math/fwd/fun/hypergeometric_pFq.hpp index c19dd90451b..793ee89111e 100644 --- a/stan/math/fwd/fun/hypergeometric_pFq.hpp +++ b/stan/math/fwd/fun/hypergeometric_pFq.hpp @@ -13,36 +13,38 @@ namespace math { * Returns the generalised hypergeometric (pFq) function applied to the * input arguments. * - * @tparam Ta Type of Eigen vector with scalar type fvar or arithmetic - * @tparam Tb Type of Eigen vector with scalar type fvar or arithmetic - * @tparam Tz Scalar of type fvar or arithmetic + * @tparam FvarVec1 An Eigen vector with arithmetic scalar type + * @tparam FvarVec2 An Eigen vector with arithmetic scalar type + * @tparam Fvar An arithmetic scalar * @param[in] a Vector of 'a' arguments (of length p) * @param[in] b Vector of 'b' arguments (of length q) * @param[in] z Scalar z argument * @return Generalised hypergeometric function */ -template * = nullptr, - require_return_type_t* = nullptr> -inline return_type_t hypergeometric_pFq(const Ta& a, const Tb& b, - const Tz& z) { - using fvar_t = return_type_t; - ref_type_t a_ref = a; - ref_type_t b_ref = b; +template * = nullptr, + require_return_type_t* = nullptr> +inline return_type_t hypergeometric_pFq( + const FvarVec1& a, const FvarVec2& b, const Fvar& z) { + using fvar_t = return_type_t; + ref_type_t a_ref = a; + ref_type_t b_ref = b; auto grad_tuple = grad_pFq(a_ref, b_ref, z); typename fvar_t::Scalar grad = 0; - if (!is_constant::value) { - grad += dot_product(forward_as>(a_ref).d(), - std::get<0>(grad_tuple)); + if (!is_constant::value) { + grad += dot_product( + forward_as>(a_ref).d(), + std::get<0>(grad_tuple)); } - if (!is_constant::value) { - grad += dot_product(forward_as>(b_ref).d(), - std::get<1>(grad_tuple)); + if (!is_constant::value) { + grad += dot_product( + forward_as>(b_ref).d(), + std::get<1>(grad_tuple)); } - if (!is_constant::value) { - grad += forward_as>(z).d_ + if (!is_constant::value) { + grad += forward_as>(z).d_ * std::get<2>(grad_tuple); } diff --git a/stan/math/fwd/fun/inverse.hpp b/stan/math/fwd/fun/inverse.hpp index 36f8da0b4c1..2ef357c79cb 100644 --- a/stan/math/fwd/fun/inverse.hpp +++ b/stan/math/fwd/fun/inverse.hpp @@ -16,20 +16,20 @@ namespace math { /** * Forward mode specialization of calculating the inverse of the matrix. * - * @tparam T type of elements in the matrix + * @tparam EigFvarMat type of elements in the matrix * * @param m specified matrix * @return Inverse of the matrix (an empty matrix if the specified matrix has * size zero). * @throw std::invalid_argument if the matrix is not square. */ -template * = nullptr> -inline Eigen::Matrix, EigMat::RowsAtCompileTime, - EigMat::ColsAtCompileTime> -inverse(const EigMat& m) { - using T = typename value_type_t::Scalar; - constexpr int R = EigMat::RowsAtCompileTime; - constexpr int C = EigMat::ColsAtCompileTime; +template * = nullptr> +inline Eigen::Matrix, EigFvarMat::RowsAtCompileTime, + EigFvarMat::ColsAtCompileTime> +inverse(const EigFvarMat& m) { + using T = typename value_type_t::Scalar; + constexpr int R = EigFvarMat::RowsAtCompileTime; + constexpr int C = EigFvarMat::ColsAtCompileTime; check_square("inverse", "m", m); if (m.size() == 0) { @@ -39,7 +39,7 @@ inverse(const EigMat& m) { Eigen::Matrix m_deriv(m.rows(), m.cols()); Eigen::Matrix m_inv(m.rows(), m.cols()); - const Eigen::Ref>& m_ref = m; + const Eigen::Ref>& m_ref = m; for (size_type j = 0; j < m.cols(); j++) { for (size_type i = 0; i < m.rows(); i++) { m_inv.coeffRef(i, j) = m_ref.coeff(i, j).val_; diff --git a/stan/math/fwd/fun/log_softmax.hpp b/stan/math/fwd/fun/log_softmax.hpp index 7cd5f1dc684..e48cd6f647a 100644 --- a/stan/math/fwd/fun/log_softmax.hpp +++ b/stan/math/fwd/fun/log_softmax.hpp @@ -14,14 +14,14 @@ namespace math { /** * Return the log softmax of the specified vector or container of vectors. * - * @tparam T Type of input vector or matrix. + * @tparam FvarVec Type of input vector or matrix. * @param[in] x Unconstrained input vector. * @return Softmax of the input. * @throw std::domain_error If the input vector is size 0. */ -template * = nullptr> -inline auto log_softmax(const T& x) { - return apply_vector_unary::apply(x, [&](const auto& alpha) { +template * = nullptr> +inline auto log_softmax(const FvarVec& x) { + return apply_vector_unary::apply(x, [&](const auto& alpha) { using T_alpha = decltype(alpha); using T_fvar = value_type_t; using T_fvar_inner = typename T_fvar::Scalar; diff --git a/stan/math/fwd/fun/log_sum_exp.hpp b/stan/math/fwd/fun/log_sum_exp.hpp index de64e918ac6..4cd5dad2410 100644 --- a/stan/math/fwd/fun/log_sum_exp.hpp +++ b/stan/math/fwd/fun/log_sum_exp.hpp @@ -47,13 +47,14 @@ inline fvar log_sum_exp(const fvar& x1, double x2) { * \f$\log \sum_{n=1}^N \exp(x_n) = \max(x) + \log \sum_{n=1}^N \exp(x_n - * \max(x))\f$. * - * @tparam T Type of input vector or matrix. + * @tparam FvarContainer Type of input vector or matrix. * @param[in] x Matrix of specified values. * @return The log of the sum of the exponentiated vector values. */ -template * = nullptr> -inline auto log_sum_exp(const T& x) { - return apply_vector_unary>::reduce( +template * = nullptr> +inline auto log_sum_exp(const FvarContainer& x) { + return apply_vector_unary>::reduce( to_ref(x), [&](const auto& v) { using T_fvar_inner = typename value_type_t::Scalar; using mat_type = Eigen::Matrix; diff --git a/stan/math/fwd/fun/norm1.hpp b/stan/math/fwd/fun/norm1.hpp index a4c35dcddd7..7747a5e9b03 100644 --- a/stan/math/fwd/fun/norm1.hpp +++ b/stan/math/fwd/fun/norm1.hpp @@ -16,13 +16,14 @@ namespace math { /** * Compute the L1 norm of the specified vector of values. * - * @tparam T Type of input vector. + * @tparam FvarContainer Type of input vector. * @param[in] x Vector of specified values. * @return L1 norm of x. */ -template * = nullptr> -inline auto norm1(const Container& x) { - return apply_vector_unary>::reduce( +template * = nullptr> +inline auto norm1(const FvarContainer& x) { + return apply_vector_unary>::reduce( to_ref(x), [&](const auto& v) { using T_fvar_inner = typename value_type_t::Scalar; return fvar(norm1(v.val()), diff --git a/stan/math/fwd/fun/norm2.hpp b/stan/math/fwd/fun/norm2.hpp index 7d78d7b7ce7..4ea3009c858 100644 --- a/stan/math/fwd/fun/norm2.hpp +++ b/stan/math/fwd/fun/norm2.hpp @@ -14,13 +14,13 @@ namespace math { /** * Compute the L2 norm of the specified vector of values. * - * @tparam T Type of input vector. + * @tparam FvarEigVec Type of input vector. * @param[in] x Vector of specified values. * @return L2 norm of x. */ -template * = nullptr> -inline auto norm2(const Container& x) { - return apply_vector_unary>::reduce( +template * = nullptr> +inline auto norm2(const FvarEigVec& x) { + return apply_vector_unary>::reduce( to_ref(x), [&](const auto& v) { using T_fvar_inner = typename value_type_t::Scalar; T_fvar_inner res = norm2(v.val()); diff --git a/stan/math/fwd/fun/sum.hpp b/stan/math/fwd/fun/sum.hpp index 2ae7887c1ca..e7322d3380d 100644 --- a/stan/math/fwd/fun/sum.hpp +++ b/stan/math/fwd/fun/sum.hpp @@ -35,17 +35,17 @@ inline fvar sum(const std::vector>& m) { /** * Return the sum of the entries of the specified matrix. * - * @tparam T type of the matrix + * @tparam FvarEig type of the matrix * * @param m Matrix. * @return Sum of matrix entries. */ -template * = nullptr> -inline value_type_t sum(const T& m) { +template * = nullptr> +inline value_type_t sum(const FvarEig& m) { if (m.size() == 0) { return 0.0; } - const Eigen::Ref>& m_ref = m; + const Eigen::Ref>& m_ref = m; return {sum(m_ref.val()), sum(m_ref.d())}; } diff --git a/stan/math/fwd/functor/operands_and_partials.hpp b/stan/math/fwd/functor/operands_and_partials.hpp index 53e97e50416..e0fc7affa2d 100644 --- a/stan/math/fwd/functor/operands_and_partials.hpp +++ b/stan/math/fwd/functor/operands_and_partials.hpp @@ -31,7 +31,7 @@ class ops_partials_edge> { }; } // namespace internal -/** \ingroup type_trait +/** * This class builds partial derivatives with respect to a set of * operands. There are two reason for the generality of this * class. The first is to handle vector and scalar arguments @@ -124,7 +124,7 @@ class operands_and_partials> { edge7_(o7), edge8_(o8) {} - /** \ingroup type_trait + /** * Build the node to be stored on the autodiff graph. * This should contain both the value and the tangent. * diff --git a/stan/math/opencl/copy.hpp b/stan/math/opencl/copy.hpp index 51838ffa171..c87fa846391 100644 --- a/stan/math/opencl/copy.hpp +++ b/stan/math/opencl/copy.hpp @@ -41,9 +41,9 @@ namespace math { * @param src source Eigen matrix * @return matrix_cl with a copy of the data in the source matrix */ -template * = nullptr> -inline matrix_cl> to_matrix_cl(T&& src) { - return matrix_cl>(std::forward(src)); +template * = nullptr> +inline matrix_cl> to_matrix_cl(EigMat&& src) { + return matrix_cl>(std::forward(src)); } /** \ingroup opencl @@ -51,15 +51,15 @@ inline matrix_cl> to_matrix_cl(T&& src) { * destination Eigen matrix. * * @tparam T_ret destination type - * @tparam T scalar in the source matrix + * @tparam Matcl scalar in the source matrix * @param src source matrix on the OpenCL device * @return Eigen matrix with a copy of the data in the source matrix */ -template * = nullptr, - require_matrix_cl_t* = nullptr, - require_st_same* = nullptr> -inline auto from_matrix_cl(const T& src) { - using T_val = value_type_t; +template * = nullptr, + require_matrix_cl_t* = nullptr, + require_st_same* = nullptr> +inline auto from_matrix_cl(const Matcl& src) { + using T_val = value_type_t; using T_ret_col_major = Eigen::Matrix, T_ret::RowsAtCompileTime, T_ret::ColsAtCompileTime>; @@ -123,27 +123,28 @@ inline auto from_matrix_cl(const T& src) { * destination type. * * @tparam T_ret destination type - * @tparam T type of expression + * @tparam Exprcl type of expression * @param src source expression * @return Eigen matrix with a copy of the data in the source matrix */ -template * = nullptr, - require_not_matrix_cl_t* = nullptr> -inline auto from_matrix_cl(const T& src) { +template * = nullptr, + require_not_matrix_cl_t* = nullptr> +inline auto from_matrix_cl(const Exprcl& src) { return from_matrix_cl(src.eval()); } /** \ingroup opencl * Copy A 1 by 1 source matrix from the Device to the host. - * @tparam T An arithmetic type to pass the value from the OpenCL matrix to. + * @tparam Arith An arithmetic type to pass the value from the OpenCL matrix to. * @param src A 1x1 matrix on the device. * @return dst Arithmetic to receive the matrix_cl value. */ -template * = nullptr, - require_same_t* = nullptr> -inline T_dst from_matrix_cl(const matrix_cl& src) { - T dst; +template * = nullptr, + require_same_t* = nullptr> +inline DstArith from_matrix_cl(const matrix_cl& src) { + Arith dst; check_size_match("from_matrix_cl", "src.rows()", src.rows(), "dst.rows()", 1); check_size_match("from_matrix_cl", "src.cols()", src.cols(), @@ -152,7 +153,8 @@ inline T_dst from_matrix_cl(const matrix_cl& src) { cl::Event copy_event; const cl::CommandQueue queue = opencl_context.queue(); queue.enqueueReadBuffer(src.buffer(), opencl_context.in_order(), 0, - sizeof(T), &dst, &src.write_events(), ©_event); + sizeof(Arith), &dst, &src.write_events(), + ©_event); copy_event.wait(); src.clear_write_events(); } catch (const cl::Error& e) { @@ -165,18 +167,18 @@ inline T_dst from_matrix_cl(const matrix_cl& src) { * Copies the source matrix that is stored on the OpenCL device to the * destination `std::vector`. * - * @tparam T_dst destination type - * @tparam T scalar in the source matrix + * @tparam DstStdVec destination type + * @tparam Arith scalar in the source matrix * @param src source matrix on the OpenCL device * @return `std::vector` with a copy of the data in the source matrix */ -template * = nullptr, - require_all_st_same* = nullptr> -inline T_dst from_matrix_cl(const matrix_cl& src) { +template * = nullptr, + require_all_st_same* = nullptr> +inline DstStdVec from_matrix_cl(const matrix_cl& src) { check_size_match("from_matrix_cl", "src.cols()", src.cols(), "dst.cols()", 1); - T_dst dst(src.rows()); + DstStdVec dst(src.rows()); if (src.rows() == 0) { return dst; } @@ -184,7 +186,7 @@ inline T_dst from_matrix_cl(const matrix_cl& src) { cl::Event copy_event; const cl::CommandQueue queue = opencl_context.queue(); queue.enqueueReadBuffer(src.buffer(), opencl_context.in_order(), 0, - sizeof(T) * src.rows(), dst.data(), + sizeof(Arith) * src.rows(), dst.data(), &src.write_events(), ©_event); copy_event.wait(); src.clear_write_events(); @@ -198,18 +200,19 @@ inline T_dst from_matrix_cl(const matrix_cl& src) { * Copies the source matrix that is stored on the OpenCL device to the * destination `std::vector` containing Eigen vectors. * - * @tparam T_dst destination type - * @tparam T scalar in the source matrix + * @tparam DstStdVecEig destination type + * @tparam Arith scalar in the source matrix * @param src source matrix on the OpenCL device * @return `std::vector` containing Eigen vectors with a copy of the data in the * source matrix */ -template * = nullptr, - require_all_st_same* = nullptr> -inline T_dst from_matrix_cl(const matrix_cl& src) { - Eigen::Matrix tmp = from_matrix_cl(src); - T_dst dst; +template * = nullptr, + require_all_st_same* = nullptr> +inline DstStdVecEig from_matrix_cl(const matrix_cl& src) { + Eigen::Matrix tmp + = from_matrix_cl(src); + DstStdVecEig dst; dst.reserve(src.cols()); for (int i = 0; i < src.cols(); i++) { dst.emplace_back(tmp.col(i)); @@ -221,14 +224,15 @@ inline T_dst from_matrix_cl(const matrix_cl& src) { * Copies the source kernel generator expression or matrix that is stored on the * OpenCL device to the destination Eigen matrix. * - * @tparam T source type + * @tparam Exprcl source type * @param src expression or source matrix on the OpenCL device * @return Eigen matrix with a copy of the data in the source matrix */ -template * = nullptr> -auto from_matrix_cl(const T& src) { +template * = nullptr> +auto from_matrix_cl(const Exprcl& src) { return from_matrix_cl< - Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic>>(src); + Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic>>( + src); } /** \ingroup opencl diff --git a/stan/math/opencl/kernel_cl.hpp b/stan/math/opencl/kernel_cl.hpp index de2706cccd6..f04e9037085 100644 --- a/stan/math/opencl/kernel_cl.hpp +++ b/stan/math/opencl/kernel_cl.hpp @@ -74,19 +74,8 @@ inline void assign_event(const cl::Event& e, K& m) { } /** \ingroup kernel_executor_opencl - * Adds the event to any \c matrix_cls in the arguments depending on whether - * they are \c in_buffer, \c out_buffer, or \c in_out_buffers. - * @tparam Arg Arguments given during kernel creation that specify the kernel - * signature. - * @tparam Args Arguments given during kernel creation that specify the kernel - * signature. - * @tparam CallArg First argument type used to call the kernel - * @tparam CallArgs Other argument types used to call the kernel. - * @param new_event The cl::Event generated involving the arguments. - * @param m Arguments to the kernel that may be \c matrix_cls or not. - * Non-matrices are ignored. - * @param args Arguments to the kernel that may be matrices or not. - * Non-matrices are ignored. + * Overload for passing a `cl::Event` which is a no-op + * @tparam T A `cl::Event` type. */ template * = nullptr> inline void assign_events(const T&) {} diff --git a/stan/math/opencl/kernel_generator/as_column_vector_or_scalar.hpp b/stan/math/opencl/kernel_generator/as_column_vector_or_scalar.hpp index cc995636933..3ae5e0b9fde 100644 --- a/stan/math/opencl/kernel_generator/as_column_vector_or_scalar.hpp +++ b/stan/math/opencl/kernel_generator/as_column_vector_or_scalar.hpp @@ -315,14 +315,14 @@ class as_column_vector_or_scalar_ /** * as_column_vector_or_scalar of a kernel generator expression. * - * @tparam T type of argument + * @tparam Matcl type of argument * @param a input argument (must be a row or a column vector) * @return as_column_vector_or_scalar of given expression */ -template * = nullptr> -inline auto as_column_vector_or_scalar(T&& a) { - auto&& a_operation = as_operation_cl(std::forward(a)).deep_copy(); +template * = nullptr> +inline auto as_column_vector_or_scalar(Matcl&& a) { + auto&& a_operation = as_operation_cl(std::forward(a)).deep_copy(); return as_column_vector_or_scalar_< std::remove_reference_t>(std::move(a_operation)); } diff --git a/stan/math/opencl/kernel_generator/cast.hpp b/stan/math/opencl/kernel_generator/cast.hpp index c56fcc23fb7..32b1260f3eb 100644 --- a/stan/math/opencl/kernel_generator/cast.hpp +++ b/stan/math/opencl/kernel_generator/cast.hpp @@ -37,7 +37,8 @@ class cast_ : public operation_cl, Scal, T> { /** * Constructor - * @param args argument expression(s) + * @tparam A set of opencl expressions + * @param arg argument expression(s) */ explicit cast_(T&& arg) : base(std::forward(arg)) {} @@ -46,7 +47,7 @@ class cast_ : public operation_cl, Scal, T> { * @param row_index_name row index variable name * @param col_index_name column index variable name * @param view_handled whether whether caller already handled matrix view - * @param var_names_arg variable names of the nested expressions + * @param var_name_arg variable names of the nested expressions * @return part of kernel with code for this expression */ inline kernel_parts generate(const std::string& row_index_name, @@ -70,6 +71,7 @@ class cast_ : public operation_cl, Scal, T> { /** * Typecast a kernel generator expression scalar. * + * @tparam Scalar a user invoked type to cast to. * @tparam T type of argument * @param a input argument * @return Typecast of given expression diff --git a/stan/math/opencl/kernel_generator/common_return_scalar.hpp b/stan/math/opencl/kernel_generator/common_return_scalar.hpp index 70888d5abe1..c3cac8b6222 100644 --- a/stan/math/opencl/kernel_generator/common_return_scalar.hpp +++ b/stan/math/opencl/kernel_generator/common_return_scalar.hpp @@ -5,7 +5,7 @@ namespace stan { namespace math { /** - * @ingroup type_traits + * @ingroup type_trait * Wrapper for `std::common_type_t` */ template diff --git a/stan/math/opencl/kernel_generator/operation_cl_lhs.hpp b/stan/math/opencl/kernel_generator/operation_cl_lhs.hpp index 3410dd24eb4..bce887bf8fd 100644 --- a/stan/math/opencl/kernel_generator/operation_cl_lhs.hpp +++ b/stan/math/opencl/kernel_generator/operation_cl_lhs.hpp @@ -104,7 +104,6 @@ class operation_cl_lhs : public operation_cl, /** * Evaluates an expression and assigns it to this. * @tparam T_expression type of expression - * @param rhs input expression */ template , expression.evaluate_into(derived()); return derived(); } - // Copy assignment delegates to general assignment operator. If we didn't - // implement this, we would get ambiguities in overload resolution with - // implicitly generated one + /* + * Copy assignment delegates to general assignment operator. If we didn't + * implement this, we would get ambiguities in overload resolution with + * implicitly generated one + * @param rhs input expression + */ inline const operation_cl_lhs& operator=( const operation_cl_lhs& rhs) const { return operator=&>(rhs); diff --git a/stan/math/opencl/kernels/device_functions/atomic_add_double.hpp b/stan/math/opencl/kernels/device_functions/atomic_add_double.hpp index 8ae6977ba6b..58a1de75892 100644 --- a/stan/math/opencl/kernels/device_functions/atomic_add_double.hpp +++ b/stan/math/opencl/kernels/device_functions/atomic_add_double.hpp @@ -21,8 +21,8 @@ static const char *atomic_add_double_device_function * Code is taken from: * https://stackoverflow.com/questions/31863587/atomic-operations-with-double-opencl * - * @param a pointer to value to add to - * @param b value to add + * @param val pointer to value to add to + * @param delta value to add */ void atomic_add_double(__global double *val, double delta) { union { @@ -46,8 +46,8 @@ static const char *atomic_add_double_device_function * Code is taken from: * https://stackoverflow.com/questions/31863587/atomic-operations-with-double-opencl * - * @param a pointer to value to add to - * @param b value to add + * @param val pointer to value to add to + * @param delta value to add */ void local_atomic_add_double(__local double *val, double delta) { union { diff --git a/stan/math/opencl/kernels/indexing_rev.hpp b/stan/math/opencl/kernels/indexing_rev.hpp index f4a601396e7..5f36157c5da 100644 --- a/stan/math/opencl/kernels/indexing_rev.hpp +++ b/stan/math/opencl/kernels/indexing_rev.hpp @@ -26,7 +26,7 @@ static const std::string indexing_rev_global_atomic_kernel_code = STRINGIFY( * @param[in,out] adj adjoint to increment * @param index * @param res adjoint of the result of indexing - * @param batch_size Number of matrices in the batch. + * @param size Number of matrices in the batch. * @note Code is a const char* held in * add_batch_kernel_code. */ @@ -64,14 +64,16 @@ static const std::string indexing_rev_local_atomic_kernel_code = STRINGIFY( * @param[in,out] adj adjoint to increment * @param index * @param res adjoint of the result of indexing - * @param batch_size Number of matrices in the batch. + * @param adj_loc + * @param index_size + * @param adj_size Number of matrices in the batch. * @note Code is a const char* held in * add_batch_kernel_code. */ - __kernel void indexing_rev(__global double* adj, const __global int* index, - const __global double* res, - __local double* adj_loc, int index_size, - int adj_size) { + __kernel void indexing_rev_local_atomic( + __global double* adj, const __global int* index, + const __global double* res, __local double* adj_loc, int index_size, + int adj_size) { const int gid = get_global_id(0); const int lid = get_local_id(0); const int gsize = get_global_size(0); @@ -116,14 +118,16 @@ static const std::string indexing_rev_local_independent_kernel_code = STRINGIFY( * @param[in,out] adj adjoint to increment * @param index * @param res adjoint of the result of indexing - * @param batch_size Number of matrices in the batch. + * @param adj_loc + * @param index_size + * @param adj_size Number of matrices in the batch. * @note Code is a const char* held in * add_batch_kernel_code. */ - __kernel void indexing_rev(__global double* adj, const __global int* index, - const __global double* res, - __local double* adj_loc, int index_size, - int adj_size) { + __kernel void indexing_rev_local_independent( + __global double* adj, const __global int* index, + const __global double* res, __local double* adj_loc, int index_size, + int adj_size) { const int gid = get_global_id(0); const int lid = get_local_id(0); const int gsize = get_global_size(0); diff --git a/stan/math/opencl/kernels/mrrr.hpp b/stan/math/opencl/kernels/mrrr.hpp index 3b32b80523b..5575a6a8d75 100644 --- a/stan/math/opencl/kernels/mrrr.hpp +++ b/stan/math/opencl/kernels/mrrr.hpp @@ -38,8 +38,8 @@ static const char* eigenvals_bisect_kernel_code = STRINGIFY( /** * Calculates i-th largest eigenvalue of tridiagonal matrix represented by a * LDL decomposition using bisection. - * @param l Subdiagonal of L. - * @param d Diagonal of D. + * @param diagonal diagonal of T + * @param subdiagonal_squared element-wise squared subdiagonal of T * @param[out] low_res Resulting low bounds on eigenvalues. * @param[out] high_res Resulting high bounds on eigenvalues. * @param min_eigval Lower bound on all eigenvalues. @@ -154,6 +154,7 @@ static const char* eigenvals_bisect_kernel_code = STRINGIFY( * @param min_eigval initial lower bound on eigenvalues * @param max_eigval initial upper bound on eigenvalues * @param shift shift of the LDL decomposition + * @param do_refine */ __kernel void eigenvals( const __global double* diagonal, diff --git a/stan/math/opencl/matrix_cl.hpp b/stan/math/opencl/matrix_cl.hpp index 0ea5e84ba35..e1778508eb4 100644 --- a/stan/math/opencl/matrix_cl.hpp +++ b/stan/math/opencl/matrix_cl.hpp @@ -482,7 +482,7 @@ class matrix_cl : public matrix_cl_base { /** * Assignment of `arena_matrix_cl`. * @tparam Expr type of the expression - * @param expression expression + * @param other expression */ // defined in rev/arena_matrix_cl.hpp matrix_cl& operator=(const arena_matrix_cl& other); @@ -576,7 +576,6 @@ class matrix_cl : public matrix_cl_base { * @tparam No_heap whether to move the object to heap first * @tparam U type of object * @param obj object - * @return event for the copy */ template * = nullptr> void initialize_buffer_no_heap_if(U&& obj) { diff --git a/stan/math/opencl/mrrr.hpp b/stan/math/opencl/mrrr.hpp index 593d3432b20..03b55fc30e8 100644 --- a/stan/math/opencl/mrrr.hpp +++ b/stan/math/opencl/mrrr.hpp @@ -285,13 +285,15 @@ struct mrrr_task { * using multiple relatively robust representations (MRRR) algorithm. Use * `tridiagonal_eigensolver` if any subdiagonal element might be (very close to) * zero. + * @tparam need_eigenvectors * @param diagonal Diagonal of of T. * @param subdiagonal Subdiagonal of T. * @param[out] eigenvalues Eigenvlues. * @param[out] eigenvectors Eigenvectors. * @param min_rel_sep Minimal relative separation of eigenvalues before * computing eigenvectors. - * @param max_ele_growth Maximal desired element growth of LDL decompositions. + * @param maximum_ele_growth Maximal desired element growth of LDL + * decompositions. */ template inline void mrrr_cl(const Eigen::Ref diagonal, @@ -443,10 +445,10 @@ inline void mrrr_cl(const Eigen::Ref diagonal, * Calculates eigenvalues and eigenvectors of a tridiagonal matrix T using MRRR * algorithm. If a subdiagonal element is close to zero compared to neighbors on * diagonal, the problem can be split into smaller ones. - * @param diagonal Diagonal of of T. - * @param subdiagonal Subdiagonal of T. - * @param[out] eigenvalues Eigenvlues. - * @param[out] eigenvectors Eigenvectors. + * @param diagonal_cl Diagonal of of T. + * @param subdiagonal_cl Subdiagonal of T. + * @param[out] eigenvalues_cl Eigenvlues. + * @param[out] eigenvectors_cl Eigenvectors. * @param split_threshold Threshold for splitting the problem */ template diff --git a/stan/math/opencl/prim/cumulative_sum.hpp b/stan/math/opencl/prim/cumulative_sum.hpp index 6027052c0f5..eeade54229d 100644 --- a/stan/math/opencl/prim/cumulative_sum.hpp +++ b/stan/math/opencl/prim/cumulative_sum.hpp @@ -12,12 +12,12 @@ namespace math { /** * Return the cumulative sum of the specified vector. * - * The cumulative sum of a vector of values \code{x} is the + * The cumulative sum of a vector of values `x` is the * - * \code x[0], x[1] + x[2], ..., x[1] + , ..., + x[x.size()-1] @endcode + * ` x[0], x[1] + x[2], ..., x[1] + , ..., + x[x.size()-1] ` * * @tparam T type of the vector - * @param x Vector of values. + * @param v Vector of values. * @return Cumulative sum of values. */ template std::invalid_argument if the * input matrices do not have matching dimensions * @@ -46,10 +44,9 @@ inline void divide_columns(matrix_cl& A, const matrix_cl& B) { * * @tparam T1 Type of first matrix * @tparam T2 Type of the divisor - * @param A Matrix to divide + * @param[in,out] A Matrix to divide inplace * @param divisor scalar to divide by * - * @return element-wise division of \c A by \c divisor. * */ template > diff --git a/stan/math/opencl/prim/gp_dot_prod_cov.hpp b/stan/math/opencl/prim/gp_dot_prod_cov.hpp index 5d7f4bc3f02..60691086a9a 100644 --- a/stan/math/opencl/prim/gp_dot_prod_cov.hpp +++ b/stan/math/opencl/prim/gp_dot_prod_cov.hpp @@ -17,7 +17,6 @@ namespace math { * @tparam T2 Type of sigma * @param x input matrix * @param sigma standard deviation - * @param length_scale length scale * * @return dot product covariance matrix that is positive semi-definite */ @@ -40,7 +39,7 @@ inline auto gp_dot_prod_cov(const T_x& x, const T_sigma sigma) { * @tparam T2 Type of sigma * @param x input matrix * @param sigma standard deviation - * @param length_scale length scale + * @param y length scale * * @return dot product covariance matrix */ diff --git a/stan/math/opencl/prim/gp_exponential_cov.hpp b/stan/math/opencl/prim/gp_exponential_cov.hpp index 8ed99d235d5..69eac9589eb 100644 --- a/stan/math/opencl/prim/gp_exponential_cov.hpp +++ b/stan/math/opencl/prim/gp_exponential_cov.hpp @@ -14,22 +14,22 @@ namespace math { /** \ingroup opencl * Matern exponential kernel on the GPU. * - * @tparam T1 Type of the matrix - * @tparam T2 Type of sigma - * @tparam T3 Type of length_scale + * @tparam Matcl1 Type of the matrix + * @tparam Arith2 Type of sigma + * @tparam Arith3 Type of length_scale * @param x input vector or matrix * @param sigma standard deviation * @param length_scale length scale * * @return dot product covariance matrix that is positive semi-definite */ -template * = nullptr, - require_all_arithmetic_t* = nullptr> -inline matrix_cl> gp_exponential_cov( - const T1& x, const T2 sigma, const T3 length_scale) { +template * = nullptr, + require_all_arithmetic_t* = nullptr> +inline matrix_cl> gp_exponential_cov( + const Matcl1& x, const Arith2 sigma, const Arith3 length_scale) { const auto& x_eval = x.eval(); - matrix_cl> res(x.cols(), x.cols()); + matrix_cl> res(x.cols(), x.cols()); int block_size = 16; int n_blocks = (x.cols() + block_size - 1) / block_size; int blocked_size = block_size * n_blocks; @@ -50,10 +50,10 @@ inline matrix_cl> gp_exponential_cov( * This function is for the cross covariance * matrix needed to compute the posterior predictive density. * - * @tparam T1 Type of the first matrix - * @tparam T2 Type of the second matrix - * @tparam T3 Type of sigma - * @tparam T4 Type of length scale + * @tparam Matcl1 Type of the first matrix + * @tparam Matcl2 Type of the second matrix + * @tparam Arith3 Type of sigma + * @tparam Arith4 Type of length scale * @param x first input vector or matrix * @param y second input vector or matrix * @param sigma standard deviation @@ -61,13 +61,16 @@ inline matrix_cl> gp_exponential_cov( * * @return dot product covariance matrix */ -template * = nullptr, - require_all_arithmetic_t* = nullptr> -inline matrix_cl> gp_exponential_cov( - const T1& x, const T2& y, const T3 sigma, const T4 length_scale) { +template < + typename Matcl1, typename Matcl2, typename Arith3, typename Arith4, + require_all_kernel_expressions_and_none_scalar_t* = nullptr, + require_all_arithmetic_t* = nullptr> +inline matrix_cl> +gp_exponential_cov(const Matcl1& x, const Matcl2& y, const Arith3 sigma, + const Arith4 length_scale) { check_size_match("gp_exponential_cov_cross", "x", x.rows(), "y", y.rows()); - matrix_cl> res(x.cols(), y.cols()); + matrix_cl> res(x.cols(), + y.cols()); const auto& x_eval = x.eval(); const auto& y_eval = y.eval(); int block_size = 16; @@ -89,22 +92,23 @@ inline matrix_cl> gp_exponential_cov( /** \ingroup opencl * Squared exponential kernel on the GPU. * - * @tparam T1 Type of the matrix - * @tparam T2 Type of sigma - * @tparam T3 Type of length_scale + * @tparam Matcl1 Type of the matrix + * @tparam Arith2 Type of sigma + * @tparam Matcl3 Type of length_scale * @param x input vector or matrix * @param sigma standard deviation * @param length_scale length scale * * @return Squared distance between elements of x. */ -template * = nullptr, - require_all_arithmetic_t* = nullptr> -inline matrix_cl> gp_exponential_cov( - const T1& x, const T2 sigma, const T3 length_scale) { +template < + typename Matcl1, typename Arith2, typename Matcl3, + require_all_kernel_expressions_and_none_scalar_t* = nullptr, + require_all_arithmetic_t* = nullptr> +inline matrix_cl> gp_exponential_cov( + const Matcl1& x, const Arith2 sigma, const Matcl3& length_scale) { const auto& x_eval = elt_divide(x, rowwise_broadcast(length_scale)).eval(); - matrix_cl> res(x.cols(), x.cols()); + matrix_cl> res(x.cols(), x.cols()); int block_size = 16; int n_blocks = (x.cols() + block_size - 1) / block_size; int blocked_size = block_size * n_blocks; @@ -125,10 +129,10 @@ inline matrix_cl> gp_exponential_cov( * This function is for the cross covariance * matrix needed to compute the posterior predictive density. * - * @tparam T1 Type of the first matrix - * @tparam T2 Type of the second matrix - * @tparam T3 Type of sigma - * @tparam T4 Type of length scale + * @tparam Matcl1 Type of the first matrix + * @tparam Matcl2 Type of the second matrix + * @tparam Arith3 Type of sigma + * @tparam Matcl4 Type of length scale * @param x first input vector or matrix * @param y second input vector or matrix * @param sigma standard deviation @@ -136,14 +140,16 @@ inline matrix_cl> gp_exponential_cov( * * @return Squared distance between elements of x and y. */ -template < - typename T1, typename T2, typename T3, typename T4, - require_all_kernel_expressions_and_none_scalar_t* = nullptr, - require_all_arithmetic_t* = nullptr> -inline matrix_cl> gp_exponential_cov( - const T1& x, const T2& y, const T3 sigma, const T4 length_scale) { +template * = nullptr, + require_all_arithmetic_t* = nullptr> +inline matrix_cl> +gp_exponential_cov(const Matcl1& x, const Matcl2& y, const Arith3 sigma, + const Matcl4& length_scale) { check_size_match("gp_exponential_cov_cross", "x", x.rows(), "y", y.rows()); - matrix_cl> res(x.cols(), y.cols()); + matrix_cl> res(x.cols(), + y.cols()); const auto& x_eval = elt_divide(x, rowwise_broadcast(length_scale)).eval(); const auto& y_eval = elt_divide(y, rowwise_broadcast(length_scale)).eval(); int block_size = 16; diff --git a/stan/math/opencl/prim/lub_constrain.hpp b/stan/math/opencl/prim/lub_constrain.hpp index 212e89537fe..73c57802729 100644 --- a/stan/math/opencl/prim/lub_constrain.hpp +++ b/stan/math/opencl/prim/lub_constrain.hpp @@ -19,7 +19,7 @@ namespace math { * *

\f$f(x) = L + (U - L) \mbox{logit}^{-1}(x)\f$ * - * @tparam T matrix expression type + * @tparam MatclT matrix expression type * @tparam L lower bound expression type * @tparam U upper bound expression type * @param[in] x Free matrix to transform. @@ -29,10 +29,11 @@ namespace math { * the free matrix. * @throw std::domain_error if ub <= lb */ -template * = nullptr, +template * = nullptr, require_all_kernel_expressions_t* = nullptr> -inline matrix_cl lub_constrain(const T& x, const L& lb, const U& ub) { +inline matrix_cl lub_constrain(const MatclT& x, const L& lb, + const U& ub) { auto diff = ub - lb; auto lb_inf = lb == NEGATIVE_INFTY; auto ub_inf = ub == INFTY; @@ -57,7 +58,7 @@ inline matrix_cl lub_constrain(const T& x, const L& lb, const U& ub) { * *

\f$f(x) = L + (U - L) \mbox{logit}^{-1}(x)\f$ * - * @tparam T matrix expression type + * @tparam MatclT matrix expression type * @tparam L lower bound expression type * @tparam U upper bound expression type * @param[in] x Free matrix to transform. @@ -68,11 +69,11 @@ inline matrix_cl lub_constrain(const T& x, const L& lb, const U& ub) { * the free matrix. * @throw std::domain_error if ub <= lb */ -template * = nullptr, +template * = nullptr, require_all_kernel_expressions_t* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub, - return_type_t& lp) { +inline auto lub_constrain(const MatclT& x, const L& lb, const U& ub, + return_type_t& lp) { auto diff = ub - lb; auto lb_inf = lb == NEGATIVE_INFTY; auto ub_inf = ub == INFTY; diff --git a/stan/math/opencl/prim/multiply.hpp b/stan/math/opencl/prim/multiply.hpp index 5198266f806..d5f9feb5565 100644 --- a/stan/math/opencl/prim/multiply.hpp +++ b/stan/math/opencl/prim/multiply.hpp @@ -111,31 +111,35 @@ inline matrix_cl> operator*(const T_a& a, /** * Matrix multiplication of a scalar and a kernel generator expressions. - * @tparam T_a type of scalar - * @tparam T_b type of the kernel generator expression + * @tparam Scalara type of scalar + * @tparam Matclb type of the kernel generator expression * @param a scalar * @param b expression * @return Matrix product of given arguments */ -template * = nullptr, - require_all_kernel_expressions_and_none_scalar_t* = nullptr, - require_all_not_var_t* = nullptr> -inline matrix_cl> multiply(const T_a& a, const T_b& b) { +template * = nullptr, + require_all_kernel_expressions_and_none_scalar_t* = nullptr, + require_all_not_var_t* = nullptr> +inline matrix_cl> multiply(const Scalara& a, + const Matclb& b) { return a * b; } /** * Matrix multiplication of a scalar and a kernel generator expressions. - * @tparam T_a type of the kernel generator expression - * @tparam T_b type of scalar + * @tparam Matcla type of the kernel generator expression + * @tparam Scalarb type of scalar * @param a expression * @param b scalar * @return Matrix product of given arguments */ -template * = nullptr, - require_all_kernel_expressions_and_none_scalar_t* = nullptr, - require_all_not_var_t* = nullptr> -inline matrix_cl> multiply(const T_a& a, const T_b& b) { +template * = nullptr, + require_all_kernel_expressions_and_none_scalar_t* = nullptr, + require_all_not_var_t* = nullptr> +inline matrix_cl> multiply(const Matcla& a, + const Scalarb& b) { return a * b; } diff --git a/stan/math/opencl/prim/normal_id_glm_lpdf.hpp b/stan/math/opencl/prim/normal_id_glm_lpdf.hpp index b999c25e535..5718c96d053 100644 --- a/stan/math/opencl/prim/normal_id_glm_lpdf.hpp +++ b/stan/math/opencl/prim/normal_id_glm_lpdf.hpp @@ -34,14 +34,14 @@ namespace math { * value (wich will be broadcast - used for all instances); * @tparam T_x_cl type of the design matrix * @tparam T_alpha_cl type of the intercept(s); - * this can be a (optionally `var_value` containing) `matrix_cl` column vector - * (of the same length as y) of intercepts or a scalar (for models with - * constant intercept) + * this can be a (optionally \ref stan::math::var_value containing) `matrix_cl` + * column vector (of the same length as y) of intercepts or a scalar (for models + * with constant intercept) * @tparam T_beta_cl type of the weight vector; - * (optionally `var_value` containing) `matrix_cl` column vector + * (optionally \ref stan::math::var_value containing) `matrix_cl` column vector * @tparam T_sigma_cl type of the (positive) scale(s); - * (optionally `var_value` containing) `matrix_cl` column vector (of the same - * length as y, for heteroskedasticity) or a scalar. + * (optionally \ref stan::math::var_value containing) `matrix_cl` column vector + * (of the same length as y, for heteroskedasticity) or a scalar. * @param y scalar or vector parameter on OpenCL device. If it is a scalar it * will be broadcast - used for all instances. * @param x design matrix on OpenCL device. This overload does not support diff --git a/stan/math/opencl/prim/sign.hpp b/stan/math/opencl/prim/sign.hpp index 39bf4398071..832088dcd1c 100644 --- a/stan/math/opencl/prim/sign.hpp +++ b/stan/math/opencl/prim/sign.hpp @@ -9,13 +9,14 @@ namespace math { /** * Returns signs of the arguments. - * @tparam T type of the argument (`matrix_cl` or kernel generator expression) + * @tparam Matcl type of the argument (`matrix_cl` or kernel generator + * expression) * @param x the argument * @return sign of `x` */ -template * = nullptr> -auto sign(const T& x) { +template * = nullptr> +auto sign(const Matcl& x) { return select(x == 0, 0, select(x < 0, -1, 1)); } diff --git a/stan/math/opencl/prim/size.hpp b/stan/math/opencl/prim/size.hpp index 37d037a2943..623c7b1e895 100644 --- a/stan/math/opencl/prim/size.hpp +++ b/stan/math/opencl/prim/size.hpp @@ -13,9 +13,9 @@ namespace math { * @param m input to determine size of * @return number of elements in m */ -template * = nullptr> -size_t size(const T& m) { +template * = nullptr> +inline size_t size(const Matcl& m) { return m.rows() * m.cols(); } diff --git a/stan/math/opencl/prim/sum.hpp b/stan/math/opencl/prim/sum.hpp index 56bcf4e38c1..a2f1d194f65 100644 --- a/stan/math/opencl/prim/sum.hpp +++ b/stan/math/opencl/prim/sum.hpp @@ -12,18 +12,18 @@ namespace math { /** * Calculates sum of given kernel generator expression. - * @tparam T type of the expression + * @tparam Matcl type of the expression * @param m expression to sum * @return sum of given expression */ -template * = nullptr> -value_type_t sum(const T& m) { - if (is_matrix_cl::value && m.size() < 1000) { +template * = nullptr> +value_type_t sum(const Matcl& m) { + if (is_matrix_cl::value && m.size() < 1000) { // for small matrices running another kernel is not worth it return sum(from_matrix_cl(m)); } - matrix_cl> res; + matrix_cl> res; if (m.rows() <= 8) { // without transpose we would use just a few threads in a work group res = sum_2d(transpose(m)); diff --git a/stan/math/opencl/qr_decomposition.hpp b/stan/math/opencl/qr_decomposition.hpp index ca4500901d6..7c375352c8d 100644 --- a/stan/math/opencl/qr_decomposition.hpp +++ b/stan/math/opencl/qr_decomposition.hpp @@ -22,8 +22,11 @@ namespace math { * Calculates QR decomposition of A using the block Householder algorithm. * * The implementation is based on the article: - * \link - * https://cpb-us-w2.wpmucdn.com/sites.gatech.edu/dist/5/462/files/2016/08/Kerr_Campbell_Richards_QRD_on_GPUs.pdf + * Kerr, Andrew, et al. “QR Decomposition on Gpus.” + * Proceedings of 2nd Workshop on General Purpose Processing on Graphics + * Processing Units - GPGPU-2, 2009, + * https://doi.org/10.1145/1513895.1513904. + * * @tparam need_Q whether Q needs to be calculated (default true) * @param A matrix to factorize * @param Q out the orthonormal matrix diff --git a/stan/math/opencl/rev/copy.hpp b/stan/math/opencl/rev/copy.hpp index dbd2994c262..e2f082c6984 100644 --- a/stan/math/opencl/rev/copy.hpp +++ b/stan/math/opencl/rev/copy.hpp @@ -108,14 +108,14 @@ inline var_value>>> to_matrix_cl( * destination var containing Eigen matrix. * * @tparam T_dst destination type - * @tparam T type of the matrix or expression on the OpenCL device + * @tparam T_src type of the matrix or expression on the OpenCL device * @param a source matrix_cl or expression * @return var with a copy of the data on the host */ -template * = nullptr, - require_all_kernel_expressions_t* = nullptr> -inline T_dst from_matrix_cl(const var_value& a) { + require_all_kernel_expressions_t* = nullptr> +inline T_dst from_matrix_cl(const var_value& a) { return make_callback_var( from_matrix_cl>(a.val()), @@ -147,20 +147,20 @@ inline T_dst from_matrix_cl(const var_value& a) { * Copies the source var that has data stored on the OpenCL device to * destination `std::vector` containing vars. * - * @tparam T_dst destination type - * @tparam T type of the matrix or expression on the OpenCL device + * @tparam T_var_stdvec_dst destination type + * @tparam T_inner type of the matrix or expression on the OpenCL device * @param a source matrix_cl or expression * @return var with a copy of the data on the host */ -template * = nullptr, - require_all_stan_scalar_t>* = nullptr, - require_all_kernel_expressions_t* = nullptr> -inline T_dst from_matrix_cl(const var_value& a) { +template * = nullptr, + require_all_stan_scalar_t>* = nullptr, + require_all_kernel_expressions_t* = nullptr> +inline T_var_stdvec_dst from_matrix_cl(const var_value& a) { check_size_match("from_matrix_cl>", "src.cols()", a.cols(), "dst.cols()", 1); std::vector val = from_matrix_cl>(a.val()); - arena_t res(val.begin(), val.end()); + arena_t res(val.begin(), val.end()); reverse_pass_callback([a, res]() mutable { a.adj() += to_matrix_cl(as_column_vector_or_scalar(res).adj()); }); @@ -172,17 +172,18 @@ inline T_dst from_matrix_cl(const var_value& a) { * destination std::vector containing either Eigen vectors of vars or vars * containing Eigen vectors. * - * @tparam T_dst destination type + * @tparam T_stdvec_dst destination type * @tparam T type of the matrix or expression on the OpenCL device * @param a source matrix_cl or expression * @return var with a copy of the data on the host */ -template * = nullptr, - require_rev_vector_t>* = nullptr, +template * = nullptr, + require_rev_vector_t>* = nullptr, require_all_kernel_expressions_t* = nullptr> -inline T_dst from_matrix_cl(const var_value& a) { +inline T_stdvec_dst from_matrix_cl(const var_value& a) { Eigen::MatrixXd val = from_matrix_cl(a.val()); - arena_t res; + arena_t res; res.reserve(a.cols()); for (int i = 0; i < a.cols(); i++) { res.emplace_back(val.col(i)); diff --git a/stan/math/opencl/rev/multiply.hpp b/stan/math/opencl/rev/multiply.hpp index ffcdb4a1ba5..67c702c12a5 100644 --- a/stan/math/opencl/rev/multiply.hpp +++ b/stan/math/opencl/rev/multiply.hpp @@ -18,26 +18,26 @@ namespace math { /** * Matrix multiplication of two reverse mode matrices and/or kernel generator * expressions. - * @tparam T_a type of first expression + * @tparam Matcl_a type of first expression * @tparam T_b type of second expression * @param A first expression * @param B second expression * @return Matrix product of given arguments */ -template < - typename T_a, typename T_b, - require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, - require_any_var_t* = nullptr> -inline auto multiply(T_a&& A, T_b&& B) { +template * = nullptr, + require_any_var_t* = nullptr> +inline auto multiply(Matcl_a&& A, T_b&& B) { check_size_match("multiply ((OpenCL))", "A.cols()", A.cols(), "B.rows()", B.rows()); - arena_t a_arena = std::forward(A); + arena_t a_arena = std::forward(A); arena_t b_arena = std::forward(B); return make_callback_var( value_of(a_arena) * value_of(b_arena), [a_arena, b_arena](vari_value>& res) mutable { - if (!is_constant::value) { + if (!is_constant::value) { adjoint_of(a_arena) += res.adj() * transpose(value_of(b_arena)); } if (!is_constant::value) { @@ -49,35 +49,37 @@ inline auto multiply(T_a&& A, T_b&& B) { /** * Matrix multiplication of two reverse mode matrices and/or kernel generator * expressions. - * @tparam T_a type of first expression + * @tparam Matcl_a type of first expression * @tparam T_b type of second expression * @param A first expression * @param B second expression * @return Matrix product of given arguments */ -template < - typename T_a, typename T_b, - require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, - require_any_var_t* = nullptr> -inline auto operator*(const T_a& A, const T_b& B) { +template * = nullptr, + require_any_var_t* = nullptr> +inline auto operator*(const Matcl_a& A, const T_b& B) { return multiply(A, B); } /** * Return matrix multiplied by a scalar. * - * @tparam T1 type of the scalar - * @tparam T2 type of the matrix or expression + * @tparam ScalarA type of the scalar + * @tparam MatclB type of the matrix or expression * * @param A scalar * @param B matrix * @return product of matrix and scalar */ -template * = nullptr, - require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, - require_any_var_t* = nullptr> -inline auto multiply(const T1& A, T2&& B) { - arena_t b_arena = std::forward(B); +template < + typename ScalarA, typename MatclB, + require_stan_scalar_t* = nullptr, + require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, + require_any_var_t* = nullptr> +inline auto multiply(const ScalarA& A, MatclB&& B) { + arena_t b_arena = std::forward(B); return make_callback_var( value_of(A) * value_of(b_arena), @@ -91,17 +93,19 @@ inline auto multiply(const T1& A, T2&& B) { /** * Return matrix multiplied by a scalar. * - * @tparam T1 type of the matrix or expression - * @tparam T2 type of the scalar + * @tparam MatclA type of the matrix or expression + * @tparam ScalarB type of the scalar * * @param A matrix * @param B scalar * @return product of matrix and scalar */ -template * = nullptr, - require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, - require_any_var_t* = nullptr> -inline auto multiply(const T1& A, const T2& B) { +template < + typename MatclA, typename ScalarB, + require_stan_scalar_t* = nullptr, + require_all_nonscalar_prim_or_rev_kernel_expression_t* = nullptr, + require_any_var_t* = nullptr> +inline auto multiply(const MatclA& A, const ScalarB& B) { return multiply(B, A); } diff --git a/stan/math/opencl/rev/softmax.hpp b/stan/math/opencl/rev/softmax.hpp index f61ba86963d..e031050f1ba 100644 --- a/stan/math/opencl/rev/softmax.hpp +++ b/stan/math/opencl/rev/softmax.hpp @@ -3,6 +3,7 @@ #ifdef STAN_OPENCL #include +#include #include #include #include diff --git a/stan/math/opencl/rev/ub_constrain.hpp b/stan/math/opencl/rev/ub_constrain.hpp index ef87c2ba07e..ff7c6e40246 100644 --- a/stan/math/opencl/rev/ub_constrain.hpp +++ b/stan/math/opencl/rev/ub_constrain.hpp @@ -26,19 +26,19 @@ namespace math { * *

where \f$U\f$ is the constant upper bound. * - * @tparam T_x kernel generator expression - * @tparam T_ub kernel generator expression + * @tparam T_xcl kernel generator expression + * @tparam T_ubcl kernel generator expression * @param[in] x unconstrained input * @param[in] ub upper bound * @return constrained matrix */ -template * = nullptr, - require_any_var_t* = nullptr, - require_any_not_stan_scalar_t* = nullptr> -inline var_value> ub_constrain(T_x&& x, T_ub&& ub) { - arena_t x_arena = std::forward(x); - arena_t ub_arena = std::forward(ub); +template * = nullptr, + require_any_var_t* = nullptr, + require_any_not_stan_scalar_t* = nullptr> +inline var_value> ub_constrain(T_xcl&& x, T_ubcl&& ub) { + arena_t x_arena = std::forward(x); + arena_t ub_arena = std::forward(ub); return make_callback_var( ub_constrain(value_of(x_arena), value_of(ub_arena)), @@ -61,20 +61,21 @@ inline var_value> ub_constrain(T_x&& x, T_ub&& ub) { * *

where \f$U\f$ is the constant upper bound. * - * @tparam T_x kernel generator expression - * @tparam T_ub kernel generator expression + * @tparam T_xcl kernel generator expression + * @tparam T_ubcl kernel generator expression * @param[in] x unconstrained input * @param[in] ub upper bound * @param[in,out] lp reference to log probability to increment * @return constrained matrix */ -template * = nullptr, - require_any_var_t* = nullptr, - require_any_not_stan_scalar_t* = nullptr> -inline var_value> ub_constrain(T_x&& x, T_ub&& ub, var& lp) { - arena_t x_arena = std::forward(x); - arena_t ub_arena = std::forward(ub); +template * = nullptr, + require_any_var_t* = nullptr, + require_any_not_stan_scalar_t* = nullptr> +inline var_value> ub_constrain(T_xcl&& x, T_ubcl&& ub, + var& lp) { + arena_t x_arena = std::forward(x); + arena_t ub_arena = std::forward(ub); double lp_inc = 0; matrix_cl res diff --git a/stan/math/opencl/scalar_type.hpp b/stan/math/opencl/scalar_type.hpp index f303bacd76f..5e0b1226564 100644 --- a/stan/math/opencl/scalar_type.hpp +++ b/stan/math/opencl/scalar_type.hpp @@ -7,7 +7,7 @@ namespace stan { -/** \ingroup type_traits +/** \ingroup type_trait * Return the scalar type of an OpenCL matrix. */ template diff --git a/stan/math/opencl/tridiagonalization.hpp b/stan/math/opencl/tridiagonalization.hpp index 6c0257069cb..69fbaea5544 100644 --- a/stan/math/opencl/tridiagonalization.hpp +++ b/stan/math/opencl/tridiagonalization.hpp @@ -87,9 +87,9 @@ inline void block_householder_tridiag_cl(const matrix_cl& A, /** * Calculates Q*A in-place. To construct Q pass an appropriate identity matrix * as input A. - * @param packed Packed result of tridiagonalization that contains householder - * vectors that define Q in columns bellow the diagonal. Usually result of a - * call to `block_householder_tridiag_cl`. + * @param packed_cl Packed result of tridiagonalization that contains + * householder vectors that define Q in columns bellow the diagonal. Usually + * result of a call to `block_householder_tridiag_cl`. * @param[in,out] A On input a matrix to multiply with Q. On output the product * Q*A. * @param r Block size. Affects only performance of the algorithm. Optimal value diff --git a/stan/math/opencl/value_type.hpp b/stan/math/opencl/value_type.hpp index 0aea7260905..8dd064e34c9 100644 --- a/stan/math/opencl/value_type.hpp +++ b/stan/math/opencl/value_type.hpp @@ -7,7 +7,7 @@ namespace stan { -/** \ingroup type_traits +/** \ingroup type_trait * Return the value type of an OpenCL matrix. */ template diff --git a/stan/math/prim/core/complex_base.hpp b/stan/math/prim/core/complex_base.hpp index c9993037145..2fa54be0dbf 100644 --- a/stan/math/prim/core/complex_base.hpp +++ b/stan/math/prim/core/complex_base.hpp @@ -36,7 +36,7 @@ class complex_base { * Construct a complex base with the specified real part and a zero * imaginary part. * - * @tparam U real type (assignable to `value_type`) + * @tparam U real type (assignable to \ref stan::value_type ) * @param[in] re real part */ template // , typename = require_stan_scalar_t> @@ -46,8 +46,8 @@ class complex_base { * Construct a complex base with the specified real and imaginary * parts. * - * @tparam U real type (assignable to `value_type`) - * @tparam V imaginary type (assignable to `value_type`) + * @tparam U real type (assignable to \ref stan::value_type ) + * @tparam V imaginary type (assignable to \ref stan::value_type ) * @param[in] re real part * @param[in] im imaginary part */ @@ -86,7 +86,7 @@ class complex_base { * Assign the specified value to the real part of this complex number * and set imaginary part to zero. * - * @tparam U argument type (assignable to `value_type`) + * @tparam U argument type (assignable to \ref stan::value_type ) * @param[in] re real part * @return this */ @@ -100,7 +100,7 @@ class complex_base { /** * Add specified real value to real part. * - * @tparam U argument type (assignable to `value_type`) + * @tparam U argument type (assignable to \ref stan::value_type ) * @param[in] x real number to add * @return this */ @@ -113,7 +113,7 @@ class complex_base { /** * Adds specified complex number to this. * - * @tparam U value type of argument (assignable to `value_type`) + * @tparam U value type of argument (assignable to \ref stan::value_type ) * @param[in] other complex number to add * @return this */ @@ -127,7 +127,7 @@ class complex_base { /** * Subtracts specified real number from real part. * - * @tparam U argument type (assignable to `value_type`) + * @tparam U argument type (assignable to \ref stan::value_type ) * @param[in] x real number to subtract * @return this */ @@ -140,7 +140,7 @@ class complex_base { /** * Subtracts specified complex number from this. * - * @tparam U value type of argument (assignable to `value_type`) + * @tparam U value type of argument (assignable to \ref stan::value_type ) * @param[in] other complex number to subtract * @return this */ @@ -154,7 +154,7 @@ class complex_base { /** * Multiplies this by the specified real number. * - * @tparam U type of argument (assignable to `value_type`) + * @tparam U type of argument (assignable to \ref stan::value_type ) * @param[in] x real number to multiply * @return this */ @@ -168,7 +168,7 @@ class complex_base { /** * Multiplies this by specified complex number. * - * @tparam U value type of argument (assignable to `value_type`) + * @tparam U value type of argument (assignable to \ref stan::value_type ) * @param[in] other complex number to multiply * @return this */ @@ -183,7 +183,7 @@ class complex_base { /** * Divides this by the specified real number. * - * @tparam U type of argument (assignable to `value_type`) + * @tparam U type of argument (assignable to \ref stan::value_type ) * @param[in] x real number to divide by * @return this */ @@ -197,7 +197,7 @@ class complex_base { /** * Divides this by the specified complex number. * - * @tparam U value type of argument (assignable to `value_type`) + * @tparam U value type of argument (assignable to \ref stan::value_type ) * @param[in] other number to divide by * @return this */ diff --git a/stan/math/prim/err/check_cholesky_factor.hpp b/stan/math/prim/err/check_cholesky_factor.hpp index 8213b4304ca..44e8119dd56 100644 --- a/stan/math/prim/err/check_cholesky_factor.hpp +++ b/stan/math/prim/err/check_cholesky_factor.hpp @@ -19,9 +19,9 @@ namespace math { * positive. Note that Cholesky factors need not be square, but require at * least as many rows M as columns N (i.e., `M >= N`). * @tparam Mat Type inheriting from `MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 or a `var_value` with the var's - * inner type inheriting from `Eigen::MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 + * defined at compile time to be equal to 1 or a \ref stan::math::var_value with + * the var's inner type inheriting from `Eigen::MatrixBase` with neither rows or + * columns defined at compile time to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Matrix to test @@ -47,9 +47,9 @@ inline void check_cholesky_factor(const char* function, const char* name, * least as many rows M as columns N (i.e., `M >= N`). * @tparam StdVec A standard vector with inner type either inheriting from * `MatrixBase` with neither rows or columns defined at compile time to be equal - * to 1 or a `var_value` with the var's inner type inheriting from - * `Eigen::MatrixBase` with neither rows or columns defined at compile time to - * be equal to 1 + * to 1 or a \ref stan::math::var_value with the var's inner type inheriting + * from `Eigen::MatrixBase` with neither rows or columns defined at compile time + * to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Standard vector of matrices to test diff --git a/stan/math/prim/err/check_cholesky_factor_corr.hpp b/stan/math/prim/err/check_cholesky_factor_corr.hpp index 1c7ff949485..49f70b46f73 100644 --- a/stan/math/prim/err/check_cholesky_factor_corr.hpp +++ b/stan/math/prim/err/check_cholesky_factor_corr.hpp @@ -23,9 +23,9 @@ namespace math { * `math::CONSTRAINT_TOLERANCE`. Tolerance is specified by * `math::CONSTRAINT_TOLERANCE`. * @tparam Mat Type inheriting from `MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 or a `var_value` with the var's - * inner type inheriting from `Eigen::MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 + * defined at compile time to be equal to 1 or a \ref stan::math::var_value with + * the var's inner type inheriting from `Eigen::MatrixBase` with neither rows or + * columns defined at compile time to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Matrix to test @@ -55,9 +55,9 @@ void check_cholesky_factor_corr(const char* function, const char* name, * `math::CONSTRAINT_TOLERANCE`. * @tparam StdVec A standard vector with inner type either inheriting from * `MatrixBase` with neither rows or columns defined at compile time to be equal - * to 1 or a `var_value` with the var's inner type inheriting from - * `Eigen::MatrixBase` with neither rows or columns defined at compile time to - * be equal to 1 + * to 1 or a \ref stan::math::var_value with the var's inner type inheriting + * from `Eigen::MatrixBase` with neither rows or columns defined at compile time + * to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Standard vector of matrics to test diff --git a/stan/math/prim/err/check_corr_matrix.hpp b/stan/math/prim/err/check_corr_matrix.hpp index 08e026ff944..a831dbc0d4a 100644 --- a/stan/math/prim/err/check_corr_matrix.hpp +++ b/stan/math/prim/err/check_corr_matrix.hpp @@ -20,9 +20,9 @@ namespace math { * A valid correlation matrix is symmetric positive definite, has a unit * diagonal (all 1 values), and has all values between -1 and 1 (inclusive). * @tparam Mat Type inheriting from `MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 or a `var_value` with the var's - * inner type inheriting from `Eigen::MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 + * defined at compile time to be equal to 1 or a \ref stan::math::var_value with + * the var's inner type inheriting from `Eigen::MatrixBase` with neither rows or + * columns defined at compile time to be equal to 1 * @param function Name of the function this was called from * @param name Name of the variable * @param y Matrix to test @@ -62,9 +62,9 @@ inline void check_corr_matrix(const char* function, const char* name, * diagonal (all 1 values), and has all values between -1 and 1 (inclusive). * @tparam StdVec A standard vector with inner type either inheriting from * `Eigen::MatrixBase` with neither rows or columns defined at compile time to - * be equal to 1 or a `var_value` with the var's inner type inheriting from - * `Eigen::MatrixBase` with neither rows or columns defined at compile time to - * be equal to 1. + * be equal to 1 or a \ref stan::math::var_value with the var's inner type + * inheriting from `Eigen::MatrixBase` with neither rows or columns defined at + * compile time to be equal to 1. * @param function Name of the function this was called from * @param name Name of the variable * @param y Matrix to test diff --git a/stan/math/prim/err/check_cov_matrix.hpp b/stan/math/prim/err/check_cov_matrix.hpp index 4e4c402cb2c..9466905725e 100644 --- a/stan/math/prim/err/check_cov_matrix.hpp +++ b/stan/math/prim/err/check_cov_matrix.hpp @@ -14,9 +14,9 @@ namespace math { * A valid covariance matrix is a square, symmetric matrix that is positive * definite. * @tparam Mat Type inheriting from `MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 or a `var_value` with the var's - * inner type inheriting from `Eigen::MatrixBase` with neither rows or columns - * defined at compile time to be equal to 1 + * defined at compile time to be equal to 1 or a \ref stan::math::var_value with + * the var's inner type inheriting from `Eigen::MatrixBase` with neither rows or + * columns defined at compile time to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Matrix to test @@ -37,9 +37,9 @@ inline void check_cov_matrix(const char* function, const char* name, * definite. * @tparam StdVec A standard vector with inner type either inheriting from * `MatrixBase` with neither rows or columns defined at compile time to be equal - * to 1 or a `var_value` with the var's inner type inheriting from - * `Eigen::MatrixBase` with neither rows or columns defined at compile time to - * be equal to 1 + * to 1 or a \ref stan::math::var_value with the var's inner type inheriting + * from `Eigen::MatrixBase` with neither rows or columns defined at compile time + * to be equal to 1 * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y standard vector of matrices to test. diff --git a/stan/math/prim/err/check_finite.hpp b/stan/math/prim/err/check_finite.hpp index c487e3182d8..7c839ceb621 100644 --- a/stan/math/prim/err/check_finite.hpp +++ b/stan/math/prim/err/check_finite.hpp @@ -22,7 +22,6 @@ namespace math { * @param function name of function (for error messages) * @param name variable name (for error messages) * @param y scalar or container to test - * @return true if all values are finite **/ template inline void check_finite(const char* function, const char* name, const T_y& y) { diff --git a/stan/math/prim/err/check_greater.hpp b/stan/math/prim/err/check_greater.hpp index 256426d893e..4adca190f00 100644 --- a/stan/math/prim/err/check_greater.hpp +++ b/stan/math/prim/err/check_greater.hpp @@ -20,8 +20,8 @@ namespace math { * is vectorized and will check each element of `y` against each element of * `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A scalar type type - * @tparam T_low A scalar type + * @tparam ScalarY A scalar type type + * @tparam ScalarLow A scalar type * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -31,10 +31,12 @@ namespace math { * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template * = nullptr, + typename... Idxs> +inline void check_greater(const char* function, const char* name, + const ScalarY& y, const ScalarLow& low, + Idxs... idxs) { if (unlikely(!(y > low))) { [](auto y, auto low, auto function, auto name, auto... idxs) STAN_COLD_PATH { @@ -51,10 +53,10 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A scalar type - * @tparam T_low A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * @tparam ScalarY A scalar type + * @tparam VecLow A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -62,15 +64,16 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @param idxs Pack of integral types to construct lazily construct the error * message indices * @throw `std::domain_error` if y is not greater or equal to low or if any - * element of y or low is `NaN` + * element of y or low is `NaN`zz */ template < - typename T_y, typename T_low, require_stan_scalar_t* = nullptr, - require_vector_t* = nullptr, - require_not_std_vector_vt* = nullptr, + typename ScalarY, typename VecLow, + require_stan_scalar_t* = nullptr, + require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +inline void check_greater(const char* function, const char* name, + const ScalarY& y, const VecLow& low, Idxs... idxs) { auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low))); for (Eigen::Index i = 0; i < low_arr.size(); ++i) { if (unlikely(!(y > low_arr.coeff(i)))) { @@ -90,10 +93,11 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A scalar type - * @tparam T_low Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam ScalarY A scalar type + * @tparam DenseLow Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -103,10 +107,11 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_dense_dynamic_t* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template * = nullptr, + require_dense_dynamic_t* = nullptr, typename... Idxs> +inline void check_greater(const char* function, const char* name, + const ScalarY& y, const DenseLow& low, Idxs... idxs) { auto&& low_arr = value_of_rec(to_ref(low)); for (Eigen::Index j = 0; j < low_arr.cols(); ++j) { for (Eigen::Index i = 0; i < low_arr.rows(); ++i) { @@ -130,10 +135,10 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar - * @tparam T_low A scalar type + * @tparam VecY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar + * @tparam ScalarLow A scalar type * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -143,11 +148,12 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_not_std_vector_vt* = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template < + typename VecY, typename ScalarLow, require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> +inline void check_greater(const char* function, const char* name, const VecY& y, + const ScalarLow& low, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); for (Eigen::Index i = 0; i < y_arr.size(); ++i) { if (unlikely(!(y_arr.coeff(i) > low))) { @@ -168,10 +174,11 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_low A scalar type + * @tparam DenseY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam ScalarLow A scalar type * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -181,10 +188,11 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template * = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> +inline void check_greater(const char* function, const char* name, + const DenseY& y, const ScalarLow& low, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); for (Eigen::Index j = 0; j < y_arr.cols(); ++j) { for (Eigen::Index i = 0; i < y_arr.rows(); ++i) { @@ -208,12 +216,12 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * associated element in `low`. This function is vectorized and will check each * element of `y` against each element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar. - * @tparam T_low A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * @tparam VecY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. + * @tparam VecLow A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -223,13 +231,13 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_all_not_std_vector_vt* = nullptr, +template * = nullptr, + require_all_not_std_vector_vt* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +inline void check_greater(const char* function, const char* name, const VecY& y, + const VecLow& low, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low))); for (Eigen::Index i = 0; i < low_arr.size(); ++i) { @@ -251,12 +259,14 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * associated element in `low`. This function is vectorized and will check each * element of `y` against each element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_low Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam DenseY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam DenseLow Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -266,10 +276,11 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template * = nullptr, + typename... Idxs> +inline void check_greater(const char* function, const char* name, + const DenseY& y, const DenseLow& low, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); auto&& low_arr = value_of_rec(to_ref(low)); for (Eigen::Index j = 0; j < low_arr.cols(); ++j) { @@ -294,9 +305,10 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A standard vector type with a `value_type` of a standard vector - * or type inheriting from `Eigen::DenseBase` - * @tparam T_low A scalar type or the same type as the underlying type in `T_y` + * @tparam ContainerY A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` + * @tparam T_low A scalar type or the same type as the underlying type in + * `ContainerY` * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -306,11 +318,12 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_not_std_vector_t* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template < + typename ContainerY, typename T_low, + require_std_vector_vt* = nullptr, + require_not_std_vector_t* = nullptr, typename... Idxs> +inline void check_greater(const char* function, const char* name, + const ContainerY& y, const T_low& low, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_greater(function, name, y[i], low, idxs..., i); } @@ -321,9 +334,10 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A scalar type or the same type as the inner type of `T_low` - * @tparam T_low A standard vector type with a `value_type` of a standard vector - * or type inheriting from `Eigen::DenseBase` + * @tparam ScalarY A scalar type or the same type as the inner type of + * `ContainerLow` + * @tparam ContainerLow A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -333,12 +347,14 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_std_vector_vt* = nullptr, - typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template < + typename ScalarY, typename ContainerLow, + require_not_std_vector_t* = nullptr, + require_std_vector_vt* = nullptr, + typename... Idxs> +inline void check_greater(const char* function, const char* name, + const ScalarY& y, const ContainerLow& low, + Idxs... idxs) { for (size_t i = 0; i < low.size(); ++i) { check_greater(function, name, y, low[i], idxs..., i); } @@ -349,10 +365,10 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `low`. * @tparam Idxs A parameter pack of Integral types - * @tparam T_y A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::EigenBase`, or another standard vector - * @tparam T_low A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::EigenBase`, or another standard vector + * @tparam StdVecY A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::EigenBase`, or another standard vector + * @tparam StdVecLow A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::EigenBase`, or another standard vector * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Variable to check @@ -362,12 +378,14 @@ inline void check_greater(const char* function, const char* name, const T_y& y, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_all_std_vector_t* = nullptr, typename... Idxs> -inline void check_greater(const char* function, const char* name, const T_y& y, - const T_low& low, Idxs... idxs) { +template * = nullptr, + require_all_std_vector_t* = nullptr, + typename... Idxs> +inline void check_greater(const char* function, const char* name, + const StdVecY& y, const StdVecLow& low, + Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_greater(function, name, y[i], low[i], idxs..., i); } diff --git a/stan/math/prim/err/check_greater_or_equal.hpp b/stan/math/prim/err/check_greater_or_equal.hpp index a2b40f7e04d..49e2ac76f46 100644 --- a/stan/math/prim/err/check_greater_or_equal.hpp +++ b/stan/math/prim/err/check_greater_or_equal.hpp @@ -20,7 +20,7 @@ namespace math { * is vectorized and will check each element of `y` against each element of * `low`. * @tparam T_y A scalar type - * @tparam T_low A scalar type + * @tparam Scalar2 A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -31,10 +31,11 @@ namespace math { * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, typename... Idxs> +template * = nullptr, + typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Scaler1& y, const Scalar2& low, Idxs... idxs) { if (unlikely(!(y >= low))) { [](auto y, auto low, auto function, auto name, @@ -52,10 +53,10 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if `y` is not greater or equal than each element of `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y A scalar type - * @tparam T_low A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar + * @tparam Scaler1 A scalar type + * @tparam Scalar2 A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -67,12 +68,12 @@ inline void check_greater_or_equal(const char* function, const char* name, * element of y or low is `NaN` */ template < - typename T_y, typename T_low, require_stan_scalar_t* = nullptr, - require_vector_t* = nullptr, - require_not_std_vector_vt* = nullptr, + typename Scaler1, typename Vec2, require_stan_scalar_t* = nullptr, + require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Scaler1& y, const Vec2& low, Idxs... idxs) { auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low))); for (Eigen::Index i = 0; i < low_arr.size(); ++i) { @@ -93,10 +94,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if `y` is not greater or equal than each element of `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y A scalar type - * @tparam T_low Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam Scaler1 A scalar type + * @tparam Dense2 Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -107,10 +109,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_dense_dynamic_t* = nullptr, typename... Idxs> +template * = nullptr, + require_dense_dynamic_t* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Scaler1& y, const Dense2& low, Idxs... idxs) { auto&& low_arr = value_of_rec(to_ref(low)); for (Eigen::Index j = 0; j < low_arr.cols(); ++j) { @@ -134,10 +137,10 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar - * @tparam T_low A scalar type + * @tparam Vec A standard vector or type inheriting from `Eigen::DenseBase` with + * compile time rows or columns equal to one and \ref stan::value_type equal to + * a stan scalar + * @tparam Scalar2 A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -148,11 +151,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_not_std_vector_vt* = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> +template * = nullptr, + require_not_std_vector_vt* = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Vec& y, const Scalar2& low, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); for (Eigen::Index i = 0; i < y_arr.size(); ++i) { @@ -174,10 +177,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_low A scalar type + * @tparam Dense1 Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam Scalar2 A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -188,10 +192,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> +template * = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Dense1& y, const Scalar2& low, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); for (Eigen::Index j = 0; j < y_arr.cols(); ++j) { @@ -215,12 +220,12 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than the * associated element in `low`. This function is vectorized and will check each * element of `y` against each element of `low`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar - * @tparam T_low A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar + * @tparam Vec1 A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar + * @tparam Vec2 A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -231,13 +236,13 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_all_not_std_vector_vt* = nullptr, +template * = nullptr, + require_all_not_std_vector_vt* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Vec1& y, const Vec2& low, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); auto&& low_arr = value_of_rec(as_array_or_scalar(to_ref(low))); @@ -260,12 +265,14 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than the * associated element in `low`. This function is vectorized and will check each * element of `y` against each element of `low`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_low Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam Dense1 Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam Dense2 Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -276,10 +283,11 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, typename... Idxs> +template * = nullptr, + typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Dense1& y, const Dense2& low, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); auto&& low_arr = value_of_rec(to_ref(low)); @@ -304,9 +312,9 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y A standard vector type with a `value_type` of a standard vector - * or type inheriting from `Eigen::DenseBase` - * @tparam T_low A standard vector type + * @tparam Container1 A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` + * @tparam NotStdVec2 A standard vector type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -317,11 +325,12 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is `NaN` */ -template * = nullptr, - require_not_std_vector_t* = nullptr, typename... Idxs> +template < + typename Container1, typename NotStdVec2, + require_std_vector_vt* = nullptr, + require_not_std_vector_t* = nullptr, typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const Container1& y, const NotStdVec2& low, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_greater_or_equal(function, name, y[i], low, idxs..., i); @@ -332,8 +341,9 @@ inline void check_greater_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not greater or equal than `low`. * This function is vectorized and will check each element of `y` against each * element of `low`. - * @tparam T_y A standard vector - * @tparam T_low A standard vector type with a `value_type` of a standard + * @tparam NotStdVec A standard vector + * @tparam Container2 A standard vector type with a \ref stan::value_type of a + * standard * @tparam Idxs A parameter pack of Integral types * vector or type inheriting from `Eigen::DenseBase` * @param function Function name (for error messages) @@ -345,12 +355,13 @@ inline void check_greater_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not greater or equal to low or if any * element of y or low is NaN */ -template * = nullptr, - require_std_vector_vt* = nullptr, - typename... Idxs> +template < + typename NotStdVec, typename Container2, + require_not_std_vector_t* = nullptr, + require_std_vector_vt* = nullptr, + typename... Idxs> inline void check_greater_or_equal(const char* function, const char* name, - const T_y& y, const T_low& low, + const NotStdVec& y, const Container2& low, Idxs... idxs) { for (size_t i = 0; i < low.size(); ++i) { check_greater_or_equal(function, name, y, low[i], idxs..., i); diff --git a/stan/math/prim/err/check_less.hpp b/stan/math/prim/err/check_less.hpp index 00960a9543b..db13fa0fd16 100644 --- a/stan/math/prim/err/check_less.hpp +++ b/stan/math/prim/err/check_less.hpp @@ -18,7 +18,7 @@ namespace math { /** * Throw an exception if `y` is not strictly less than `high`. This function is * vectorized and will check each element of `y` against each element of `high`. - * @tparam T_y A scalar type + * @tparam ScalarY A scalar type * @tparam T_high A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) @@ -30,9 +30,10 @@ namespace math { * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +template * = nullptr, + typename... Idxs> +inline void check_less(const char* function, const char* name, const ScalarY& y, const T_high& high, Idxs... idxs) { if (!(y < high)) { [](auto y, auto high, auto function, auto name, @@ -49,10 +50,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if `y` is not strictly less than each element of `high`. * This function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A scalar type + * @tparam ScalarY A scalar type * @tparam T_high A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -64,11 +65,12 @@ inline void check_less(const char* function, const char* name, const T_y& y, * high is `NaN` */ template < - typename T_y, typename T_high, require_stan_scalar_t* = nullptr, + typename ScalarY, typename T_high, + require_stan_scalar_t* = nullptr, require_vector_t* = nullptr, require_not_std_vector_vt* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +inline void check_less(const char* function, const char* name, const ScalarY& y, const T_high& high, Idxs... idxs) { auto&& high_arr = as_array_or_scalar(value_of_rec(to_ref(high))); for (Eigen::Index i = 0; i < high_arr.size(); ++i) { @@ -88,10 +90,11 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if `y` is not strictly less than each element of `high`. * This function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A scalar type - * @tparam T_high Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam ScalarY A scalar type + * @tparam T_high Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -102,9 +105,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, +template * = nullptr, require_dense_dynamic_t* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +inline void check_less(const char* function, const char* name, const ScalarY& y, const T_high& high, Idxs... idxs) { auto&& high_arr = value_of_rec(to_ref(high)); for (Eigen::Index j = 0; j < high_arr.cols(); ++j) { @@ -128,9 +132,9 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than `high`. * This function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar. + * @tparam VecY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam T_high A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) @@ -142,10 +146,11 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, - require_not_std_vector_vt* = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +template < + typename VecY, typename T_high, require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> +inline void check_less(const char* function, const char* name, const VecY& y, const T_high& high, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); for (Eigen::Index i = 0; i < y_arr.size(); ++i) { @@ -166,9 +171,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than `high`. * This function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one + * @tparam DenseY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam T_high A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) @@ -180,10 +186,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, +template * = nullptr, require_stan_scalar_t* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +inline void check_less(const char* function, const char* name, const DenseY& y, const T_high& high, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); for (Eigen::Index j = 0; j < y_arr.cols(); ++j) { @@ -206,12 +212,12 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than each * element of `high`. This function is vectorized and will check each element of * `y` against each element of `high`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar. + * @tparam VecY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam T_high A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -222,12 +228,12 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, - require_all_not_std_vector_vt* = nullptr, + require_all_not_std_vector_vt* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +inline void check_less(const char* function, const char* name, const VecY& y, const T_high& high, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); auto&& high_arr = value_of_rec(to_ref(high)); @@ -249,12 +255,14 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than each * element of `high`. This function is vectorized and will check each element of * `y` against each element of `high`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_high Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam VecY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam T_high Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -265,9 +273,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, +template * = nullptr, + typename... Idxs> +inline void check_less(const char* function, const char* name, const VecY& y, const T_high& high, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); auto&& high_arr = value_of_rec(to_ref(high)); @@ -292,8 +301,8 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than `high`. * This function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A standard vector type with a `value_type` of a standard vector - * or type inheriting from `Eigen::DenseBase` + * @tparam ContainerY A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` * @tparam T_high A scalar type or the same type as the inner type of `T_high` * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) @@ -305,11 +314,12 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, - require_not_std_vector_t* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, - const T_high& high, Idxs... idxs) { +template < + typename ContainerY, typename T_high, + require_std_vector_vt* = nullptr, + require_not_std_vector_t* = nullptr, typename... Idxs> +inline void check_less(const char* function, const char* name, + const ContainerY& y, const T_high& high, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_less(function, name, y[i], high, idxs..., i); } @@ -320,8 +330,8 @@ inline void check_less(const char* function, const char* name, const T_y& y, * This function is vectorized and will check each element of `y` against each * element of `high`. * @tparam T_y A scalar type or the same type as the inner type of `T_high` - * @tparam T_high A standard vector type with a `value_type` of a standard - * vector or type inheriting from `Eigen::DenseBase` + * @tparam T_high A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -347,10 +357,10 @@ inline void check_less(const char* function, const char* name, const T_y& y, * Throw an exception if each element of `y` is not strictly less than each * associated element of `high`. This function is vectorized and will check each * element of `y` against each element of `high`. - * @tparam T_y A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::DenseBase`, or another standard vector - * @tparam T_high A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::DenseBase`, or another standard vector + * @tparam StdVecY A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::DenseBase`, or another standard vector + * @tparam T_high A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::DenseBase`, or another standard vector * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -361,11 +371,12 @@ inline void check_less(const char* function, const char* name, const T_y& y, * @throw `domain_error` if y is not less than high or if any element of y or * high is `NaN` */ -template * = nullptr, - require_all_std_vector_t* = nullptr, typename... Idxs> -inline void check_less(const char* function, const char* name, const T_y& y, + require_all_std_vector_t* = nullptr, + typename... Idxs> +inline void check_less(const char* function, const char* name, const StdVecY& y, const T_high& high, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_less(function, name, y[i], high[i], idxs..., i); diff --git a/stan/math/prim/err/check_less_or_equal.hpp b/stan/math/prim/err/check_less_or_equal.hpp index ef76609a9cf..aed0b9363a6 100644 --- a/stan/math/prim/err/check_less_or_equal.hpp +++ b/stan/math/prim/err/check_less_or_equal.hpp @@ -19,8 +19,8 @@ namespace math { /** * Throw an exception if `y` is not less than `high`. This function is * vectorized and will check each element of `y` against each element of `high`. - * @tparam T_y A scalar type - * @tparam T_high A scalar type + * @tparam ScalarY A scalar type + * @tparam ScalarHigh A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -31,10 +31,11 @@ namespace math { * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, typename... Idxs> +template * = nullptr, + typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const ScalarY& y, const ScalarHigh& high, Idxs... idxs) { if (unlikely(!(y <= high))) { [](auto y, auto high, auto function, auto name, @@ -52,10 +53,10 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if `y` is not less than each element of `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A scalar type - * @tparam T_high A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * @tparam ScalarY A scalar type + * @tparam VecHigh A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -67,12 +68,13 @@ inline void check_less_or_equal(const char* function, const char* name, * or high is `NaN` */ template < - typename T_y, typename T_high, require_stan_scalar_t* = nullptr, - require_vector_t* = nullptr, - require_not_std_vector_vt* = nullptr, + typename ScalarY, typename VecHigh, + require_stan_scalar_t* = nullptr, + require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const ScalarY& y, const VecHigh& high, Idxs... idxs) { auto&& high_arr = value_of_rec(as_array_or_scalar(to_ref(high))); for (Eigen::Index i = 0; i < high_arr.size(); ++i) { @@ -93,10 +95,11 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if `y` is not less than each element of `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A scalar type - * @tparam T_high Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam ScalarY A scalar type + * @tparam DenseHigh Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -107,10 +110,11 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_dense_dynamic_t* = nullptr, typename... Idxs> +template * = nullptr, + require_dense_dynamic_t* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const ScalarY& y, const DenseHigh& high, Idxs... idxs) { auto&& high_arr = value_of_rec(to_ref(high)); for (Eigen::Index j = 0; j < high_arr.cols(); ++j) { @@ -134,10 +138,10 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar. - * @tparam T_high A scalar type + * @tparam VecY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. + * @tparam ScalarHigh A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -148,11 +152,12 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_not_std_vector_vt* = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> +template < + typename VecY, typename ScalarHigh, require_vector_t* = nullptr, + require_not_std_vector_vt* = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const VecY& y, const ScalarHigh& high, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); for (Eigen::Index i = 0; i < y_arr.size(); ++i) { @@ -174,10 +179,11 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_high A scalar type + * @tparam DenseY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam ScalarHigh A scalar type * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -188,11 +194,11 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_stan_scalar_t* = nullptr, typename... Idxs> +template * = nullptr, + require_stan_scalar_t* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const DenseY& y, const ScalarHigh& high, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); for (Eigen::Index j = 0; j < y_arr.cols(); ++j) { @@ -216,12 +222,12 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than the associated * element of `high`. This function is vectorized and will check each element of * `y` against each element of `high`. - * @tparam T_y A standard vector or type inheriting from `Eigen::DenseBase` with - * compile time rows or columns equal to one and `value_type` equal to a stan - * scalar. - * @tparam T_high A standard vector or type inheriting from `Eigen::DenseBase` - * with compile time rows or columns equal to one and `value_type` equal to a - * stan scalar. + * @tparam DenseY A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. + * @tparam VecHigh A standard vector or type inheriting from `Eigen::DenseBase` + * with compile time rows or columns equal to one and \ref stan::value_type + * equal to a stan scalar. * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -232,13 +238,13 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_all_not_std_vector_vt* = nullptr, +template * = nullptr, + require_all_not_std_vector_vt* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const DenseY& y, const VecHigh& high, Idxs... idxs) { auto&& y_arr = value_of_rec(as_array_or_scalar(to_ref(y))); auto&& high_arr = value_of_rec(as_array_or_scalar(to_ref(high))); @@ -261,12 +267,14 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than the associated * element of `high`. This function is vectorized and will check each element of * `y` against each element of `high`. - * @tparam T_y Type inheriting from `Eigen::DenseBase` or a `var_value` with the - * var's inner type inheriting from `Eigen::DenseBase` where the compile time - * number of rows or columns is not equal to one - * @tparam T_high Type inheriting from `Eigen::DenseBase` or a `var_value` with - * the var's inner type inheriting from `Eigen::DenseBase` where the compile - * time number of rows or columns is not equal to one + * @tparam DenseY Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one + * @tparam DenseHigh Type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with the var's inner type inheriting from + * `Eigen::DenseBase` where the compile time number of rows or columns is not + * equal to one * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -277,10 +285,11 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, typename... Idxs> +template * = nullptr, + typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const DenseY& y, const DenseHigh& high, Idxs... idxs) { auto&& y_arr = value_of_rec(to_ref(y)); auto&& high_arr = value_of_rec(to_ref(high)); @@ -305,9 +314,9 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A standard vector type with a `value_type` of a standard vector - * or type inheriting from `Eigen::DenseBase` - * @tparam T_high A scalar or the same `value_type` of `T_y` + * @tparam ContainerY A standard vector type with a \ref stan::value_type of a + * standard vector or type inheriting from `Eigen::DenseBase` + * @tparam T_high A scalar or the same \ref stan::value_type of `ContainerY` * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -318,11 +327,12 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_not_std_vector_t* = nullptr, typename... Idxs> +template < + typename ContainerY, typename T_high, + require_std_vector_vt* = nullptr, + require_not_std_vector_t* = nullptr, typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const ContainerY& y, const T_high& high, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_less_or_equal(function, name, y[i], high, idxs..., i); @@ -333,9 +343,10 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if `y` is not less than each element of `high`. This * function is vectorized and will check each element of `y` against each * element of `high`. - * @tparam T_y A scalar type or the same `value_type` of `T_high` - * @tparam T_high A standard vector type with a `value_type` of a standard - * vector or type inheriting from `Eigen::DenseBase` + * @tparam T_y A scalar type or the same \ref stan::value_type of + * `ContainerHigh` + * @tparam ContainerHigh A standard vector type with a \ref stan::value_type of + * a standard vector or type inheriting from `Eigen::DenseBase` * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -346,12 +357,13 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_std_vector_vt* = nullptr, - typename... Idxs> +template < + typename T_y, typename ContainerHigh, + require_not_std_vector_t* = nullptr, + require_std_vector_vt* = nullptr, + typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const T_y& y, const ContainerHigh& high, Idxs... idxs) { for (size_t i = 0; i < high.size(); ++i) { check_less_or_equal(function, name, y, high[i], idxs..., i); @@ -362,10 +374,10 @@ inline void check_less_or_equal(const char* function, const char* name, * Throw an exception if each element of `y` is not less than each associated * element of `high`. This function is vectorized and will check each element of * `y` against each element of `high`. - * @tparam T_y A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::EigenBase`, or another standard vector - * @tparam T_high A standard vector type whose `value_type` is a scalar, type - * inheriting from `Eigen::EigenBase`, or another standard vector + * @tparam StdVecY A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::EigenBase`, or another standard vector + * @tparam StdVecHigh A standard vector type whose \ref stan::value_type is a + * scalar, type inheriting from `Eigen::EigenBase`, or another standard vector * @tparam Idxs A parameter pack of Integral types * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -376,12 +388,13 @@ inline void check_less_or_equal(const char* function, const char* name, * @throw `std::domain_error` if y is not less than high or if any element of y * or high is `NaN` */ -template * = nullptr, - require_all_std_vector_t* = nullptr, typename... Idxs> +template * = nullptr, + require_all_std_vector_t* = nullptr, + typename... Idxs> inline void check_less_or_equal(const char* function, const char* name, - const T_y& y, const T_high& high, + const StdVecY& y, const StdVecHigh& high, Idxs... idxs) { for (size_t i = 0; i < y.size(); ++i) { check_less_or_equal(function, name, y[i], high[i], idxs..., i); diff --git a/stan/math/prim/err/check_matching_dims.hpp b/stan/math/prim/err/check_matching_dims.hpp index fd4b9baf933..c858d06393c 100644 --- a/stan/math/prim/err/check_matching_dims.hpp +++ b/stan/math/prim/err/check_matching_dims.hpp @@ -13,8 +13,8 @@ namespace math { /** * Check if the two containers have the same dimensions. - * @tparam T1 type of the first container - * @tparam T2 type of the second container + * @tparam Container1 type of the first container + * @tparam Container2 type of the second container * @param function name of function (for error messages) * @param name1 variable name for the first container (for error messages) * @param y1 first container to test @@ -23,11 +23,13 @@ namespace math { * @throw std::invalid_argument if the dimensions of the * containers do not match */ -template * = nullptr, +template * = nullptr, require_all_not_nonscalar_prim_or_rev_kernel_expression_t< - T1, T2>* = nullptr> + Container1, Container2>* = nullptr> inline void check_matching_dims(const char* function, const char* name1, - const T1& y1, const char* name2, const T2& y2) { + const Container1& y1, const char* name2, + const Container2& y2) { std::vector y1_d = dims(y1); std::vector y2_d = dims(y2); auto error_throw = [&]() STAN_COLD_PATH { @@ -63,8 +65,10 @@ inline void check_matching_dims(const char* function, const char* name1, /** * Check if two matrices have the same row and column dimensions. - * @tparam T1 Either an Eigen type or a `var_value` with underlying Eigen type. - * @tparam T2 Either an Eigen type or a `var_value` with underlying Eigen type. + * @tparam Mat1 Either an Eigen type or a \ref stan::math::var_value with + * underlying Eigen type. + * @tparam Mat2 Either an Eigen type or a \ref stan::math::var_value with + * underlying Eigen type. * @param function name of function (for error messages) * @param name1 variable name for the first container (for error messages) * @param y1 first matrix to test @@ -73,14 +77,15 @@ inline void check_matching_dims(const char* function, const char* name1, * @throw std::invalid_argument if the dimensions of the * containers do not match */ -template < - typename T1, typename T2, - require_any_t, is_matrix>, - conjunction, - is_prim_or_rev_kernel_expression>>* = nullptr, - require_any_not_stan_scalar_t* = nullptr> +template , is_matrix>, + conjunction, + is_prim_or_rev_kernel_expression>>* = nullptr, + require_any_not_stan_scalar_t* = nullptr> inline void check_matching_dims(const char* function, const char* name1, - const T1& y1, const char* name2, const T2& y2) { + const Mat1& y1, const char* name2, + const Mat2& y2) { if (y1.rows() != y2.rows() || y1.cols() != y2.cols()) { [&]() STAN_COLD_PATH { std::ostringstream y1_err; @@ -95,10 +100,10 @@ inline void check_matching_dims(const char* function, const char* name1, /** * Check if two matrices have the same row and column dimensions. - * @tparam T1 Either an Eigen type, a `var_value` with underlying Eigen type, or - * scalar. - * @tparam T2 Either an Eigen type, a `var_value` with underlying Eigen type, or - * scalar. + * @tparam T1 Either an Eigen type, a \ref stan::math::var_value with underlying + * Eigen type, or scalar. + * @tparam T2 Either an Eigen type, a \ref stan::math::var_value with underlying + * Eigen type, or scalar. * @param function name of function (for error messages) * @param name1 variable name for the first container (for error messages) * @param y1 first argument to test @@ -122,8 +127,8 @@ inline void check_matching_dims(const char* function, const char* name1, * sizes as well. For example, a 4x1 matrix is not the same as a vector * with 4 elements. * @tparam check_compile Whether to check the static sizes - * @tparam Mat1 type of the first matrix - * @tparam Mat2 type of the second matrix + * @tparam EigMat1 type of the first matrix + * @tparam EigMat2 type of the second matrix * @param function name of function (for error messages) * @param name1 variable name for the first matrix (for error messages) * @param y1 first matrix to test @@ -132,16 +137,16 @@ inline void check_matching_dims(const char* function, const char* name1, * @throw std::invalid_argument if the dimensions of the matrices * do not match */ -template > +template > inline void check_matching_dims(const char* function, const char* name1, - const Mat1& y1, const char* name2, - const Mat2& y2) { + const EigMat1& y1, const char* name2, + const EigMat2& y2) { if (check_compile - && (static_cast(Mat1::RowsAtCompileTime) - != static_cast(Mat2::RowsAtCompileTime) - || static_cast(Mat1::ColsAtCompileTime) - != static_cast(Mat2::ColsAtCompileTime))) { + && (static_cast(EigMat1::RowsAtCompileTime) + != static_cast(EigMat2::RowsAtCompileTime) + || static_cast(EigMat1::ColsAtCompileTime) + != static_cast(EigMat2::ColsAtCompileTime))) { [&]() STAN_COLD_PATH { std::ostringstream msg; msg << "Static rows and cols of " << name1 << " and " << name2 diff --git a/stan/math/prim/err/check_ordered.hpp b/stan/math/prim/err/check_ordered.hpp index 88d5baa5316..80f914bc0ec 100644 --- a/stan/math/prim/err/check_ordered.hpp +++ b/stan/math/prim/err/check_ordered.hpp @@ -17,7 +17,7 @@ namespace math { /** * Throw an exception if the specified vector is not sorted into strictly * increasing order. - * @tparam T_y A type inheriting from EigenBase with either 1 compile time row + * @tparam Vec A type inheriting from EigenBase with either 1 compile time row * or column * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -25,9 +25,9 @@ namespace math { * @throw `std::domain_error` if the vector elements are not ordered, if there * are duplicated values, or if any element is `NaN` */ -template * = nullptr, - require_not_std_vector_t* = nullptr> -void check_ordered(const char* function, const char* name, const T_y& y) { +template * = nullptr, + require_not_std_vector_t* = nullptr> +void check_ordered(const char* function, const char* name, const Vec& y) { const auto& y_ref = to_ref(value_of_rec(y)); for (Eigen::Index n = 1; n < y_ref.size(); n++) { if (!(y_ref[n] > y_ref[n - 1])) { @@ -50,15 +50,16 @@ void check_ordered(const char* function, const char* name, const T_y& y) { /** * Throw an exception if the specified vector is not sorted into strictly * increasing order. - * @tparam T_y A standard vector with inner scalar type + * @tparam StdVec A standard vector with inner scalar type * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y `std::vector` to test * @throw `std::domain_error` if the vector elements are not ordered, if there * are duplicated values, or if any element is `NaN` */ -template * = nullptr> -void check_ordered(const char* function, const char* name, const T_y& y) { +template * = nullptr> +void check_ordered(const char* function, const char* name, const StdVec& y) { for (size_t n = 1; n < y.size(); n++) { if (!(y[n] > y[n - 1])) { [&]() STAN_COLD_PATH { @@ -80,16 +81,16 @@ void check_ordered(const char* function, const char* name, const T_y& y) { /** * Throw an exception if each vector in a standard vector is not sorted into * strictly increasing order. - * @tparam T_y A standard vector with an inner vector type + * @tparam Container A standard vector with an inner vector type * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y `std::vector` to test * @throw `std::domain_error` if the vector elements are not ordered, if there * are duplicated values, or if any element is `NaN` */ -template * = nullptr, - require_not_vt_stan_scalar* = nullptr> -void check_ordered(const char* function, const char* name, const T_y& y) { +template * = nullptr, + require_not_vt_stan_scalar* = nullptr> +void check_ordered(const char* function, const char* name, const Container& y) { for (size_t i = 0; i < y.size(); ++i) { check_ordered(function, internal::make_iter_name(name, i).c_str(), y[i]); } diff --git a/stan/math/prim/err/check_positive_ordered.hpp b/stan/math/prim/err/check_positive_ordered.hpp index cc36790af5f..5775bb0b64c 100644 --- a/stan/math/prim/err/check_positive_ordered.hpp +++ b/stan/math/prim/err/check_positive_ordered.hpp @@ -50,8 +50,8 @@ void check_positive_ordered(const char* function, const char* name, /** * Throw an exception if any of the vectors in a standard vector contains * negative values or is not sorted into strictly increasing order. - * @tparam StdVec A standard vector type with an `value_type` inheriting from - * `Eigen::EigenBase` with 1 compile time row or column + * @tparam StdVec A standard vector type with an \ref stan::value_type + * inheriting from `Eigen::EigenBase` with 1 compile time row or column * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param y Vector to test diff --git a/stan/math/prim/err/check_simplex.hpp b/stan/math/prim/err/check_simplex.hpp index 67b6bb831c1..6e4d966772b 100644 --- a/stan/math/prim/err/check_simplex.hpp +++ b/stan/math/prim/err/check_simplex.hpp @@ -22,7 +22,7 @@ namespace math { * function tests that the sum is within the tolerance specified by * `CONSTRAINT_TOLERANCE`. This function only accepts Eigen vectors, statically * typed vectors, not general matrices with 1 column. - * @tparam T A type inheriting from `Eigen::EigenBase` + * @tparam Mat A type inheriting from `Eigen::EigenBase` * @param function Function name (for error messages) * @param name Variable name (for error messages) * @param theta Vector to test @@ -30,15 +30,15 @@ namespace math { * @throw `std::domain_error` if the vector is not a simplex or if any element * is `NaN` */ -template * = nullptr> -void check_simplex(const char* function, const char* name, const T& theta) { +template * = nullptr> +void check_simplex(const char* function, const char* name, const Mat& theta) { using std::fabs; check_nonzero_size(function, name, theta); auto&& theta_ref = to_ref(value_of_rec(theta)); if (!(fabs(1.0 - theta_ref.sum()) <= CONSTRAINT_TOLERANCE)) { [&]() STAN_COLD_PATH { std::stringstream msg; - scalar_type_t sum = theta_ref.sum(); + scalar_type_t sum = theta_ref.sum(); msg << "is not a valid simplex."; msg.precision(10); msg << " sum(" << name << ") = " << sum << ", but should be "; @@ -68,7 +68,7 @@ void check_simplex(const char* function, const char* name, const T& theta) { * to 1. This function tests that the sum is within the tolerance specified by * `CONSTRAINT_TOLERANCE`. This function only accepts Eigen vectors, statically * typed vectors, not general matrices with 1 column. - * @tparam T A standard vector with inner type inheriting from + * @tparam Container A standard vector with inner type inheriting from * `Eigen::EigenBase` * @param function Function name (for error messages) * @param name Variable name (for error messages) @@ -77,8 +77,9 @@ void check_simplex(const char* function, const char* name, const T& theta) { * @throw `std::domain_error` if the vector is not a simplex or if any element * is `NaN` */ -template * = nullptr> -void check_simplex(const char* function, const char* name, const T& theta) { +template * = nullptr> +void check_simplex(const char* function, const char* name, + const Container& theta) { for (size_t i = 0; i < theta.size(); ++i) { check_simplex(function, internal::make_iter_name(name, i).c_str(), theta[i]); diff --git a/stan/math/prim/err/elementwise_check.hpp b/stan/math/prim/err/elementwise_check.hpp index de2e192d41d..e689b7e0e8c 100644 --- a/stan/math/prim/err/elementwise_check.hpp +++ b/stan/math/prim/err/elementwise_check.hpp @@ -35,12 +35,12 @@ class Iser { /** * Check the scalar. - * @tparam T type of scalar + * @tparam Scalar type of scalar * @param x scalar * @return `false` if the scalar fails the error check */ - template > - bool is(const T& x) { + template > + bool is(const Scalar& x) { return is_good(value_of_rec(x)); } @@ -98,7 +98,7 @@ void elementwise_throw_domain_error(const Args... args) { * works on scalars. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam Scalar type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -111,10 +111,11 @@ void elementwise_throw_domain_error(const Args... args) { * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr> +template * = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const Scalar& x, + const char* must_be, const Indexings&... indexings) { if (unlikely(!is_good(value_of_rec(x)))) { [&]() STAN_COLD_PATH { @@ -129,7 +130,7 @@ inline void elementwise_check(const F& is_good, const char* function, * overload works on Eigen types that support linear indexing. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam EigVec type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -142,23 +143,25 @@ inline void elementwise_check(const F& is_good, const char* function, * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr, - std::enable_if_t<(Eigen::internal::traits::Flags +template * = nullptr, + std::enable_if_t<(Eigen::internal::traits::Flags & Eigen::LinearAccessBit) - || T::IsVectorAtCompileTime>* = nullptr> + || EigVec::IsVectorAtCompileTime>* = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const EigVec& x, + const char* must_be, const Indexings&... indexings) { for (size_t i = 0; i < x.size(); i++) { auto scal = value_of_rec(x.coeff(i)); if (unlikely(!is_good(scal))) { [&]() STAN_COLD_PATH { - if (is_eigen_vector::value) { + if (is_eigen_vector::value) { internal::elementwise_throw_domain_error( function, ": ", name, indexings..., "[", i + error_index::value, "] is ", scal, ", but must be ", must_be, "!"); - } else if (Eigen::internal::traits::Flags & Eigen::RowMajorBit) { + } else if (Eigen::internal::traits::Flags + & Eigen::RowMajorBit) { internal::elementwise_throw_domain_error( function, ": ", name, indexings..., "[", i / x.cols() + error_index::value, ", ", @@ -181,7 +184,7 @@ inline void elementwise_check(const F& is_good, const char* function, * overload works on col-major Eigen types that do not support linear indexing. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam EigMat type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -194,15 +197,16 @@ inline void elementwise_check(const F& is_good, const char* function, * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr, - std::enable_if_t::Flags +template * = nullptr, + std::enable_if_t::Flags & Eigen::LinearAccessBit) - && !T::IsVectorAtCompileTime - && !(Eigen::internal::traits::Flags + && !EigMat::IsVectorAtCompileTime + && !(Eigen::internal::traits::Flags & Eigen::RowMajorBit)>* = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const EigMat& x, + const char* must_be, const Indexings&... indexings) { for (size_t i = 0; i < x.rows(); i++) { for (size_t j = 0; j < x.cols(); j++) { @@ -224,7 +228,7 @@ inline void elementwise_check(const F& is_good, const char* function, * overload works on row-major Eigen types that do not support linear indexing. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam EigRowMajorMat type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -237,15 +241,17 @@ inline void elementwise_check(const F& is_good, const char* function, * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr, - std::enable_if_t< - !(Eigen::internal::traits::Flags & Eigen::LinearAccessBit) - && !T::IsVectorAtCompileTime - && static_cast(Eigen::internal::traits::Flags - & Eigen::RowMajorBit)>* = nullptr> +template * = nullptr, + std::enable_if_t::Flags + & Eigen::LinearAccessBit) + && !EigRowMajorMat::IsVectorAtCompileTime + && static_cast( + Eigen::internal::traits::Flags + & Eigen::RowMajorBit)>* = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const EigRowMajorMat& x, + const char* must_be, const Indexings&... indexings) { for (size_t j = 0; j < x.cols(); j++) { for (size_t i = 0; i < x.rows(); i++) { @@ -267,7 +273,7 @@ inline void elementwise_check(const F& is_good, const char* function, * overload works on `std::vector` types. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam StdVec type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -280,10 +286,11 @@ inline void elementwise_check(const F& is_good, const char* function, * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr> +template * = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const StdVec& x, + const char* must_be, const Indexings&... indexings) { for (size_t j = 0; j < x.size(); j++) { elementwise_check(is_good, function, name, x[j], must_be, indexings..., "[", @@ -296,7 +303,7 @@ inline void elementwise_check(const F& is_good, const char* function, * overload works on `var`s containing Eigen types. * * @tparam F type of predicate - * @tparam T type of `x` + * @tparam VarMat type of `x` * @tparam Indexings types of `indexings` * @param is_good predicate to check, must accept doubles and produce bools * @param function function name (for error messages) @@ -309,10 +316,11 @@ inline void elementwise_check(const F& is_good, const char* function, * @throws `std::domain_error` if `is_good` returns `false` for the value * of any element in `x` */ -template * = nullptr> +template * = nullptr> inline void elementwise_check(const F& is_good, const char* function, - const char* name, const T& x, const char* must_be, + const char* name, const VarMat& x, + const char* must_be, const Indexings&... indexings) { elementwise_check(is_good, function, name, x.val(), must_be, indexings...); } diff --git a/stan/math/prim/err/make_iter_name.hpp b/stan/math/prim/err/make_iter_name.hpp index 07547bc7be6..daf18c03ee8 100644 --- a/stan/math/prim/err/make_iter_name.hpp +++ b/stan/math/prim/err/make_iter_name.hpp @@ -27,7 +27,7 @@ inline auto make_iter_name(const char* name) { return std::string(name); } * Given a name and index, generate a new name with the index attached. * This will produce strings of the form `[]`. * @param name The name of the argument. - * @param i The index. + * @param idxs A parameter pack of indices indices. */ template inline auto make_iter_name(const char* name, Idxs... idxs) { diff --git a/stan/math/prim/fun/accumulator.hpp b/stan/math/prim/fun/accumulator.hpp index d9d508451da..7f75a3a1113 100644 --- a/stan/math/prim/fun/accumulator.hpp +++ b/stan/math/prim/fun/accumulator.hpp @@ -46,11 +46,11 @@ class accumulator { * of values to the buffer. * * @tparam S type of the matrix - * @param m Matrix of values to add + * @param x Matrix of values to add */ template * = nullptr> - inline void add(const S& m) { - buf_.push_back(stan::math::sum(m)); + inline void add(const S& x) { + buf_.push_back(stan::math::sum(x)); } /** @@ -74,7 +74,7 @@ class accumulator { /** * Sum each entry and then push to the buffer. * @tparam S A Type inheriting from `matrix_cl_base` - * @param x An OpenCL matrix + * @param xs An OpenCL matrix */ template * = nullptr> diff --git a/stan/math/prim/fun/append_col.hpp b/stan/math/prim/fun/append_col.hpp index fc6245143ec..d4349f6f580 100644 --- a/stan/math/prim/fun/append_col.hpp +++ b/stan/math/prim/fun/append_col.hpp @@ -21,21 +21,22 @@ namespace math { * (vector, vector) -> matrix, * (row vector, row vector) -> row_vector. * - * @tparam T1 type of the first matrix - * @tparam T2 type of the second matrix + * @tparam EigMat1 type of the first matrix + * @tparam EigMat2 type of the second matrix * * @param A First matrix. * @param B Second matrix. * @return Result of appending the first matrix followed by the * second matrix side by side. */ -template > -inline auto append_col(const T1& A, const T2& B) { +template > +inline auto append_col(const EigMat1& A, const EigMat2& B) { using Eigen::Dynamic; using Eigen::Matrix; - using T_return = return_type_t; + using T_return = return_type_t; constexpr int row_type - = (T1::RowsAtCompileTime == 1 && T2::RowsAtCompileTime == 1) + = (EigMat1::RowsAtCompileTime == 1 && EigMat2::RowsAtCompileTime == 1) ? 1 : Eigen::Dynamic; @@ -61,7 +62,7 @@ inline auto append_col(const T1& A, const T2& B) { * @tparam Scal type of the scalar * @tparam RowVec type of the row vector * - * @param A scalar. + * @param a scalar. * @param B row vector. * @return Result of stacking the scalar on top of the row vector. */ @@ -69,13 +70,13 @@ template * = nullptr, require_t>* = nullptr> inline Eigen::Matrix, 1, Eigen::Dynamic> append_col( - const Scal& A, const RowVec& B) { + const Scal& a, const RowVec& B) { using Eigen::Dynamic; using Eigen::Matrix; using T_return = return_type_t; Matrix result(B.size() + 1); - result << A, B.template cast(); + result << a, B.template cast(); return result; } @@ -90,20 +91,20 @@ inline Eigen::Matrix, 1, Eigen::Dynamic> append_col( * @tparam Scal type of the scalar * * @param A row vector. - * @param B scalar. + * @param b scalar. * @return Result of stacking the row vector on top of the scalar. */ template >* = nullptr, require_stan_scalar_t* = nullptr> inline Eigen::Matrix, 1, Eigen::Dynamic> append_col( - const RowVec& A, const Scal& B) { + const RowVec& A, const Scal& b) { using Eigen::Dynamic; using Eigen::Matrix; using T_return = return_type_t; Matrix result(A.size() + 1); - result << A.template cast(), B; + result << A.template cast(), b; return result; } diff --git a/stan/math/prim/fun/append_row.hpp b/stan/math/prim/fun/append_row.hpp index 76c7e43e461..72e34654f7e 100644 --- a/stan/math/prim/fun/append_row.hpp +++ b/stan/math/prim/fun/append_row.hpp @@ -20,20 +20,21 @@ namespace math { * (row_vector, row_vector) -> matrix, * (vector, vector) -> vector. * - * @tparam T1 type of the first matrix - * @tparam T2 type of the second matrix + * @tparam EigMat1 type of the first matrix + * @tparam EigMat2 type of the second matrix * * @param A First matrix. * @param B Second matrix. * @return Result of stacking first matrix on top of second. */ -template * = nullptr> -inline auto append_row(const T1& A, const T2& B) { +template * = nullptr> +inline auto append_row(const EigMat1& A, const EigMat2& B) { using Eigen::Dynamic; using Eigen::Matrix; - using T_return = return_type_t; + using T_return = return_type_t; constexpr int col_type - = (T1::ColsAtCompileTime == 1 && T2::ColsAtCompileTime == 1) + = (EigMat1::ColsAtCompileTime == 1 && EigMat2::ColsAtCompileTime == 1) ? 1 : Eigen::Dynamic; @@ -58,7 +59,7 @@ inline auto append_row(const T1& A, const T2& B) { * @tparam Scal type of the scalar * @tparam ColVec type of the vector * - * @param A scalar. + * @param a scalar. * @param B vector. * @return Result of stacking the scalar on top of the vector. */ @@ -66,13 +67,13 @@ template * = nullptr, require_t>* = nullptr> inline Eigen::Matrix, Eigen::Dynamic, 1> append_row( - const Scal& A, const ColVec& B) { + const Scal& a, const ColVec& B) { using Eigen::Dynamic; using Eigen::Matrix; using T_return = return_type_t; Matrix result(B.size() + 1); - result << A, B.template cast(); + result << a, B.template cast(); return result; } @@ -86,20 +87,20 @@ inline Eigen::Matrix, Eigen::Dynamic, 1> append_row( * @tparam Scal type of the scalar * * @param A vector. - * @param B scalar. + * @param b scalar. * @return Result of stacking the vector on top of the scalar. */ template >* = nullptr, require_stan_scalar_t* = nullptr> inline Eigen::Matrix, Eigen::Dynamic, 1> append_row( - const ColVec& A, const Scal& B) { + const ColVec& A, const Scal& b) { using Eigen::Dynamic; using Eigen::Matrix; using T_return = return_type_t; Matrix result(A.size() + 1); - result << A.template cast(), B; + result << A.template cast(), b; return result; } diff --git a/stan/math/prim/fun/as_array_or_scalar.hpp b/stan/math/prim/fun/as_array_or_scalar.hpp index 46bafdd7ee9..0fa699d5c33 100644 --- a/stan/math/prim/fun/as_array_or_scalar.hpp +++ b/stan/math/prim/fun/as_array_or_scalar.hpp @@ -11,82 +11,85 @@ namespace math { /** * Returns specified input value. * - * @tparam T Type of element. + * @tparam Scalar Type of element. * @param v Specified value. * @return Same value. */ -template * = nullptr> -inline T as_array_or_scalar(T&& v) { - return std::forward(v); +template * = nullptr> +inline Scalar as_array_or_scalar(Scalar&& v) { + return std::forward(v); } /** * Returns a reference to rvalue specified input value. * - * @tparam T Type of element. + * @tparam Scalar Type of element. * @param v Specified value. * @return Same value. */ -template * = nullptr> -inline T& as_array_or_scalar(T& v) { +template * = nullptr> +inline Scalar& as_array_or_scalar(Scalar& v) { return v; } /** * Returns specified input value. * - * @tparam T Type of element. + * @tparam EigArray Type of element. * @param v Specified value. * @return Same value. */ -template * = nullptr> -inline T as_array_or_scalar(T&& v) { - return std::forward(v); +template * = nullptr> +inline EigArray as_array_or_scalar(EigArray&& v) { + return std::forward(v); } /** * Converts a matrix type to an array. * - * @tparam T Type of \c Eigen \c Matrix or expression + * @tparam Eig Type of \c Eigen \c Matrix or expression * @param v Specified \c Eigen \c Matrix or expression. * @return Matrix converted to an array. */ -template , - require_not_eigen_array_t* = nullptr> -inline auto as_array_or_scalar(T&& v) { - return make_holder([](auto& x) { return x.array(); }, std::forward(v)); +template , + require_not_eigen_array_t* = nullptr> +inline auto as_array_or_scalar(Eig&& v) { + return make_holder([](auto& x) { return x.array(); }, std::forward(v)); } /** * Converts a std::vector type to an array. * - * @tparam T Type of scalar element. + * @tparam StdVec Type of scalar element. * @param v Specified vector. * @return Matrix converted to an array. */ -template * = nullptr, - require_not_std_vector_t>* = nullptr> -inline auto as_array_or_scalar(T&& v) { +template * = nullptr, + require_not_std_vector_t>* = nullptr> +inline auto as_array_or_scalar(StdVec&& v) { using T_map - = Eigen::Map, Eigen::Dynamic, 1>>; + = Eigen::Map, Eigen::Dynamic, 1>>; return make_holder([](auto& x) { return T_map(x.data(), x.size()); }, - std::forward(v)); + std::forward(v)); } /** * Converts an std::vector to an Eigen Array. - * @tparam T A standard vector with inner container of a standard vector + * @tparam Container A standard vector with inner container of a standard vector * with an inner stan scalar. * @param v specified vector of vectorised * @return An Eigen Array with dynamic rows and columns. */ -template * = nullptr, - require_std_vector_vt>* = nullptr> -inline auto as_array_or_scalar(T&& v) { - Eigen::Array, -1, -1> ret(v.size(), v[0].size()); +template < + typename Container, + require_std_vector_vt* = nullptr, + require_std_vector_vt>* = nullptr> +inline auto as_array_or_scalar(Container&& v) { + Eigen::Array, -1, -1> ret(v.size(), v[0].size()); for (size_t i = 0; i < v.size(); ++i) { - ret.row(i) = Eigen::Map, 1, -1>>( - v[i].data(), v[i].size()); + ret.row(i) + = Eigen::Map, 1, -1>>( + v[i].data(), v[i].size()); } return ret; } diff --git a/stan/math/prim/fun/as_column_vector_or_scalar.hpp b/stan/math/prim/fun/as_column_vector_or_scalar.hpp index 0c999c63582..fdd8fbfe9b3 100644 --- a/stan/math/prim/fun/as_column_vector_or_scalar.hpp +++ b/stan/math/prim/fun/as_column_vector_or_scalar.hpp @@ -18,8 +18,8 @@ class empty_broadcast_array; * @param a Specified scalar. * @return the scalar. */ -template * = nullptr> -inline T as_column_vector_or_scalar(const T& a) { +template * = nullptr> +inline Scalar as_column_vector_or_scalar(const Scalar& a) { return a; } @@ -35,47 +35,48 @@ internal::empty_broadcast_array& as_column_vector_or_scalar( /** * no-op that returns a column vector. * - * @tparam T Type inheriting from `EigenBase` with dynamic compile time rows - * and fixed column of 1. + * @tparam EigColVec Type inheriting from `EigenBase` with dynamic compile time + * rows and fixed column of 1. * @param a Specified vector. * @return Same vector. */ -template * = nullptr> -inline T&& as_column_vector_or_scalar(T&& a) { - return std::forward(a); +template * = nullptr> +inline EigColVec&& as_column_vector_or_scalar(EigColVec&& a) { + return std::forward(a); } /** * Converts a row vector to an eigen column vector. For row vectors this returns - * a `Transpose>`. + * a `Transpose>`. * - * @tparam T Type inheriting from `EigenBase` with dynamic compile time columns - * and fixed row of 1. + * @tparam EigRowVec Type inheriting from `EigenBase` with dynamic compile time + * columns and fixed row of 1. * @param a Specified vector. * @return Transposed vector. */ -template * = nullptr, - require_not_eigen_col_vector_t* = nullptr> -inline auto as_column_vector_or_scalar(T&& a) { - return make_holder([](auto& x) { return x.transpose(); }, std::forward(a)); +template * = nullptr, + require_not_eigen_col_vector_t* = nullptr> +inline auto as_column_vector_or_scalar(EigRowVec&& a) { + return make_holder([](auto& x) { return x.transpose(); }, + std::forward(a)); } /** * Converts `std::vector` to a column vector. * - * @tparam T `std::vector` type. + * @tparam StdVec `std::vector` type. * @param a Specified vector. * @return input converted to a column vector. */ -template * = nullptr> -inline auto as_column_vector_or_scalar(T&& a) { - using plain_vector = Eigen::Matrix, Eigen::Dynamic, 1>; - using optionally_const_vector - = std::conditional_t>::value, - const plain_vector, plain_vector>; +template * = nullptr> +inline auto as_column_vector_or_scalar(StdVec&& a) { + using plain_vector = Eigen::Matrix, Eigen::Dynamic, 1>; + using optionally_const_vector = std::conditional_t< + std::is_const>::value, const plain_vector, + plain_vector>; using T_map = Eigen::Map; return make_holder([](auto& x) { return T_map(x.data(), x.size()); }, - std::forward(a)); + std::forward(a)); } } // namespace math diff --git a/stan/math/prim/fun/ceil.hpp b/stan/math/prim/fun/ceil.hpp index c257837250e..9f17e4cf01d 100644 --- a/stan/math/prim/fun/ceil.hpp +++ b/stan/math/prim/fun/ceil.hpp @@ -45,15 +45,15 @@ inline auto ceil(const Container& x) { * Version of `ceil()` that accepts std::vectors, Eigen Matrix/Array objects * or expressions, and containers of these. * - * @tparam Container Type of x + * @tparam ArithContainer Type of x * @param x Container * @return Least integer >= each value in x. */ -template * = nullptr, - require_not_var_matrix_t* = nullptr> -inline auto ceil(const Container& x) { - return apply_vector_unary::apply( +template * = nullptr, + require_not_var_matrix_t* = nullptr> +inline auto ceil(const ArithContainer& x) { + return apply_vector_unary::apply( x, [](const auto& v) { return v.array().ceil(); }); } diff --git a/stan/math/prim/fun/cholesky_corr_constrain.hpp b/stan/math/prim/fun/cholesky_corr_constrain.hpp index c949b85554d..6ef30f5450d 100644 --- a/stan/math/prim/fun/cholesky_corr_constrain.hpp +++ b/stan/math/prim/fun/cholesky_corr_constrain.hpp @@ -82,9 +82,9 @@ cholesky_corr_constrain(const EigVec& y, int K, return_type_t& lp) { * Constraint Transforms. * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param y Linearly Serialized vector of size `(K * (K - 1))/2` holding the * column major order elements of the lower triangurlar * @param K The size of the matrix to return @@ -107,17 +107,19 @@ inline auto cholesky_corr_constrain(const T& y, int K, return_type_t& lp) { * Constraint Transforms. * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param y Linearly Serialized vector of size `(K * (K - 1))/2` holding the * column major order elements of the lower triangurlar * @param K The size of the matrix to return * @param[in,out] lp log density accumulator */ -template * = nullptr> -inline auto cholesky_corr_constrain(const T& y, int K, return_type_t& lp) { - return apply_vector_unary::apply(y, [&lp, K](auto&& v) { +template * = nullptr> +inline auto cholesky_corr_constrain(const StdVec& y, int K, + return_type_t& lp) { + return apply_vector_unary::apply(y, [&lp, K](auto&& v) { return cholesky_corr_constrain(v, K, lp); }); } diff --git a/stan/math/prim/fun/cholesky_corr_free.hpp b/stan/math/prim/fun/cholesky_corr_free.hpp index f5746eaceeb..8f14bc8fa1b 100644 --- a/stan/math/prim/fun/cholesky_corr_free.hpp +++ b/stan/math/prim/fun/cholesky_corr_free.hpp @@ -36,13 +36,13 @@ auto cholesky_corr_free(const T& x) { /** * Overload of `cholesky_corr_free()` to untransform each matrix * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase`. + * @tparam StdVec A standard vector with with a \ref stan::value_type which + * inherits from `Eigen::MatrixBase`. * @param x The standard vector to untransform. */ -template * = nullptr> -auto cholesky_corr_free(const T& x) { - return apply_vector_unary::apply( +template * = nullptr> +auto cholesky_corr_free(const StdVec& x) { + return apply_vector_unary::apply( x, [](auto&& v) { return cholesky_corr_free(v); }); } diff --git a/stan/math/prim/fun/cholesky_factor_constrain.hpp b/stan/math/prim/fun/cholesky_factor_constrain.hpp index 701c29fe06e..edd9a66db58 100644 --- a/stan/math/prim/fun/cholesky_factor_constrain.hpp +++ b/stan/math/prim/fun/cholesky_factor_constrain.hpp @@ -18,18 +18,18 @@ namespace math { * specified vector. A total of (N choose 2) + N + (M - N) * N * elements are required to read an M by N Cholesky factor. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x Vector of unconstrained values * @param M number of rows * @param N number of columns * @return Cholesky factor */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cholesky_factor_constrain(const T& x, int M, int N) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cholesky_factor_constrain(const EigVec& x, int M, int N) { using std::exp; - using T_scalar = value_type_t; + using T_scalar = value_type_t; check_greater_or_equal("cholesky_factor_constrain", "num rows (must be greater or equal to num cols)", M, N); @@ -62,8 +62,8 @@ cholesky_factor_constrain(const T& x, int M, int N) { * transform. A total of (N choose 2) + N + N * (M - N) free parameters are * required to read an M by N Cholesky factor. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x Vector of unconstrained values * @param M number of rows * @param N number of columns @@ -71,9 +71,10 @@ cholesky_factor_constrain(const T& x, int M, int N) { * determinant * @return Cholesky factor */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cholesky_factor_constrain(const T& x, int M, int N, return_type_t& lp) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cholesky_factor_constrain(const EigVec& x, int M, int N, + return_type_t& lp) { check_size_match("cholesky_factor_constrain", "x.size()", x.size(), "((N * (N + 1)) / 2 + (M - N) * N)", ((N * (N + 1)) / 2 + (M - N) * N)); @@ -97,9 +98,9 @@ cholesky_factor_constrain(const T& x, int M, int N, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param x Vector of unconstrained values * @param M number of rows * @param N number of columns @@ -127,19 +128,20 @@ inline auto cholesky_factor_constrain(const T& x, int M, int N, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param x Vector of unconstrained values * @param M number of rows * @param N number of columns * @param[in,out] lp log density accumulator * @return Cholesky factor */ -template * = nullptr> -inline auto cholesky_factor_constrain(const T& x, int M, int N, - return_type_t& lp) { - return apply_vector_unary::apply(x, [&lp, M, N](auto&& v) { +template * = nullptr> +inline auto cholesky_factor_constrain(const StdVec& x, int M, int N, + return_type_t& lp) { + return apply_vector_unary::apply(x, [&lp, M, N](auto&& v) { return cholesky_factor_constrain(v, M, N, lp); }); } diff --git a/stan/math/prim/fun/cholesky_factor_free.hpp b/stan/math/prim/fun/cholesky_factor_free.hpp index 0cc4185a3fc..c0099cb42bf 100644 --- a/stan/math/prim/fun/cholesky_factor_free.hpp +++ b/stan/math/prim/fun/cholesky_factor_free.hpp @@ -51,13 +51,13 @@ Eigen::Matrix, Eigen::Dynamic, 1> cholesky_factor_free( /** * Overload of `cholesky_factor_free()` to untransform each matrix * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase`. + * @tparam StdVec A standard vector with with a \ref stan::value_type which + * inherits from `Eigen::MatrixBase`. * @param x The standard vector to untransform. */ -template * = nullptr> -auto cholesky_factor_free(const T& x) { - return apply_vector_unary::apply( +template * = nullptr> +auto cholesky_factor_free(const StdVec& x) { + return apply_vector_unary::apply( x, [](auto&& v) { return cholesky_factor_free(v); }); } diff --git a/stan/math/prim/fun/corr_matrix_constrain.hpp b/stan/math/prim/fun/corr_matrix_constrain.hpp index 8509ec8af16..72b10b56a30 100644 --- a/stan/math/prim/fun/corr_matrix_constrain.hpp +++ b/stan/math/prim/fun/corr_matrix_constrain.hpp @@ -86,9 +86,9 @@ corr_matrix_constrain(const T& x, Eigen::Index k, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param x Vector of unconstrained partial correlations * @param k Dimensionality of returned correlation matrix * @param[in,out] lp log density accumulator @@ -116,10 +116,10 @@ inline auto corr_matrix_constrain(const T& x, Eigen::Index k, * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column - * @param x Vector of unconstrained partial correlations - * @param k Dimensionality of returned correlation matrix + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @param y Vector of unconstrained partial correlations + * @param K Dimensionality of returned correlation matrix * @param[in,out] lp log density accumulator */ template * = nullptr> diff --git a/stan/math/prim/fun/corr_matrix_free.hpp b/stan/math/prim/fun/corr_matrix_free.hpp index 3a0242ab257..003273d20b6 100644 --- a/stan/math/prim/fun/corr_matrix_free.hpp +++ b/stan/math/prim/fun/corr_matrix_free.hpp @@ -55,8 +55,8 @@ Eigen::Matrix, Eigen::Dynamic, 1> corr_matrix_free(const T& y) { /** * Overload of `corr_matrix_free()` to untransform each matrix * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase`. + * @tparam T A standard vector with with a \ref stan::value_type which inherits + * from `Eigen::MatrixBase`. * @param x The standard vector to untransform. */ template * = nullptr> diff --git a/stan/math/prim/fun/cov_matrix_constrain.hpp b/stan/math/prim/fun/cov_matrix_constrain.hpp index 6b761b10000..e3d763233cc 100644 --- a/stan/math/prim/fun/cov_matrix_constrain.hpp +++ b/stan/math/prim/fun/cov_matrix_constrain.hpp @@ -20,21 +20,21 @@ namespace math { * *

See cov_matrix_free() for the inverse transform. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x The vector to convert to a covariance matrix. * @param K The number of rows and columns of the resulting * covariance matrix. * @throws std::invalid_argument if (x.size() != K + (K choose 2)). */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cov_matrix_constrain(const T& x, Eigen::Index K) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cov_matrix_constrain(const EigVec& x, Eigen::Index K) { using Eigen::Dynamic; using Eigen::Matrix; using std::exp; - Matrix, Dynamic, Dynamic> L(K, K); + Matrix, Dynamic, Dynamic> L(K, K); check_size_match("cov_matrix_constrain", "x.size()", x.size(), "K + (K choose 2)", (K * (K + 1)) / 2); const auto& x_ref = to_ref(x); @@ -53,23 +53,24 @@ cov_matrix_constrain(const T& x, Eigen::Index K) { * by K resulting from transforming the specified finite vector of * size K plus (K choose 2). * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x The vector to convert to a covariance matrix. * @param K The dimensions of the resulting covariance matrix. * @param lp Reference * @throws std::domain_error if (x.size() != K + (K choose 2)). */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cov_matrix_constrain(const T& x, Eigen::Index K, return_type_t& lp) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cov_matrix_constrain(const EigVec& x, Eigen::Index K, + return_type_t& lp) { using Eigen::Dynamic; using Eigen::Matrix; using std::exp; using std::log; check_size_match("cov_matrix_constrain", "x.size()", x.size(), "K + (K choose 2)", (K * (K + 1)) / 2); - Matrix, Dynamic, Dynamic> L(K, K); + Matrix, Dynamic, Dynamic> L(K, K); const auto& x_ref = to_ref(x); int i = 0; for (Eigen::Index m = 0; m < K; ++m) { @@ -96,9 +97,9 @@ cov_matrix_constrain(const T& x, Eigen::Index K, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param x The vector to convert to a covariance matrix * @param K The dimensions of the resulting covariance matrix * @param[in, out] lp log density accumulator @@ -124,18 +125,19 @@ inline auto cov_matrix_constrain(const T& x, Eigen::Index K, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param x The vector to convert to a covariance matrix * @param K The dimensions of the resulting covariance matrix * @param[in, out] lp log density accumulator * @throws std::domain_error if (x.size() != K + (K choose 2)). */ -template * = nullptr> -inline auto cov_matrix_constrain(const T& x, Eigen::Index K, - return_type_t& lp) { - return apply_vector_unary::apply(x, [&lp, K](auto&& v) { +template * = nullptr> +inline auto cov_matrix_constrain(const StdVec& x, Eigen::Index K, + return_type_t& lp) { + return apply_vector_unary::apply(x, [&lp, K](auto&& v) { return cov_matrix_constrain(v, K, lp); }); } diff --git a/stan/math/prim/fun/cov_matrix_constrain_lkj.hpp b/stan/math/prim/fun/cov_matrix_constrain_lkj.hpp index a74bbc0844d..1a32117f022 100644 --- a/stan/math/prim/fun/cov_matrix_constrain_lkj.hpp +++ b/stan/math/prim/fun/cov_matrix_constrain_lkj.hpp @@ -22,17 +22,17 @@ namespace math { * in corr_matrix_constrain(Matrix, size_t) * with the constrained deviations. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x Input vector of unconstrained partial correlations and * standard deviations. * @param k Dimensionality of returned covariance matrix. * @return Covariance matrix derived from the unconstrained partial * correlations and deviations. */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cov_matrix_constrain_lkj(const T& x, size_t k) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cov_matrix_constrain_lkj(const EigVec& x, size_t k) { size_t k_choose_2 = (k * (k - 1)) / 2; const auto& x_ref = to_ref(x); return read_cov_matrix(corr_constrain(x_ref.head(k_choose_2)), @@ -45,8 +45,8 @@ cov_matrix_constrain_lkj(const T& x, size_t k) { * values and increment the specified log probability reference * with the log absolute Jacobian determinant. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase and - * have one compile-time dimension equal to 1) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase + * and have one compile-time dimension equal to 1) * @param x Input vector of unconstrained partial correlations and * standard deviations. * @param k Dimensionality of returned covariance matrix. @@ -54,9 +54,9 @@ cov_matrix_constrain_lkj(const T& x, size_t k) { * @return Covariance matrix derived from the unconstrained partial * correlations and deviations. */ -template * = nullptr> -inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> -cov_matrix_constrain_lkj(const T& x, size_t k, return_type_t& lp) { +template * = nullptr> +inline Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic> +cov_matrix_constrain_lkj(const EigVec& x, size_t k, return_type_t& lp) { size_t k_choose_2 = (k * (k - 1)) / 2; const auto& x_ref = x; return read_cov_matrix(corr_constrain(x_ref.head(k_choose_2)), @@ -73,9 +73,9 @@ cov_matrix_constrain_lkj(const T& x, size_t k, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time rows or - * columns equal to 1 + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time rows or columns equal to 1 * @param x Input vector of unconstrained partial correlations and * standard deviations * @param k Dimensionality of returned covariance matrix @@ -103,9 +103,9 @@ inline auto cov_matrix_constrain_lkj(const T& x, size_t k, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time rows or columns equal to 1 + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time rows or columns equal to 1 * @param x Input vector of unconstrained partial correlations and * standard deviations * @param k Dimensionality of returned covariance matrix @@ -113,10 +113,11 @@ inline auto cov_matrix_constrain_lkj(const T& x, size_t k, * @return Covariance matrix derived from the unconstrained partial * correlations and deviations. */ -template * = nullptr> -inline auto cov_matrix_constrain_lkj(const T& x, size_t k, - return_type_t& lp) { - return apply_vector_unary::apply(x, [&lp, k](auto&& v) { +template * = nullptr> +inline auto cov_matrix_constrain_lkj(const StdVec& x, size_t k, + return_type_t& lp) { + return apply_vector_unary::apply(x, [&lp, k](auto&& v) { return cov_matrix_constrain_lkj(v, k, lp); }); } diff --git a/stan/math/prim/fun/cov_matrix_free.hpp b/stan/math/prim/fun/cov_matrix_free.hpp index a507655bf28..0da53fb210a 100644 --- a/stan/math/prim/fun/cov_matrix_free.hpp +++ b/stan/math/prim/fun/cov_matrix_free.hpp @@ -61,13 +61,13 @@ Eigen::Matrix, Eigen::Dynamic, 1> cov_matrix_free(const T& y) { /** * Overload of `cov_matrix_free()` to untransform each matrix * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase`. + * @tparam StdVec A standard vector with with a \ref stan::value_type which + * inherits from `Eigen::MatrixBase`. * @param x The standard vector to untransform. */ -template * = nullptr> -auto cov_matrix_free(const T& x) { - return apply_vector_unary::apply( +template * = nullptr> +auto cov_matrix_free(const StdVec& x) { + return apply_vector_unary::apply( x, [](auto&& v) { return cov_matrix_free(v); }); } diff --git a/stan/math/prim/fun/cov_matrix_free_lkj.hpp b/stan/math/prim/fun/cov_matrix_free_lkj.hpp index 81c16068813..b8c8da58b37 100644 --- a/stan/math/prim/fun/cov_matrix_free_lkj.hpp +++ b/stan/math/prim/fun/cov_matrix_free_lkj.hpp @@ -52,13 +52,13 @@ Eigen::Matrix, Eigen::Dynamic, 1> cov_matrix_free_lkj( /** * Overload of `cov_matrix_free_lkj()` to untransform each matrix * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase`. + * @tparam StdVec A standard vector with with a \ref stan::value_type which + * inherits from `Eigen::MatrixBase`. * @param x The standard vector to untransform. */ -template * = nullptr> -auto cov_matrix_free_lkj(const T& x) { - return apply_vector_unary::apply( +template * = nullptr> +auto cov_matrix_free_lkj(const StdVec& x) { + return apply_vector_unary::apply( x, [](auto&& v) { return cov_matrix_free_lkj(v); }); } diff --git a/stan/math/prim/fun/dims.hpp b/stan/math/prim/fun/dims.hpp index 332a32e6089..6d9ec7a417a 100644 --- a/stan/math/prim/fun/dims.hpp +++ b/stan/math/prim/fun/dims.hpp @@ -12,22 +12,23 @@ namespace math { * Pushes dimensions of given argument into given result vector. * * For a scalar that is a no-op. - * @tparam type of scalar + * @tparam Scalar type of scalar * @param x argument * @param result result */ -template * = nullptr> -inline void dims(const T& x, std::vector& result) {} +template * = nullptr> +inline void dims(const Scalar& x, std::vector& result) {} /** * Pushes dimensions of given argument into given result vector. * * For an Eigen type those are the numbers of rows and columns. + * @tparam Mat A Matrix * @param x argument * @param result result */ -template * = nullptr> -inline void dims(const T& x, std::vector& result) { +template * = nullptr> +inline void dims(const Mat& x, std::vector& result) { result.push_back(x.rows()); result.push_back(x.cols()); } diff --git a/stan/math/prim/fun/distance.hpp b/stan/math/prim/fun/distance.hpp index c46e9eed6c4..19bac2ec047 100644 --- a/stan/math/prim/fun/distance.hpp +++ b/stan/math/prim/fun/distance.hpp @@ -15,16 +15,17 @@ namespace math { /** * Returns the distance between two scalars. * - * @tparam T1 type of first scalar. - * @tparam T2 type of second scalar + * @tparam Scalar1 type of first scalar. + * @tparam Scalar2 type of second scalar * @param x1 First scalar. * @param x2 Second scalar. * @return Distance between two scalars * @throw std::domain_error If the arguments are not finite. */ -template * = nullptr> -inline return_type_t distance(const T1& x1, const T2& x2) { +template * = nullptr> +inline return_type_t distance(const Scalar1& x1, + const Scalar2& x2) { check_finite("distance", "x1", x1); check_finite("distance", "x2", x2); return abs(x1 - x2); @@ -33,9 +34,9 @@ inline return_type_t distance(const T1& x1, const T2& x2) { /** * Returns the distance between the specified vectors. * - * @tparam T1 type of the first vector (must be derived from \c + * @tparam Vec1 type of the first vector (must be derived from \c * Eigen::MatrixBase and have one compile time dimension equal to 1) - * @tparam T2 type of the second vector (must be derived from \c + * @tparam Vec2 type of the second vector (must be derived from \c * Eigen::MatrixBase and have one compile time dimension equal to 1) * @param x1 First vector. * @param x2 Second vector. @@ -43,8 +44,9 @@ inline return_type_t distance(const T1& x1, const T2& x2) { * @throw std::domain_error If the vectors are not the same * size. */ -template * = nullptr> -inline return_type_t distance(const T1& x1, const T2& x2) { +template * = nullptr> +inline return_type_t distance(const Vec1& x1, const Vec2& x2) { using std::sqrt; check_matching_sizes("distance", "x1", x1, "x2", x2); return sqrt(squared_distance(x1, x2)); diff --git a/stan/math/prim/fun/dot_self.hpp b/stan/math/prim/fun/dot_self.hpp index 89d5deffe25..a65ec7d06d5 100644 --- a/stan/math/prim/fun/dot_self.hpp +++ b/stan/math/prim/fun/dot_self.hpp @@ -22,12 +22,12 @@ inline double dot_self(const std::vector& x) { * Returns squared norm of a vector or matrix. For vectors that equals the dot * product of the specified vector with itself. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase) + * @tparam Vec type of the vector (must be derived from \c Eigen::MatrixBase) * @param v Vector. */ -template * = nullptr, - require_not_eigen_vt* = nullptr> -inline value_type_t dot_self(const T& v) { +template * = nullptr, + require_not_eigen_vt* = nullptr> +inline value_type_t dot_self(const Vec& v) { return v.squaredNorm(); } diff --git a/stan/math/prim/fun/grad_pFq.hpp b/stan/math/prim/fun/grad_pFq.hpp index e5f90c79c3d..2e5498e2088 100644 --- a/stan/math/prim/fun/grad_pFq.hpp +++ b/stan/math/prim/fun/grad_pFq.hpp @@ -55,8 +55,7 @@ namespace internal { * @param[in] a Vector of 'a' arguments to function * @param[in] b Vector of 'b' arguments to function * @param[in] z Scalar z argument - * @param[in] outer_precision Convergence criteria for infinite sum - * @param[in] inner_precision Convergence criteria for infinite sum + * @param[in] precision Convergence criteria for infinite sum * @param[in] outer_steps Maximum number of iterations for infinite sum * @param[in] inner_steps Maximum number of iterations for infinite sum * @return Generalised hypergeometric function @@ -325,7 +324,8 @@ void grad_pFq_impl(TupleT&& grad_tuple, const Ta& a, const Tb& b, const Tz& z, * @param[in] b Vector of 'b' arguments to function * @param[in] z Scalar z argument * @param[in] precision Convergence criteria for infinite sum - * @param[in] max_steps Maximum number of iterations for infinite sum + * @param[in] outer_steps Maximum number of iterations for infinite sum + * @param[in] inner_steps Maximum number of iterations for infinite sum * @return Tuple of gradients */ template diff --git a/stan/math/prim/fun/hypergeometric_pFq.hpp b/stan/math/prim/fun/hypergeometric_pFq.hpp index a5e2c919b33..cd4da4eca20 100644 --- a/stan/math/prim/fun/hypergeometric_pFq.hpp +++ b/stan/math/prim/fun/hypergeometric_pFq.hpp @@ -20,18 +20,22 @@ namespace math { * * See 'grad_pFq.hpp' for the derivatives wrt each parameter * + * @tparam ArithVec1 An Eigen vector with arithmetic scalar type + * @tparam ArithVec2 An Eigen vector with arithmetic scalar type + * @tparam Arithmetic An arithmetic scalar * @param[in] a Vector of 'a' arguments to function * @param[in] b Vector of 'b' arguments to function * @param[in] z Scalar z argument * @return Generalised hypergeometric function */ -template * = nullptr, - require_arithmetic_t* = nullptr> -return_type_t hypergeometric_pFq(const Ta& a, const Tb& b, - const Tz& z) { - plain_type_t a_ref = a; - plain_type_t b_ref = b; +template < + typename ArithVec1, typename ArithVec2, typename Arithmetic, + require_all_eigen_st* = nullptr, + require_arithmetic_t* = nullptr> +return_type_t hypergeometric_pFq( + const ArithVec1& a, const ArithVec2& b, const Arithmetic& z) { + plain_type_t a_ref = a; + plain_type_t b_ref = b; check_finite("hypergeometric_pFq", "a", a_ref); check_finite("hypergeometric_pFq", "b", b_ref); check_finite("hypergeometric_pFq", "z", z); diff --git a/stan/math/prim/fun/lb_constrain.hpp b/stan/math/prim/fun/lb_constrain.hpp index f31da80cfbf..c3e4e00d1c3 100644 --- a/stan/math/prim/fun/lb_constrain.hpp +++ b/stan/math/prim/fun/lb_constrain.hpp @@ -26,15 +26,16 @@ namespace math { * *

where \f$L\f$ is the constant lower bound. * - * @tparam T Scalar. - * @tparam L Scalar. + * @tparam ScalarT Scalar. + * @tparam ScalarL Scalar. * @param[in] x Unconstrained input * @param[in] lb Lower bound * @return Constrained matrix */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(const T& x, const L& lb) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(const ScalarT& x, const ScalarL& lb) { if (unlikely(value_of_rec(lb) == NEGATIVE_INFTY)) { return identity_constrain(x, lb); } else { @@ -48,16 +49,18 @@ inline auto lb_constrain(const T& x, const L& lb) { * reference with the log absolute Jacobian determinant of the * transform. * - * @tparam T Scalar. - * @tparam L Scalar. + * @tparam ScalarT Scalar. + * @tparam ScalarL Scalar. * @param[in] x unconstrained input * @param[in] lb lower bound on output * @param[in,out] lp reference to log probability to increment * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(const ScalarT& x, const ScalarL& lb, + return_type_t& lp) { if (value_of_rec(lb) == NEGATIVE_INFTY) { return identity_constrain(x, lb); } else { @@ -70,16 +73,16 @@ inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { * Specialization of `lb_constrain` to apply a scalar lower bound elementwise * to each input. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam L Scalar. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam ScalarL Scalar. * @param[in] x unconstrained input * @param[in] lb lower bound on output * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(T&& x, L&& lb) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(EigT&& x, ScalarL&& lb) { return eval(x.unaryExpr([lb](auto&& x) { return lb_constrain(x, lb); })); } @@ -87,17 +90,18 @@ inline auto lb_constrain(T&& x, L&& lb) { * Specialization of `lb_constrain` to apply a scalar lower bound elementwise * to each input. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam L Scalar. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam ScalarL Scalar. * @param[in] x unconstrained input * @param[in] lb lower bound on output * @param[in,out] lp reference to log probability to increment * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(const EigT& x, const ScalarL& lb, + return_type_t& lp) { return eval( x.unaryExpr([lb, &lp](auto&& xx) { return lb_constrain(xx, lb, lp); })); } @@ -106,15 +110,16 @@ inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { * Specialization of `lb_constrain` to apply a matrix of lower bounds * elementwise to each input element. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam L A type inheriting from `EigenBase`. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam EigL A type inheriting from `EigenBase`. * @param[in] x unconstrained input * @param[in] lb lower bound on output * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(T&& x, L&& lb) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(EigT&& x, EigL&& lb) { check_matching_dims("lb_constrain", "x", x, "lb", lb); return eval(x.binaryExpr( lb, [](auto&& x, auto&& lb) { return lb_constrain(x, lb); })); @@ -124,16 +129,18 @@ inline auto lb_constrain(T&& x, L&& lb) { * Specialization of `lb_constrain` to apply a matrix of lower bounds * elementwise to each input element. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam L A type inheriting from `EigenBase`. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam EigL A type inheriting from `EigenBase`. * @param[in] x unconstrained input * @param[in] lb lower bound on output * @param[in,out] lp reference to log probability to increment * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto lb_constrain(const EigT& x, const EigL& lb, + return_type_t& lp) { check_matching_dims("lb_constrain", "x", x, "lb", lb); return eval(x.binaryExpr( lb, [&lp](auto&& xx, auto&& lbb) { return lb_constrain(xx, lbb, lp); })); @@ -143,7 +150,7 @@ inline auto lb_constrain(const T& x, const L& lb, return_type_t& lp) { * Specialization of `lb_constrain` to apply a container of lower bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam L A type inheriting from `EigenBase` or a scalar. * @param[in] x unconstrained input * @param[in] lb lower bound on output @@ -162,7 +169,7 @@ inline auto lb_constrain(const std::vector& x, const L& lb) { * Specialization of `lb_constrain` to apply a container of lower bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam L A type inheriting from `EigenBase` or a standard vector. * @param[in] x unconstrained input * @param[in] lb lower bound on output @@ -183,7 +190,7 @@ inline auto lb_constrain(const std::vector& x, const L& lb, * Specialization of `lb_constrain` to apply a container of lower bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam L A type inheriting from `EigenBase` or a standard vector. * @param[in] x unconstrained input * @param[in] lb lower bound on output @@ -203,7 +210,7 @@ inline auto lb_constrain(const std::vector& x, const std::vector& lb) { * Specialization of `lb_constrain` to apply a container of lower bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam L A type inheriting from `EigenBase` or a standard vector. * @param[in] x unconstrained input * @param[in] lb lower bound on output @@ -230,10 +237,12 @@ inline auto lb_constrain(const std::vector& x, const std::vector& lb, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam L A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam T A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam L A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar * @param[in] x unconstrained input * @param[in] lb lower bound on output * @param[in, out] lp log density accumulator diff --git a/stan/math/prim/fun/lgamma.hpp b/stan/math/prim/fun/lgamma.hpp index 8c5fec86e79..c2b1ebc981b 100644 --- a/stan/math/prim/fun/lgamma.hpp +++ b/stan/math/prim/fun/lgamma.hpp @@ -2,6 +2,7 @@ #define STAN_MATH_PRIM_FUN_LGAMMA_HPP /** + * @file stan/math/prim/fun/lgamma.hpp * The lgamma implementation in stan-math is based on either the * reentrant safe lgamma_r implementation from C or the * boost::math::lgamma implementation. The reentrant safe lgamma_r diff --git a/stan/math/prim/fun/lmultiply.hpp b/stan/math/prim/fun/lmultiply.hpp index e8747dcacea..09e114b2d8e 100644 --- a/stan/math/prim/fun/lmultiply.hpp +++ b/stan/math/prim/fun/lmultiply.hpp @@ -15,14 +15,16 @@ namespace math { * `lmultiply(x, y) = x * log(y)` if `x` or `y` is non-zero and * `lmultiply(0, 0) = 0` otherwise. * - * @tparam T1 type of the first argument - * @tparam T2 type of the second argument + * @tparam Scalar1 type of the first argument + * @tparam Scalar2 type of the second argument * @param a first argument * @param b second argument * @return the first argument times the log of the second argument */ -template * = nullptr> -inline return_type_t lmultiply(const T1 a, const T2 b) { +template * = nullptr> +inline return_type_t lmultiply(const Scalar1 a, + const Scalar2 b) { using std::log; if (a == 0 && b == 0) { return 0; @@ -35,15 +37,16 @@ inline return_type_t lmultiply(const T1 a, const T2 b) { * elementwise, with broadcasting if one of the arguments is a scalar. * At least one of the arguments must be a container. * - * @tparam T1 type of the first argument - * @tparam T2 type of the second argument + * @tparam Container1 type of the first argument + * @tparam Container2 type of the second argument * @param a first argument * @param b second argument * @return result of applying `lmultiply` to the arguments */ -template * = nullptr, - require_all_not_var_matrix_t* = nullptr> -inline auto lmultiply(const T1& a, const T2& b) { +template * = nullptr, + require_all_not_var_matrix_t* = nullptr> +inline auto lmultiply(const Container1& a, const Container2& b) { return apply_scalar_binary( a, b, [&](const auto& c, const auto& d) { return lmultiply(c, d); }); } diff --git a/stan/math/prim/fun/log_sum_exp.hpp b/stan/math/prim/fun/log_sum_exp.hpp index d106abc14db..0c817a3d4cb 100644 --- a/stan/math/prim/fun/log_sum_exp.hpp +++ b/stan/math/prim/fun/log_sum_exp.hpp @@ -72,13 +72,14 @@ inline return_type_t log_sum_exp(const T2& a, const T1& b) { * \f$\log \sum_{n=1}^N \exp(x_n) = \max(x) + \log \sum_{n=1}^N \exp(x_n - * \max(x))\f$. * - * @tparam T type of input vector or matrix + * @tparam ArithContainer type of input vector or matrix * @param[in] x matrix of specified values * @return The log of the sum of the exponentiated vector values. */ -template * = nullptr> -inline auto log_sum_exp(const T& x) { - return apply_vector_unary::reduce(x, [&](const auto& v) { +template * = nullptr> +inline auto log_sum_exp(const ArithContainer& x) { + return apply_vector_unary::reduce(x, [&](const auto& v) { if (v.size() == 0) { return NEGATIVE_INFTY; } diff --git a/stan/math/prim/fun/lub_constrain.hpp b/stan/math/prim/fun/lub_constrain.hpp index a3e91883f51..95ecf3cc887 100644 --- a/stan/math/prim/fun/lub_constrain.hpp +++ b/stan/math/prim/fun/lub_constrain.hpp @@ -30,9 +30,9 @@ namespace math { * *

\f$f(x) = L + (U - L) \mbox{logit}^{-1}(x)\f$ * - * @tparam T Scalar. - * @tparam L Scalar. - * @tparam U Scalar. + * @tparam ScalarT Scalar. + * @tparam ScalarL Scalar. + * @tparam ScalarU Scalar. * @param[in] x Free scalar to transform. * @param[in] lb Lower bound. * @param[in] ub Upper bound. @@ -40,10 +40,11 @@ namespace math { * the free scalar. * @throw std::domain_error if ub <= lb */ -template * = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(T&& x, L&& lb, U&& ub) { +template < + typename ScalarT, typename ScalarL, typename ScalarU, + require_all_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(ScalarT&& x, ScalarL&& lb, ScalarU&& ub) { const bool is_lb_inf = value_of(lb) == NEGATIVE_INFTY; const bool is_ub_inf = value_of(ub) == INFTY; if (unlikely(is_ub_inf && is_lb_inf)) { @@ -65,7 +66,7 @@ inline auto lub_constrain(T&& x, L&& lb, U&& ub) { * density with the log absolute Jacobian determinant. * *

The transform is as defined in - * lub_constrain(T, double, double). The log absolute + * lub_constrain(ScalarT, double, double). The log absolute * Jacobian determinant is given by * *

\f$\log \left| \frac{d}{dx} \left( @@ -80,9 +81,9 @@ inline auto lub_constrain(T&& x, L&& lb, U&& ub) { *

\f$ {} = \log (U - L) + \log (\mbox{logit}^{-1}(x)) * + \log (1 - \mbox{logit}^{-1}(x))\f$ * - * @tparam T Scalar. - * @tparam L Scalar. - * @tparam U Scalar. + * @tparam ScalarT Scalar. + * @tparam ScalarL Scalar. + * @tparam ScalarU Scalar. * @param[in] x Free scalar to transform. * @param[in] lb Lower bound. * @param[in] ub Upper bound. @@ -91,10 +92,12 @@ inline auto lub_constrain(T&& x, L&& lb, U&& ub) { * the free scalar. * @throw std::domain_error if ub <= lb */ -template * = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(T&& x, L&& lb, U&& ub, return_type_t& lp) { +template < + typename ScalarT, typename ScalarL, typename ScalarU, + require_all_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(ScalarT&& x, ScalarL&& lb, ScalarU&& ub, + return_type_t& lp) { const bool is_lb_inf = value_of(lb) == NEGATIVE_INFTY; const bool is_ub_inf = value_of(ub) == INFTY; if (unlikely(is_ub_inf && is_lb_inf)) { @@ -114,10 +117,11 @@ inline auto lub_constrain(T&& x, L&& lb, U&& ub, return_type_t& lp) { /** * Overload for Eigen matrix and scalar bounds. */ -template * = nullptr, - require_all_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub) { +template * = nullptr, + require_all_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const ScalarL& lb, const ScalarU& ub) { return eval( x.unaryExpr([ub, lb](auto&& xx) { return lub_constrain(xx, lb, ub); })); } @@ -125,11 +129,12 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub) { /** * Overload for Eigen matrix and scalar bounds plus lp. */ -template * = nullptr, - require_all_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub, - return_type_t& lp) { +template * = nullptr, + require_all_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const ScalarL& lb, const ScalarU& ub, + return_type_t& lp) { return eval(x.unaryExpr( [lb, ub, &lp](auto&& xx) { return lub_constrain(xx, lb, ub, lp); })); } @@ -138,11 +143,11 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub, * Overload for Eigen matrix with matrix lower bound and scalar upper * bound. */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const EigL& lb, const ScalarU& ub) { check_matching_dims("lub_constrain", "x", x, "lb", lb); return eval(x.binaryExpr( lb, [ub](auto&& x, auto&& lb) { return lub_constrain(x, lb, ub); })); @@ -152,12 +157,12 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub) { * Overload for Eigen matrix with matrix lower bound and scalar upper * bound plus lp. */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub, - return_type_t& lp) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const EigL& lb, const ScalarU& ub, + return_type_t& lp) { check_matching_dims("lub_constrain", "x", x, "lb", lb); return eval(x.binaryExpr(lb, [ub, &lp](auto&& x, auto&& lb) { return lub_constrain(x, lb, ub, lp); @@ -168,11 +173,11 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub, * Overload for Eigen matrix with scalar lower bound and matrix upper * bound. */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const ScalarL& lb, const EigU& ub) { check_matching_dims("lub_constrain", "x", x, "ub", ub); return eval(x.binaryExpr( ub, [lb](auto&& x, auto&& ub) { return lub_constrain(x, lb, ub); })); @@ -182,12 +187,12 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub) { * Overload for Eigen matrix with scalar lower bound and matrix upper * bound plus lp. */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub, - return_type_t& lp) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const ScalarL& lb, const EigU& ub, + return_type_t& lp) { check_matching_dims("lub_constrain", "x", x, "ub", ub); return eval(x.binaryExpr(ub, [lb, &lp](auto&& x, auto&& ub) { return lub_constrain(x, lb, ub, lp); @@ -197,16 +202,17 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub, /** * Overload for Eigen matrix and matrix bounds. */ -template * = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub) { +template * = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const EigL& lb, const EigU& ub) { check_matching_dims("lub_constrain", "x", x, "lb", lb); check_matching_dims("lub_constrain", "x", x, "ub", ub); auto x_ref = to_ref(x); auto lb_ref = to_ref(lb); auto ub_ref = to_ref(ub); - promote_scalar_t, T> x_ret(x.rows(), x.cols()); + promote_scalar_t, EigT> x_ret(x.rows(), + x.cols()); for (Eigen::Index j = 0; j < x_ref.cols(); ++j) { for (Eigen::Index i = 0; i < x_ref.rows(); ++i) { x_ret.coeffRef(i, j) = lub_constrain( @@ -219,17 +225,18 @@ inline auto lub_constrain(const T& x, const L& lb, const U& ub) { /** * Overload for Eigen matrix and matrix bounds plus lp. */ -template * = nullptr, - require_not_var_t>* = nullptr> -inline auto lub_constrain(const T& x, const L& lb, const U& ub, - return_type_t& lp) { +template * = nullptr, + require_not_var_t>* = nullptr> +inline auto lub_constrain(const EigT& x, const EigL& lb, const EigU& ub, + return_type_t& lp) { check_matching_dims("lub_constrain", "x", x, "lb", lb); check_matching_dims("lub_constrain", "x", x, "ub", ub); auto x_ref = to_ref(x); auto lb_ref = to_ref(lb); auto ub_ref = to_ref(ub); - promote_scalar_t, T> x_ret(x.rows(), x.cols()); + promote_scalar_t, EigT> x_ret(x.rows(), + x.cols()); for (Eigen::Index j = 0; j < x_ref.cols(); ++j) { for (Eigen::Index i = 0; i < x_ref.rows(); ++i) { x_ret.coeffRef(i, j) = lub_constrain( @@ -376,12 +383,15 @@ inline auto lub_constrain(const std::vector& x, const std::vector& lb, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam L A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam U A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam T A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam L A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam U A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar * @param[in] x Free scalar to transform * @param[in] lb Lower bound * @param[in] ub Upper bound diff --git a/stan/math/prim/fun/multiply_log.hpp b/stan/math/prim/fun/multiply_log.hpp index 63f1d792e97..b7166dae7be 100644 --- a/stan/math/prim/fun/multiply_log.hpp +++ b/stan/math/prim/fun/multiply_log.hpp @@ -59,15 +59,16 @@ inline return_type_t multiply_log(const T_a a, const T_b b) { * Enables the vectorised application of the multiply_log * function, when the first and/or second arguments are containers. * - * @tparam T1 type of first input - * @tparam T2 type of second input + * @tparam Container1 type of first input + * @tparam Container2 type of second input * @param a First input * @param b Second input * @return multiply_log function applied to the two inputs. */ -template * = nullptr, - require_all_not_var_matrix_t* = nullptr> -inline auto multiply_log(const T1& a, const T2& b) { +template * = nullptr, + require_all_not_var_matrix_t* = nullptr> +inline auto multiply_log(const Container1& a, const Container2& b) { return apply_scalar_binary( a, b, [&](const auto& c, const auto& d) { return multiply_log(c, d); }); } diff --git a/stan/math/prim/fun/norm1.hpp b/stan/math/prim/fun/norm1.hpp index c842ff27917..3364c1525b0 100644 --- a/stan/math/prim/fun/norm1.hpp +++ b/stan/math/prim/fun/norm1.hpp @@ -12,13 +12,14 @@ namespace math { * Returns L1 norm of a vector. For vectors that equals the * sum of magnitudes of its individual elements. * - * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase) + * @tparam EigVec type of the vector (must be derived from \c Eigen::MatrixBase) * @param v Vector. * @return L1 norm of v. */ -template * = nullptr> -inline double norm1(const T& v) { - ref_type_t v_ref = v; +template * = nullptr> +inline double norm1(const EigVec& v) { + ref_type_t v_ref = v; return v_ref.template lpNorm<1>(); } @@ -27,8 +28,8 @@ inline double norm1(const T& v) { * sum of magnitudes of its individual elements. * * @tparam Container type of the vector (must be derived from \c std::Vector) - * @param v Vector. - * @return L1 norm of v. + * @param x Vector. + * @return L1 norm of x. */ template * = nullptr> inline auto norm1(const Container& x) { diff --git a/stan/math/prim/fun/norm2.hpp b/stan/math/prim/fun/norm2.hpp index 07040003943..ba955d4e07a 100644 --- a/stan/math/prim/fun/norm2.hpp +++ b/stan/math/prim/fun/norm2.hpp @@ -14,7 +14,7 @@ namespace math { * * @tparam T type of the vector (must be derived from \c Eigen::MatrixBase) * @param v Vector. - * @return L2 norm of v. + * @return L2 norm of x. */ template * = nullptr> inline double norm2(const T& v) { @@ -27,7 +27,7 @@ inline double norm2(const T& v) { * sum of squares of the elements. * * @tparam Container type of the vector (must be derived from \c std::vector) - * @param v Vector. + * @param x Vector. * @return L2 norm of v. */ template * = nullptr> diff --git a/stan/math/prim/fun/num_elements.hpp b/stan/math/prim/fun/num_elements.hpp index 27bcadd1b62..2348c72dda2 100644 --- a/stan/math/prim/fun/num_elements.hpp +++ b/stan/math/prim/fun/num_elements.hpp @@ -12,11 +12,10 @@ namespace math { * Returns 1, the number of elements in a primitive type. * * @tparam T scalar type - * @param x Argument of primitive type. * @return 1 */ template * = nullptr> -inline int num_elements(const T& x) { +inline constexpr int num_elements(const T& /* x*/) { return 1; } @@ -24,13 +23,12 @@ inline int num_elements(const T& x) { * Returns the size of the specified matrix. * * @tparam T type of the matrix - * - * @param m argument matrix + * @param x argument matrix * @return size of matrix */ template * = nullptr> -inline int num_elements(const T& m) { - return m.size(); +inline int num_elements(const T& x) { + return x.size(); } /** @@ -39,15 +37,15 @@ inline int num_elements(const T& m) { * elements has the same number of elements. * * @tparam T type of elements in the vector - * @param v argument vector + * @param x argument vector * @return number of contained arguments */ template -inline int num_elements(const std::vector& v) { - if (v.size() == 0) { +inline int num_elements(const std::vector& x) { + if (x.size() == 0) { return 0; } - return v.size() * num_elements(v[0]); + return x.size() * num_elements(x[0]); } } // namespace math diff --git a/stan/math/prim/fun/offset_multiplier_constrain.hpp b/stan/math/prim/fun/offset_multiplier_constrain.hpp index 85a58ce4771..2ae8cbb814f 100644 --- a/stan/math/prim/fun/offset_multiplier_constrain.hpp +++ b/stan/math/prim/fun/offset_multiplier_constrain.hpp @@ -282,12 +282,15 @@ inline auto offset_multiplier_constrain(const std::vector& x, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam M A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam S A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam T1 A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam M1 A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam S1 A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar * @param[in] x Unconstrained scalar input * @param[in] mu offset of constrained output * @param[in] sigma multiplier of constrained output @@ -296,9 +299,10 @@ inline auto offset_multiplier_constrain(const std::vector& x, * @throw std::domain_error if sigma <= 0 * @throw std::domain_error if mu is not finite */ -template -inline auto offset_multiplier_constrain(const T& x, const M& mu, const S& sigma, - return_type_t& lp) { +template +inline auto offset_multiplier_constrain(const T1& x, const M1& mu, + const S1& sigma, + return_type_t& lp) { if (Jacobian) { return offset_multiplier_constrain(x, mu, sigma, lp); } else { diff --git a/stan/math/prim/fun/ordered_constrain.hpp b/stan/math/prim/fun/ordered_constrain.hpp index ac0c18ca74d..acf5d587e94 100644 --- a/stan/math/prim/fun/ordered_constrain.hpp +++ b/stan/math/prim/fun/ordered_constrain.hpp @@ -70,15 +70,15 @@ inline auto ordered_constrain(const EigVec& x, value_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T1 A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param x Free vector of scalars * @param[in, out] lp log density accumulator * @return Positive, increasing ordered vector. */ -template * = nullptr> -inline auto ordered_constrain(const T& x, return_type_t& lp) { +template * = nullptr> +inline auto ordered_constrain(const T1& x, return_type_t& lp) { if (Jacobian) { return ordered_constrain(x, lp); } else { @@ -97,16 +97,17 @@ inline auto ordered_constrain(const T& x, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param x Free vector of scalars * @param[in, out] lp log density accumulator * @return Positive, increasing ordered vector. */ -template * = nullptr> -inline auto ordered_constrain(const T& x, return_type_t& lp) { - return apply_vector_unary::apply( +template * = nullptr> +inline auto ordered_constrain(const StdVec& x, return_type_t& lp) { + return apply_vector_unary::apply( x, [&lp](auto&& v) { return ordered_constrain(v, lp); }); } diff --git a/stan/math/prim/fun/ordered_free.hpp b/stan/math/prim/fun/ordered_free.hpp index 4764bceb6a8..f846e948100 100644 --- a/stan/math/prim/fun/ordered_free.hpp +++ b/stan/math/prim/fun/ordered_free.hpp @@ -44,8 +44,8 @@ plain_type_t ordered_free(const EigVec& y) { /** * Overload of `ordered_free()` to untransform each Eigen vector * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase` with compile time rows or columns equal to 1. + * @tparam T A standard vector with with a \ref stan::value_type which inherits + * from `Eigen::MatrixBase` with compile time rows or columns equal to 1. * @param x The standard vector to untransform. */ template * = nullptr> diff --git a/stan/math/prim/fun/positive_constrain.hpp b/stan/math/prim/fun/positive_constrain.hpp index b6d46129c42..be4ff686329 100644 --- a/stan/math/prim/fun/positive_constrain.hpp +++ b/stan/math/prim/fun/positive_constrain.hpp @@ -55,14 +55,15 @@ inline auto positive_constrain(const T& x, S& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam T1 A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar * @param x unconstrained value or container * @param[in, out] lp log density accumulator * @return positive constrained version of unconstrained value(s) */ -template * = nullptr> -inline auto positive_constrain(const T& x, return_type_t& lp) { +template * = nullptr> +inline auto positive_constrain(const T1& x, return_type_t& lp) { if (Jacobian) { return positive_constrain(x, lp); } else { @@ -79,16 +80,17 @@ inline auto positive_constrain(const T& x, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::EigenBase`, a `var_value` with inner type inheriting from - * `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::EigenBase`, a \ref stan::math::var_value with inner type inheriting + * from `Eigen::EigenBase`, a standard vector, or a scalar * @param x unconstrained value or container * @param[in, out] lp log density accumulator * @return positive constrained version of unconstrained value(s) */ -template * = nullptr> -inline auto positive_constrain(const T& x, return_type_t& lp) { - return apply_vector_unary::apply( +template * = nullptr> +inline auto positive_constrain(const StdVec& x, return_type_t& lp) { + return apply_vector_unary::apply( x, [&lp](auto&& v) { return positive_constrain(v, lp); }); } diff --git a/stan/math/prim/fun/positive_ordered_constrain.hpp b/stan/math/prim/fun/positive_ordered_constrain.hpp index f3f0adf1fcf..5e4719177bf 100644 --- a/stan/math/prim/fun/positive_ordered_constrain.hpp +++ b/stan/math/prim/fun/positive_ordered_constrain.hpp @@ -66,8 +66,8 @@ inline auto positive_ordered_constrain(const Vec& x, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam Vec A type inheriting from `Eigen::EigenBase`, a `var_value` with - * inner type inheriting from `Eigen::EigenBase` + * @tparam Vec A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase` * @param x Free vector of scalars * @param[in, out] lp log density accumulato * @return Positive, increasing ordered vector @@ -93,8 +93,8 @@ inline auto positive_ordered_constrain(const Vec& x, return_type_t& lp) { * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform * @tparam Vec A standard vector with inner type inheriting from - * `Eigen::EigenBase`, a `var_value` with inner type inheriting from - * `Eigen::EigenBase` + * `Eigen::EigenBase`, a \ref stan::math::var_value with inner type inheriting + * from `Eigen::EigenBase` * @param x Free vector of scalars * @param[in, out] lp log density accumulato * @return Positive, increasing ordered vector diff --git a/stan/math/prim/fun/positive_ordered_free.hpp b/stan/math/prim/fun/positive_ordered_free.hpp index c627f03ec5c..c3e8626a269 100644 --- a/stan/math/prim/fun/positive_ordered_free.hpp +++ b/stan/math/prim/fun/positive_ordered_free.hpp @@ -44,8 +44,8 @@ auto positive_ordered_free(const EigVec& y) { /** * Overload of `positive_ordered_free()` to untransform each Eigen vector * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase` with compile time rows or columns equal to 1. + * @tparam T A standard vector with with a \ref stan::value_type which inherits + * from `Eigen::MatrixBase` with compile time rows or columns equal to 1. * @param x The standard vector to untransform. */ template * = nullptr> diff --git a/stan/math/prim/fun/pow.hpp b/stan/math/prim/fun/pow.hpp index 2ed54148042..708f9033d39 100644 --- a/stan/math/prim/fun/pow.hpp +++ b/stan/math/prim/fun/pow.hpp @@ -32,18 +32,19 @@ inline complex_return_t complex_pow(const U& x, const V& y) { * Return the first argument raised to the power of the second * argument. * - * @tparam T1 type of first argument - * @tparam T2 type of second argument + * @tparam Scalar1 type of first argument + * @tparam Scalar2 type of second argument * @param a first argument * @param b second argument * @return the first argument raised to the power of the second * argument. */ -template , std::is_arithmetic>, - disjunction, std::is_arithmetic>>* = nullptr> -inline auto pow(const T1& a, const T2& b) { +template < + typename Scalar1, typename Scalar2, + require_all_t, std::is_arithmetic>, + disjunction, + std::is_arithmetic>>* = nullptr> +inline auto pow(const Scalar1& a, const Scalar2& b) { return std::pow(a, b); } @@ -51,8 +52,8 @@ inline auto pow(const T1& a, const T2& b) { * Returns the elementwise raising of the first argument to the power of the * second argument. * - * @tparam T1 type of first argument - * @tparam T2 type of second argument + * @tparam Container1 type of first argument + * @tparam Container2 type of second argument * @param a first argument * @param b second argument * @return the elementwise raising of the first argument to the power of the diff --git a/stan/math/prim/fun/rep_matrix.hpp b/stan/math/prim/fun/rep_matrix.hpp index 7333ec3833d..bfcf652d56c 100644 --- a/stan/math/prim/fun/rep_matrix.hpp +++ b/stan/math/prim/fun/rep_matrix.hpp @@ -12,16 +12,16 @@ namespace math { * Implementation of rep_matrix returning an Eigen matrix with scalar * type equal to the input scalar type. * @tparam Ret An Eigen type. - * @tparam T A Scalar type. + * @tparam Scalar1 A Scalar type. * @param x A Scalar whose values are propogated to all values in the return * matrix. * @param m Number or rows. * @param n Number of columns. */ -template * = nullptr, - require_stan_scalar_t* = nullptr> -inline auto rep_matrix(const T& x, int m, int n) { + require_stan_scalar_t* = nullptr> +inline auto rep_matrix(const Scalar1& x, int m, int n) { check_nonnegative("rep_matrix", "rows", m); check_nonnegative("rep_matrix", "cols", n); return Ret::Constant(m, n, x); @@ -30,16 +30,17 @@ inline auto rep_matrix(const T& x, int m, int n) { /** * Default Implementation of rep_matrix returning an Eigen matrix with scalar * type equal to the input scalar type. - * @tparam T A Scalar type. + * @tparam Scalar2 A Scalar type. * @param x A Scalar whose values are propogated to all values in the return * matrix. * @param m Number or rows. * @param n Number of columns. */ -template * = nullptr> -inline auto rep_matrix(const T& x, int m, int n) { +template * = nullptr> +inline auto rep_matrix(const Scalar2& x, int m, int n) { return rep_matrix< - Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic>>(x, m, n); + Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic>>( + x, m, n); } /** diff --git a/stan/math/prim/fun/simplex_constrain.hpp b/stan/math/prim/fun/simplex_constrain.hpp index 4a7342620a1..6fb2e7c66df 100644 --- a/stan/math/prim/fun/simplex_constrain.hpp +++ b/stan/math/prim/fun/simplex_constrain.hpp @@ -90,9 +90,9 @@ inline auto simplex_constrain(const Vec& y, value_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam Vec A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam Vec A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param[in] y free vector * @param[in, out] lp log density accumulator * @return simplex of dimensionality one greater than `y` @@ -116,8 +116,8 @@ auto simplex_constrain(const Vec& y, return_type_t& lp) { * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform * @tparam Vec A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param[in] y free vector * @param[in, out] lp log density accumulator * @return simplex of dimensionality one greater than `y` diff --git a/stan/math/prim/fun/simplex_free.hpp b/stan/math/prim/fun/simplex_free.hpp index ad984d1070a..062b68b25f3 100644 --- a/stan/math/prim/fun/simplex_free.hpp +++ b/stan/math/prim/fun/simplex_free.hpp @@ -48,8 +48,8 @@ auto simplex_free(const Vec& x) { /** * Overload of `simplex_free()` to untransform each Eigen vector * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase` with compile time rows or columns equal to 1. + * @tparam T A standard vector with with a \ref stan::value_type which inherits + * from `Eigen::MatrixBase` with compile time rows or columns equal to 1. * @param x The standard vector to untransform. */ template * = nullptr> diff --git a/stan/math/prim/fun/to_matrix.hpp b/stan/math/prim/fun/to_matrix.hpp index 28b9def5f55..64086661b2a 100644 --- a/stan/math/prim/fun/to_matrix.hpp +++ b/stan/math/prim/fun/to_matrix.hpp @@ -28,15 +28,15 @@ inline EigMat to_matrix(EigMat&& x) { * Eigen row or column vector. * The runtime dimensions will be the same as the input. * - * @tparam EigMat type of the vector/row vector + * @tparam EigVec type of the vector/row vector * * @param x input vector/row vector * @return the matrix representation of the input */ template * = nullptr> -inline auto to_matrix(EigVec&& matrix) { +inline auto to_matrix(EigVec&& x) { return Eigen::Matrix, Eigen::Dynamic, Eigen::Dynamic>( - std::forward(matrix)); + std::forward(x)); } /** diff --git a/stan/math/prim/fun/to_ref.hpp b/stan/math/prim/fun/to_ref.hpp index ceece5719eb..d22edc0ff3f 100644 --- a/stan/math/prim/fun/to_ref.hpp +++ b/stan/math/prim/fun/to_ref.hpp @@ -8,7 +8,10 @@ namespace math { /** * This evaluates expensive Eigen expressions. If given expression involves no - * calculations this is a no-op that should be optimized away. + * calculations this is a no-op that should be optimized away. If `T` satisfies + * the conditions explained in the docs for `ret_type` then the return type will + * be `T`. Otherwise the return type will be the `plain_type` of `T`. + * For more details on how the return type is selected see `ret_type`. * @tparam T argument type * @param a argument * @return optionally evaluated argument diff --git a/stan/math/prim/fun/ub_constrain.hpp b/stan/math/prim/fun/ub_constrain.hpp index f753f744b52..cdfee461bc1 100644 --- a/stan/math/prim/fun/ub_constrain.hpp +++ b/stan/math/prim/fun/ub_constrain.hpp @@ -25,15 +25,16 @@ namespace math { * *

where \f$U\f$ is the upper bound. * - * @tparam T type of Matrix - * @tparam U type of upper bound + * @tparam ScalarT type of Matrix + * @tparam ScalarU type of upper bound * @param[in] x free Matrix. * @param[in] ub upper bound * @return matrix constrained to have upper bound */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const ScalarT& x, const ScalarU& ub) { if (value_of_rec(ub) == INFTY) { return identity_constrain(x, ub); } else { @@ -54,18 +55,19 @@ inline auto ub_constrain(const T& x, const U& ub) { *

\f$ \log | \frac{d}{dx} -\mbox{exp}(x) + U | * = \log | -\mbox{exp}(x) + 0 | = x\f$. * - * @tparam T type of scalar - * @tparam U type of upper bound + * @tparam ScalarT type of scalar + * @tparam ScalarU type of upper bound * @tparam S type of log probability * @param[in] x free scalar * @param[in] ub upper bound * @param[in,out] lp log density * @return scalar constrained to have upper bound */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub, - std::decay_t>& lp) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const ScalarT& x, const ScalarU& ub, + std::decay_t>& lp) { if (value_of_rec(ub) == INFTY) { return identity_constrain(x, ub); } else { @@ -78,16 +80,16 @@ inline auto ub_constrain(const T& x, const U& ub, * Specialization of `ub_constrain` to apply a scalar upper bound elementwise * to each input. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam U Scalar. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam ScalarU Scalar. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @return upper-bound constrained value corresponding to inputs */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const EigT& x, const ScalarU& ub) { return eval(x.unaryExpr([ub](auto&& xx) { return ub_constrain(xx, ub); })); } @@ -95,18 +97,18 @@ inline auto ub_constrain(const T& x, const U& ub) { * Specialization of `ub_constrain` to apply a scalar upper bound elementwise * to each input. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam U Scalar. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam ScalarU Scalar. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @param[in,out] lp reference to log probability to increment * @return upper-bound constrained value corresponding to inputs */ -template * = nullptr, - require_stan_scalar_t* = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub, - std::decay_t>& lp) { +template * = nullptr, + require_stan_scalar_t* = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const EigT& x, const ScalarU& ub, + std::decay_t>& lp) { return eval( x.unaryExpr([ub, &lp](auto&& xx) { return ub_constrain(xx, ub, lp); })); } @@ -115,15 +117,16 @@ inline auto ub_constrain(const T& x, const U& ub, * Specialization of `ub_constrain` to apply a matrix of upper bounds * elementwise to each input element. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam U A type inheriting from `EigenBase`. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam EigU A type inheriting from `EigenBase`. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @return upper-bound constrained value corresponding to inputs */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const EigT& x, const EigU& ub) { check_matching_dims("ub_constrain", "x", x, "ub", ub); return eval(x.binaryExpr( ub, [](auto&& xx, auto&& ubb) { return ub_constrain(xx, ubb); })); @@ -133,17 +136,18 @@ inline auto ub_constrain(const T& x, const U& ub) { * Specialization of `ub_constrain` to apply a matrix of upper bounds * elementwise to each input element. * - * @tparam T A type inheriting from `EigenBase`. - * @tparam U A type inheriting from `EigenBase`. + * @tparam EigT A type inheriting from `EigenBase`. + * @tparam EigU A type inheriting from `EigenBase`. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @param[in,out] lp reference to log probability to increment * @return upper-bound constrained value corresponding to inputs */ -template * = nullptr, - require_all_not_st_var* = nullptr> -inline auto ub_constrain(const T& x, const U& ub, - std::decay_t>& lp) { +template * = nullptr, + require_all_not_st_var* = nullptr> +inline auto ub_constrain(const EigT& x, const EigU& ub, + std::decay_t>& lp) { check_matching_dims("ub_constrain", "x", x, "ub", ub); return eval(x.binaryExpr( ub, [&lp](auto&& xx, auto&& ubb) { return ub_constrain(xx, ubb, lp); })); @@ -153,14 +157,15 @@ inline auto ub_constrain(const T& x, const U& ub, * Specialization of `ub_constrain` to apply a scalar upper bound elementwise * to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. - * @tparam U Scalar. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . + * @tparam ScalarU Scalar. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr> -inline auto ub_constrain(const std::vector& x, const U& ub) { +template * = nullptr> +inline auto ub_constrain(const std::vector& x, const ScalarU& ub) { std::vector> ret(x.size()); for (size_t i = 0; i < x.size(); ++i) { ret[i] = ub_constrain(x[i], ub); @@ -172,16 +177,17 @@ inline auto ub_constrain(const std::vector& x, const U& ub) { * Specialization of `ub_constrain` to apply a scalar upper bound elementwise * to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. - * @tparam U Scalar. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . + * @tparam ScalarU Scalar. * @param[in] x unconstrained input * @param[in] ub upper bound on output * @param[in,out] lp reference to log probability to increment * @return lower-bound constrained value corresponding to inputs */ -template * = nullptr> -inline auto ub_constrain(const std::vector& x, const U& ub, - return_type_t& lp) { +template * = nullptr> +inline auto ub_constrain(const std::vector& x, const ScalarU& ub, + return_type_t& lp) { std::vector> ret(x.size()); for (size_t i = 0; i < x.size(); ++i) { ret[i] = ub_constrain(x[i], ub, lp); @@ -193,7 +199,7 @@ inline auto ub_constrain(const std::vector& x, const U& ub, * Specialization of `ub_constrain` to apply a container of upper bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam U A type inheriting from `EigenBase` or a standard vector. * @param[in] x unconstrained input * @param[in] ub upper bound on output @@ -213,7 +219,7 @@ inline auto ub_constrain(const std::vector& x, const std::vector& ub) { * Specialization of `ub_constrain` to apply a container of upper bounds * elementwise to each input element. * - * @tparam T A Any type with a Scalar `scalar_type`. + * @tparam T A Any type with a Scalar \ref stan::scalar_type . * @tparam U A type inheriting from `EigenBase` or a standard vector. * @param[in] x unconstrained input * @param[in] ub upper bound on output @@ -240,10 +246,12 @@ inline auto ub_constrain(const std::vector& x, const std::vector& ub, * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar - * @tparam U A type inheriting from `Eigen::EigenBase`, a `var_value` with inner - * type inheriting from `Eigen::EigenBase`, a standard vector, or a scalar + * @tparam T A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar + * @tparam U A type inheriting from `Eigen::EigenBase`, a \ref + * stan::math::var_value with inner type inheriting from `Eigen::EigenBase`, a + * standard vector, or a scalar * @param[in] x unconstrained input * @param[in] ub upper bound on output * @param[in, out] lp log density accumulator diff --git a/stan/math/prim/fun/unit_vector_constrain.hpp b/stan/math/prim/fun/unit_vector_constrain.hpp index 7239c765f56..91db98089e5 100644 --- a/stan/math/prim/fun/unit_vector_constrain.hpp +++ b/stan/math/prim/fun/unit_vector_constrain.hpp @@ -17,18 +17,18 @@ namespace math { * href="https://en.wikipedia.org/wiki/N-sphere#Generating_random_points">the * Wikipedia page on generating random points on an N-sphere. * - * @tparam T type inheriting from `EigenBase` that does not have an fvar + * @tparam EigColVec type inheriting from `EigenBase` that does not have an fvar * scalar type. * @param y vector of K unrestricted variables * @return Unit length vector of dimension K */ -template * = nullptr, - require_not_vt_autodiff* = nullptr> -inline plain_type_t unit_vector_constrain(const T& y) { +template * = nullptr, + require_not_vt_autodiff* = nullptr> +inline plain_type_t unit_vector_constrain(const EigColVec& y) { using std::sqrt; check_nonzero_size("unit_vector_constrain", "y", y); auto&& y_ref = to_ref(y); - value_type_t SN = dot_self(y_ref); + value_type_t SN = dot_self(y_ref); check_positive_finite("unit_vector_constrain", "norm", SN); return y_ref.array() / sqrt(SN); } @@ -65,9 +65,9 @@ inline plain_type_t unit_vector_constrain(const T1& y, T2& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A type inheriting from `Eigen::DenseBase` or a `var_value` with - * inner type inheriting from `Eigen::DenseBase` with compile time dynamic rows - * and 1 column + * @tparam T A type inheriting from `Eigen::DenseBase` or a \ref + * stan::math::var_value with inner type inheriting from `Eigen::DenseBase` with + * compile time dynamic rows and 1 column * @param y vector of K unrestricted variables * @param[in, out] lp log density accumulator * @return Unit length vector of dimension K @@ -90,16 +90,17 @@ inline auto unit_vector_constrain(const T& y, return_type_t& lp) { * * @tparam Jacobian if `true`, increment log density accumulator with log * absolute Jacobian determinant of constraining transform - * @tparam T A standard vector with inner type inheriting from - * `Eigen::DenseBase` or a `var_value` with inner type inheriting from - * `Eigen::DenseBase` with compile time dynamic rows and 1 column + * @tparam StdVec A standard vector with inner type inheriting from + * `Eigen::DenseBase` or a \ref stan::math::var_value with inner type inheriting + * from `Eigen::DenseBase` with compile time dynamic rows and 1 column * @param y vector of K unrestricted variables * @param[in, out] lp log density accumulator * @return Unit length vector of dimension K */ -template * = nullptr> -inline auto unit_vector_constrain(const T& y, return_type_t& lp) { - return apply_vector_unary::apply( +template * = nullptr> +inline auto unit_vector_constrain(const StdVec& y, return_type_t& lp) { + return apply_vector_unary::apply( y, [&lp](auto&& v) { return unit_vector_constrain(v, lp); }); } diff --git a/stan/math/prim/fun/unit_vector_free.hpp b/stan/math/prim/fun/unit_vector_free.hpp index 870e30e6b35..d4d5c039d0d 100644 --- a/stan/math/prim/fun/unit_vector_free.hpp +++ b/stan/math/prim/fun/unit_vector_free.hpp @@ -31,8 +31,8 @@ inline auto unit_vector_free(EigVec&& x) { /** * Overload of `unit_vector_free()` to untransform each Eigen vector * in a standard vector. - * @tparam T A standard vector with with a `value_type` which inherits from - * `Eigen::MatrixBase` with compile time rows or columns equal to 1. + * @tparam T A standard vector with with a \ref stan::value_type which inherits + * from `Eigen::MatrixBase` with compile time rows or columns equal to 1. * @param x The standard vector to untransform. */ template * = nullptr> diff --git a/stan/math/prim/fun/value_of_rec.hpp b/stan/math/prim/fun/value_of_rec.hpp index fcba922ca30..70b2a392723 100644 --- a/stan/math/prim/fun/value_of_rec.hpp +++ b/stan/math/prim/fun/value_of_rec.hpp @@ -21,12 +21,12 @@ namespace math { * types requiring pass-by-reference, this template function * should be specialized. * - * @tparam T Type of scalar. + * @tparam Scalar Type of scalar. * @param x Scalar to convert to double. * @return Value of scalar cast to a double. */ -template > -inline double value_of_rec(const T x) { +template > +inline double value_of_rec(const Scalar x) { return static_cast(x); } @@ -86,10 +86,10 @@ inline std::vector value_of_rec(const std::vector& x) { * @param x Specified std::vector. * @return Specified std::vector. */ -template * = nullptr, - require_vt_same* = nullptr> -inline T value_of_rec(T&& x) { - return std::forward(x); +template * = nullptr, + require_vt_same* = nullptr> +inline StdVec value_of_rec(StdVec&& x) { + return std::forward(x); } /** @@ -98,18 +98,18 @@ inline T value_of_rec(T&& x) { * T must implement value_of_rec. See * test/unit/math/fwd/fun/value_of_test.cpp for fvar and var usage. * - * @tparam T Type of matrix + * @tparam EigMat Type of matrix * @param[in] M Matrix to be converted * @return Matrix of values **/ -template , - typename = require_eigen_t> -inline auto value_of_rec(T&& M) { +template , + typename = require_eigen_t> +inline auto value_of_rec(EigMat&& M) { return make_holder( [](auto& m) { return m.unaryExpr([](auto x) { return value_of_rec(x); }); }, - std::forward(M)); + std::forward(M)); } /** @@ -120,14 +120,14 @@ inline auto value_of_rec(T&& M) { * *

This inline pass-through no-op should be compiled away. * - * @tparam T Type of matrix. + * @tparam ArithEigMat Type of matrix. * @param x Specified matrix. * @return Specified matrix. */ -template , - typename = require_eigen_t> -inline T value_of_rec(T&& x) { - return std::forward(x); +template , + typename = require_eigen_t> +inline ArithEigMat value_of_rec(ArithEigMat&& x) { + return std::forward(x); } } // namespace math } // namespace stan diff --git a/stan/math/prim/functor/apply_scalar_binary.hpp b/stan/math/prim/functor/apply_scalar_binary.hpp index 5210e901121..a84c2757efb 100644 --- a/stan/math/prim/functor/apply_scalar_binary.hpp +++ b/stan/math/prim/functor/apply_scalar_binary.hpp @@ -24,17 +24,18 @@ namespace math { * * This base template function takes (and returns) scalars. * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam Scalar1 Type of first argument to which functor is applied. + * @tparam Scalar2 Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x First input to which operation is applied. * @param y Second input to which operation is applied. * @param f functor to apply to inputs. * @return Scalar with result of applying functor to input. */ -template * = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr> +inline auto apply_scalar_binary(const Scalar1& x, const Scalar2& y, + const F& f) { return f(x, y); } @@ -43,17 +44,17 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * is used for more efficient indexing of both row- and column-major inputs * without separate loops. * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam Eig1 Type of first argument to which functor is applied. + * @tparam Eig2 Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x First Eigen input to which operation is applied. * @param y Second Eigen input to which operation is applied. * @param f functor to apply to Eigen input. * @return Eigen object with result of applying functor to inputs. */ -template * = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr> +inline auto apply_scalar_binary(const Eig1& x, const Eig2& y, const F& f) { check_matching_dims("Binary function", "x", x, "y", y); return x.binaryExpr(y, f); } @@ -62,20 +63,21 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Specialisation for use with one Eigen vector (row or column) and * a one-dimensional std::vector of integer types * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam EigVec Type of first argument to which functor is applied. + * @tparam StdVec Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x Eigen input to which operation is applied. * @param y Integer std::vector input to which operation is applied. * @param f functor to apply to inputs. * @return Eigen object with result of applying functor to inputs. */ -template * = nullptr, - require_std_vector_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_std_vector_vt* = nullptr> +inline auto apply_scalar_binary(const EigVec& x, const StdVec& y, const F& f) { check_matching_sizes("Binary function", "x", x, "y", y); - using int_vec_t = promote_scalar_t, plain_type_t>; + using int_vec_t + = promote_scalar_t, plain_type_t>; Eigen::Map y_map(y.data(), y.size()); return x.binaryExpr(y_map, f); } @@ -84,20 +86,22 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Specialisation for use with a one-dimensional std::vector of integer types * and one Eigen vector (row or column). * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam StdVec Type of first argument to which functor is applied. + * @tparam StdVec Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x Integer std::vector input to which operation is applied. * @param y Eigen input to which operation is applied. * @param f functor to apply to inputs. * @return Eigen object with result of applying functor to inputs. */ -template * = nullptr, - require_eigen_vector_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_eigen_vector_vt* = nullptr> +inline auto apply_scalar_binary(const StdVec1& x, const EigVec2& y, + const F& f) { check_matching_sizes("Binary function", "x", x, "y", y); - using int_vec_t = promote_scalar_t, plain_type_t>; + using int_vec_t + = promote_scalar_t, plain_type_t>; Eigen::Map x_map(x.data(), x.size()); return x_map.binaryExpr(y, f); } @@ -106,19 +110,20 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Specialisation for use with one Eigen matrix and * a two-dimensional std::vector of integer types * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam EigMat Type of first argument to which functor is applied. + * @tparam Container Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x Eigen matrix input to which operation is applied. * @param y Nested integer std::vector input to which operation is applied. * @param f functor to apply to inputs. * @return Eigen object with result of applying functor to inputs. */ -template * = nullptr, - require_std_vector_vt* = nullptr, - require_std_vector_st* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_std_vector_vt* = nullptr, + require_std_vector_st* = nullptr> +inline auto apply_scalar_binary(const EigMat& x, const Container& y, + const F& f) { if (num_elements(x) != num_elements(y)) { std::ostringstream msg; msg << "Inputs to vectorized binary function must match in" @@ -139,19 +144,20 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Specialisation for use with a two-dimensional std::vector of integer types * and one Eigen matrix. * - * @tparam T1 Type of first argument to which functor is applied. - * @tparam T2 Type of second argument to which functor is applied. + * @tparam StdVecVec Type of first argument to which functor is applied. + * @tparam EigMat Type of second argument to which functor is applied. * @tparam F Type of functor to apply. * @param x Nested integer std::vector input to which operation is applied. * @param y Eigen matrix input to which operation is applied. * @param f functor to apply to inputs. * @return Eigen object with result of applying functor to inputs. */ -template * = nullptr, - require_std_vector_st* = nullptr, - require_eigen_matrix_dynamic_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_std_vector_st* = nullptr, + require_eigen_matrix_dynamic_vt* = nullptr> +inline auto apply_scalar_binary(const StdVecVec& x, const EigMat& y, + const F& f) { if (num_elements(x) != num_elements(y)) { std::ostringstream msg; msg << "Inputs to vectorized binary function must match in" @@ -175,8 +181,8 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * for the scalar to be captured and applied to each element in the Eigen * object. * - * @tparam T1 Type of Eigen object to which functor is applied. - * @tparam T2 Type of scalar to which functor is applied. + * @tparam Eig Type of Eigen object to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. * @tparam F Type of functor to apply. * @param x Eigen input to which operation is applied. * @param y Scalar input to which operation is applied. @@ -186,9 +192,10 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Note: The return expresssion needs to be evaluated, otherwise the captured * function and scalar fall out of scope. */ -template * = nullptr, - require_stan_scalar_t* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_stan_scalar_t* = nullptr> +inline auto apply_scalar_binary(const Eig& x, const Scalar& y, const F& f) { return x.unaryExpr([&f, y](const auto& v) { return f(v, y); }); } @@ -199,8 +206,8 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * allows for the scalar to be captured and applied to each element in the * Eigen object. * - * @tparam T1 Type of scalar to which functor is applied. - * @tparam T2 Type of Eigen object to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. + * @tparam Eig Type of Eigen object to which functor is applied. * @tparam F Type of functor to apply. * @param x Scalar input to which operation is applied. * @param y Eigen input to which operation is applied. @@ -210,9 +217,10 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * Note: The return expresssion needs to be evaluated, otherwise the captured * function and scalar fall out of scope. */ -template * = nullptr, require_eigen_t* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_eigen_t* = nullptr> +inline auto apply_scalar_binary(const Scalar& x, const Eig& y, const F& f) { return y.unaryExpr([&f, x](const auto& v) { return f(x, v); }); } @@ -225,17 +233,19 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * return scalar types differ (e.g., functions implicitly promoting * integers). * - * @tparam T1 Type of first std::vector to which functor is applied. - * @tparam T2 Type of second std::vector to which functor is applied. + * @tparam StdVec1 Type of first std::vector to which functor is applied. + * @tparam StdVec2 Type of second std::vector to which functor is applied. * @tparam F Type of functor to apply. * @param x First std::vector input to which operation is applied. * @param y Second std::vector input to which operation is applied. * @param f functor to apply to std::vector inputs. * @return std::vector with result of applying functor to inputs. */ -template * = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template < + typename StdVec1, typename StdVec2, typename F, + require_all_std_vector_vt* = nullptr> +inline auto apply_scalar_binary(const StdVec1& x, const StdVec2& y, + const F& f) { check_matching_sizes("Binary function", "x", x, "y", y); decltype(auto) x_vec = as_column_vector_or_scalar(x); decltype(auto) y_vec = as_column_vector_or_scalar(y); @@ -256,18 +266,19 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * return scalar types differ (e.g., functions implicitly promoting * integers). * - * @tparam T1 Type of std::vector to which functor is applied. - * @tparam T2 Type of scalar to which functor is applied. + * @tparam StdVecScalar Type of std::vector to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. * @tparam F Type of functor to apply. * @param x std::vector input to which operation is applied. * @param y Scalar input to which operation is applied. * @param f functor to apply to std::vector and scalar inputs. * @return std::vector with result of applying functor to inputs. */ -template * = nullptr, - require_stan_scalar_t* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_stan_scalar_t* = nullptr> +inline auto apply_scalar_binary(const StdVecScalar& x, const Scalar& y, + const F& f) { decltype(auto) x_vec = as_column_vector_or_scalar(x); using T_return = std::decay_t; std::vector result(x.size()); @@ -286,18 +297,18 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * return scalar types differ (e.g., functions implicitly promoting * integers). * - * @tparam T1 Type of scalar to which functor is applied. - * @tparam T2 Type of std::vector to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. + * @tparam StdVec Type of std::vector to which functor is applied. * @tparam F Type of functor to apply. * @param x Scalar input to which operation is applied. * @param y std::vector input to which operation is applied. * @param f functor to apply to std::vector and scalar inputs. * @return std::vector with result of applying functor to inputs. */ -template * = nullptr, - require_std_vector_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr, + require_std_vector_vt* = nullptr> +inline auto apply_scalar_binary(const Scalar& x, const StdVec& y, const F& f) { decltype(auto) y_vec = as_column_vector_or_scalar(y); using T_return = std::decay_t; std::vector result(y.size()); @@ -312,18 +323,19 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * return scalar types differ (e.g., functions implicitly promoting * integers). * - * @tparam T1 Type of first std::vector to which functor is applied. - * @tparam T2 Type of second std::vector to which functor is applied. + * @tparam Container1 Type of first std::vector to which functor is applied. + * @tparam Container2 Type of second std::vector to which functor is applied. * @tparam F Type of functor to apply. * @param x First std::vector input to which operation is applied. * @param y Second std::vector input to which operation is applied. * @param f functor to apply to std::vector inputs. * @return std::vector with result of applying functor to inputs. */ -template < - typename T1, typename T2, typename F, - require_all_std_vector_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template * = nullptr> +inline auto apply_scalar_binary(const Container1& x, const Container2& y, + const F& f) { check_matching_sizes("Binary function", "x", x, "y", y); using T_return = plain_type_t; size_t y_size = y.size(); @@ -340,18 +352,20 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * where the input and return scalar types differ (e.g., functions implicitly * promoting integers). * - * @tparam T1 Type of std::vector to which functor is applied. - * @tparam T2 Type of scalar to which functor is applied. + * @tparam Container Type of std::vector to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. * @tparam F Type of functor to apply. * @param x std::vector input to which operation is applied. * @param y Scalar input to which operation is applied. * @param f functor to apply to inputs. * @return std::vector with result of applying functor to inputs. */ -template * = nullptr, - require_stan_scalar_t* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template < + typename Container, typename Scalar, typename F, + require_std_vector_vt* = nullptr, + require_stan_scalar_t* = nullptr> +inline auto apply_scalar_binary(const Container& x, const Scalar& y, + const F& f) { using T_return = plain_type_t; size_t x_size = x.size(); std::vector result(x_size); @@ -367,18 +381,20 @@ inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { * where the input and return scalar types differ (e.g., functions implicitly * promoting integers). * - * @tparam T1 Type of scalar to which functor is applied. - * @tparam T2 Type of std::vector to which functor is applied. + * @tparam Scalar Type of scalar to which functor is applied. + * @tparam Scalar Type of std::vector to which functor is applied. * @tparam F Type of functor to apply. * @param x Scalar input to which operation is applied. * @param y std::vector input to which operation is applied. * @param f functor to apply to inputs. * @return std::vector with result of applying functor to inputs. */ -template * = nullptr, - require_std_vector_vt* = nullptr> -inline auto apply_scalar_binary(const T1& x, const T2& y, const F& f) { +template < + typename Scalar, typename Container, typename F, + require_stan_scalar_t* = nullptr, + require_std_vector_vt* = nullptr> +inline auto apply_scalar_binary(const Scalar& x, const Container& y, + const F& f) { using T_return = plain_type_t; size_t y_size = y.size(); std::vector result(y_size); diff --git a/stan/math/prim/functor/operands_and_partials.hpp b/stan/math/prim/functor/operands_and_partials.hpp index 9b3faeff4dc..078d34dac7e 100644 --- a/stan/math/prim/functor/operands_and_partials.hpp +++ b/stan/math/prim/functor/operands_and_partials.hpp @@ -76,13 +76,10 @@ class ops_partials_edge> { typename, typename, typename> friend class stan::math::operands_and_partials; }; -template -constexpr double - ops_partials_edge>::operands_; } // namespace internal -/** \ingroup type_trait - * \callergraph +/** + * * This template builds partial derivatives with respect to a * set of * operands. There are two reason for the generality of this @@ -144,7 +141,7 @@ class operands_and_partials { const Op5& /* op5 */, const Op6& /* op6 */, const Op7& /* op7 */, const Op8& /* op8 */) noexcept {} - /** \ingroup type_trait + /** * Build the node to be stored on the autodiff graph. * This should contain both the value and the tangent. * diff --git a/stan/math/prim/meta/base_type.hpp b/stan/math/prim/meta/base_type.hpp index 80cebb44cb0..56c1399bb45 100644 --- a/stan/math/prim/meta/base_type.hpp +++ b/stan/math/prim/meta/base_type.hpp @@ -11,14 +11,19 @@ namespace stan { -/** +/** \ingroup type_trait * Metaprogram structure to determine the base base type of a template * argument. Qualifiers `const` and `volatile` are removed from all * types as are references. * *

This base class should be specialized for structured types.

* - * @tparam T type of non-container + * This type trait operates similarly to \ref stan::scalar_type where it is + * recursively called on containers, however + * `scalar_type_t>` and `value_type_t>` + * will return a `std::complex`, while this type trait will return `T`. + * + * @tparam T type * @ingroup type_trait */ template @@ -26,10 +31,13 @@ struct base_type { using type = std::decay_t; }; +/** \ingroup type_trait + * See the docs for \ref stan::base_type + */ template using base_type_t = typename base_type::type; -/** +/** \ingroup type_trait * Specialization of base_type for vector to recursively return the inner * base type. * @@ -41,7 +49,7 @@ struct base_type::value>> { using type = base_type_t::value_type>; }; -/** +/** \ingroup type_trait * Template metaprogram defining the base base type of * values stored in an Eigen matrix. * @@ -53,7 +61,7 @@ struct base_type::value>> { using type = base_type_t::Scalar>; }; -/** +/** \ingroup type_trait * Template metaprogram defining the base type for values * stored in a complex number. * diff --git a/stan/math/prim/meta/forward_as.hpp b/stan/math/prim/meta/forward_as.hpp index 838e1d336fc..42cacb04bb4 100644 --- a/stan/math/prim/meta/forward_as.hpp +++ b/stan/math/prim/meta/forward_as.hpp @@ -15,7 +15,7 @@ constexpr bool eigen_static_size_match(T1 desired, T2 actual) { } } // namespace internal -/** \ingroup type_trait +/** * Assume which type we get. If actual type is convertible to assumed type or in * case of eigen types compile time rows and columns also match or desired sizes * are dynamic this is a no-op. Otherwise it throws std::runtime_error, which @@ -38,7 +38,7 @@ inline T_actual&& forward_as(T_actual&& a) { // NOLINT return std::forward(a); } -/** \ingroup type_trait +/** * Assume which type we get. If actual type is not convertible to assumed type * or in case of eigen types compile time rows and columns are not the same and * desired sizes are not dynamic this has return type of \c T_desired, but it @@ -62,7 +62,7 @@ inline T_desired forward_as(const T_actual& a) { throw std::runtime_error("Wrong type assumed! Please file a bug report."); } -/** \ingroup type_trait +/** * Assume which type we get. If actual type is convertible to assumed type or in * case of eigen types compile time rows and columns also match or desired sizes * are dynamic this is a no-op. Otherwise it throws std::runtime_error, diff --git a/stan/math/prim/meta/holder.hpp b/stan/math/prim/meta/holder.hpp index 796caf8a541..8c41b811336 100644 --- a/stan/math/prim/meta/holder.hpp +++ b/stan/math/prim/meta/holder.hpp @@ -15,6 +15,10 @@ * \ingroup eigen_expressions * \defgroup returning_expressions Returning expressions */ + +namespace stan { +namespace math { + /** * \ingroup returning_expressions * @@ -59,14 +63,11 @@ * be created either by directly supplying pointers to such objects to `holder` * function or by forwarding function arguments and moving local variables to * `make_holder`, which will move any rvalues to heap first. + * + * This was implenmented following the tutorial on edding new expressions to + * Eigen: https://eigen.tuxfamily.org/dox/TopicNewExpressionType.html + * */ - -// This was implenmented following the tutorial on edding new expressions to -// Eigen: https://eigen.tuxfamily.org/dox/TopicNewExpressionType.html - -namespace stan { -namespace math { - template class Holder; @@ -76,6 +77,9 @@ class Holder; namespace Eigen { namespace internal { +/** + * Traits for holder class + */ template struct traits> { typedef typename ArgType::StorageKind StorageKind; @@ -108,8 +112,8 @@ namespace math { * A no-op Eigen operation. This object also owns pointers to dynamically * allocated objects used in its argument expression. When this object is * destructed, those objects are deleted. - * @tparam Derived derived type - * @tparam T type of the argument + * @tparam ArgType type of the argument + * @tparam Ptrs Types of pointers to intermediate types. */ template class Holder @@ -165,6 +169,9 @@ class Holder namespace Eigen { namespace internal { +/** + * evaluator overload for `Holder`. + */ template struct evaluator> : evaluator_base> { @@ -340,16 +347,16 @@ auto make_holder_impl(const F& func, std::index_sequence, * rvalue argument will be moved to heap first. The arguments moved to heap are * deleted once the expression is destructed. * - * @tparam F type of the functor + * @tparam ExprF type of the functor * @tparam Args types of the arguments * @param func the functor * @param args arguments for the functor * @return `holder` referencing expression constructed by given functor */ -template ()(std::declval()...))>* = nullptr> -auto make_holder(const F& func, Args&&... args) { +template ()(std::declval()...))>* = nullptr> +auto make_holder(const ExprF& func, Args&&... args) { return internal::make_holder_impl(func, std::make_index_sequence(), std::forward(args)...); diff --git a/stan/math/prim/meta/is_autodiff.hpp b/stan/math/prim/meta/is_autodiff.hpp index c24be6480a4..bee9bf02e87 100644 --- a/stan/math/prim/meta/is_autodiff.hpp +++ b/stan/math/prim/meta/is_autodiff.hpp @@ -9,7 +9,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks if decayed type is a var or fvar * @tparam The type to check * @ingroup type_trait diff --git a/stan/math/prim/meta/is_base_pointer_convertible.hpp b/stan/math/prim/meta/is_base_pointer_convertible.hpp index 814656d92c5..2791504731f 100644 --- a/stan/math/prim/meta/is_base_pointer_convertible.hpp +++ b/stan/math/prim/meta/is_base_pointer_convertible.hpp @@ -7,7 +7,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks if a type's pointer is convertible to a templated base type's pointer. * If the arbitrary function * ``` diff --git a/stan/math/prim/meta/is_complex.hpp b/stan/math/prim/meta/is_complex.hpp index c4edba88fb6..6fcb85c2d2e 100644 --- a/stan/math/prim/meta/is_complex.hpp +++ b/stan/math/prim/meta/is_complex.hpp @@ -11,7 +11,7 @@ namespace stan { namespace internal { -/** +/** \ingroup type_trait * Provides a member constant `value` which is equal to `true` if * `T` is an instance of `std::complex` and `false` otherwise. * @@ -26,7 +26,7 @@ struct is_complex_impl> : std::true_type {}; } // namespace internal -/** +/** \ingroup type_trait * If `T` is an arithmetic type (that is, an instance of * `std::complex`) or a cv-qualified version thereof, provides the * member constant `value` equal `true`; for any other type the value is @@ -58,8 +58,8 @@ struct scalar_type::value>> { STAN_ADD_REQUIRE_UNARY(complex, is_complex, require_stan_scalar_complex); STAN_ADD_REQUIRE_UNARY_INNER(complex, is_complex, require_stan_scalar_complex); -/** - * If the `value_type` of the type `T` is of type +/** \ingroup type_trait + * If the \ref stan::value_type of the type `T` is of type * `std::complex` or a cv-qualified version thereof, provides the * member constant `value` equal `true`; for any other type the value is * `false`. @@ -70,8 +70,8 @@ STAN_ADD_REQUIRE_UNARY_INNER(complex, is_complex, require_stan_scalar_complex); template struct is_vt_complex : is_complex>> {}; -/** - * If the `value_type` of the type `T` is not of type +/** \ingroup type_trait + * If the \ref stan::value_type of the type `T` is not of type * `std::complex` or a cv-qualified version thereof, provides the * member constant `value` equal `true`; for any other type the value is * `false`. diff --git a/stan/math/prim/meta/is_container.hpp b/stan/math/prim/meta/is_container.hpp index b24f0f3d558..a78ad0a91c2 100644 --- a/stan/math/prim/meta/is_container.hpp +++ b/stan/math/prim/meta/is_container.hpp @@ -14,7 +14,7 @@ namespace stan { -/** +/** \ingroup type_trait * Deduces whether type is eigen matrix or standard vector. * @tparam Container type to check */ diff --git a/stan/math/prim/meta/is_container_or_var_matrix.hpp b/stan/math/prim/meta/is_container_or_var_matrix.hpp index 5d970ce31da..a47cd2c7c2a 100644 --- a/stan/math/prim/meta/is_container_or_var_matrix.hpp +++ b/stan/math/prim/meta/is_container_or_var_matrix.hpp @@ -15,7 +15,7 @@ namespace stan { -/** +/** \ingroup type_trait * Deduces whether type is eigen matrix, standard vector, or var. * @tparam Container type to check */ diff --git a/stan/math/prim/meta/is_dense_dynamic.hpp b/stan/math/prim/meta/is_dense_dynamic.hpp index 69fef72a16b..590ba4cbd93 100644 --- a/stan/math/prim/meta/is_dense_dynamic.hpp +++ b/stan/math/prim/meta/is_dense_dynamic.hpp @@ -27,7 +27,7 @@ struct is_dense_dynamic_impl>> : bool_constant>::value> {}; } // namespace internal -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::DenseBase and has dynamic rows * and columns or is a `var_value<>` whose inner type satisfies the conditions * above. If true this will have a static member function named value with diff --git a/stan/math/prim/meta/is_detected.hpp b/stan/math/prim/meta/is_detected.hpp index 487ce961d33..033f68493f6 100644 --- a/stan/math/prim/meta/is_detected.hpp +++ b/stan/math/prim/meta/is_detected.hpp @@ -9,7 +9,7 @@ namespace stan { template class, typename = void> struct is_detected : std::false_type {}; -/** +/** \ingroup type_trait * Checks whether a valid type is detected. Most commonly used to detect * attributes of objects. * @tparam T The type to be checked. diff --git a/stan/math/prim/meta/is_double_or_int.hpp b/stan/math/prim/meta/is_double_or_int.hpp index 9a8d3ed5b20..e1fa7668b7a 100644 --- a/stan/math/prim/meta/is_double_or_int.hpp +++ b/stan/math/prim/meta/is_double_or_int.hpp @@ -7,7 +7,7 @@ #include namespace stan { -/** +/** \ingroup type_trait * Checks if decayed type is a double or integer * @tparam The type to check * @ingroup type_trait diff --git a/stan/math/prim/meta/is_eigen.hpp b/stan/math/prim/meta/is_eigen.hpp index ab2d114b9c8..138ca606231 100644 --- a/stan/math/prim/meta/is_eigen.hpp +++ b/stan/math/prim/meta/is_eigen.hpp @@ -10,7 +10,7 @@ namespace stan { -/** +/** \ingroup type_trait * Check if type derives from `EigenBase` * @tparam T Type to check if it is derived from `EigenBase` * @tparam Enable used for SFINAE deduction. @@ -20,7 +20,7 @@ template struct is_eigen : bool_constant::value> {}; -/** +/** \ingroup type_trait * Template metaprogram defining the base scalar type of * values stored in an Eigen matrix. * @@ -32,7 +32,7 @@ struct scalar_type::value>> { using type = scalar_type_t::Scalar>; }; -/** +/** \ingroup type_trait * Template metaprogram defining the type of values stored in an * Eigen matrix, vector, or row vector. * @@ -47,7 +47,7 @@ struct value_type::value>> { STAN_ADD_REQUIRE_UNARY(eigen, is_eigen, require_eigens_types); STAN_ADD_REQUIRE_CONTAINER(eigen, is_eigen, require_eigens_types); -/** +/** \ingroup type_trait * Check if a type is derived from `Eigen::ArrayBase` * @tparam T type to check * @ingroup type_trait @@ -59,7 +59,7 @@ struct is_eigen_array STAN_ADD_REQUIRE_UNARY(eigen_array, is_eigen_array, require_eigens_types); STAN_ADD_REQUIRE_CONTAINER(eigen_array, is_eigen_array, require_eigens_types); -/** +/** \ingroup type_trait * Check if a type is derived from `Eigen::MatrixBase` or `Eigen::ArrayBase` * @tparam T type to check. * @ingroup type_trait @@ -82,7 +82,7 @@ struct is_eigen_contiguous_map_impl>> } // namespace internal -/** +/** \ingroup type_trait * Check if a type is an `Eigen::Map` with contiguous stride * @ingroup type_trait */ diff --git a/stan/math/prim/meta/is_eigen_dense_base.hpp b/stan/math/prim/meta/is_eigen_dense_base.hpp index 3ce1dbe8ebc..b227fe29052 100644 --- a/stan/math/prim/meta/is_eigen_dense_base.hpp +++ b/stan/math/prim/meta/is_eigen_dense_base.hpp @@ -9,7 +9,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::DenseBase. * If true this will have a static member function named value with a type * of true, else value is false. diff --git a/stan/math/prim/meta/is_eigen_dense_dynamic.hpp b/stan/math/prim/meta/is_eigen_dense_dynamic.hpp index fc5e2e85335..f13ab607408 100644 --- a/stan/math/prim/meta/is_eigen_dense_dynamic.hpp +++ b/stan/math/prim/meta/is_eigen_dense_dynamic.hpp @@ -11,7 +11,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::DenseBase and has dynamic rows * and columns. If true this will have a static member function named value with * a type of true, else value is false. diff --git a/stan/math/prim/meta/is_eigen_matrix.hpp b/stan/math/prim/meta/is_eigen_matrix.hpp index 112c9c99731..565bc4c4fc0 100644 --- a/stan/math/prim/meta/is_eigen_matrix.hpp +++ b/stan/math/prim/meta/is_eigen_matrix.hpp @@ -13,7 +13,7 @@ namespace stan { namespace internal { -/** +/** \ingroup type_trait * Underlying implimenation to check if an Eigen matrix has rows or cols not * equal to 1. */ @@ -30,7 +30,7 @@ struct is_eigen_matrix_dynamic_impl } // namespace internal -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::MatrixBase and has columns and * rows not equal to 1. If true this will have a * static member function named value with a type of true, else value is false. diff --git a/stan/math/prim/meta/is_eigen_matrix_base.hpp b/stan/math/prim/meta/is_eigen_matrix_base.hpp index 9e4e6e9465e..e301edef861 100644 --- a/stan/math/prim/meta/is_eigen_matrix_base.hpp +++ b/stan/math/prim/meta/is_eigen_matrix_base.hpp @@ -9,7 +9,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::MatrixBase. * If true this will have a static member function named value with a type * of true, else value is false. diff --git a/stan/math/prim/meta/is_eigen_sparse_base.hpp b/stan/math/prim/meta/is_eigen_sparse_base.hpp index 2c1028730bf..0a6cb78a946 100644 --- a/stan/math/prim/meta/is_eigen_sparse_base.hpp +++ b/stan/math/prim/meta/is_eigen_sparse_base.hpp @@ -9,7 +9,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks whether type T is derived from Eigen::SparseMatrixBase. * If true this will have a static member function named value with a type * of true, else value is false. diff --git a/stan/math/prim/meta/is_kernel_expression.hpp b/stan/math/prim/meta/is_kernel_expression.hpp index 1063302f41a..776e96cc863 100644 --- a/stan/math/prim/meta/is_kernel_expression.hpp +++ b/stan/math/prim/meta/is_kernel_expression.hpp @@ -26,7 +26,7 @@ class operation_cl_base {}; */ class operation_cl_lhs_base {}; -/** +/** \ingroup type_trait * Determines whether a type is non-scalar type that is a valid kernel generator * expression. */ @@ -38,7 +38,7 @@ template struct is_kernel_expression_and_not_scalar> : std::true_type {}; -/** +/** \ingroup type_trait * Determines whether a type is is a valid kernel generator expression. Valid * expressions are kernel generator operations, scalars and \c matrix_cl and * references of these types. @@ -49,7 +49,7 @@ struct is_kernel_expression || std::is_arithmetic>::value> { }; -/** +/** \ingroup type_trait * Enables a template if all given types are non-scalar types that are a * valid kernel generator expressions. */ @@ -57,7 +57,7 @@ template using require_all_kernel_expressions_and_none_scalar_t = require_all_t...>; -/** +/** \ingroup type_trait * Enables a template if all given types are are a valid kernel generator * expressions. */ @@ -65,7 +65,7 @@ template using require_all_kernel_expressions_t = require_all_t...>; -/** +/** \ingroup type_trait * Determines whether a type is an assignable kernel generator * expression. */ @@ -76,14 +76,14 @@ struct is_kernel_expression_lhs template struct is_kernel_expression_lhs> : std::true_type {}; -/** +/** \ingroup type_trait * Determines whether a type is a var containing a kernel generator expression. */ template struct is_rev_kernel_expression : math::conjunction, is_kernel_expression>> {}; -/** +/** \ingroup type_trait * Determines whether a type is either a kernel generator * expression or a var containing a kernel generator expression. */ @@ -92,7 +92,7 @@ struct is_prim_or_rev_kernel_expression : math::disjunction, is_rev_kernel_expression> { }; -/** +/** \ingroup type_trait * Determines whether a type is either a non-scalar kernel generator * expression or a var containing a non-scalar kernel generator expression. */ diff --git a/stan/math/prim/meta/is_matrix.hpp b/stan/math/prim/meta/is_matrix.hpp index c8f4138bb0a..58c92f84316 100644 --- a/stan/math/prim/meta/is_matrix.hpp +++ b/stan/math/prim/meta/is_matrix.hpp @@ -7,9 +7,10 @@ #include namespace stan { -/** - * Check if a type is derived from `Eigen::EigenBase` or is a `var_value` - * whose `value_type` is derived from `Eigen::EigenBase` +/** \ingroup type_trait + * Check if a type is derived from `Eigen::EigenBase` or is a \ref + * stan::math::var_value whose \ref stan::value_type is derived from + * `Eigen::EigenBase` * @tparam T type to check. * @ingroup type_trait */ diff --git a/stan/math/prim/meta/is_matrix_cl.hpp b/stan/math/prim/meta/is_matrix_cl.hpp index 1d7841405a8..4919c968504 100644 --- a/stan/math/prim/meta/is_matrix_cl.hpp +++ b/stan/math/prim/meta/is_matrix_cl.hpp @@ -18,7 +18,7 @@ class matrix_cl_base {}; } // namespace math -/** \ingroup type_traits +/** \ingroup type_trait * Checks if the decayed type of T is a matrix_cl. */ template diff --git a/stan/math/prim/meta/is_stan_scalar.hpp b/stan/math/prim/meta/is_stan_scalar.hpp index fe97573ed30..1cc991be4ea 100644 --- a/stan/math/prim/meta/is_stan_scalar.hpp +++ b/stan/math/prim/meta/is_stan_scalar.hpp @@ -15,7 +15,7 @@ namespace stan { -/** +/** \ingroup type_trait * Checks if decayed type is a var, fvar, or arithmetic * @tparam The type to check * @ingroup type_trait diff --git a/stan/math/prim/meta/is_string_convertible.hpp b/stan/math/prim/meta/is_string_convertible.hpp index b2fd9d9522b..d056672d588 100644 --- a/stan/math/prim/meta/is_string_convertible.hpp +++ b/stan/math/prim/meta/is_string_convertible.hpp @@ -7,7 +7,7 @@ namespace stan { -/** +/** \ingroup type_trait * Deduces whether type is convertible to string * @tparam T type to check * @ingroup type_trait diff --git a/stan/math/prim/meta/is_var_dense_dynamic.hpp b/stan/math/prim/meta/is_var_dense_dynamic.hpp index 0fc63a06ee5..d258c83caca 100644 --- a/stan/math/prim/meta/is_var_dense_dynamic.hpp +++ b/stan/math/prim/meta/is_var_dense_dynamic.hpp @@ -7,9 +7,9 @@ #include namespace stan { -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase` and has dynamic rows and columns +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase` and has dynamic rows and columns * @tparam T type to check. * @ingroup type_trait */ diff --git a/stan/math/prim/meta/is_var_eigen.hpp b/stan/math/prim/meta/is_var_eigen.hpp index a5678c3bc31..6070c96f70f 100644 --- a/stan/math/prim/meta/is_var_eigen.hpp +++ b/stan/math/prim/meta/is_var_eigen.hpp @@ -7,9 +7,9 @@ #include namespace stan { -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase` +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase` * @tparam T type to check. * @ingroup type_trait */ diff --git a/stan/math/prim/meta/is_var_matrix.hpp b/stan/math/prim/meta/is_var_matrix.hpp index 9193b10f809..2bb852c6535 100644 --- a/stan/math/prim/meta/is_var_matrix.hpp +++ b/stan/math/prim/meta/is_var_matrix.hpp @@ -8,9 +8,9 @@ #include namespace stan { -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase` +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase` * @tparam T type to check. * @ingroup type_trait */ @@ -22,10 +22,10 @@ struct is_var_matrix STAN_ADD_REQUIRE_UNARY(var_matrix, is_var_matrix, require_eigens_types); STAN_ADD_REQUIRE_UNARY_INNER(var_matrix, is_var_matrix, require_eigens_types); -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase`. And the type must have a compile time constant number - * of columns equal to 1. +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase`. And the type must have a compile time + * constant number of columns equal to 1. * @tparam T type to check. * @ingroup type_trait */ @@ -38,10 +38,10 @@ STAN_ADD_REQUIRE_UNARY(var_col_vector, is_var_col_vector, require_eigens_types); STAN_ADD_REQUIRE_UNARY_INNER(var_col_vector, is_var_col_vector, require_eigens_types); -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase`. And the type must have a compile time constant number - * of rows equal to 1. +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase`. And the type must have a compile time + * constant number of rows equal to 1. * @tparam T type to check. * @ingroup type_trait */ @@ -54,10 +54,10 @@ STAN_ADD_REQUIRE_UNARY(var_row_vector, is_var_row_vector, require_eigens_types); STAN_ADD_REQUIRE_UNARY_INNER(var_row_vector, is_var_row_vector, require_eigens_types); -/** - * Check if a type is a `var_value` whose `value_type` is derived from - * `Eigen::EigenBase`. And the type must have a compile time constant number - * of columns or rows equal to 1. +/** \ingroup type_trait + * Check if a type is a \ref stan::math::var_value whose \ref stan::value_type + * is derived from `Eigen::EigenBase`. And the type must have a compile time + * constant number of columns or rows equal to 1. * @tparam T type to check. * @ingroup type_trait */ @@ -69,9 +69,9 @@ struct is_var_vector STAN_ADD_REQUIRE_UNARY(var_vector, is_var_vector, require_eigens_types); STAN_ADD_REQUIRE_UNARY_INNER(var_vector, is_var_vector, require_eigens_types); -/** - * Check if any types in a parameter pack are a `var_value` whose `value_type` - * is derived from `Eigen::EigenBase` +/** \ingroup type_trait + * Check if any types in a parameter pack are a \ref stan::math::var_value + * whose \ref stan::value_type is derived from `Eigen::EigenBase` * @tparam Types parameter pack of types to check. * @ingroup type_trait */ diff --git a/stan/math/prim/meta/is_vector.hpp b/stan/math/prim/meta/is_vector.hpp index e6e907ef6a9..e0ca2a07ddb 100644 --- a/stan/math/prim/meta/is_vector.hpp +++ b/stan/math/prim/meta/is_vector.hpp @@ -140,7 +140,7 @@ struct is_eigen_vector : bool_constant::value STAN_ADD_REQUIRE_UNARY(eigen_vector, is_eigen_vector, require_eigens_types); STAN_ADD_REQUIRE_CONTAINER(eigen_vector, is_eigen_vector, require_eigens_types); -/** +/** \ingroup type_trait * Require `Row` is a row vector and `Col` is a column vector. * @ingroup require_eigen_types */ @@ -148,7 +148,7 @@ template using require_eigen_row_and_col_t = require_t< math::conjunction, is_eigen_col_vector>>; -/** +/** \ingroup type_trait * Require `Row` is not a row vector and `Col` is not a column vector. * @ingroup require_eigen_types */ @@ -156,7 +156,7 @@ template using require_not_eigen_row_and_col_t = require_not_t< math::conjunction, is_eigen_col_vector>>; -/** +/** \ingroup type_trait * Require `Row` is a row vector and `Col` is a column vector. * @ingroup require_eigen_types */ @@ -164,7 +164,7 @@ template using require_row_and_col_vector_t = require_t, is_col_vector>>; -/** +/** \ingroup type_trait * Require `Row` is not a row vector and `Col` is not a column vector. * @ingroup require_eigen_types */ diff --git a/stan/math/prim/meta/is_vector_like.hpp b/stan/math/prim/meta/is_vector_like.hpp index b5bb48833cd..43d9e35271a 100644 --- a/stan/math/prim/meta/is_vector_like.hpp +++ b/stan/math/prim/meta/is_vector_like.hpp @@ -12,7 +12,7 @@ namespace stan { namespace internal { -/** +/** \ingroup type_trait * @brief Used to detect if object has operator[](int) defined */ template diff --git a/stan/math/prim/meta/partials_return_type.hpp b/stan/math/prim/meta/partials_return_type.hpp index a220ea7af5b..5a4f86e4151 100644 --- a/stan/math/prim/meta/partials_return_type.hpp +++ b/stan/math/prim/meta/partials_return_type.hpp @@ -40,6 +40,9 @@ struct partials_return_type { using type = promote_args_t>>; }; +/** \ingroup type_trait + * See the docs for \ref stan::partials_return_type + */ template using partials_return_t = typename partials_return_type::type; diff --git a/stan/math/prim/meta/partials_type.hpp b/stan/math/prim/meta/partials_type.hpp index a0d2a534977..beaa3bdacf1 100644 --- a/stan/math/prim/meta/partials_type.hpp +++ b/stan/math/prim/meta/partials_type.hpp @@ -14,7 +14,8 @@ struct partials_type { }; /** \ingroup type_trait - * Helper alias for accessing the partial type. + * Helper alias for accessing the partial type. See docs for \ref + * stan::partials_type */ template using partials_type_t = typename partials_type::type; diff --git a/stan/math/prim/meta/plain_type.hpp b/stan/math/prim/meta/plain_type.hpp index 511ff730545..65024a1b20a 100644 --- a/stan/math/prim/meta/plain_type.hpp +++ b/stan/math/prim/meta/plain_type.hpp @@ -7,9 +7,21 @@ namespace stan { -/** - * Determines plain (non expression) type associated with \c T. For non \c Eigen - * types it is the decayed input type. +/** \ingroup type_trait + * Determines plain result (non expression) type associated with `T`. + * For non `Eigen` types it is the decayed input type. + * For Example, + * ```cpp + * stan::plain_type + * ``` + * aka + * ```cpp + * stan::plain_type, + * Eigen::MatrixXd, Eigen::MatrixXd>> + * ``` + * the `type` will be `Eigen::MatrixXd`. `stan::plain_type`'s `type` + * will be a double. while `stan::plain_type>`'s `type` will + * be a `std::vector` * @tparam T type to determine plain type of */ template @@ -17,6 +29,10 @@ struct plain_type { using type = std::decay_t; }; +/** \ingroup type_trait + * Determine the non-expression type of an Eigen object. See \ref + * stan::plain_type for examples. + */ template using plain_type_t = typename plain_type::type; @@ -40,9 +56,10 @@ struct eval_return_type { template using eval_return_type_t = typename eval_return_type::type; -/** +/** \ingroup type_trait * Determines plain (non expression) type associated with \c T. For \c Eigen * expression it is a type the expression can be evaluated into. + * See the docs for \ref stan::plain_type for more information. * @tparam T type to determine plain type of */ template diff --git a/stan/math/prim/meta/promote_scalar_type.hpp b/stan/math/prim/meta/promote_scalar_type.hpp index fee623ab141..b46028d037c 100644 --- a/stan/math/prim/meta/promote_scalar_type.hpp +++ b/stan/math/prim/meta/promote_scalar_type.hpp @@ -9,7 +9,7 @@ namespace stan { namespace math { -/** +/** \ingroup type_trait * Template metaprogram to calculate a type for converting a * convertible type. This is the base case. * @@ -24,7 +24,7 @@ struct promote_scalar_type { using type = T; }; -/** +/** \ingroup type_trait * Template metaprogram to calculate a type for a container whose * underlying scalar is converted from the second template * parameter type to the first. @@ -40,11 +40,12 @@ struct promote_scalar_type> { using type = std::vector::type>; }; -/** - * Specialization for `var_value` when the type to convert to is a `var_value`. - * @tparam T a `var_value`. - * @tparam S A `var_value` whose template type is derived from `EigenBase`. - * This specialization holds type `S`. +/** \ingroup type_trait + * Specialization for \ref stan::math::var_value when the type to convert to is + * a \ref stan::math::var_value . + * @tparam T a \ref stan::math::var_value . + * @tparam S A \ref stan::math::var_value whose template type is derived from + * `EigenBase`. This specialization holds type `S`. */ template struct promote_scalar_type< @@ -55,11 +56,12 @@ struct promote_scalar_type< using type = std::decay_t; }; -/** - * Specialization for `var_value` when the type to convert to is arithmetic. +/** \ingroup type_trait + * Specialization for \ref stan::math::var_value when the type to convert to is + * arithmetic. * @tparam T an arithmetic type. - * @tparam S A `var_value` whose template type is derived from `EigenBase`. - * This specialization the promoted value type of `S`. + * @tparam S A \ref stan::math::var_value whose template type is derived from + * `EigenBase`. This specialization the promoted value type of `S`. */ template struct promote_scalar_type>::type; }; -/** +/** \ingroup type_trait * Template metaprogram to calculate a type for a matrix, vector, row vector or * Eigen::Array whose underlying scalar is converted from the second template * parameter type to the first. @@ -93,6 +95,10 @@ struct promote_scalar_type> { S::RowsAtCompileTime, S::ColsAtCompileTime>>::type; }; +/** \ingroup type_trait + * Overload for specializing sets of tuples. + * See the docs for \ref stan::math::promote_scalar_type. + */ template struct promote_scalar_type, std::tuple> { @@ -100,6 +106,9 @@ struct promote_scalar_type, std::decay_t, std::decay_t>::type...>; }; +/** \ingroup type_trait + * See the docs for \ref stan::math::promote_scalar_type. + */ template using promote_scalar_t = typename promote_scalar_type, std::decay_t>::type; diff --git a/stan/math/prim/meta/ref_type.hpp b/stan/math/prim/meta/ref_type.hpp index 93d37df0387..f543b08451c 100644 --- a/stan/math/prim/meta/ref_type.hpp +++ b/stan/math/prim/meta/ref_type.hpp @@ -1,6 +1,10 @@ #ifndef STAN_MATH_PRIM_META_REF_TYPE_HPP #define STAN_MATH_PRIM_META_REF_TYPE_HPP +/** + * \file + */ + #include #include #include @@ -10,15 +14,37 @@ namespace stan { -/** +/** \ingroup type_trait * If the condition is true determines appropriate type for assigning expression * of given type to, to evaluate expensive expressions, but not make a copy if T - * involves no calculations. This works similarly as `Eigen::Ref`. It also - * handles rvalue references, so it can be used with perfect forwarding. If the - * condition is false the expression will never be evaluated. + * involves no calculations. This works similarly as + * [`Eigen::Ref`](https://eigen.tuxfamily.org/dox/classEigen_1_1Ref.html). The + * deduction scheme used in `ref_type_if` also handles rvalue references, so it + * can be used with perfect forwarding. If the condition is false the expression + * will never be evaluated. + * + * Internally, this type trait compares `T` and `Eigen::Ref` to see whether + * the defines all of the following trait flags as true for each type. + * 1. HasDirectAccess + * - The underlying array of coefficients can be directly accessed as a plain + * strided array (This is true for objects with ownership of memory but not for + * expressions). + * 2. StorageOrderMatch + * - Both are either RowMajor or ColumnMajor + * 3. InnerStrideMatch && OuterStrideMatch + * - The inner and outer strides are exactly equal + * 4. AlignmentMatch + * - The memory alignment of both are the same + * 5. ScalarTypeMatch + * - The underlying scalar types are the same + * + * If any of the above conditionals fail then the type returned is the same as + * from `plain_type`. If all of the above conditions pass then this type trait's + * `type` holds a `const T&` for lvalue inputs and `T` for rvalue references. * * Warning: if a variable of this type could be assigned a rvalue, make sure * template parameter `T` is of correct reference type (rvalue). + * @tparam Condition If false, `type` will hold `T`. * @tparam T type to determine reference for */ template @@ -50,9 +76,15 @@ struct ref_type_if> { typename ref_type_if::Base>::type; }; +/** \ingroup type_trait + * See the docs for \ref stan::ref_type_if + */ template using ref_type_t = typename ref_type_if::type; +/** \ingroup type_trait + * See the docs for \ref stan::ref_type_if + */ template using ref_type_if_t = typename ref_type_if::type; diff --git a/stan/math/prim/meta/require_helpers.hpp b/stan/math/prim/meta/require_helpers.hpp index 9e2f91dc096..5cedb949f57 100644 --- a/stan/math/prim/meta/require_helpers.hpp +++ b/stan/math/prim/meta/require_helpers.hpp @@ -11,52 +11,52 @@ namespace stan { -/** +/** \ingroup type_trait * If condition is true, template is enabled - * @ingroup type_traits + * @ingroup type_trait */ template using require_t = std::enable_if_t; -/** +/** \ingroup type_trait * If condition is false, template is disabled - * @ingroup type_traits + * @ingroup type_trait */ template using require_not_t = std::enable_if_t; -/** +/** \ingroup type_trait * If all conditions are true, template is enabled * Returns a type void if all conditions are true and otherwise fails. - * @ingroup type_traits + * @ingroup type_trait */ template using require_all_t = std::enable_if_t::value>; -/** +/** \ingroup type_trait * If any condition is true, template is enabled. * * Returns a type void if any of the conditions are true and otherwise fails. - * @ingroup type_traits + * @ingroup type_trait */ template using require_any_t = std::enable_if_t::value>; -/** +/** \ingroup type_trait * If all conditions are false, template is enabled. * * Returns a type void if all of the conditions are false. - * @ingroup type_traits + * @ingroup type_trait */ template using require_all_not_t = std::enable_if_t::value>; -/** +/** \ingroup type_trait * If any condition is false, template is enabled. * * Returns a type void if any of the conditions are false. - * @ingroup type_traits + * @ingroup type_trait */ template using require_any_not_t @@ -69,236 +69,284 @@ using require_any_not_t * @param checker A struct that returns holds a boolean `value` * @param doxygen_group The doxygen group to add this requires to. */ -#define STAN_ADD_REQUIRE_UNARY(check_type, checker, doxygen_group) \ - /*! \ingroup doxygen_group */ \ - /*! \defgroup check_type##_types check_type */ \ - /*! \addtogroup check_type##_types */ \ - /*! @{ */ \ - /*! \brief Require type satisfies checker */ \ - template \ - using require_##check_type##_t = require_t>>; \ - \ - /*! \brief Require type does not satisfy checker */ \ - template \ - using require_not_##check_type##_t \ - = require_not_t>>; \ - \ - /*! \brief Require all of the types satisfy checker */ \ - template \ - using require_all_##check_type##_t \ - = require_all_t>...>; \ - \ - /*! \brief Require any of the types satisfy checker */ \ - template \ - using require_any_##check_type##_t \ - = require_any_t>...>; \ - \ - /*! \brief Require none of the types satisfy checker */ \ - template \ - using require_all_not_##check_type##_t \ - = require_all_not_t>...>; \ - \ - /*! \brief Require at least one of the types do not satisfy checker */ \ - template \ - using require_any_not_##check_type##_t \ - = require_any_not_t>...>; \ +#define STAN_ADD_REQUIRE_UNARY(check_type, checker, doxygen_group) \ + /*! \ingroup doxygen_group */ \ + /*! \defgroup check_type##_types check_type */ \ + /*! \addtogroup check_type##_types */ \ + /*! @{ */ \ + /*! \brief `##checker##` is true */ \ + template \ + using require_##check_type##_t = require_t>>; \ + \ + /*! \brief `##checker##` is false */ \ + template \ + using require_not_##check_type##_t \ + = require_not_t>>; \ + \ + /*! \brief `stan::math::conjunction<##checker##...>` is true */ \ + template \ + using require_all_##check_type##_t \ + = require_all_t>...>; \ + \ + /*! \brief `stan::math::disjunction<##checker##...> `is true */ \ + template \ + using require_any_##check_type##_t \ + = require_any_t>...>; \ + \ + /*! \brief `stan::math::conjunction<##checker##...>` is false */ \ + template \ + using require_all_not_##check_type##_t \ + = require_all_not_t>...>; \ + \ + /*! \brief `stan::math::disjunction<##checker##...>` is false */ \ + template \ + using require_any_not_##check_type##_t \ + = require_any_not_t>...>; \ /*! @} */ /** \ingroup macro_helpers - * Adds unary require aliases that check the `value_type`. - * @param check_type The name of the type to check, used to define - * `require__t`. - * @param checker A struct that returns holds a boolean `value` - * @param doxygen_group The doxygen group to add this requires to. - */ -#define STAN_ADD_REQUIRE_UNARY_INNER(check_type, checker, doxygen_group) \ - /*! \ingroup doxygen_group */ \ - /*! \addtogroup check_type##_types */ \ - /*! @{ */ \ - /*! \brief Require value type satisfies checker */ \ - template \ - using require_vt_##check_type \ - = require_t>>>; \ - \ - /*! \brief Require value type does not satisfy checker */ \ - template \ - using require_not_vt_##check_type \ - = require_not_t>>>; \ - \ - /*! \brief Require all of the value types satisfy checker */ \ - template \ - using require_all_vt_##check_type \ - = require_all_t>>...>; \ - \ - /*! \brief Require any of the value types satisfy checker */ \ - template \ - using require_any_vt_##check_type \ - = require_any_t>>...>; \ - \ - /*! \brief Require none of the value types satisfy checker */ \ - template \ - using require_all_not_vt_##check_type \ - = require_all_not_t>>...>; \ - \ - /*! \brief Require at least one of the value types do not satisfy checker */ \ - template \ - using require_any_not_vt_##check_type \ - = require_any_not_t>>...>; \ - \ - /*! \brief Require scalar type satisfies checker */ \ - template \ - using require_st_##check_type \ - = require_t>>>; \ - \ - /*! \brief Require scalar type does not satisfy checker */ \ - template \ - using require_not_st_##check_type \ - = require_not_t>>>; \ - \ - /*! \brief Require all of the scalar types satisfy checker */ \ - template \ - using require_all_st_##check_type \ - = require_all_t>>...>; \ - \ - /*! \brief Require any of the scalar types satisfy checker */ \ - template \ - using require_any_st_##check_type \ - = require_any_t>>...>; \ - \ - /*! \brief Require none of the scalar types satisfy checker */ \ - template \ - using require_all_not_st_##check_type \ - = require_all_not_t>>...>; \ - \ - /*! \brief Any of the scalar types do not satisfy checker */ \ - template \ - using require_any_not_st_##check_type \ - = require_any_not_t>>...>; \ -/*! @} */ - -/** \ingroup macro_helpers - * Adds binary require aliases. + * Adds unary require aliases that check the \ref stan::value_type . * @param check_type The name of the type to check, used to define * `require__t`. * @param checker A struct that returns holds a boolean `value` * @param doxygen_group The doxygen group to add this requires to. */ -#define STAN_ADD_REQUIRE_BINARY(check_type, checker, doxygen_group) \ +#define STAN_ADD_REQUIRE_UNARY_INNER(check_type, checker, doxygen_group) \ /*! \ingroup doxygen_group */ \ - /*! \defgroup check_type##_types check_type */ \ /*! \addtogroup check_type##_types */ \ /*! @{ */ \ - /*! \brief Require types `T` and `S` satisfies checker */ \ - template \ - using require_##check_type##_t \ - = require_t, std::decay_t>>; \ + /*! \brief `##checker##>` is true */ \ + template \ + using require_vt_##check_type \ + = require_t>>>; \ \ - /*! \brief Require types `T` and `S` does not satisfy checker */ \ - template \ - using require_not_##check_type##_t \ - = require_not_t, std::decay_t>>; \ + /*! \brief `##checker##>` is false */ \ + template \ + using require_not_vt_##check_type \ + = require_not_t>>>; \ \ - /*! \brief Require `T` and all of the `Types` satisfy checker */ \ - template \ - using require_all_##check_type##_t \ - = require_all_t, std::decay_t>...>; \ + /*! \brief \ + `stan::math::conjunction<##checker##>...>` is \ + true */ \ + template \ + using require_all_vt_##check_type \ + = require_all_t>>...>; \ \ - /*! \brief Require any of the `Types` and `T` satisfy checker */ \ - template \ - using require_any_##check_type##_t \ - = require_any_t, std::decay_t>...>; \ + /*! \brief \ + `stan::math::disjunction<##checker##>...>` is \ + true */ \ + template \ + using require_any_vt_##check_type \ + = require_any_t>>...>; \ \ - /*! \brief Require none of the `Types` and `T` satisfy checker */ \ - template \ - using require_all_not_##check_type##_t \ - = require_all_not_t, std::decay_t>...>; \ + /*! \brief \ + `stan::math::conjunction<##checker##>...>` is \ + false */ \ + template \ + using require_all_not_vt_##check_type \ + = require_all_not_t>>...>; \ \ - /*! \brief Any one of the `Types` and `T` do not satisfy */ \ - template \ - using require_any_not_##check_type##_t \ - = require_any_not_t, std::decay_t>...>; \ + /*! \brief \ + `stan::math::disjunction<##checker##>...>` is \ + false */ \ + template \ + using require_any_not_vt_##check_type = require_any_not_t< \ + checker>>...>; \ + \ + /*! \brief `##checker##>` is true */ \ + template \ + using require_st_##check_type \ + = require_t>>>; \ + \ + /*! \brief `##checker##>` is false */ \ + template \ + using require_not_st_##check_type \ + = require_not_t>>>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##>...>` is \ + true */ \ + template \ + using require_all_st_##check_type \ + = require_all_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##>...>` is \ + true */ \ + template \ + using require_any_st_##check_type \ + = require_any_t>>...>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##>...>` is \ + false */ \ + template \ + using require_all_not_st_##check_type \ + = require_all_not_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##>...>` is \ + false */ \ + template \ + using require_any_not_st_##check_type \ + = require_any_not_t>>...>; \ /*! @} */ /** \ingroup macro_helpers - * Adds binary require aliases that check the `scalar_type`. + * Adds binary require aliases. * @param check_type The name of the type to check, used to define * `require__t`. * @param checker A struct that returns holds a boolean `value` * @param doxygen_group The doxygen group to add this requires to. */ -#define STAN_ADD_REQUIRE_BINARY_INNER(check_type, checker, doxygen_group) \ +#define STAN_ADD_REQUIRE_BINARY(check_type, checker, doxygen_group) \ /*! \ingroup doxygen_group */ \ + /*! \defgroup check_type##_types check_type */ \ /*! \addtogroup check_type##_types */ \ /*! @{ */ \ - /*! \brief Require that value types of `T` and `S` satisfies checker */ \ - template \ - using require_st_##check_type \ - = require_t>, \ - scalar_type_t>>>; \ - \ - /*! \brief Require scalar types of `T` and `S` does not satisfy checker */ \ - template \ - using require_not_st_##check_type \ - = require_not_t>, \ - scalar_type_t>>>; \ - \ - /*! \brief All scalar types of `T` and all of the `Types` satisfy checker */ \ - template \ - using require_all_st_##check_type \ - = require_all_t>, \ - scalar_type_t>>...>; \ - \ - /*! \brief Any of the scalar types of `Types` and `T` satisfy checker */ \ - template \ - using require_any_st_##check_type \ - = require_any_t>, \ - scalar_type_t>>...>; \ - \ - /*! \brief None of the scalar types of `Types` and `T` satisfy checker */ \ - template \ - using require_all_not_st_##check_type \ - = require_all_not_t>, \ - scalar_type_t>>...>; \ - \ - /*! \brief Any of the scalar types `Types` and `T` do not satisfy checker */ \ - template \ - using require_any_not_st_##check_type \ - = require_any_not_t>, \ - scalar_type_t>>...>; \ - \ - /*! \brief Value types of `T` and `S` satisfies checker */ \ + /*! \brief `stan::math::conjunction<##checker##, ##checker##> is true` \ + */ \ template \ - using require_vt_##check_type = require_t< \ - checker>, value_type_t>>>; \ + using require_##check_type##_t \ + = require_t, std::decay_t>>; \ \ - /*! \brief Value types of `T` and `S` does not satisfy checker */ \ + /*! \brief `stan::math::conjunction<##checker##, ##checker##>` is true \ + */ \ template \ - using require_not_vt_##check_type = require_not_t< \ - checker>, value_type_t>>>; \ + using require_not_##check_type##_t \ + = require_not_t, std::decay_t>>; \ \ - /*! \brief Value types of `T` and all of the `Types` satisfy checker */ \ + /*! \brief `stan::math::conjunction<##checker##, ##checker##>` is true \ + */ \ template \ - using require_all_vt_##check_type \ - = require_all_t>, \ - value_type_t>>...>; \ + using require_all_##check_type##_t \ + = require_all_t, std::decay_t>...>; \ \ - /*! \brief Any of the value types of `Types` and `T` satisfy checker */ \ + /*! \brief `stan::math::disjunction<##checker##, ##checker##>` is true \ + */ \ template \ - using require_any_vt_##check_type \ - = require_any_t>, \ - value_type_t>>...>; \ + using require_any_##check_type##_t \ + = require_any_t, std::decay_t>...>; \ \ - /*! \brief None of the value types of `Types` and `T` satisfy checker */ \ + /*! \brief \ + `stan::math::disjunction<##checker##, ##checker##>` is \ + false */ \ template \ - using require_all_not_vt_##check_type \ - = require_all_not_t>, \ - value_type_t>>...>; \ + using require_all_not_##check_type##_t \ + = require_all_not_t, std::decay_t>...>; \ \ - /*! \brief Any of the value types `Types` and `T` do not satisfy checker */ \ + /*! \brief \ + `stan::math::conjunction<##checker##, ##checker##>` is \ + false */ \ template \ - using require_any_not_vt_##check_type \ - = require_any_not_t>, \ - value_type_t>>...>; \ + using require_any_not_##check_type##_t \ + = require_any_not_t, std::decay_t>...>; \ +/*! @} */ + +/** \ingroup macro_helpers + * Adds binary require aliases that check the \ref stan::scalar_type . + * @param check_type The name of the type to check, used to define + * `require__t`. + * @param checker A struct that returns holds a boolean `value` + * @param doxygen_group The doxygen group to add this requires to. + */ +#define STAN_ADD_REQUIRE_BINARY_INNER(check_type, checker, doxygen_group) \ + /*! \ingroup doxygen_group */ \ + /*! \addtogroup check_type##_types */ \ + /*! @{ */ \ + /*! \brief \ + `##checker##, stan::scalar_type_t>` is \ + true */ \ + template \ + using require_st_##check_type \ + = require_t>, \ + scalar_type_t>>>; \ + \ + /*! \brief \ + `##checker##, stan::scalar_type_t>` is \ + false */ \ + template \ + using require_not_st_##check_type \ + = require_not_t>, \ + scalar_type_t>>>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##, \ + stan::scalar_type_t>...>` is true */ \ + template \ + using require_all_st_##check_type \ + = require_all_t>, \ + scalar_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##, \ + stan::scalar_type_t>...>` is true */ \ + template \ + using require_any_st_##check_type \ + = require_any_t>, \ + scalar_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##, \ + stan::scalar_type_t>...>` is false */ \ + template \ + using require_all_not_st_##check_type \ + = require_all_not_t>, \ + scalar_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##, \ + stan::scalar_type_t>...>` is false */ \ + template \ + using require_any_not_st_##check_type \ + = require_any_not_t>, \ + scalar_type_t>>...>; \ + \ + /*! \brief \ + `##checker##, stan::value_type_t>` is \ + true */ \ + template \ + using require_vt_##check_type = require_t< \ + checker>, value_type_t>>>; \ + \ + /*! \brief \ + `##checker##, stan::value_type_t>` is \ + false */ \ + template \ + using require_not_vt_##check_type = require_not_t< \ + checker>, value_type_t>>>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##, \ + stan::value_type_t>...>` is true */ \ + template \ + using require_all_vt_##check_type \ + = require_all_t>, \ + value_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##, \ + stan::value_type_t>...>` is true */ \ + template \ + using require_any_vt_##check_type \ + = require_any_t>, \ + value_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::conjunction<##checker##, \ + stan::value_type_t>...>` is false */ \ + template \ + using require_all_not_vt_##check_type \ + = require_all_not_t>, \ + value_type_t>>...>; \ + \ + /*! \brief \ + `stan::math::disjunction<##checker##, \ + stan::value_type_t>...>` is false */ \ + template \ + using require_any_not_vt_##check_type \ + = require_any_not_t>, \ + value_type_t>>...>; \ /*! @} */ /** @@ -334,86 +382,124 @@ using container_type_check_base /*! \defgroup check_type##_types check_type */ \ /*! \addtogroup check_type##_types */ \ /*! @{ */ \ - /*! \brief Require type satisfies checker */ \ - /*! and value type satisfies `TypeCheck` */ \ - /*! @tparam TypeCheck The type trait to check the value type against*/ \ + /*! \brief Require both conditions to be true. */ \ + /*! */ \ + /*! Require `##checker##` is true */ \ + /*! and TypeCheck> is true `*/ \ + /*! is true */ \ + /*! @tparam Check the type to check */ \ + /*! @tparam TypeCheck type trait to check \ref stan::value_type against */ \ template