mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Support reshaping with static shapes and dimensions conversion in tensor broadcasting
This commit is contained in:
@@ -115,7 +115,7 @@ static void test_static_broadcasting()
|
||||
Tensor<float, 3, DataLayout> tensor(8,3,5);
|
||||
tensor.setRandom();
|
||||
|
||||
#if EIGEN_HAS_CONSTEXPR
|
||||
#if defined(EIGEN_HAS_INDEX_LIST)
|
||||
Eigen::IndexList<Eigen::type2index<2>, Eigen::type2index<3>, Eigen::type2index<4>> broadcasts;
|
||||
#else
|
||||
Eigen::array<int, 3> broadcasts;
|
||||
|
||||
@@ -41,6 +41,28 @@ static void test_simple_reshape()
|
||||
}
|
||||
}
|
||||
|
||||
template <typename>
|
||||
static void test_static_reshape() {
|
||||
#if defined(EIGEN_HAS_INDEX_LIST)
|
||||
using Eigen::type2index;
|
||||
|
||||
Tensor<float, 5> tensor(2, 3, 1, 7, 1);
|
||||
tensor.setRandom();
|
||||
|
||||
// New dimensions: [2, 3, 7]
|
||||
Eigen::IndexList<type2index<2>, type2index<3>, type2index<7>> dim;
|
||||
Tensor<float, 3> reshaped = tensor.reshape(dim);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
VERIFY_IS_EQUAL(tensor(i, j, 0, k, 0), reshaped(i, j, k));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename>
|
||||
static void test_reshape_in_expr() {
|
||||
MatrixXf m1(2,3*5*7*11);
|
||||
@@ -462,6 +484,7 @@ static void test_composition()
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_morphing)
|
||||
{
|
||||
CALL_SUBTEST_1(test_simple_reshape<void>());
|
||||
CALL_SUBTEST_1(test_static_reshape<void>());
|
||||
CALL_SUBTEST_1(test_reshape_in_expr<void>());
|
||||
CALL_SUBTEST_1(test_reshape_as_lvalue<void>());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user