Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for the meta functions #1332

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e0119a3
This refactors all of the meta functions to either use standard
SteveBronder Sep 1, 2019
8d52a2a
Merge remote-tracking branch 'upstream/develop' into refactor/type_tr…
SteveBronder Sep 1, 2019
3d73532
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 1, 2019
5920e49
fix cpplint
SteveBronder Sep 1, 2019
c3688db
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 1, 2019
6aefc3f
and // NOLINT to the long long and unsigned long long var constructor
SteveBronder Sep 1, 2019
fb954b2
and // NOLINT to the long long and unsigned long long var constructor
SteveBronder Sep 1, 2019
6c4f425
fix docs
SteveBronder Sep 1, 2019
fa0038e
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 1, 2019
a39fa30
add _v constexpr methods
SteveBronder Sep 1, 2019
7a10aaf
add _v constexpr methods
SteveBronder Sep 1, 2019
831e4ba
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 1, 2019
3a0f717
Revert "add _v constexpr methods"
SteveBronder Sep 2, 2019
7d1abd3
revert _v types and add tests for is_eigen and is_std_vector
SteveBronder Sep 2, 2019
86b1761
revert _v types and add tests for is_eigen and is_std_vector
SteveBronder Sep 2, 2019
4bbc922
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 2, 2019
f4b9a7d
remove the unsigned long long and long long constructors added to var
SteveBronder Sep 2, 2019
0cdcc6d
scalar_type returns pointers, though this does not remove inner const
SteveBronder Sep 2, 2019
36697b0
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot Sep 2, 2019
0a79182
fix is_var_or_arithmetic test
SteveBronder Sep 2, 2019
0ae4fb3
add test for pointers to is_vector_like
SteveBronder Sep 2, 2019
55bfcfe
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 2, 2019
780cb36
fix C style cast
SteveBronder Sep 2, 2019
e17d59c
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot Sep 2, 2019
d146a0d
Merge remote-tracking branch 'upstream/develop' into refactor/type_tr…
SteveBronder Sep 3, 2019
cdad20e
added tests previously in is_var_or_arithmetic, removed eigen/vector …
SteveBronder Sep 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ lib/boost_*/user-config.jam

# clang-tidy output
.clang-fixes.log

# Clang compilation database
compile_commands.json

# Visual Studio Project Setup
.vscode/*
5 changes: 4 additions & 1 deletion stan/math/fwd/core/fvar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <stan/math/prim/meta.hpp>
#include <stan/math/prim/scal/fun/is_nan.hpp>
#include <stan/math/fwd/meta.hpp>
#include <ostream>

namespace stan {
Expand Down Expand Up @@ -49,6 +48,10 @@ struct fvar {
*/
T d_;

/**
* The Type inside of the fvar.
*/
using Scalar = T;
/**
* Return the value of this variable.
*
Expand Down
1 change: 0 additions & 1 deletion stan/math/fwd/meta.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef STAN_MATH_FWD_META_HPP
#define STAN_MATH_FWD_META_HPP

#include <stan/math/fwd/scal/meta/ad_promotable.hpp>
#include <stan/math/fwd/scal/meta/is_fvar.hpp>
#include <stan/math/fwd/scal/meta/partials_type.hpp>
#include <stan/math/fwd/scal/meta/operands_and_partials.hpp>
Expand Down
30 changes: 0 additions & 30 deletions stan/math/fwd/scal/meta/ad_promotable.hpp

This file was deleted.

21 changes: 14 additions & 7 deletions stan/math/fwd/scal/meta/is_fvar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@

#include <stan/math/fwd/core.hpp>
#include <stan/math/prim/scal/meta/is_fvar.hpp>
#include <type_traits>

namespace stan {
/**
* Defines a public enum named value and sets it to true(1)
* when instantiated with the stan::math::fvar type.
*/

namespace internal {
template <typename T>
struct is_fvar_impl : std::false_type {};

template <typename T>
struct is_fvar_impl<math::fvar<T>> : std::true_type {};

} // namespace internal

template <typename T>
struct is_fvar<stan::math::fvar<T> > {
enum { value = true };
};
struct is_fvar<T,
std::enable_if_t<internal::is_fvar_impl<std::decay_t<T>>::value>>
: std::true_type {};

} // namespace stan
#endif
6 changes: 4 additions & 2 deletions stan/math/fwd/scal/meta/partials_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#define STAN_MATH_FWD_SCAL_META_PARTIALS_TYPE_HPP

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/scal/meta/is_fvar.hpp>
#include <stan/math/prim/scal/meta/partials_type.hpp>
#include <type_traits>

