Skip to content

Commit cb204e0

Browse files
authored
Merge pull request #1181 from bstatcomp/feature/issue-1122-add-comments-to-metaprograms
Issue #1122: Add comments to the metaprograms
2 parents a4f6d61 + a32bcf7 commit cb204e0

20 files changed

+152
-20
lines changed

stan/math/fwd/scal/meta/ad_promotable.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ namespace math {
88

99
template <typename T>
1010
struct fvar;
11-
11+
/**
12+
* Template traits metaprogram to determine if a variable
13+
* of one template type is promotable to the base type of
14+
* a second fvar template type.
15+
*
16+
* <p>It will declare an enum <code>value</code> equal to
17+
* <code>true</code> if the variable type is promotable to
18+
* the base type of the fvar template type,
19+
* <code>false</code> otherwise.
20+
*
21+
* @tparam T promoted type
22+
*/
1223
template <typename V, typename T>
1324
struct ad_promotable<V, fvar<T> > {
1425
enum { value = ad_promotable<V, T>::value };

stan/math/fwd/scal/meta/is_fvar.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include <stan/math/prim/scal/meta/is_fvar.hpp>
66

77
namespace stan {
8-
8+
/**
9+
* Defines a public enum named value and sets it to true(1)
10+
* when instantiated with the stan::math::fvar type.
11+
*/
912
template <typename T>
1013
struct is_fvar<stan::math::fvar<T> > {
1114
enum { value = true };

stan/math/prim/arr/meta/contains_std_vector.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#include <vector>
77

88
namespace stan {
9-
9+
/**
10+
* Extends std::true_type when instantiated with at least 1 template
11+
* parameter of type std::vector<T>.
12+
*/
1013
template <typename T, typename... Ts>
1114
struct contains_std_vector<std::vector<T>, Ts...> : std::true_type {};
1215

stan/math/prim/arr/meta/get.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
#include <vector>
66

77
namespace stan {
8-
8+
/**
9+
* Returns the n-th element of the provided std::vector.
10+
*
11+
* @param x input vector
12+
* @param n index of the element to return
13+
* @return n-th element of the input vector
14+
*/
915
template <typename T>
1016
inline T get(const std::vector<T>& x, size_t n) {
1117
return x[n];

stan/math/prim/arr/meta/is_constant_struct.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
#include <vector>
77

88
namespace stan {
9-
9+
/**
10+
* Defines a public enum named value and sets it to true(1)
11+
* if the type of the elements in the provided std::vector
12+
* is a constant struct, false(0) otherwise.
13+
* @tparam type of the elements in the std::vector
14+
*/
1015
template <typename T>
1116
struct is_constant_struct<std::vector<T> > {
1217
enum { value = is_constant_struct<T>::value };

stan/math/prim/arr/meta/length.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
#include <vector>
66

77
namespace stan {
8-
8+
/**
9+
* Returns the length of the provided std::vector.
10+
*
11+
* @param x input vector
12+
* @tparam T type of the elements in the vector
13+
* @return the length of the input vector
14+
*/
915
template <typename T>
1016
size_t length(const std::vector<T>& x) {
1117
return x.size();

stan/math/prim/mat/meta/is_constant_struct.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@
66
#include <stan/math/prim/scal/meta/is_constant.hpp>
77

88
namespace stan {
9-
9+
/**
10+
* Defines a public enum named value and sets it to true(1)
11+
* if the type of the elements in the provided Eigen matrix
12+
* is a constant struct, false(0) otherwise.
13+
* @tparam type of the elements in the Eigen matrix
14+
* @tparam R number of rows in the provided matrix
15+
* @tparam C number of columns in the provided matrix
16+
*/
1017
template <typename T, int R, int C>
1118
struct is_constant_struct<Eigen::Matrix<T, R, C> > {
1219
enum { value = is_constant_struct<T>::value };
1320
};
1421

22+
/**
23+
* Defines a public enum named value and sets it to true(1)
24+
* if the type of the elements in the provided Eigen Block
25+
* is a constant struct, false(0) otherwise.
26+
* @tparam type of the elements in the Eigen Block
27+
*/
1528
template <typename T>
1629
struct is_constant_struct<Eigen::Block<T> > {
1730
enum { value = is_constant_struct<T>::value };

stan/math/prim/mat/meta/length.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
namespace stan {
77

8+
/**
9+
* Returns the size of the provided Eigen matrix.
10+
*
11+
* @param m a const Eigen matrix
12+
* @tparam T type of matrix.
13+
* @tparam R number of rows in the input matrix.
14+
* @tparam C number of columns in the input matrix.
15+
* @return the size of the input matrix
16+
*/
817
template <typename T, int R, int C>
918
size_t length(const Eigen::Matrix<T, R, C>& m) {
1019
return m.size();

stan/math/prim/mat/meta/scalar_type.hpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,64 @@
55
#include <stan/math/prim/arr/meta/scalar_type.hpp>
66

77
namespace stan {
8-
8+
/**
9+
* Template metaprogram defining the base scalar type of
10+
* values stored in an Eigen matrix.
11+
*
12+
* @tparam T type of matrix.
13+
* @tparam R number of rows for matrix.
14+
* @tparam C number of columns for matrix.
15+
*/
916
template <typename T, int R, int C>
1017
struct scalar_type<Eigen::Matrix<T, R, C> > {
1118
typedef typename scalar_type<T>::type type;
1219
};
1320

21+
/**
22+
* Template metaprogram defining the base scalar type of
23+
* values stored in a const Eigen matrix.
24+
*
25+
* @tparam T type of matrix.
26+
* @tparam R number of rows for matrix.
27+
* @tparam C number of columns for matrix.
28+
*/
1429
template <typename T, int R, int C>
1530
struct scalar_type<const Eigen::Matrix<T, R, C> > {
1631
typedef typename scalar_type<T>::type type;
1732
};
1833

34+
/**
35+
* Template metaprogram defining the base scalar type of
36+
* values stored in a referenced Eigen matrix.
37+
*
38+
* @tparam T type of matrix.
39+
* @tparam R number of rows for matrix.
40+
* @tparam C number of columns for matrix.
41+
*/
1942
template <typename T, int R, int C>
2043
struct scalar_type<Eigen::Matrix<T, R, C>&> {
2144
typedef typename scalar_type<T>::type type;
2245
};
2346

47+
/**
48+
* Template metaprogram defining the base scalar type of
49+
* values stored in a referenced const Eigen matrix.
50+
*
51+
* @tparam T type of matrix.
52+
* @tparam R number of rows for matrix.
53+
* @tparam C number of columns for matrix.
54+
*/
2455
template <typename T, int R, int C>
2556
struct scalar_type<const Eigen::Matrix<T, R, C>&> {
2657
typedef typename scalar_type<T>::type type;
2758
};
2859

60+
/**
61+
* Template metaprogram defining the base scalar type of
62+
* values stored in an Eigen Block.
63+
*
64+
* @tparam T type of block.
65+
*/
2966
template <typename T>
3067
struct scalar_type<Eigen::Block<T> > {
3168
typedef typename scalar_type<T>::type type;

stan/math/prim/scal/meta/contains_fvar.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
namespace stan {
99

1010
/**
11-
* Defines a public enum named value which is defined to be true (1)
12-
* if any of the template parameters includes a fvar as their base scalar and
13-
* false (0) otherwise.
11+
* Extends std::true_type when instantiated with at least 1
12+
* template parameter that is a fvar. Extends std::false_type
13+
* otherwise.
14+
* @tparam T Types to test
1415
*/
1516
template <typename... T>
1617
using contains_fvar

0 commit comments

Comments
 (0)