mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-10 16:33:15 +08:00
Fix direct index aliased assignment.
This commit is contained in:
parent
1a45d2168e
commit
4ae5647355
@ -308,6 +308,12 @@ struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
|
|||||||
const XprType& m_xpr;
|
const XprType& m_xpr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Catch assignments to an IndexedView.
|
||||||
|
template <typename ArgType, typename RowIndices, typename ColIndices>
|
||||||
|
struct evaluator_assume_aliasing<IndexedView<ArgType, RowIndices, ColIndices>> {
|
||||||
|
static const bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
@ -840,11 +840,21 @@ void check_tutorial_examples() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check_aliasing() {
|
||||||
|
Eigen::Vector<float, 5> z = {0.0f, 1.1f, 2.2f, 3.3f, 4.4f};
|
||||||
|
std::vector<int> left_indices = {0, 1, 3, 4};
|
||||||
|
std::vector<int> right_indices = {1, 3, 4, 0};
|
||||||
|
z(left_indices) = z(right_indices);
|
||||||
|
Eigen::Vector<float, 5> expected = {1.1f, 3.3f, 2.2f, 4.4f, 0.0f};
|
||||||
|
VERIFY_IS_EQUAL(z, expected);
|
||||||
|
}
|
||||||
|
|
||||||
EIGEN_DECLARE_TEST(indexed_view) {
|
EIGEN_DECLARE_TEST(indexed_view) {
|
||||||
for (int i = 0; i < g_repeat; i++) {
|
for (int i = 0; i < g_repeat; i++) {
|
||||||
CALL_SUBTEST_1(check_indexed_view());
|
CALL_SUBTEST_1(check_indexed_view());
|
||||||
}
|
}
|
||||||
CALL_SUBTEST_1(check_tutorial_examples());
|
CALL_SUBTEST_1(check_tutorial_examples());
|
||||||
|
CALL_SUBTEST_1(check_aliasing());
|
||||||
|
|
||||||
// static checks of some internals:
|
// static checks of some internals:
|
||||||
STATIC_CHECK((internal::is_valid_index_type<int>::value));
|
STATIC_CHECK((internal::is_valid_index_type<int>::value));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user