namespace stan {

template <typename T>
struct partials_type<stan::math::fvar<T> > {
typedef T type;
struct partials_type<T, std::enable_if_t<is_fvar<std::decay_t<T>>::value>> {
using type = typename std::decay_t<T>::Scalar;
};

} // namespace stan
Expand Down
2 changes: 0 additions & 2 deletions stan/math/mix/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#define STAN_MATH_MIX_META_HPP

#include <stan/math/prim/scal/meta/ad_promotable.hpp>
#include <stan/math/rev/scal/meta/ad_promotable.hpp>
#include <stan/math/fwd/scal/meta/ad_promotable.hpp>

#include <stan/math/fwd/core.hpp>
#include <stan/math/fwd/scal/meta/is_fvar.hpp>
Expand Down
20 changes: 0 additions & 20 deletions stan/math/prim/arr/meta/contains_std_vector.hpp

This file was deleted.

9 changes: 4 additions & 5 deletions stan/math/prim/arr/meta/index_type.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef STAN_MATH_PRIM_ARR_META_INDEX_TYPE_HPP
#define STAN_MATH_PRIM_ARR_META_INDEX_TYPE_HPP

#include <stan/math/prim/arr/meta/is_vector.hpp>
#include <stan/math/prim/scal/meta/index_type.hpp>
#include <type_traits>
#include <vector>

namespace stan {
Expand All @@ -14,11 +16,8 @@ namespace math {
* @tparam T type of elements in standard vector.
*/
template <typename T>
struct index_type<std::vector<T> > {
/**
* Typedef for index of standard vectors.
*/
typedef typename std::vector<T>::size_type type;
struct index_type<T, std::enable_if_t<is_std_vector<T>::value>> {
using type = typename std::decay_t<T>::size_type;
};

} // namespace math
Expand Down
9 changes: 6 additions & 3 deletions stan/math/prim/arr/meta/is_constant.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#ifndef STAN_MATH_PRIM_ARR_META_IS_CONSTANT_HPP
#define STAN_MATH_PRIM_ARR_META_IS_CONSTANT_HPP

#include <stan/math/prim/arr/meta/is_vector.hpp>
#include <stan/math/prim/scal/meta/bool_constant.hpp>
#include <stan/math/prim/scal/meta/is_constant.hpp>
#include <type_traits>
#include <vector>

namespace stan {
/**
* Defines a public enum named value and sets it to true
* Defines a static member named value and sets it to true
* if the type of the elements in the provided std::vector
* is constant, false otherwise. This is used in
* the is_constant_all metaprogram.
* @tparam type of the elements in the std::vector
*/
template <typename T>
struct is_constant<std::vector<T> > {
enum { value = is_constant<T>::value };
struct is_constant<T, std::enable_if_t<is_std_vector<T>::value>>
: bool_constant<is_constant<typename std::decay_t<T>::value_type>::value> {
};

} // namespace stan
Expand Down
33 changes: 23 additions & 10 deletions stan/math/prim/arr/meta/is_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@
#define STAN_MATH_PRIM_ARR_META_IS_VECTOR_HPP

#include <stan/math/prim/scal/meta/is_vector.hpp>
#include <type_traits>
#include <vector>

namespace stan {

// FIXME: use boost::type_traits::remove_all_extents to
// extend to array/ptr types
namespace internal {

/**
* This underlying implimentation is used when the type is not an std vector.
*/
template <typename T>
struct is_vector<const T> {
enum { value = is_vector<T>::value };
typedef T type;
};
struct is_std_vector_impl : std::false_type {};

/**
* This specialization implimentation has a static member named value when the
* template type is an std vector.
*/
template <typename... Args>
struct is_std_vector_impl<std::vector<Args...>> : std::true_type {};

} // namespace internal

/**
* Checks if the decayed type of T is a standard vector.
*/
template <typename T>
struct is_vector<std::vector<T> > {
enum { value = 1 };
typedef T type;
};
struct is_std_vector<
T, std::enable_if_t<internal::is_std_vector_impl<std::decay_t<T>>::value>>
: std::true_type {};

} // namespace stan
#endif
24 changes: 8 additions & 16 deletions stan/math/prim/arr/meta/scalar_type.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
#ifndef STAN_MATH_PRIM_ARR_META_SCALAR_TYPE_HPP
#define STAN_MATH_PRIM_ARR_META_SCALAR_TYPE_HPP

#include <stan/math/prim/arr/meta/is_vector.hpp>
#include <stan/math/prim/scal/meta/scalar_type.hpp>
#include <type_traits>
#include <vector>

namespace stan {
/**
* Specialization of scalar_type for vector to recursivly return the inner
* scalar type.
*/
template <typename T>
struct scalar_type<std::vector<T> > {
typedef typename scalar_type<T>::type type;
struct scalar_type<T, std::enable_if_t<is_std_vector<T>::value>> {
using type = scalar_type_t<typename std::decay_t<T>::value_type>;
};

template <typename T>
struct scalar_type<const std::vector<T> > {
typedef typename scalar_type<T>::type type;
};

template <typename T>
struct scalar_type<std::vector<T>&> {
typedef typename scalar_type<T>::type type;
};

template <typename T>
struct scalar_type<const std::vector<T>&> {
typedef typename scalar_type<T>::type type;
};
} // namespace stan
#endif
9 changes: 3 additions & 6 deletions stan/math/prim/arr/meta/value_type.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP
#define STAN_MATH_PRIM_ARR_META_VALUE_TYPE_HPP

#include <stan/math/prim/arr/meta/is_vector.hpp>
#include <stan/math/prim/scal/meta/value_type.hpp>
#include <vector>

Expand All @@ -14,12 +15,8 @@ namespace math {
* @tparam T type of elements in standard vector.
*/
template <typename T>
struct value_type<std::vector<T> > {
/**
* Type of value stored in a standard vector with type
* <code>T</code> entries.
*/
typedef T type;
struct value_type<T, std::enable_if_t<is_std_vector<T>::value>> {
using type = typename std::decay_t<T>::value_type;
};

} // namespace math
Expand Down
12 changes: 6 additions & 6 deletions stan/math/prim/mat/meta/index_type.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef STAN_MATH_PRIM_MAT_META_INDEX_TYPE_HPP
#define STAN_MATH_PRIM_MAT_META_INDEX_TYPE_HPP

#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/is_eigen.hpp>
#include <stan/math/prim/scal/meta/index_type.hpp>
#include <Eigen/Core>
#include <type_traits>

namespace stan {
namespace math {
Expand All @@ -12,12 +14,10 @@ namespace math {
* an Eigen matrix, vector, or row vector.
*
* @tparam T type of matrix.
* @tparam R number of rows for matrix.
* @tparam C number of columns for matrix.
*/
template <typename T, int R, int C>
struct index_type<Eigen::Matrix<T, R, C> > {
typedef typename Eigen::Matrix<T, R, C>::Index type;
template <typename T>
struct index_type<T, std::enable_if_t<is_eigen<T>::value>> {
using type = typename std::decay_t<T>::Index;
};

} // namespace math
Expand Down
24 changes: 6 additions & 18 deletions stan/math/prim/mat/meta/is_constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#define STAN_MATH_PRIM_MAT_META_IS_CONSTANT_HPP

#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/is_eigen.hpp>
#include <stan/math/prim/scal/meta/bool_constant.hpp>
#include <stan/math/prim/scal/meta/is_constant.hpp>
#include <type_traits>

namespace stan {
/**
Expand All @@ -11,26 +14,11 @@ namespace stan {
* is constant, false otherwise. This is used in
* the is_constant_all metaprogram.
*
* @tparam T type of the elements in the Eigen Matrix
* @tparam R number of rows in the Eigen Matrix
* @tparam C number of cols in the eigen Matrix
*/
template <typename T, int R, int C>
struct is_constant<Eigen::Matrix<T, R, C> > {
enum { value = is_constant<T>::value };
};

/**
* Defines a public enum named value and sets it to true
* if the type of the elements in the provided Eigen Block
* is constant, false otherwise. This is used in
* the is_constant_all metaprogram.
* @tparam type of the elements in the Eigen Block
* @tparam T type of the Eigen Matrix
*/
template <typename T>
struct is_constant<Eigen::Block<T> > {
enum { value = is_constant<T>::value };
};
struct is_constant<T, std::enable_if_t<is_eigen<T>::value>>
: bool_constant<is_constant<typename std::decay_t<T>::Scalar>::value> {};

} // namespace stan
#endif
Loading