mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
add writeable IndexedView
This commit is contained in:
@@ -558,27 +558,27 @@ template<typename Derived> class DenseBase
|
||||
EIGEN_DEVICE_FUNC void reverseInPlace();
|
||||
|
||||
template<typename RowIndices, typename ColIndices>
|
||||
struct IndexedViewType {
|
||||
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 IndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||
! (internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||
|| (internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value)),
|
||||
typename IndexedViewType<RowIndices,ColIndices>::type >::type
|
||||
typename ConstIndexedViewType<RowIndices,ColIndices>::type >::type
|
||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
||||
return typename IndexedViewType<RowIndices,ColIndices>::type(
|
||||
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 IndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||
internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::IsBlockAlike
|
||||
&& !(internal::is_integral<RowIndices>::value && internal::is_integral<ColIndices>::value),
|
||||
typename internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::BlockType>::type
|
||||
typename internal::traits<typename ConstIndexedViewType<RowIndices,ColIndices>::type>::BlockType>::type
|
||||
operator()(const RowIndices& rowIndices, const ColIndices& colIndices) const {
|
||||
typedef typename internal::traits<typename IndexedViewType<RowIndices,ColIndices>::type>::BlockType BlockType;
|
||||
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(),
|
||||
@@ -609,6 +609,58 @@ template<typename Derived> class DenseBase
|
||||
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_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
|
||||
#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
|
||||
|
||||
@@ -104,6 +104,7 @@ class IndexedView : public IndexedViewImpl<XprType, RowIndices, ColIndices, type
|
||||
public:
|
||||
typedef typename IndexedViewImpl<XprType, RowIndices, ColIndices, typename internal::traits<XprType>::StorageKind>::Base Base;
|
||||
EIGEN_GENERIC_PUBLIC_INTERFACE(IndexedView)
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(IndexedView)
|
||||
|
||||
typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
|
||||
typedef typename internal::remove_all<XprType>::type NestedExpression;
|
||||
@@ -180,6 +181,12 @@ struct unary_evaluator<IndexedView<ArgType, RowIndices, ColIndices>, IndexBased>
|
||||
return m_argImpl.coeff(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
Scalar& coeffRef(Index row, Index col)
|
||||
{
|
||||
return m_argImpl.coeffRef(m_xpr.rowIndices()[row], m_xpr.colIndices()[col]);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
evaluator<ArgType> m_argImpl;
|
||||
|
||||
Reference in New Issue
Block a user