mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
refactor indexedviewmethods, enable non-const ref access with symbolic indices
This commit is contained in:
parent
1a5dfd7c0f
commit
bfbc66e078
@ -93,7 +93,6 @@ class IndexedViewImpl;
|
|||||||
* - std::vector<int>
|
* - std::vector<int>
|
||||||
* - std::valarray<int>
|
* - std::valarray<int>
|
||||||
* - std::array<int>
|
* - std::array<int>
|
||||||
* - Plain C arrays: int[N]
|
|
||||||
* - Eigen::ArrayXi
|
* - Eigen::ArrayXi
|
||||||
* - decltype(ArrayXi::LinSpaced(...))
|
* - decltype(ArrayXi::LinSpaced(...))
|
||||||
* - Any view/expressions of the previous types
|
* - Any view/expressions of the previous types
|
||||||
|
@ -9,200 +9,207 @@
|
|||||||
|
|
||||||
#if !defined(EIGEN_PARSED_BY_DOXYGEN)
|
#if !defined(EIGEN_PARSED_BY_DOXYGEN)
|
||||||
|
|
||||||
// This file is automatically included twice to generate const and non-const versions
|
|
||||||
|
|
||||||
#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
|
||||||
#define EIGEN_INDEXED_VIEW_METHOD_CONST const
|
|
||||||
#define EIGEN_INDEXED_VIEW_METHOD_TYPE ConstIndexedViewType
|
|
||||||
#else
|
|
||||||
#define EIGEN_INDEXED_VIEW_METHOD_CONST
|
|
||||||
#define EIGEN_INDEXED_VIEW_METHOD_TYPE IndexedViewType
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// define some aliases to ease readability
|
// define some aliases to ease readability
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
struct IvcRowType : public internal::IndexedViewCompatibleType<Indices,RowsAtCompileTime> {};
|
using IvcRowType = typename internal::IndexedViewCompatibleType<Indices, RowsAtCompileTime>::type;
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
struct IvcColType : public internal::IndexedViewCompatibleType<Indices,ColsAtCompileTime> {};
|
using IvcColType = typename internal::IndexedViewCompatibleType<Indices, ColsAtCompileTime>::type;
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
struct IvcType : public internal::IndexedViewCompatibleType<Indices,SizeAtCompileTime> {};
|
using IvcType = typename internal::IndexedViewCompatibleType<Indices, SizeAtCompileTime>::type;
|
||||||
|
|
||||||
typedef typename internal::IndexedViewCompatibleType<Index,1>::type IvcIndex;
|
typedef typename internal::IndexedViewCompatibleType<Index, 1>::type IvcIndex;
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
typename IvcRowType<Indices>::type
|
IvcRowType<Indices> ivcRow(const Indices& indices) const {
|
||||||
ivcRow(const Indices& indices) const {
|
return internal::makeIndexedViewCompatible(
|
||||||
return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,RowsAtCompileTime>(derived().rows()),Specialized);
|
indices, internal::variable_if_dynamic<Index, RowsAtCompileTime>(derived().rows()), Specialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
typename IvcColType<Indices>::type
|
IvcColType<Indices> ivcCol(const Indices& indices) const {
|
||||||
ivcCol(const Indices& indices) const {
|
return internal::makeIndexedViewCompatible(
|
||||||
return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,ColsAtCompileTime>(derived().cols()),Specialized);
|
indices, internal::variable_if_dynamic<Index, ColsAtCompileTime>(derived().cols()), Specialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
typename IvcColType<Indices>::type
|
IvcColType<Indices> ivcSize(const Indices& indices) const {
|
||||||
ivcSize(const Indices& indices) const {
|
return internal::makeIndexedViewCompatible(
|
||||||
return internal::makeIndexedViewCompatible(indices, internal::variable_if_dynamic<Index,SizeAtCompileTime>(derived().size()),Specialized);
|
indices, internal::variable_if_dynamic<Index, SizeAtCompileTime>(derived().size()), Specialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
#endif
|
template <typename RowIndices, typename ColIndices>
|
||||||
|
using IndexedViewType = IndexedView<Derived, IvcRowType<RowIndices>, IvcColType<ColIndices>>;
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
template <typename RowIndices, typename ColIndices>
|
||||||
struct EIGEN_INDEXED_VIEW_METHOD_TYPE {
|
using ConstIndexedViewType = IndexedView<const Derived, IvcRowType<RowIndices>, IvcColType<ColIndices>>;
|
||||||
typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,
|
|
||||||
typename IvcRowType<RowIndices>::type,
|
|
||||||
typename IvcColType<ColIndices>::type> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
// This is the generic version
|
// This is the generic version
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
template <typename RowIndices, typename ColIndices>
|
||||||
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
&& internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsIndexedView,
|
internal::traits<IndexedViewType<RowIndices, ColIndices>>::ReturnAsIndexedView,
|
||||||
typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>
|
IndexedViewType<RowIndices, ColIndices>>
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
|
||||||
{
|
return IndexedViewType<RowIndices, ColIndices>(derived(), ivcRow(rowIndices), ivcCol(colIndices));
|
||||||
return typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type
|
}
|
||||||
(derived(), ivcRow(rowIndices), ivcCol(colIndices));
|
|
||||||
|
template <typename RowIndices, typename ColIndices>
|
||||||
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
|
internal::traits<ConstIndexedViewType<RowIndices, ColIndices>>::ReturnAsIndexedView,
|
||||||
|
ConstIndexedViewType<RowIndices, ColIndices>>
|
||||||
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
||||||
|
return ConstIndexedViewType<RowIndices, ColIndices>(derived(), ivcRow(rowIndices), ivcCol(colIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following overload returns a Block<> object
|
// The following overload returns a Block<> object
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
template <typename RowIndices, typename ColIndices>
|
||||||
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
&& internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsBlock,
|
internal::traits<IndexedViewType<RowIndices, ColIndices>>::ReturnAsBlock,
|
||||||
typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>
|
typename internal::traits<IndexedViewType<RowIndices, ColIndices>>::BlockType>
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
|
||||||
{
|
typedef typename internal::traits<IndexedViewType<RowIndices, ColIndices>>::BlockType BlockType;
|
||||||
typedef typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType BlockType;
|
IvcRowType<RowIndices> actualRowIndices = ivcRow(rowIndices);
|
||||||
typename IvcRowType<RowIndices>::type actualRowIndices = ivcRow(rowIndices);
|
IvcColType<ColIndices> actualColIndices = ivcCol(colIndices);
|
||||||
typename IvcColType<ColIndices>::type actualColIndices = ivcCol(colIndices);
|
return BlockType(derived(), internal::first(actualRowIndices), internal::first(actualColIndices),
|
||||||
return BlockType(derived(),
|
internal::index_list_size(actualRowIndices), internal::index_list_size(actualColIndices));
|
||||||
internal::first(actualRowIndices),
|
}
|
||||||
internal::first(actualColIndices),
|
|
||||||
internal::index_list_size(actualRowIndices),
|
template <typename RowIndices, typename ColIndices>
|
||||||
internal::index_list_size(actualColIndices));
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
|
internal::traits<ConstIndexedViewType<RowIndices, ColIndices>>::ReturnAsBlock,
|
||||||
|
typename internal::traits<ConstIndexedViewType<RowIndices, ColIndices>>::BlockType>
|
||||||
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
||||||
|
typedef typename internal::traits<ConstIndexedViewType<RowIndices, ColIndices>>::BlockType BlockType;
|
||||||
|
IvcRowType<RowIndices> actualRowIndices = ivcRow(rowIndices);
|
||||||
|
IvcColType<ColIndices> actualColIndices = ivcCol(colIndices);
|
||||||
|
return BlockType(derived(), internal::first(actualRowIndices), internal::first(actualColIndices),
|
||||||
|
internal::index_list_size(actualRowIndices), internal::index_list_size(actualColIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following overload returns a Scalar
|
// The following overload returns a Scalar
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
template <typename RowIndices, typename ColIndices>
|
||||||
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices,ColIndices>::value
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
&& internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::ReturnAsScalar,
|
internal::traits<IndexedViewType<RowIndices, ColIndices>>::ReturnAsScalar,
|
||||||
CoeffReturnType >
|
Scalar&>
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
|
||||||
{
|
return Base::operator()(internal::eval_expr_given_size(rowIndices, rows()),
|
||||||
return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols()));
|
internal::eval_expr_given_size(colIndices, cols()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following three overloads are needed to handle raw Index[N] arrays.
|
template <typename RowIndices, typename ColIndices>
|
||||||
|
std::enable_if_t<internal::valid_indexed_view_overload<RowIndices, ColIndices>::value &&
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
|
internal::traits<ConstIndexedViewType<RowIndices, ColIndices>>::ReturnAsScalar,
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
|
CoeffReturnType>
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
||||||
{
|
return Base::operator()(internal::eval_expr_given_size(rowIndices, rows()),
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename IvcColType<ColIndices>::type>
|
internal::eval_expr_given_size(colIndices, cols()));
|
||||||
(derived(), rowIndices, ivcCol(colIndices));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
|
|
||||||
{
|
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcRowType<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
(derived(), ivcRow(rowIndices), colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
|
|
||||||
{
|
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
(derived(), rowIndices, colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Overloads for 1D vectors/arrays
|
// Overloads for 1D vectors/arrays
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
std::enable_if_t<
|
std::enable_if_t<IsRowMajor && (!(internal::get_compile_time_incr<IvcType<Indices>>::value == 1 ||
|
||||||
IsRowMajor && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
|
internal::is_valid_index_type<Indices>::value)),
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type> >
|
IndexedView<Derived, IvcIndex, IvcType<Indices>>>
|
||||||
operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const Indices& indices) {
|
||||||
{
|
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,typename IvcType<Indices>::type>
|
return IndexedView<Derived, IvcIndex, IvcType<Indices>>(derived(), IvcIndex(0), ivcCol(indices));
|
||||||
(derived(), IvcIndex(0), ivcCol(indices));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
std::enable_if_t<
|
std::enable_if_t<IsRowMajor && (!(internal::get_compile_time_incr<IvcType<Indices>>::value == 1 ||
|
||||||
(!IsRowMajor) && (!(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1 || internal::is_valid_index_type<Indices>::value)),
|
internal::is_valid_index_type<Indices>::value)),
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex> >
|
IndexedView<const Derived, IvcIndex, IvcType<Indices>>>
|
||||||
operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const Indices& indices) const {
|
||||||
{
|
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename IvcType<Indices>::type,IvcIndex>
|
return IndexedView<const Derived, IvcIndex, IvcType<Indices>>(derived(), IvcIndex(0), ivcCol(indices));
|
||||||
(derived(), ivcRow(indices), IvcIndex(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Indices>
|
template <typename Indices>
|
||||||
std::enable_if_t<
|
std::enable_if_t<(!IsRowMajor) && (!(internal::get_compile_time_incr<IvcType<Indices>>::value == 1 ||
|
||||||
(internal::get_compile_time_incr<typename IvcType<Indices>::type>::value==1) && (!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
|
internal::is_valid_index_type<Indices>::value)),
|
||||||
VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value> >
|
IndexedView<Derived, IvcType<Indices>, IvcIndex>>
|
||||||
operator()(const Indices& indices) EIGEN_INDEXED_VIEW_METHOD_CONST
|
operator()(const Indices& indices) {
|
||||||
{
|
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
typename IvcType<Indices>::type actualIndices = ivcSize(indices);
|
return IndexedView<Derived, IvcType<Indices>, IvcIndex>(derived(), ivcRow(indices), IvcIndex(0));
|
||||||
return VectorBlock<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,internal::array_size<Indices>::value>
|
|
||||||
(derived(), internal::first(actualIndices), internal::index_list_size(actualIndices));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IndexType>
|
template <typename Indices>
|
||||||
std::enable_if_t<symbolic::is_symbolic<IndexType>::value, CoeffReturnType >
|
std::enable_if_t<(!IsRowMajor) && (!(internal::get_compile_time_incr<IvcType<Indices>>::value == 1 ||
|
||||||
operator()(const IndexType& id) EIGEN_INDEXED_VIEW_METHOD_CONST
|
internal::is_valid_index_type<Indices>::value)),
|
||||||
{
|
IndexedView<const Derived, IvcType<Indices>, IvcIndex>>
|
||||||
return Base::operator()(internal::eval_expr_given_size(id,size()));
|
operator()(const Indices& indices) const {
|
||||||
}
|
|
||||||
|
|
||||||
template<typename IndicesT, std::size_t IndicesN>
|
|
||||||
std::enable_if_t<IsRowMajor,
|
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]> >
|
|
||||||
operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
|
|
||||||
{
|
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,IvcIndex,const IndicesT (&)[IndicesN]>
|
return IndexedView<const Derived, IvcType<Indices>, IvcIndex>(derived(), ivcRow(indices), IvcIndex(0));
|
||||||
(derived(), IvcIndex(0), indices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IndicesT, std::size_t IndicesN>
|
template <typename Indices>
|
||||||
std::enable_if_t<!IsRowMajor,
|
std::enable_if_t<(internal::get_compile_time_incr<IvcType<Indices>>::value == 1) &&
|
||||||
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex> >
|
(!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
|
||||||
operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST
|
VectorBlock<Derived, internal::array_size<Indices>::value>>
|
||||||
{
|
operator()(const Indices& indices) {
|
||||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const IndicesT (&)[IndicesN],IvcIndex>
|
IvcType<Indices> actualIndices = ivcSize(indices);
|
||||||
(derived(), indices, IvcIndex(0));
|
return VectorBlock<Derived, internal::array_size<Indices>::value>(derived(), internal::first(actualIndices),
|
||||||
|
internal::index_list_size(actualIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef EIGEN_INDEXED_VIEW_METHOD_CONST
|
template <typename Indices>
|
||||||
#undef EIGEN_INDEXED_VIEW_METHOD_TYPE
|
std::enable_if_t<(internal::get_compile_time_incr<IvcType<Indices>>::value == 1) &&
|
||||||
|
(!internal::is_valid_index_type<Indices>::value) && (!symbolic::is_symbolic<Indices>::value),
|
||||||
|
VectorBlock<const Derived, internal::array_size<Indices>::value>>
|
||||||
|
operator()(const Indices& indices) const {
|
||||||
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
|
IvcType<Indices> actualIndices = ivcSize(indices);
|
||||||
|
return VectorBlock<const Derived, internal::array_size<Indices>::value>(derived(), internal::first(actualIndices),
|
||||||
|
internal::index_list_size(actualIndices));
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
template <typename IndexType>
|
||||||
#define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
std::enable_if_t<symbolic::is_symbolic<IndexType>::value, Scalar&> operator()(const IndexType& id) {
|
||||||
#include "IndexedViewMethods.h"
|
return Base::operator()(internal::eval_expr_given_size(id, size()));
|
||||||
#undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
}
|
||||||
#endif
|
|
||||||
|
template <typename IndexType>
|
||||||
|
std::enable_if_t<symbolic::is_symbolic<IndexType>::value, CoeffReturnType> operator()(const IndexType& id) const {
|
||||||
|
return Base::operator()(internal::eval_expr_given_size(id, size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IndicesT, std::size_t IndicesN>
|
||||||
|
std::enable_if_t<IsRowMajor, IndexedView<Derived, IvcIndex, const IndicesT (&)[IndicesN]>> operator()(
|
||||||
|
const IndicesT (&indices)[IndicesN]) {
|
||||||
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
|
return IndexedView<Derived, IvcIndex, const IndicesT(&)[IndicesN]>(derived(), IvcIndex(0), indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IndicesT, std::size_t IndicesN>
|
||||||
|
std::enable_if_t<IsRowMajor, IndexedView<const Derived, IvcIndex, const IndicesT (&)[IndicesN]>> operator()(
|
||||||
|
const IndicesT (&indices)[IndicesN]) const {
|
||||||
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
|
return IndexedView<const Derived, IvcIndex, const IndicesT(&)[IndicesN]>(derived(), IvcIndex(0), indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IndicesT, std::size_t IndicesN>
|
||||||
|
std::enable_if_t<!IsRowMajor, IndexedView<Derived, const IndicesT (&)[IndicesN], IvcIndex>> operator()(
|
||||||
|
const IndicesT (&indices)[IndicesN]) {
|
||||||
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
|
return IndexedView<Derived, const IndicesT(&)[IndicesN], IvcIndex>(derived(), indices, IvcIndex(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IndicesT, std::size_t IndicesN>
|
||||||
|
std::enable_if_t<!IsRowMajor, IndexedView<const Derived, const IndicesT (&)[IndicesN], IvcIndex>> operator()(
|
||||||
|
const IndicesT (&indices)[IndicesN]) const {
|
||||||
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||||
|
return IndexedView<const Derived, const IndicesT(&)[IndicesN], IvcIndex>(derived(), indices, IvcIndex(0));
|
||||||
|
}
|
||||||
|
|
||||||
#else // EIGEN_PARSED_BY_DOXYGEN
|
#else // EIGEN_PARSED_BY_DOXYGEN
|
||||||
|
|
||||||
|
@ -289,13 +289,8 @@ void check_indexed_view()
|
|||||||
VERIFY( (A(all, std::array<int,4>{{1,3,2,4}})).ColsAtCompileTime == 4);
|
VERIFY( (A(all, std::array<int,4>{{1,3,2,4}})).ColsAtCompileTime == 4);
|
||||||
|
|
||||||
VERIFY_IS_APPROX( (A(std::array<int,3>{{1,3,5}}, std::array<int,4>{{9,6,3,0}})), A(seqN(1,3,2), seqN(9,4,-3)) );
|
VERIFY_IS_APPROX( (A(std::array<int,3>{{1,3,5}}, std::array<int,4>{{9,6,3,0}})), A(seqN(1,3,2), seqN(9,4,-3)) );
|
||||||
|
VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).RowsAtCompileTime, 3);
|
||||||
VERIFY_IS_APPROX( A({3, 1, 6, 5}, all), A(std::array<int,4>{{3, 1, 6, 5}}, all) );
|
VERIFY_IS_EQUAL(A(std::array<int, 3>{1, 3, 5}, std::array<int, 4>{3, 1, 6, 5}).ColsAtCompileTime, 4);
|
||||||
VERIFY_IS_APPROX( A(all,{3, 1, 6, 5}), A(all,std::array<int,4>{{3, 1, 6, 5}}) );
|
|
||||||
VERIFY_IS_APPROX( A({1,3,5},{3, 1, 6, 5}), A(std::array<int,3>{{1,3,5}},std::array<int,4>{{3, 1, 6, 5}}) );
|
|
||||||
|
|
||||||
VERIFY_IS_EQUAL( A({1,3,5},{3, 1, 6, 5}).RowsAtCompileTime, 3 );
|
|
||||||
VERIFY_IS_EQUAL( A({1,3,5},{3, 1, 6, 5}).ColsAtCompileTime, 4 );
|
|
||||||
|
|
||||||
VERIFY_IS_APPROX( a({3, 1, 6, 5}), a(std::array<int,4>{{3, 1, 6, 5}}) );
|
VERIFY_IS_APPROX( a({3, 1, 6, 5}), a(std::array<int,4>{{3, 1, 6, 5}}) );
|
||||||
VERIFY_IS_EQUAL( a({1,3,5}).SizeAtCompileTime, 3 );
|
VERIFY_IS_EQUAL( a({1,3,5}).SizeAtCompileTime, 3 );
|
||||||
@ -364,6 +359,9 @@ void check_indexed_view()
|
|||||||
A(X,Y) = 1;
|
A(X,Y) = 1;
|
||||||
A(XX,Y) = 1;
|
A(XX,Y) = 1;
|
||||||
A(X,YY) = 1;
|
A(X,YY) = 1;
|
||||||
|
// check symbolic indices
|
||||||
|
a(last) = 1;
|
||||||
|
A(last, last) = 1;
|
||||||
|
|
||||||
// Check compilation of varying integer types as index types:
|
// Check compilation of varying integer types as index types:
|
||||||
Index i = n/2;
|
Index i = n/2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user