Skip to content

Commit

Permalink
Merge pull request #1794 from stan-dev/cleanup/require_base
Browse files Browse the repository at this point in the history
Cleanup requires with macros
  • Loading branch information
t4c1 authored Mar 30, 2020
2 parents 6db1e57 + 878d3f4 commit 4649606
Show file tree
Hide file tree
Showing 71 changed files with 995 additions and 1,468 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
The <b>Stan Math Library</b> is a C++, reverse-mode automatic differentiation library designed to be usable, extensive and extensible, efficient, scalable, stable, portable, and redistributable in order to facilitate the construction and utilization of algorithms that utilize derivatives.

[![DOI](https://zenodo.org/badge/38388440.svg)](https://zenodo.org/badge/latestdoi/38388440)
\htmlonly
<div><a href="https://zenodo.org/badge/latestdoi/38388440"><img src="https://zenodo.org/badge/38388440.svg"/></a></div>
\endhtmlonly

Licensing
---------
Expand Down
19 changes: 5 additions & 14 deletions doxygen/doxygen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,6 @@ EXTENSION_MAPPING =

MARKDOWN_SUPPORT = YES

# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
# to that level are automatically included in the table of contents, even if
# they do not have an id attribute.
# Note: This feature currently applies only to Markdown headings.
# Minimum value: 0, maximum value: 99, default value: 0.
# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.

TOC_INCLUDE_HEADINGS = 0

# When enabled doxygen tries to link words that correspond to documented
# classes, or namespaces to their corresponding documentation. Such a link can
# be prevented in individual cases by putting a % sign in front of the word or
Expand Down Expand Up @@ -1157,7 +1148,7 @@ HTML_EXTRA_STYLESHEET =
# files will be copied as-is; there are no commands or markers available.
# This tag requires that the tag GENERATE_HTML is set to YES.

HTML_EXTRA_FILES = "./doxygen/pretty_stuff/standoxy.css"
HTML_EXTRA_FILES = doxygen/pretty_stuff/standoxy.css

# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
# will adjust the colors in the style sheet and background images according to
Expand Down Expand Up @@ -2014,7 +2005,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

MACRO_EXPANSION = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
Expand Down Expand Up @@ -2054,8 +2045,8 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = STAN_OPENCL \
STAN_MPI
PREDEFINED = STAN_OPENCL=true \
STAN_MPI=true

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand All @@ -2074,7 +2065,7 @@ EXPAND_AS_DEFINED =
# The default value is: YES.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

SKIP_FUNCTION_MACROS = YES
SKIP_FUNCTION_MACROS = NO

#---------------------------------------------------------------------------
# Configuration options related to external references
Expand Down
129 changes: 0 additions & 129 deletions stan/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,135 +16,6 @@
* Distributions with scalar, vector, or array input.
*/

/**
* \defgroup type_trait Type Traits
* The type traits in Stan math are a mix of custom traits for detecting
* value and container types of Eigen matrices, standard vectors, standard
* complex numbers, and backports of C++17 traits.
*/

/**
* \ingroup type_traits
* \defgroup require_meta Pseudo-Concepts with requires<>
* The requires type traits are wrappers for turning on and off definitions
* during compile time. You can think of these as "legacy concepts" aka I think
* the closest thing you can get to C++20 concepts without having the requires
* keyword.
*
* Legacy concepts are done through enable_if_t aliases which are called
* require_*. There are 5 basic types of requires.
*
* requires_*_t: This means the function requires a certain type to turn on.
*For instance
*~~~~~{.cpp}
* // Works for arithmetic types
* template <typename T, require_arithmetic_t<T>...>
* auto add(T&& x, T&& y) { return x + y; }
*~~~~~
* require_not_*_t : When we want to disable for a type
*~~~~~{.cpp}
* // Works for non-arithmetic types
* template <typename T, require_not_arithmetic_t<T>...>
* auto add(T&& x, T&& y) { return x + y; }
*~~~~~
* require_all_*_t : Takes a parameter pack of types to enable if all types
*satisfy the check.
*~~~~~{.cpp}
* // Works if T1 and T2 are arithmetic
* template <typename T1, typename T2, require_all_arithmetic_t<T1, T2>...>
* auto add(T1&& x, T2&& y) { return x + y; }
*~~~~~
* require_any_*_t : Takes a parameter pack of types to enable if any of the
*types satisfy the check.
*~~~~~{.cpp}
* // Works if either T1 or T2 enherit from EigenBase
* template <typename T1, typename T2, require_any_eigen_t<T1, T2>...>
* auto add(T1&& x, T2&& y) { return x + y; }
*~~~~~
* require_not_any_*_t : Takes a parameter pack of types to enable if any one
*of the types are not satisfied.
*~~~~~{.cpp}
* // Works if either neither T1 or T2 are arithmetic
* template <typename T1, typename T2, require_not_any_arithmetic_t<T1, T2>...>
* auto add(T1 x, T2 y) { return x + y; }
*~~~~~
* require_not_all_*_t : Takes a parameter pack of types to enable if all of
*the types are not satisfied.
*~~~~~{.cpp}
* // Works if neither T1 and T2 are arithmetic
* template <typename T1, typename T2, require_not_all_arithmetic_t<T1, T2>...>
* auto add(T1 x, T2 y) { return x + y; }
*~~~~~
*
* In addition, std::vector and Eigen types have additional requires to detect
*if the value_type (the first underlying type) or the scalar_type (the
*containers underlying scalar type) satisfy a condition to enable a class or
*function.
*
* The container requires have a _vt and _st to symbolize the above. A function
*that accepts eigen matrices of whose whose value type is floating point types
*can be defined as
*
*~~~~~{.cpp}
* template <typename Mat1, typename Mat2,
* require_all_eigen_vt<std::is_floating_point, Mat1, Mat2>...>
* auto add(Mat1&& A, Mat2&& B) { return A + B;}
*~~~~~
* A function that accepts standard vectors of Eigen vectors whose scalar type
*is floating point types can be defined as
*
*~~~~~{.cpp}
* template <typename Vec1, typename Vec2,
* require_all_std_vector_vt<is_eigen_vector, Vec1, Vec2>...,
* require_all_std_vector_st<is_floating_point, Vec1, Vec2>...>
* auto add(Vec1&& A, Vec2&& B) {
* std::vector<decltype<A[0] + B[0]>> return_vec;
* std::transform(A.begin(), A.end(), B.begin(), return_vec.begin(),
* [](auto&& x, auto&& y) {
* return x + y;
* });
* return return_vec;
* }
*~~~~~
*
* In general, these methods allow Stan to have more generic types so that the
* library can forward along Eigen expression and have better move semantics.
* For instance, the code below will accept any arbitrary Eigen expression
* that, if it's an rvalue, can be forwarded to another function.
*
*~~~~~{.cpp}
* template <typename Mat1, typename Mat2,
* require_all_eigen_vt<is_arithmetic, Mat1, Mat2>...>
* inline auto a_func(Mat1&& m1, Mat2&& m2) {
* check_nan(m1);
* check_nan(m2);
* // If m1 and/or m2 is an rvalue it will be moved over to this function
* // instead of copied to an lvalue
* auto B = another_func(std::forward<Mat1>(m1), std::forward<Mat2>(m2)); //
*(3) return B;
*~~~~~
*/

/**
* \ingroup require_meta
* \defgroup require_base_types Basic Type Pseudo-Concepts
* These type traits check the type properties of simple objects and are denoted
* with a _t at the end. They check only the direct type and do not inspect
* anything about type properties composed within a type.
*/

/**
* \ingroup require_meta
* \defgroup require_container_types Container Pseudo-Concepts
* These type traits check the type properties of objects that act as
* containers. The @c _vt methods check that a containers @c value_type fulfills
* certain conditions while @c _st methods check that the objects @c scalar_type
* fulfills certain conditions. @c value_type and @c scalar_type differ in that
* @c value_type is the first level of a container while @c scalar_type
* recursively goes through containers of containers till it comes to a simple
* type.
*/

#include <stan/math/rev.hpp>

#endif
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/mdivide_left.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace math {

template <typename T1, typename T2,
require_all_eigen_vt<is_fvar, T1, T2>* = nullptr,
require_same_vt<T1, T2>* = nullptr>
require_vt_same<T1, T2>* = nullptr>
inline Eigen::Matrix<value_type_t<T1>, T1::RowsAtCompileTime,
T2::ColsAtCompileTime>
mdivide_left(const T1& A, const T2& b) {
Expand Down
6 changes: 3 additions & 3 deletions stan/math/fwd/fun/mdivide_left_tri_low.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace math {

template <typename T1, typename T2,
require_all_eigen_vt<is_fvar, T1, T2>* = nullptr,
require_same_vt<T1, T2>* = nullptr>
require_vt_same<T1, T2>* = nullptr>
inline Eigen::Matrix<value_type_t<T1>, T1::RowsAtCompileTime,
T2::ColsAtCompileTime>
mdivide_left_tri_low(const T1& A, const T2& b) {
Expand Down Expand Up @@ -50,7 +50,7 @@ mdivide_left_tri_low(const T1& A, const T2& b) {
}

template <typename T1, typename T2, require_eigen_t<T1>* = nullptr,
require_same_vt<double, T1>* = nullptr,
require_vt_same<double, T1>* = nullptr,
require_eigen_vt<is_fvar, T2>* = nullptr>
inline Eigen::Matrix<value_type_t<T2>, T1::RowsAtCompileTime,
T2::ColsAtCompileTime>
Expand Down Expand Up @@ -82,7 +82,7 @@ mdivide_left_tri_low(const T1& A, const T2& b) {

template <typename T1, typename T2, require_eigen_vt<is_fvar, T1>* = nullptr,
require_eigen_t<T2>* = nullptr,
require_same_vt<double, T2>* = nullptr>
require_vt_same<double, T2>* = nullptr>
inline Eigen::Matrix<value_type_t<T1>, T1::RowsAtCompileTime,
T2::ColsAtCompileTime>
mdivide_left_tri_low(const T1& A, const T2& b) {
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/multiply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace math {

template <typename Mat1, typename Mat2,
require_all_eigen_vt<is_fvar, Mat1, Mat2>* = nullptr,
require_same_vt<Mat1, Mat2>* = nullptr,
require_vt_same<Mat1, Mat2>* = nullptr,
require_not_eigen_row_and_col_t<Mat1, Mat2>* = nullptr>
inline auto multiply(const Mat1& m1, const Mat2& m2) {
check_multiplicable("multiply", "m1", m1, "m2", m2);
Expand Down
2 changes: 1 addition & 1 deletion stan/math/fwd/fun/to_fvar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ inline promote_scalar_t<fvar<value_type_t<T>>, T> to_fvar(const T& m) {
}

template <typename T1, typename T2, require_all_eigen_t<T1, T2>* = nullptr,
require_same_vt<T1, T2>* = nullptr>
require_vt_same<T1, T2>* = nullptr>
inline promote_scalar_t<fvar<value_type_t<T1>>, T1> to_fvar(const T1& val,
const T2& deriv) {
check_matching_dims("to_fvar", "value", val, "deriv", deriv);
Expand Down
83 changes: 2 additions & 81 deletions stan/math/opencl/is_matrix_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,87 +45,8 @@ struct is_matrix_cl<
T, std::enable_if_t<internal::is_matrix_cl_impl<std::decay_t<T>>::value>>
: std::true_type {};

template <typename T>
using require_matrix_cl_t = require_t<is_matrix_cl<T>>;

template <typename T>
using require_not_matrix_cl_t = require_not_t<is_matrix_cl<T>>;

template <typename... Types>
using require_all_matrix_cl_t = require_all_t<is_matrix_cl<Types>...>;

template <typename... Types>
using require_any_matrix_cl_t = require_any_t<is_matrix_cl<Types>...>;

template <typename... Types>
using require_all_not_matrix_cl_t = require_all_not_t<is_matrix_cl<Types>...>;

template <typename... Types>
using require_any_not_matrix_cl_t = require_any_not_t<is_matrix_cl<Types>...>;

/** \ingroup opencl
* matrix_cl
*/
template <template <class...> class TypeCheck, class... Check>
struct is_matrix_cl_value_check
: container_value_type_check_base<is_matrix_cl, TypeCheck, Check...> {};

template <template <class...> class TypeCheck, class... Check>
using require_matrix_cl_vt
= require_t<is_matrix_cl_value_check<TypeCheck, Check...>>;

template <template <class...> class TypeCheck, class... Check>
using require_not_matrix_cl_vt
= require_not_t<is_matrix_cl_value_check<TypeCheck, Check...>>;

template <template <class...> class TypeCheck, class... Check>
using require_any_matrix_cl_vt
= require_any_t<is_matrix_cl_value_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_any_not_matrix_cl_vt
= require_any_not_t<is_matrix_cl_value_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_all_matrix_cl_vt
= require_all_t<is_matrix_cl_value_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_all_not_matrix_cl_vt
= require_all_not_t<is_matrix_cl_value_check<TypeCheck, Check>...>;

// Scalar Check

/** \ingroup opencl
* matrix_cl
*/
template <template <class...> class TypeCheck, class... Check>
struct is_matrix_cl_scalar_check
: container_scalar_type_check_base<is_matrix_cl, TypeCheck, Check...> {};

template <template <class...> class TypeCheck, class... Check>
using require_matrix_cl_st
= require_t<is_matrix_cl_scalar_check<TypeCheck, Check...>>;

template <template <class...> class TypeCheck, class... Check>
using require_not_matrix_cl_st
= require_not_t<is_matrix_cl_scalar_check<TypeCheck, Check...>>;

template <template <class...> class TypeCheck, class... Check>
using require_any_matrix_cl_st
= require_any_t<is_matrix_cl_scalar_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_any_not_matrix_cl_st
= require_any_not_t<is_matrix_cl_scalar_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_all_matrix_cl_st
= require_all_t<is_matrix_cl_scalar_check<TypeCheck, Check>...>;

template <template <class...> class TypeCheck, class... Check>
using require_all_not_matrix_cl_st
= require_all_not_t<is_matrix_cl_scalar_check<TypeCheck, Check>...>;
STAN_ADD_REQUIRE_UNARY(matrix_cl, is_matrix_cl, opencl);
STAN_ADD_REQUIRE_CONTAINER(matrix_cl, is_matrix_cl, opencl);

} // namespace stan
#endif
Expand Down
7 changes: 3 additions & 4 deletions stan/math/opencl/kernel_generator/transpose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ class transpose_

/**
* generates kernel code for this and nested expressions.
* @param[in,out] generated set of already generated operations
* @param ng name generator for this kernel
* @param i row index variable name
* @param j column index variable name
* @param i row index variable name.
* @param j column index variable name.
* @param var_name_arg The name of this variable.
* @return part of kernel with code for this and nested expressions
*/
inline kernel_parts generate(const std::string& i, const std::string& j,
Expand Down
Loading

0 comments on commit 4649606

Please sign in to comment.