Merged in ezhulenev/eigen-02 (pull request PR-498)

Add DSizes index type promotion
This commit is contained in:
Rasmus Munk Larsen
2018-09-17 21:58:38 +00:00
2 changed files with 36 additions and 1 deletions

View File

@@ -290,10 +290,27 @@ struct DSizes : array<DenseIndex, NumDims> {
}
}
#ifdef EIGEN_HAS_CXX11
// Enable DSizes index type promotion only if we are promoting to the
// larger type, e.g. allow to promote dimensions of type int to long.
template<typename OtherIndex,
typename std::enable_if<
std::is_same<
DenseIndex,
typename internal::promote_index_type<DenseIndex, OtherIndex>::type
>::value, int>::type = 0>
EIGEN_DEVICE_FUNC
explicit DSizes(const array<OtherIndex, NumDims>& other) {
for (int i = 0; i < NumDims; ++i) {
(*this)[i] = static_cast<DenseIndex>(other[i]);
}
}
#endif // EIGEN_HAS_CXX11
#ifdef EIGEN_HAS_INDEX_LIST
template <typename FirstType, typename... OtherTypes>
EIGEN_DEVICE_FUNC
DSizes(const Eigen::IndexList<FirstType, OtherTypes...>& dimensions) {
explicit DSizes(const Eigen::IndexList<FirstType, OtherTypes...>& dimensions) {
for (int i = 0; i < dimensions.count; ++i) {
(*this)[i] = dimensions[i];
}