mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #54 - really fix const correctness except in Sparse
This commit is contained in:
@@ -177,8 +177,8 @@ template<typename XprType> struct blas_traits
|
||||
ExtractType,
|
||||
typename _ExtractType::PlainObject
|
||||
>::type DirectLinearAccessType;
|
||||
static inline ExtractType extract(const XprType& x) { return x; }
|
||||
static inline Scalar extractScalarFactor(const XprType&) { return Scalar(1); }
|
||||
static inline const ExtractType extract(const XprType& x) { return x; }
|
||||
static inline const Scalar extractScalarFactor(const XprType&) { return Scalar(1); }
|
||||
};
|
||||
|
||||
// pop conjugate
|
||||
@@ -194,7 +194,7 @@ struct blas_traits<CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr> >
|
||||
IsComplex = NumTraits<Scalar>::IsComplex,
|
||||
NeedToConjugate = Base::NeedToConjugate ? 0 : IsComplex
|
||||
};
|
||||
static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline Scalar extractScalarFactor(const XprType& x) { return conj(Base::extractScalarFactor(x.nestedExpression())); }
|
||||
};
|
||||
|
||||
@@ -206,7 +206,7 @@ struct blas_traits<CwiseUnaryOp<scalar_multiple_op<Scalar>, NestedXpr> >
|
||||
typedef blas_traits<NestedXpr> Base;
|
||||
typedef CwiseUnaryOp<scalar_multiple_op<Scalar>, NestedXpr> XprType;
|
||||
typedef typename Base::ExtractType ExtractType;
|
||||
static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline Scalar extractScalarFactor(const XprType& x)
|
||||
{ return x.functor().m_other * Base::extractScalarFactor(x.nestedExpression()); }
|
||||
};
|
||||
@@ -219,7 +219,7 @@ struct blas_traits<CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> >
|
||||
typedef blas_traits<NestedXpr> Base;
|
||||
typedef CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr> XprType;
|
||||
typedef typename Base::ExtractType ExtractType;
|
||||
static inline ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline const ExtractType extract(const XprType& x) { return Base::extract(x.nestedExpression()); }
|
||||
static inline Scalar extractScalarFactor(const XprType& x)
|
||||
{ return - Base::extractScalarFactor(x.nestedExpression()); }
|
||||
};
|
||||
@@ -245,11 +245,16 @@ struct blas_traits<Transpose<NestedXpr> >
|
||||
static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x.nestedExpression()); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct blas_traits<const T>
|
||||
: blas_traits<T>
|
||||
{};
|
||||
|
||||
template<typename T, bool HasUsableDirectAccess=blas_traits<T>::HasUsableDirectAccess>
|
||||
struct extract_data_selector {
|
||||
static const typename T::Scalar* run(const T& m)
|
||||
{
|
||||
return &blas_traits<T>::extract(m).const_cast_derived().coeffRef(0,0); // FIXME this should be .data()
|
||||
return const_cast<typename T::Scalar*>(&blas_traits<T>::extract(m).coeffRef(0,0)); // FIXME this should be .data()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,15 @@
|
||||
#define EIGEN_FORWARDDECLARATIONS_H
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename T> struct traits;
|
||||
|
||||
// here we say once and for all that traits<const T> == traits<T>
|
||||
// When constness must affect traits, it has to be constness on template parameters on which T itself depends.
|
||||
// For example, traits<Map<const T> > != traits<Map<T> >, but
|
||||
// traits<const Map<T> > == traits<Map<T> >
|
||||
template<typename T> struct traits<const T> : traits<T> {};
|
||||
|
||||
template<typename Derived> struct has_direct_access
|
||||
{
|
||||
enum { ret = (traits<Derived>::Flags & DirectAccessBit) ? 1 : 0 };
|
||||
@@ -49,6 +56,7 @@ template<typename T> struct NumTraits;
|
||||
|
||||
template<typename Derived> struct EigenBase;
|
||||
template<typename Derived> class DenseBase;
|
||||
template<typename Derived> class PlainObjectBase;
|
||||
|
||||
|
||||
template<typename Derived,
|
||||
@@ -92,7 +100,7 @@ template<typename Derived> class DiagonalBase;
|
||||
template<typename _DiagonalVectorType> class DiagonalWrapper;
|
||||
template<typename _Scalar, int SizeAtCompileTime, int MaxSizeAtCompileTime=SizeAtCompileTime> class DiagonalMatrix;
|
||||
template<typename MatrixType, typename DiagonalType, int ProductOrder> class DiagonalProduct;
|
||||
template<typename MatrixType, int Index> class Diagonal;
|
||||
template<typename MatrixType, int Index = 0> class Diagonal;
|
||||
template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> class PermutationMatrix;
|
||||
template<int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime> class Transpositions;
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS,
|
||||
YOU_CANNOT_MIX_ARRAYS_AND_MATRICES,
|
||||
YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION,
|
||||
YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION,
|
||||
THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY,
|
||||
YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT,
|
||||
THIS_METHOD_IS_ONLY_FOR_1x1_EXPRESSIONS
|
||||
};
|
||||
@@ -187,6 +187,6 @@
|
||||
|
||||
#define EIGEN_STATIC_ASSERT_LVALUE(Derived) \
|
||||
EIGEN_STATIC_ASSERT(int(internal::traits<Derived>::Flags) & LvalueBit, \
|
||||
YOU_ARE_TRYING_TO_WRITE_INTO_A_READ_ONLY_EXPRESSION)
|
||||
THIS_EXPRESSION_IS_NOT_A_LVALUE__IT_IS_READ_ONLY)
|
||||
|
||||
#endif // EIGEN_STATIC_ASSERT_H
|
||||
|
||||
@@ -377,19 +377,6 @@ struct special_scalar_op_base<Derived,Scalar,OtherScalar,true> : public DenseCo
|
||||
{ return static_cast<const special_scalar_op_base&>(matrix).operator*(scalar); }
|
||||
};
|
||||
|
||||
template<typename ExpressionType> struct HNormalizedReturnType {
|
||||
|
||||
enum {
|
||||
SizeAtCompileTime = ExpressionType::SizeAtCompileTime,
|
||||
SizeMinusOne = SizeAtCompileTime==Dynamic ? Dynamic : SizeAtCompileTime-1
|
||||
};
|
||||
typedef Block<ExpressionType,
|
||||
traits<ExpressionType>::ColsAtCompileTime==1 ? SizeMinusOne : 1,
|
||||
traits<ExpressionType>::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne;
|
||||
typedef CwiseUnaryOp<scalar_quotient1_op<typename traits<ExpressionType>::Scalar>,
|
||||
StartMinusOne > Type;
|
||||
};
|
||||
|
||||
template<typename XprType, typename CastType> struct cast_return_type
|
||||
{
|
||||
typedef typename XprType::Scalar CurrentScalarType;
|
||||
@@ -455,6 +442,13 @@ struct plain_diag_type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template<typename ExpressionType>
|
||||
struct is_lvalue
|
||||
{
|
||||
enum { value = !bool(is_const<ExpressionType>::value) &&
|
||||
bool(traits<ExpressionType>::Flags & LvalueBit) };
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
#endif // EIGEN_XPRHELPER_H
|
||||
|
||||
Reference in New Issue
Block a user