mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-05 04:35:46 +08:00
introduce a new LvalueBit flag and split DenseCoeffBase into three level of accessors
This commit is contained in:
parent
3abbdfd621
commit
95f2e7f3f5
@ -55,7 +55,7 @@ struct ei_traits<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
|
|||||||
ColsAtCompileTime = Cols,
|
ColsAtCompileTime = Cols,
|
||||||
MaxRowsAtCompileTime = Rows,
|
MaxRowsAtCompileTime = Rows,
|
||||||
MaxColsAtCompileTime = Cols,
|
MaxColsAtCompileTime = Cols,
|
||||||
Flags = 0
|
Flags = LvalueBit
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ struct ei_traits<Block<XprType, BlockRows, BlockCols, HasDirectAccess> > : ei_tr
|
|||||||
&& (InnerStrideAtCompileTime == 1)
|
&& (InnerStrideAtCompileTime == 1)
|
||||||
? PacketAccessBit : 0,
|
? PacketAccessBit : 0,
|
||||||
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ? LinearAccessBit : 0,
|
||||||
Flags0 = ei_traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | DirectAccessBit),
|
Flags0 = ei_traits<XprType>::Flags & (HereditaryBits | MaskPacketAccessBit | LvalueBit | DirectAccessBit),
|
||||||
Flags1 = Flags0 | FlagsLinearAccessBit,
|
Flags1 = Flags0 | FlagsLinearAccessBit,
|
||||||
Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0)
|
Flags = (Flags1 & ~RowMajorBit) | (IsRowMajor ? RowMajorBit : 0)
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,7 @@ struct ei_traits<CwiseUnaryView<ViewOp, MatrixType> >
|
|||||||
typedef typename MatrixType::Nested MatrixTypeNested;
|
typedef typename MatrixType::Nested MatrixTypeNested;
|
||||||
typedef typename ei_cleantype<MatrixTypeNested>::type _MatrixTypeNested;
|
typedef typename ei_cleantype<MatrixTypeNested>::type _MatrixTypeNested;
|
||||||
enum {
|
enum {
|
||||||
Flags = (ei_traits<_MatrixTypeNested>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)),
|
Flags = (ei_traits<_MatrixTypeNested>::Flags & (HereditaryBits | LvalueBit | LinearAccessBit | DirectAccessBit)),
|
||||||
CoeffReadCost = ei_traits<_MatrixTypeNested>::CoeffReadCost + ei_functor_traits<ViewOp>::Cost,
|
CoeffReadCost = ei_traits<_MatrixTypeNested>::CoeffReadCost + ei_functor_traits<ViewOp>::Cost,
|
||||||
MatrixTypeInnerStride = ei_inner_stride_at_compile_time<MatrixType>::ret,
|
MatrixTypeInnerStride = ei_inner_stride_at_compile_time<MatrixType>::ret,
|
||||||
// need to cast the sizeof's from size_t to int explicitly, otherwise:
|
// need to cast the sizeof's from size_t to int explicitly, otherwise:
|
||||||
|
@ -25,15 +25,15 @@
|
|||||||
#ifndef EIGEN_DENSECOEFFSBASE_H
|
#ifndef EIGEN_DENSECOEFFSBASE_H
|
||||||
#define EIGEN_DENSECOEFFSBASE_H
|
#define EIGEN_DENSECOEFFSBASE_H
|
||||||
|
|
||||||
template<typename Derived, bool EnableDirectAccessAPI>
|
template<typename Derived>
|
||||||
class DenseCoeffsBase : public EigenBase<Derived>
|
class DenseCoeffsBase<Derived,ReadOnlyAccessors> : public EigenBase<Derived>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename ei_traits<Derived>::StorageKind StorageKind;
|
typedef typename ei_traits<Derived>::StorageKind StorageKind;
|
||||||
typedef typename ei_traits<Derived>::Index Index;
|
typedef typename ei_traits<Derived>::Index Index;
|
||||||
typedef typename ei_traits<Derived>::Scalar Scalar;
|
typedef typename ei_traits<Derived>::Scalar Scalar;
|
||||||
typedef typename ei_packet_traits<Scalar>::type PacketScalar;
|
typedef typename ei_packet_traits<Scalar>::type PacketScalar;
|
||||||
typedef typename ei_meta_if<ei_has_direct_access<Derived>::ret,
|
typedef typename ei_meta_if<bool(ei_traits<Derived>::Flags&LvalueBit),
|
||||||
const Scalar&,
|
const Scalar&,
|
||||||
typename ei_meta_if<ei_is_arithmetic<Scalar>::ret, Scalar, const Scalar>::ret
|
typename ei_meta_if<ei_is_arithmetic<Scalar>::ret, Scalar, const Scalar>::ret
|
||||||
>::ret CoeffReturnType;
|
>::ret CoeffReturnType;
|
||||||
@ -239,11 +239,11 @@ class DenseCoeffsBase : public EigenBase<Derived>
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
class DenseCoeffsBase<Derived, true> : public DenseCoeffsBase<Derived, false>
|
class DenseCoeffsBase<Derived, WriteAccessors> : public DenseCoeffsBase<Derived, ReadOnlyAccessors>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef DenseCoeffsBase<Derived, false> Base;
|
typedef DenseCoeffsBase<Derived, ReadOnlyAccessors> Base;
|
||||||
|
|
||||||
typedef typename ei_traits<Derived>::StorageKind StorageKind;
|
typedef typename ei_traits<Derived>::StorageKind StorageKind;
|
||||||
typedef typename ei_traits<Derived>::Index Index;
|
typedef typename ei_traits<Derived>::Index Index;
|
||||||
@ -512,6 +512,23 @@ class DenseCoeffsBase<Derived, true> : public DenseCoeffsBase<Derived, false>
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Derived>
|
||||||
|
class DenseCoeffsBase<Derived, DirectAccessors> : public DenseCoeffsBase<Derived, WriteAccessors>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef DenseCoeffsBase<Derived, WriteAccessors> Base;
|
||||||
|
typedef typename ei_traits<Derived>::Index Index;
|
||||||
|
typedef typename ei_traits<Derived>::Scalar Scalar;
|
||||||
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
|
|
||||||
|
using Base::rows;
|
||||||
|
using Base::cols;
|
||||||
|
using Base::size;
|
||||||
|
using Base::derived;
|
||||||
|
|
||||||
/** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
|
/** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
|
||||||
*
|
*
|
||||||
* \sa outerStride(), rowStride(), colStride()
|
* \sa outerStride(), rowStride(), colStride()
|
||||||
@ -531,6 +548,7 @@ class DenseCoeffsBase<Derived, true> : public DenseCoeffsBase<Derived, false>
|
|||||||
return derived().outerStride();
|
return derived().outerStride();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME shall we remove it ?
|
||||||
inline Index stride() const
|
inline Index stride() const
|
||||||
{
|
{
|
||||||
return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
|
return Derived::IsVectorAtCompileTime ? innerStride() : outerStride();
|
||||||
|
@ -62,7 +62,7 @@ struct ei_traits<Diagonal<MatrixType,DiagIndex> >
|
|||||||
MatrixType::MaxColsAtCompileTime)
|
MatrixType::MaxColsAtCompileTime)
|
||||||
: (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex),
|
: (EIGEN_SIZE_MIN_PREFER_FIXED(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex),
|
||||||
MaxColsAtCompileTime = 1,
|
MaxColsAtCompileTime = 1,
|
||||||
Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit) & ~RowMajorBit,
|
Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | LvalueBit | DirectAccessBit) & ~RowMajorBit,
|
||||||
CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
|
CoeffReadCost = _MatrixTypeNested::CoeffReadCost,
|
||||||
MatrixTypeOuterStride = ei_outer_stride_at_compile_time<MatrixType>::ret,
|
MatrixTypeOuterStride = ei_outer_stride_at_compile_time<MatrixType>::ret,
|
||||||
InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
|
InnerStrideAtCompileTime = MatrixTypeOuterStride == Dynamic ? Dynamic : MatrixTypeOuterStride+1,
|
||||||
|
@ -105,6 +105,9 @@ struct ei_traits<DiagonalMatrix<_Scalar,SizeAtCompileTime,MaxSizeAtCompileTime>
|
|||||||
typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
|
typedef Matrix<_Scalar,SizeAtCompileTime,1,0,MaxSizeAtCompileTime,1> DiagonalVectorType;
|
||||||
typedef Dense StorageKind;
|
typedef Dense StorageKind;
|
||||||
typedef DenseIndex Index;
|
typedef DenseIndex Index;
|
||||||
|
enum {
|
||||||
|
Flags = LvalueBit
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
|
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime>
|
||||||
@ -213,7 +216,7 @@ struct ei_traits<DiagonalWrapper<_DiagonalVectorType> >
|
|||||||
ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
ColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
||||||
MaxRowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
MaxRowsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
||||||
MaxColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
MaxColsAtCompileTime = DiagonalVectorType::SizeAtCompileTime,
|
||||||
Flags = 0
|
Flags = ei_traits<DiagonalVectorType>::Flags & LvalueBit
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ struct ei_traits<Reverse<MatrixType, Direction> >
|
|||||||
LinearAccess = ( (Direction==BothDirections) && (int(_MatrixTypeNested::Flags)&PacketAccessBit) )
|
LinearAccess = ( (Direction==BothDirections) && (int(_MatrixTypeNested::Flags)&PacketAccessBit) )
|
||||||
? LinearAccessBit : 0,
|
? LinearAccessBit : 0,
|
||||||
|
|
||||||
Flags = int(_MatrixTypeNested::Flags) & (HereditaryBits | PacketAccessBit | LinearAccess | DirectAccessBit),
|
Flags = int(_MatrixTypeNested::Flags) & (HereditaryBits | LvalueBit | PacketAccessBit | LinearAccess),
|
||||||
|
|
||||||
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
|
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
|
||||||
};
|
};
|
||||||
|
@ -139,6 +139,14 @@ const unsigned int DirectAccessBit = 0x20;
|
|||||||
* means the first coefficient packet is guaranteed to be aligned */
|
* means the first coefficient packet is guaranteed to be aligned */
|
||||||
const unsigned int AlignedBit = 0x40;
|
const unsigned int AlignedBit = 0x40;
|
||||||
|
|
||||||
|
/** \ingroup flags
|
||||||
|
*
|
||||||
|
* Means the expression is writable. Note that DirectAccessBit implies LvalueBit.
|
||||||
|
* Internaly, it is mainly used to enable the writable coeff accessors, and makes
|
||||||
|
* the read-only coeff accessors to return by const reference.
|
||||||
|
*/
|
||||||
|
const unsigned int LvalueBit = 0x80;
|
||||||
|
|
||||||
const unsigned int NestByRefBit = 0x100;
|
const unsigned int NestByRefBit = 0x100;
|
||||||
|
|
||||||
// list of flags that are inherited by default
|
// list of flags that are inherited by default
|
||||||
@ -234,6 +242,10 @@ enum {
|
|||||||
IsSparse
|
IsSparse
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AccessorLevels {
|
||||||
|
ReadOnlyAccessors, WriteAccessors, DirectAccessors
|
||||||
|
};
|
||||||
|
|
||||||
enum DecompositionOptions {
|
enum DecompositionOptions {
|
||||||
Pivoting = 0x01, // LDLT,
|
Pivoting = 0x01, // LDLT,
|
||||||
NoPivoting = 0x02, // LDLT,
|
NoPivoting = 0x02, // LDLT,
|
||||||
|
@ -36,7 +36,10 @@ template<typename Derived> struct ei_has_direct_access
|
|||||||
|
|
||||||
template<typename Derived> struct EigenBase;
|
template<typename Derived> struct EigenBase;
|
||||||
template<typename Derived> class DenseBase;
|
template<typename Derived> class DenseBase;
|
||||||
template<typename Derived, bool EnableDirectAccessAPI = ei_has_direct_access<Derived>::ret>
|
template<typename Derived,
|
||||||
|
AccessorLevels Level = (ei_traits<Derived>::Flags & DirectAccessBit) ? DirectAccessors
|
||||||
|
: (ei_traits<Derived>::Flags & LvalueBit) ? WriteAccessors
|
||||||
|
: ReadOnlyAccessors>
|
||||||
class DenseCoeffsBase;
|
class DenseCoeffsBase;
|
||||||
|
|
||||||
template<typename _Scalar, int _Rows, int _Cols,
|
template<typename _Scalar, int _Rows, int _Cols,
|
||||||
|
@ -155,7 +155,7 @@ class ei_compute_matrix_flags
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum { ret = LinearAccessBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit };
|
enum { ret = LinearAccessBit | LvalueBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit };
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int _Rows, int _Cols> struct ei_size_at_compile_time
|
template<int _Rows, int _Cols> struct ei_size_at_compile_time
|
||||||
@ -355,7 +355,7 @@ template<typename T, int n=1, typename PlainObject = typename ei_eval<T>::type>
|
|||||||
|
|
||||||
template<unsigned int Flags> struct ei_are_flags_consistent
|
template<unsigned int Flags> struct ei_are_flags_consistent
|
||||||
{
|
{
|
||||||
enum { ret = true };
|
enum { ret = EIGEN_IMPLIES(bool(Flags&DirectAccessBit), bool(Flags&LvalueBit)) };
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Derived, typename XprKind = typename ei_traits<Derived>::XprKind>
|
template<typename Derived, typename XprKind = typename ei_traits<Derived>::XprKind>
|
||||||
|
@ -130,7 +130,7 @@ template<typename _MatrixType> class HessenbergDecomposition
|
|||||||
{
|
{
|
||||||
if(matrix.rows()<2)
|
if(matrix.rows()<2)
|
||||||
{
|
{
|
||||||
m_isInitialized = true;
|
m_isInitialized = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_hCoeffs.resize(matrix.rows()-1,1);
|
m_hCoeffs.resize(matrix.rows()-1,1);
|
||||||
@ -160,7 +160,7 @@ template<typename _MatrixType> class HessenbergDecomposition
|
|||||||
m_matrix = matrix;
|
m_matrix = matrix;
|
||||||
if(matrix.rows()<2)
|
if(matrix.rows()<2)
|
||||||
{
|
{
|
||||||
m_isInitialized = true;
|
m_isInitialized = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
m_hCoeffs.resize(matrix.rows()-1,1);
|
m_hCoeffs.resize(matrix.rows()-1,1);
|
||||||
@ -360,7 +360,7 @@ template<typename MatrixType> struct HessenbergDecompositionMatrixHReturnType
|
|||||||
result = m_hess.packedMatrix();
|
result = m_hess.packedMatrix();
|
||||||
Index n = result.rows();
|
Index n = result.rows();
|
||||||
if (n>2)
|
if (n>2)
|
||||||
result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
|
result.bottomLeftCorner(n-2, n-2).template triangularView<Lower>().setZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
Index rows() const { return m_hess.packedMatrix().rows(); }
|
Index rows() const { return m_hess.packedMatrix().rows(); }
|
||||||
|
@ -54,7 +54,7 @@ struct ei_traits<DynamicSparseMatrix<_Scalar, _Flags, _Index> >
|
|||||||
ColsAtCompileTime = Dynamic,
|
ColsAtCompileTime = Dynamic,
|
||||||
MaxRowsAtCompileTime = Dynamic,
|
MaxRowsAtCompileTime = Dynamic,
|
||||||
MaxColsAtCompileTime = Dynamic,
|
MaxColsAtCompileTime = Dynamic,
|
||||||
Flags = _Flags | NestByRefBit,
|
Flags = _Flags | NestByRefBit | LvalueBit,
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
SupportedAccessPatterns = OuterRandomAccessPattern
|
SupportedAccessPatterns = OuterRandomAccessPattern
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ struct ei_traits<SparseMatrix<_Scalar, _Options, _Index> >
|
|||||||
ColsAtCompileTime = Dynamic,
|
ColsAtCompileTime = Dynamic,
|
||||||
MaxRowsAtCompileTime = Dynamic,
|
MaxRowsAtCompileTime = Dynamic,
|
||||||
MaxColsAtCompileTime = Dynamic,
|
MaxColsAtCompileTime = Dynamic,
|
||||||
Flags = _Options | NestByRefBit,
|
Flags = _Options | NestByRefBit | LvalueBit,
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
SupportedAccessPatterns = InnerRandomAccessPattern
|
SupportedAccessPatterns = InnerRandomAccessPattern
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,7 @@ struct ei_traits<SparseVector<_Scalar, _Options, _Index> >
|
|||||||
ColsAtCompileTime = IsColVector ? 1 : Dynamic,
|
ColsAtCompileTime = IsColVector ? 1 : Dynamic,
|
||||||
MaxRowsAtCompileTime = RowsAtCompileTime,
|
MaxRowsAtCompileTime = RowsAtCompileTime,
|
||||||
MaxColsAtCompileTime = ColsAtCompileTime,
|
MaxColsAtCompileTime = ColsAtCompileTime,
|
||||||
Flags = _Options | NestByRefBit,
|
Flags = _Options | NestByRefBit | LvalueBit,
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
SupportedAccessPatterns = InnerRandomAccessPattern
|
SupportedAccessPatterns = InnerRandomAccessPattern
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user