mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
s/asMatrix()/matrix()
This commit is contained in:
parent
b6898996d4
commit
71a171c267
@ -154,11 +154,11 @@ template<typename Derived> class ArrayBase
|
||||
{ return cwiseNotEqual(other).all(); }
|
||||
|
||||
public:
|
||||
MatrixWrapper<Derived> asMatrix() { return derived(); }
|
||||
const MatrixWrapper<Derived> asMatrix() const { return derived(); }
|
||||
MatrixWrapper<Derived> matrix() { return derived(); }
|
||||
const MatrixWrapper<Derived> matrix() const { return derived(); }
|
||||
|
||||
// template<typename Dest>
|
||||
// inline void evalTo(Dest& dst) const { dst = asMatrix(); }
|
||||
// inline void evalTo(Dest& dst) const { dst = matrix(); }
|
||||
|
||||
protected:
|
||||
ArrayBase() : Base() {}
|
||||
|
@ -25,6 +25,15 @@
|
||||
#ifndef EIGEN_ARRAYWRAPPER_H
|
||||
#define EIGEN_ARRAYWRAPPER_H
|
||||
|
||||
/** \class ArrayWrapper
|
||||
*
|
||||
* \brief Expression of a mathematical vector or matrix as an array object
|
||||
*
|
||||
* This class is the return type of MatrixBase::array(), and most of the time
|
||||
* this is the only way it is use.
|
||||
*
|
||||
* \sa MatrixBase::array(), class MatrixWrapper
|
||||
*/
|
||||
template<typename ExpressionType>
|
||||
struct ei_traits<ArrayWrapper<ExpressionType> >
|
||||
: public ei_traits<ExpressionType>
|
||||
@ -97,6 +106,16 @@ class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
|
||||
const ExpressionType& m_expression;
|
||||
};
|
||||
|
||||
/** \class MatrixWrapper
|
||||
*
|
||||
* \brief Expression of an array as a mathematical vector or matrix
|
||||
*
|
||||
* This class is the return type of ArrayBase::matrix(), and most of the time
|
||||
* this is the only way it is use.
|
||||
*
|
||||
* \sa MatrixBase::matrix(), class ArrayWrapper
|
||||
*/
|
||||
|
||||
template<typename ExpressionType>
|
||||
struct ei_traits<MatrixWrapper<ExpressionType> >
|
||||
: public ei_traits<ExpressionType>
|
||||
|
@ -98,9 +98,9 @@ template<typename UnaryOp, typename MatrixType>
|
||||
class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense>
|
||||
: public MatrixType::template MakeBase< CwiseUnaryOp<UnaryOp, MatrixType> >::Type
|
||||
{
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression() const
|
||||
{ return derived().nestedExpression(); }
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& matrix()
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression()
|
||||
{ return derived().nestedExpression(); }
|
||||
|
||||
public:
|
||||
@ -111,24 +111,24 @@ class CwiseUnaryOpImpl<UnaryOp,MatrixType,Dense>
|
||||
|
||||
EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const
|
||||
{
|
||||
return derived()._functor()(matrix().coeff(row, col));
|
||||
return derived()._functor()(nestedExpression().coeff(row, col));
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const
|
||||
{
|
||||
return derived()._functor().packetOp(matrix().template packet<LoadMode>(row, col));
|
||||
return derived()._functor().packetOp(nestedExpression().template packet<LoadMode>(row, col));
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE const Scalar coeff(int index) const
|
||||
{
|
||||
return derived()._functor()(matrix().coeff(index));
|
||||
return derived()._functor()(nestedExpression().coeff(index));
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
EIGEN_STRONG_INLINE PacketScalar packet(int index) const
|
||||
{
|
||||
return derived()._functor().packetOp(matrix().template packet<LoadMode>(index));
|
||||
return derived()._functor().packetOp(nestedExpression().template packet<LoadMode>(index));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -90,9 +90,9 @@ class CwiseUnaryView : ei_no_assignment_operator,
|
||||
template<typename ViewOp, typename MatrixType>
|
||||
class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> : public MatrixBase<CwiseUnaryView<ViewOp, MatrixType> >
|
||||
{
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression() const
|
||||
{ return derived().nestedExpression(); }
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& matrix()
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression()
|
||||
{ return derived().nestedExpression(); }
|
||||
|
||||
public:
|
||||
@ -102,22 +102,22 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense> : public MatrixBase<CwiseUnary
|
||||
|
||||
EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const
|
||||
{
|
||||
return derived()._functor()(matrix().coeff(row, col));
|
||||
return derived()._functor()(nestedExpression().coeff(row, col));
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE const Scalar coeff(int index) const
|
||||
{
|
||||
return derived()._functor()(matrix().coeff(index));
|
||||
return derived()._functor()(nestedExpression().coeff(index));
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar& coeffRef(int row, int col)
|
||||
{
|
||||
return derived()._functor()(matrix().const_cast_derived().coeffRef(row, col));
|
||||
return derived()._functor()(nestedExpression().const_cast_derived().coeffRef(row, col));
|
||||
}
|
||||
|
||||
EIGEN_STRONG_INLINE Scalar& coeffRef(int index)
|
||||
{
|
||||
return derived()._functor()(matrix().const_cast_derived().coeffRef(index));
|
||||
return derived()._functor()(nestedExpression().const_cast_derived().coeffRef(index));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -92,9 +92,9 @@ template<typename MatrixType> class Transpose
|
||||
template<typename MatrixType> class TransposeImpl<MatrixType,Dense>
|
||||
: public MatrixType::template MakeBase<Transpose<MatrixType> >::Type
|
||||
{
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& matrix() const
|
||||
const typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression() const
|
||||
{ return derived().nestedExpression(); }
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& matrix()
|
||||
typename ei_cleantype<typename MatrixType::Nested>::type& nestedExpression()
|
||||
{ return derived().nestedExpression(); }
|
||||
|
||||
public:
|
||||
@ -105,52 +105,52 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Dense>
|
||||
|
||||
// EIGEN_EXPRESSION_IMPL_COMMON(MatrixBase<Transpose<MatrixType> >)
|
||||
|
||||
inline int stride() const { return matrix().stride(); }
|
||||
inline Scalar* data() { return matrix().data(); }
|
||||
inline const Scalar* data() const { return matrix().data(); }
|
||||
inline int stride() const { return nestedExpression().stride(); }
|
||||
inline Scalar* data() { return nestedExpression().data(); }
|
||||
inline const Scalar* data() const { return nestedExpression().data(); }
|
||||
|
||||
inline Scalar& coeffRef(int row, int col)
|
||||
{
|
||||
return matrix().const_cast_derived().coeffRef(col, row);
|
||||
return nestedExpression().const_cast_derived().coeffRef(col, row);
|
||||
}
|
||||
|
||||
inline Scalar& coeffRef(int index)
|
||||
{
|
||||
return matrix().const_cast_derived().coeffRef(index);
|
||||
return nestedExpression().const_cast_derived().coeffRef(index);
|
||||
}
|
||||
|
||||
inline const CoeffReturnType coeff(int row, int col) const
|
||||
{
|
||||
return matrix().coeff(col, row);
|
||||
return nestedExpression().coeff(col, row);
|
||||
}
|
||||
|
||||
inline const CoeffReturnType coeff(int index) const
|
||||
{
|
||||
return matrix().coeff(index);
|
||||
return nestedExpression().coeff(index);
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
inline const PacketScalar packet(int row, int col) const
|
||||
{
|
||||
return matrix().template packet<LoadMode>(col, row);
|
||||
return nestedExpression().template packet<LoadMode>(col, row);
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
inline void writePacket(int row, int col, const PacketScalar& x)
|
||||
{
|
||||
matrix().const_cast_derived().template writePacket<LoadMode>(col, row, x);
|
||||
nestedExpression().const_cast_derived().template writePacket<LoadMode>(col, row, x);
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
inline const PacketScalar packet(int index) const
|
||||
{
|
||||
return matrix().template packet<LoadMode>(index);
|
||||
return nestedExpression().template packet<LoadMode>(index);
|
||||
}
|
||||
|
||||
template<int LoadMode>
|
||||
inline void writePacket(int index, const PacketScalar& x)
|
||||
{
|
||||
matrix().const_cast_derived().template writePacket<LoadMode>(index, x);
|
||||
nestedExpression().const_cast_derived().template writePacket<LoadMode>(index, x);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -51,14 +51,14 @@ template<typename MatrixType> void array(const MatrixType& m)
|
||||
|
||||
// scalar addition
|
||||
VERIFY_IS_APPROX(m1.array() + s1, s1 + m1.array());
|
||||
VERIFY_IS_APPROX((m1.array() + s1).asMatrix(), MatrixType::Constant(rows,cols,s1) + m1);
|
||||
VERIFY_IS_APPROX(((m1*Scalar(2)).array() - s2).asMatrix(), (m1+m1) - MatrixType::Constant(rows,cols,s2) );
|
||||
VERIFY_IS_APPROX((m1.array() + s1).matrix(), MatrixType::Constant(rows,cols,s1) + m1);
|
||||
VERIFY_IS_APPROX(((m1*Scalar(2)).array() - s2).matrix(), (m1+m1) - MatrixType::Constant(rows,cols,s2) );
|
||||
m3 = m1;
|
||||
m3.array() += s2;
|
||||
VERIFY_IS_APPROX(m3, (m1.array() + s2).asMatrix());
|
||||
VERIFY_IS_APPROX(m3, (m1.array() + s2).matrix());
|
||||
m3 = m1;
|
||||
m3.array() -= s1;
|
||||
VERIFY_IS_APPROX(m3, (m1.array() - s1).asMatrix());
|
||||
VERIFY_IS_APPROX(m3, (m1.array() - s1).matrix());
|
||||
|
||||
// reductions
|
||||
VERIFY_IS_APPROX(m1.colwise().sum().sum(), m1.sum());
|
||||
@ -130,8 +130,8 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
|
||||
// count
|
||||
VERIFY(((m1.array().abs()+1)>RealScalar(0.1)).count() == rows*cols);
|
||||
// TODO allows colwise/rowwise for array
|
||||
VERIFY_IS_APPROX(((m1.array().abs()+1)>RealScalar(0.1)).asMatrix().colwise().count(), RowVectorXi::Constant(cols,rows));
|
||||
VERIFY_IS_APPROX(((m1.array().abs()+1)>RealScalar(0.1)).asMatrix().rowwise().count(), VectorXi::Constant(rows, cols));
|
||||
VERIFY_IS_APPROX(((m1.array().abs()+1)>RealScalar(0.1)).matrix().colwise().count(), RowVectorXi::Constant(cols,rows));
|
||||
VERIFY_IS_APPROX(((m1.array().abs()+1)>RealScalar(0.1)).matrix().rowwise().count(), VectorXi::Constant(rows, cols));
|
||||
}
|
||||
|
||||
template<typename VectorType> void lpNorm(const VectorType& v)
|
||||
|
@ -95,7 +95,7 @@ template<typename Scalar> void quaternion(void)
|
||||
VERIFY_IS_APPROX(-v1.normalized(),(q2.setFromTwoVectors(v1,-v1)*v1).normalized());
|
||||
if (ei_is_same_type<Scalar,double>::ret)
|
||||
{
|
||||
v3 = (v1.array()+eps).asMatrix();
|
||||
v3 = (v1.array()+eps).matrix();
|
||||
VERIFY_IS_APPROX( v3.normalized(),(q2.setFromTwoVectors(v1, v3)*v1).normalized());
|
||||
VERIFY_IS_APPROX(-v3.normalized(),(q2.setFromTwoVectors(v1,-v3)*v1).normalized());
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ template<typename MatrixType> void nomalloc(const MatrixType& m)
|
||||
|
||||
VERIFY_IS_APPROX((m1+m2)*s1, s1*m1+s1*m2);
|
||||
VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
|
||||
VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), (m1.array()*m1.array()).asMatrix());
|
||||
VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), (m1.array()*m1.array()).matrix());
|
||||
if (MatrixType::RowsAtCompileTime<EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD) {
|
||||
// If the matrices are too large, we have better to use the optimized GEMM
|
||||
// routines which allocates temporaries. However, on some platforms
|
||||
|
Loading…
x
Reference in New Issue
Block a user