Skip to content

Commit 39e9930

Browse files
committed
use eigen internal traits for getting the scalar type of a eigen type
1 parent 7ada875 commit 39e9930

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

stan/math/prim/meta/is_eigen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct scalar_type<T, std::enable_if_t<is_eigen<T>::value>> {
4141
*/
4242
template <typename T>
4343
struct value_type<T, std::enable_if_t<is_eigen<T>::value>> {
44-
using type = typename std::decay_t<T>::Scalar;
44+
using type = typename Eigen::internal::traits<std::decay_t<T>>::Scalar;
4545
};
4646

4747
/*! \ingroup require_eigens_types */

test/unit/math/prim/meta/value_type_test.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include <stan/math/prim/meta.hpp>
21
#include <test/unit/util.hpp>
2+
#include <stan/math/prim/meta.hpp>
3+
#include <unsupported/Eigen/KroneckerProduct>
34
#include <gtest/gtest.h>
45
#include <vector>
56

@@ -35,3 +36,11 @@ TEST(MathMetaPrim, value_type_matrix) {
3536
EXPECT_SAME_TYPE(Eigen::RowVectorXd,
3637
value_type<std::vector<Eigen::RowVectorXd> >::type);
3738
}
39+
40+
TEST(MathMetaPrim, value_type_kronecker) {
41+
Eigen::Matrix<double,2,2> A;
42+
const auto B = Eigen::kroneckerProduct(A, Eigen::Matrix<double,2,2>::Identity());
43+
Eigen::Matrix<double,4,1> C = Eigen::Matrix<double,4,1>::Random(4, 1);
44+
EXPECT_TRUE((std::is_same<double, stan::value_type_t<decltype(B)>>::value));
45+
Eigen::MatrixXd D = B * C;
46+
}

0 commit comments

Comments
 (0)