mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-01 16:24:28 +08:00
Factorize const and non-const version of the generic operator() method.
This commit is contained in:
parent
d072fc4b14
commit
17eac60446
@ -557,116 +557,13 @@ template<typename Derived> class DenseBase
|
|||||||
}
|
}
|
||||||
EIGEN_DEVICE_FUNC void reverseInPlace();
|
EIGEN_DEVICE_FUNC void reverseInPlace();
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
struct ConstIndexedViewType {
|
|
||||||
typedef IndexedView<const Derived,typename internal::MakeIndexing<RowIndices>::type,typename internal::MakeIndexing<ColIndices>::type> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
typename internal::enable_if<
|
|
||||||
! (internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
|
||||||
|| (internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value)),
|
|
||||||
typename ConstIndexedViewType<RowIndices,ColIndices>::type >::type
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
|
||||||
return typename ConstIndexedViewType<RowIndices,ColIndices>::type(
|
|
||||||
derived(), internal::make_indexing(rowIndices,derived().rows()), internal::make_indexing(colIndices,derived().cols()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
typename internal::enable_if<
|
|
||||||
internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
|
||||||
&& !(internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value),
|
|
||||||
typename internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::BlockType>::type
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
|
||||||
typedef typename internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::BlockType BlockType;
|
|
||||||
typename internal::MakeIndexing<RowIndices>::type actualRowIndices = internal::make_indexing(rowIndices,derived().rows());
|
|
||||||
typename internal::MakeIndexing<ColIndices>::type actualColIndices = internal::make_indexing(colIndices,derived().cols());
|
|
||||||
return BlockType(derived(),
|
|
||||||
internal::first(actualRowIndices),
|
|
||||||
internal::first(actualColIndices),
|
|
||||||
internal::size(actualRowIndices),
|
|
||||||
internal::size(actualColIndices));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
|
|
||||||
IndexedView<const Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>
|
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) const {
|
|
||||||
return IndexedView<const Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>(
|
|
||||||
derived(), rowIndices, internal::make_indexing(colIndices,derived().cols()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<const Derived,typename internal::MakeIndexing<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) const {
|
|
||||||
return IndexedView<const Derived,typename internal::MakeIndexing<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>(
|
|
||||||
derived(), internal::make_indexing(rowIndices,derived().rows()), colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<const Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) const {
|
|
||||||
return IndexedView<const Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>(
|
|
||||||
derived(), rowIndices, colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
struct IndexedViewType {
|
|
||||||
typedef IndexedView<Derived,typename internal::MakeIndexing<RowIndices>::type,typename internal::MakeIndexing<ColIndices>::type> type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
typename internal::enable_if<
|
|
||||||
! (internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
|
||||||
|| (internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value)),
|
|
||||||
typename IndexedViewType<RowIndices,ColIndices>::type >::type
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
|
|
||||||
return typename IndexedViewType<RowIndices,ColIndices>::type(
|
|
||||||
derived(), internal::make_indexing(rowIndices,derived().rows()), internal::make_indexing(colIndices,derived().cols()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndices>
|
|
||||||
typename internal::enable_if<
|
|
||||||
internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
|
||||||
&& !(internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value),
|
|
||||||
typename internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::BlockType>::type
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) {
|
|
||||||
typedef typename internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::BlockType BlockType;
|
|
||||||
typename internal::MakeIndexing<RowIndices>::type actualRowIndices = internal::make_indexing(rowIndices,derived().rows());
|
|
||||||
typename internal::MakeIndexing<ColIndices>::type actualColIndices = internal::make_indexing(colIndices,derived().cols());
|
|
||||||
return BlockType(derived(),
|
|
||||||
internal::first(actualRowIndices),
|
|
||||||
internal::first(actualColIndices),
|
|
||||||
internal::size(actualRowIndices),
|
|
||||||
internal::size(actualColIndices));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
|
|
||||||
IndexedView<Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>
|
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) {
|
|
||||||
return IndexedView<Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>(
|
|
||||||
derived(), rowIndices, internal::make_indexing(colIndices,derived().cols()));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<Derived,typename internal::MakeIndexing<RowIndices>::type, const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndices& rowIndices, const ColIndicesT (&colIndices)[ColIndicesN]) {
|
|
||||||
return IndexedView<Derived,typename internal::MakeIndexing<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>(
|
|
||||||
derived(), internal::make_indexing(rowIndices,derived().rows()), colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndicesT, std::size_t ColIndicesN>
|
|
||||||
IndexedView<Derived,const RowIndicesT (&)[RowIndicesN], const ColIndicesT (&)[ColIndicesN]>
|
|
||||||
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&colIndices)[ColIndicesN]) {
|
|
||||||
return IndexedView<Derived,const RowIndicesT (&)[RowIndicesN],const ColIndicesT (&)[ColIndicesN]>(
|
|
||||||
derived(), rowIndices, colIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
|
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase
|
||||||
#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
|
#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
|
||||||
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
|
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
|
||||||
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
|
#define EIGEN_DOC_UNARY_ADDONS(X,Y)
|
||||||
# include "../plugins/CommonCwiseUnaryOps.h"
|
# include "../plugins/CommonCwiseUnaryOps.h"
|
||||||
# include "../plugins/BlockMethods.h"
|
# include "../plugins/BlockMethods.h"
|
||||||
|
# include "../plugins/IndexedViewMethods.h"
|
||||||
# ifdef EIGEN_DENSEBASE_PLUGIN
|
# ifdef EIGEN_DENSEBASE_PLUGIN
|
||||||
# include EIGEN_DENSEBASE_PLUGIN
|
# include EIGEN_DENSEBASE_PLUGIN
|
||||||
# endif
|
# endif
|
||||||
|
@ -71,8 +71,8 @@ class IndexedViewImpl;
|
|||||||
* \tparam ColIndices the type of the object defining the sequence of column indices
|
* \tparam ColIndices the type of the object defining the sequence of column indices
|
||||||
*
|
*
|
||||||
* This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection
|
* This class represents an expression of a sub-matrix (or sub-vector) defined as the intersection
|
||||||
* of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f${r_0,r_1,..r_{m-1}\f$
|
* of sub-sets of rows and columns, that are themself defined by generic sequences of row indices \f$ \{r_0,r_1,..r_{m-1}\} \f$
|
||||||
* and column indices \f${c_0,c_1,..c_{n-1}\f$. Let \f$ A \f$ be the nested matrix, then the resulting matrix \f$ B \f$ has \c m
|
* and column indices \f$ \{c_0,c_1,..c_{n-1} \}\f$. Let \f$ A \f$ be the nested matrix, then the resulting matrix \f$ B \f$ has \c m
|
||||||
* rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) \f$.
|
* rows and \c n columns, and its entries are given by: \f$ B(i,j) = A(r_i,c_j) \f$.
|
||||||
*
|
*
|
||||||
* The \c RowIndices and \c ColIndices types must be compatible with the following API:
|
* The \c RowIndices and \c ColIndices types must be compatible with the following API:
|
||||||
|
81
Eigen/src/plugins/IndexedViewMethods.h
Normal file
81
Eigen/src/plugins/IndexedViewMethods.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// This file is part of Eigen, a lightweight C++ template library
|
||||||
|
// for linear algebra.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the Mozilla
|
||||||
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||||
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
template<typename RowIndices, typename ColIndices>
|
||||||
|
struct EIGEN_INDEXED_VIEW_METHOD_TYPE {
|
||||||
|
typedef IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename internal::MakeIndexing<RowIndices>::type,typename internal::MakeIndexing<ColIndices>::type> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename RowIndices, typename ColIndices>
|
||||||
|
typename internal::enable_if<
|
||||||
|
! (internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||||
|
|| (internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value)),
|
||||||
|
typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type >::type
|
||||||
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST {
|
||||||
|
return typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type(
|
||||||
|
derived(), internal::make_indexing(rowIndices,derived().rows()), internal::make_indexing(colIndices,derived().cols()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RowIndices, typename ColIndices>
|
||||||
|
typename internal::enable_if<
|
||||||
|
internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||||
|
&& !(internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value),
|
||||||
|
typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType>::type
|
||||||
|
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST {
|
||||||
|
typedef typename internal::traits<typename EIGEN_INDEXED_VIEW_METHOD_TYPE<RowIndices,ColIndices>::type>::BlockType BlockType;
|
||||||
|
typename internal::MakeIndexing<RowIndices>::type actualRowIndices = internal::make_indexing(rowIndices,derived().rows());
|
||||||
|
typename internal::MakeIndexing<ColIndices>::type actualColIndices = internal::make_indexing(colIndices,derived().cols());
|
||||||
|
return BlockType(derived(),
|
||||||
|
internal::first(actualRowIndices),
|
||||||
|
internal::first(actualColIndices),
|
||||||
|
internal::size(actualRowIndices),
|
||||||
|
internal::size(actualColIndices));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RowIndicesT, std::size_t RowIndicesN, typename ColIndices>
|
||||||
|
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>
|
||||||
|
operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndices& colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST {
|
||||||
|
return IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,const RowIndicesT (&)[RowIndicesN],typename internal::MakeIndexing<ColIndices>::type>(
|
||||||
|
derived(), rowIndices, internal::make_indexing(colIndices,derived().cols()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RowIndices, typename ColIndicesT, std::size_t ColIndicesN>
|
||||||
|
IndexedView<EIGEN_INDEXED_VIEW_METHOD_CONST Derived,typename internal::MakeIndexing<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 internal::MakeIndexing<RowIndices>::type,const ColIndicesT (&)[ColIndicesN]>(
|
||||||
|
derived(), internal::make_indexing(rowIndices,derived().rows()), 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef EIGEN_INDEXED_VIEW_METHOD_CONST
|
||||||
|
#undef EIGEN_INDEXED_VIEW_METHOD_TYPE
|
||||||
|
|
||||||
|
#ifndef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
||||||
|
#define EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
||||||
|
#include "IndexedViewMethods.h"
|
||||||
|
#undef EIGEN_INDEXED_VIEW_METHOD_2ND_PASS
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user