a lot of cleaning and fixes

This commit is contained in:
Gael Guennebaud 2009-12-16 19:18:40 +01:00
parent 22a6ab1f4b
commit 9f79558839
20 changed files with 258 additions and 298 deletions

View File

@ -77,6 +77,8 @@ template<typename Derived> class ArrayBase
using Base::CoeffReadCost; using Base::CoeffReadCost;
using Base::_HasDirectAccess; using Base::_HasDirectAccess;
using Base::derived;
using Base::const_cast_derived;
using Base::rows; using Base::rows;
using Base::cols; using Base::cols;
using Base::size; using Base::size;
@ -107,18 +109,15 @@ template<typename Derived> class ArrayBase
typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType; typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType;
#endif // not EIGEN_PARSED_BY_DOXYGEN #endif // not EIGEN_PARSED_BY_DOXYGEN
#ifndef EIGEN_PARSED_BY_DOXYGEN
using AnyMatrixBase<Derived>::derived;
inline Derived& const_cast_derived() const
{ return *static_cast<Derived*>(const_cast<ArrayBase*>(this)); }
#endif // not EIGEN_PARSED_BY_DOXYGEN
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
# include "../plugins/CommonCwiseUnaryOps.h" # include "../plugins/CommonCwiseUnaryOps.h"
# include "../plugins/MatrixCwiseUnaryOps.h" # include "../plugins/MatrixCwiseUnaryOps.h"
# include "../plugins/ArrayCwiseUnaryOps.h" # include "../plugins/ArrayCwiseUnaryOps.h"
# include "../plugins/CommonCwiseBinaryOps.h" # include "../plugins/CommonCwiseBinaryOps.h"
# include "../plugins/ArrayCwiseBinaryOps.h" # include "../plugins/ArrayCwiseBinaryOps.h"
# ifdef EIGEN_ARRAYBASE_PLUGIN
# include EIGEN_ARRAYBASE_PLUGIN
# endif
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
@ -142,6 +141,8 @@ template<typename Derived> class ArrayBase
Derived& operator+=(const Scalar& scalar) Derived& operator+=(const Scalar& scalar)
{ return *this = derived() + scalar; } { return *this = derived() + scalar; }
Derived& operator-=(const Scalar& scalar)
{ return *this = derived() - scalar; }
template<typename OtherDerived> template<typename OtherDerived>
Derived& operator+=(const ArrayBase<OtherDerived>& other); Derived& operator+=(const ArrayBase<OtherDerived>& other);
@ -177,9 +178,7 @@ template<typename Derived> class ArrayBase
// const VectorwiseOp<Derived,Vertical> colwise() const; // const VectorwiseOp<Derived,Vertical> colwise() const;
// VectorwiseOp<Derived,Vertical> colwise(); // VectorwiseOp<Derived,Vertical> colwise();
#ifdef EIGEN_ARRAYBASE_PLUGIN
#include EIGEN_ARRAYBASE_PLUGIN
#endif
public: public:
MatrixWrapper<Derived> asMatrix() { return derived(); } MatrixWrapper<Derived> asMatrix() { return derived(); }

View File

@ -63,11 +63,11 @@ struct ei_traits<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType> template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
class Select : ei_no_assignment_operator, class Select : ei_no_assignment_operator,
public ConditionMatrixType::template MakeBase< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::Type public ThenMatrixType::template MakeBase< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::Type
{ {
public: public:
typedef typename ConditionMatrixType::template MakeBase< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::Type Base; typedef typename ThenMatrixType::template MakeBase< Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >::Type Base;
_EIGEN_GENERIC_PUBLIC_INTERFACE(Select) _EIGEN_GENERIC_PUBLIC_INTERFACE(Select)
Select(const ConditionMatrixType& conditionMatrix, Select(const ConditionMatrixType& conditionMatrix,

View File

@ -39,9 +39,14 @@ template<typename Derived> struct AnyMatrixBase
{ {
typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType; typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType;
/** \returns a reference to the derived object */
Derived& derived() { return *static_cast<Derived*>(this); } Derived& derived() { return *static_cast<Derived*>(this); }
/** \returns a const reference to the derived object */
const Derived& derived() const { return *static_cast<const Derived*>(this); } const Derived& derived() const { return *static_cast<const Derived*>(this); }
inline Derived& const_cast_derived() const
{ return *static_cast<Derived*>(const_cast<AnyMatrixBase*>(this)); }
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */ /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
inline int rows() const { return derived().rows(); } inline int rows() const { return derived().rows(); }
/** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/

View File

@ -194,7 +194,7 @@ EIGEN_STRONG_INLINE Derived &
MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other) MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
{ {
SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, Derived> tmp(derived()); SelfCwiseBinaryOp<ei_scalar_sum_op<Scalar>, Derived> tmp(derived());
tmp = other; tmp = other.derived();
return derived(); return derived();
} }

View File

@ -51,6 +51,9 @@ template<typename Derived> class DenseBase
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;
using AnyMatrixBase<Derived>::derived;
using AnyMatrixBase<Derived>::const_cast_derived;
#endif // not EIGEN_PARSED_BY_DOXYGEN #endif // not EIGEN_PARSED_BY_DOXYGEN
enum { enum {
@ -391,6 +394,21 @@ template<typename Derived> class DenseBase
bool isZero(RealScalar prec = precision<Scalar>()) const; bool isZero(RealScalar prec = precision<Scalar>()) const;
bool isOnes(RealScalar prec = precision<Scalar>()) const; bool isOnes(RealScalar prec = precision<Scalar>()) const;
EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other)
{
SelfCwiseBinaryOp<ei_scalar_product_op<Scalar>, Derived> tmp(derived());
typedef typename Derived::PlainMatrixType PlainMatrixType;
tmp = PlainMatrixType::Constant(rows(),cols(),other);
return derived();
}
EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other)
{
SelfCwiseBinaryOp<typename ei_meta_if<NumTraits<Scalar>::HasFloatingPoint,ei_scalar_product_op<Scalar>,ei_scalar_quotient_op<Scalar> >::ret, Derived> tmp(derived());
typedef typename Derived::PlainMatrixType PlainMatrixType;
tmp = PlainMatrixType::Constant(rows(),cols(), NumTraits<Scalar>::HasFloatingPoint ? Scalar(1)/other : other);
return derived();
}
// template<typename OtherDerived> // template<typename OtherDerived>
// inline bool operator==(const DenseBase<OtherDerived>& other) const // inline bool operator==(const DenseBase<OtherDerived>& other) const
// { return cwiseEqual(other).all(); } // { return cwiseEqual(other).all(); }
@ -446,12 +464,6 @@ template<typename Derived> class DenseBase
template<typename Visitor> template<typename Visitor>
void visit(Visitor& func) const; void visit(Visitor& func) const;
#ifndef EIGEN_PARSED_BY_DOXYGEN
using AnyMatrixBase<Derived>::derived;
inline Derived& const_cast_derived() const
{ return *static_cast<Derived*>(const_cast<DenseBase*>(this)); }
#endif // not EIGEN_PARSED_BY_DOXYGEN
inline const WithFormat<Derived> format(const IOFormat& fmt) const; inline const WithFormat<Derived> format(const IOFormat& fmt) const;
/////////// Array module /////////// /////////// Array module ///////////

View File

@ -52,7 +52,7 @@ enum { StreamPrecision = -1,
* Example: \include IOFormat.cpp * Example: \include IOFormat.cpp
* Output: \verbinclude IOFormat.out * Output: \verbinclude IOFormat.out
* *
* \sa MatrixBase::format(), class WithFormat * \sa DenseBase::format(), class WithFormat
*/ */
struct IOFormat struct IOFormat
{ {
@ -86,12 +86,12 @@ struct IOFormat
* \param ExpressionType the type of the object on which IO stream operations are performed * \param ExpressionType the type of the object on which IO stream operations are performed
* *
* This class represents an expression with stream operators controlled by a given IOFormat. * This class represents an expression with stream operators controlled by a given IOFormat.
* It is the return type of MatrixBase::format() * It is the return type of DenseBase::format()
* and most of the time this is the only way it is used. * and most of the time this is the only way it is used.
* *
* See class IOFormat for some examples. * See class IOFormat for some examples.
* *
* \sa MatrixBase::format(), class IOFormat * \sa DenseBase::format(), class IOFormat
*/ */
template<typename ExpressionType> template<typename ExpressionType>
class WithFormat class WithFormat

View File

@ -69,89 +69,36 @@ template<typename Derived> class MatrixBase
typedef typename ei_packet_traits<Scalar>::type PacketScalar; typedef typename ei_packet_traits<Scalar>::type PacketScalar;
typedef DenseBase<Derived> Base; typedef DenseBase<Derived> Base;
using Base::RowsAtCompileTime;
using Base::ColsAtCompileTime;
using Base::SizeAtCompileTime;
using Base::MaxRowsAtCompileTime;
using Base::MaxColsAtCompileTime;
using Base::MaxSizeAtCompileTime;
using Base::IsVectorAtCompileTime;
using Base::Flags;
using Base::CoeffReadCost;
using Base::_HasDirectAccess;
using Base::derived;
using Base::const_cast_derived;
using Base::rows; using Base::rows;
using Base::cols; using Base::cols;
using Base::size; using Base::size;
using Base::coeff; using Base::coeff;
using Base::coeffRef; using Base::coeffRef;
using Base::lazyAssign;
using Base::operator=;
using Base::operator+=;
using Base::operator-=;
using Base::operator*=;
using Base::operator/=;
typedef typename Base::CoeffReturnType CoeffReturnType;
#endif // not EIGEN_PARSED_BY_DOXYGEN #endif // not EIGEN_PARSED_BY_DOXYGEN
enum {
RowsAtCompileTime = ei_traits<Derived>::RowsAtCompileTime,
/**< The number of rows at compile-time. This is just a copy of the value provided
* by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant.
* \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */
ColsAtCompileTime = ei_traits<Derived>::ColsAtCompileTime,
/**< The number of columns at compile-time. This is just a copy of the value provided
* by the \a Derived type. If a value is not known at compile-time,
* it is set to the \a Dynamic constant.
* \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */
SizeAtCompileTime = (ei_size_at_compile_time<ei_traits<Derived>::RowsAtCompileTime,
ei_traits<Derived>::ColsAtCompileTime>::ret),
/**< This is equal to the number of coefficients, i.e. the number of
* rows times the number of columns, or to \a Dynamic if this is not
* known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */
MaxRowsAtCompileTime = ei_traits<Derived>::MaxRowsAtCompileTime,
/**< This value is equal to the maximum possible number of rows that this expression
* might have. If this expression might have an arbitrarily high number of rows,
* this value is set to \a Dynamic.
*
* This value is useful to know when evaluating an expression, in order to determine
* whether it is possible to avoid doing a dynamic memory allocation.
*
* \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime
*/
MaxColsAtCompileTime = ei_traits<Derived>::MaxColsAtCompileTime,
/**< This value is equal to the maximum possible number of columns that this expression
* might have. If this expression might have an arbitrarily high number of columns,
* this value is set to \a Dynamic.
*
* This value is useful to know when evaluating an expression, in order to determine
* whether it is possible to avoid doing a dynamic memory allocation.
*
* \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime
*/
MaxSizeAtCompileTime = (ei_size_at_compile_time<ei_traits<Derived>::MaxRowsAtCompileTime,
ei_traits<Derived>::MaxColsAtCompileTime>::ret),
/**< This value is equal to the maximum possible number of coefficients that this expression
* might have. If this expression might have an arbitrarily high number of coefficients,
* this value is set to \a Dynamic.
*
* This value is useful to know when evaluating an expression, in order to determine
* whether it is possible to avoid doing a dynamic memory allocation.
*
* \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime
*/
IsVectorAtCompileTime = ei_traits<Derived>::RowsAtCompileTime == 1
|| ei_traits<Derived>::ColsAtCompileTime == 1,
/**< This is set to true if either the number of rows or the number of
* columns is known at compile-time to be equal to 1. Indeed, in that case,
* we are dealing with a column-vector (if there is only one column) or with
* a row-vector (if there is only one row). */
Flags = ei_traits<Derived>::Flags,
/**< This stores expression \ref flags flags which may or may not be inherited by new expressions
* constructed from this one. See the \ref flags "list of flags".
*/
CoeffReadCost = ei_traits<Derived>::CoeffReadCost,
/**< This is a rough measure of how expensive it is to read one coefficient from
* this expression.
*/
#ifndef EIGEN_PARSED_BY_DOXYGEN
_HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC
#endif
};
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
/** This is the "real scalar" type; if the \a Scalar type is already real numbers /** This is the "real scalar" type; if the \a Scalar type is already real numbers
@ -167,30 +114,9 @@ template<typename Derived> class MatrixBase
EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType;
#endif // not EIGEN_PARSED_BY_DOXYGEN #endif // not EIGEN_PARSED_BY_DOXYGEN
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
// inline int rows() const { return derived().rows(); }
/** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
// inline int cols() const { return derived().cols(); }
/** \returns the number of coefficients, which is rows()*cols().
* \sa rows(), cols(), SizeAtCompileTime. */
// inline int size() const { return rows() * cols(); }
/** \returns the size of the main diagonal, which is min(rows(),cols()). /** \returns the size of the main diagonal, which is min(rows(),cols()).
* \sa rows(), cols(), SizeAtCompileTime. */ * \sa rows(), cols(), SizeAtCompileTime. */
inline int diagonalSize() const { return std::min(rows(),cols()); } inline int diagonalSize() const { return std::min(rows(),cols()); }
/** \returns the number of nonzero coefficients which is in practice the number
* of stored coefficients. */
inline int nonZeros() const { return size(); }
/** \returns true if either the number of rows or the number of columns is equal to 1.
* In other words, this function returns
* \code rows()==1 || cols()==1 \endcode
* \sa rows(), cols(), IsVectorAtCompileTime. */
inline bool isVector() const { return rows()==1 || cols()==1; }
/** \returns the size of the storage major dimension,
* i.e., the number of columns for a columns major matrix, and the number of rows otherwise */
int outerSize() const { return (int(Flags)&RowMajorBit) ? this->rows() : this->cols(); }
/** \returns the size of the inner dimension according to the storage order,
* i.e., the number of rows for a columns major matrix, and the number of cols otherwise */
int innerSize() const { return (int(Flags)&RowMajorBit) ? this->cols() : this->rows(); }
/** Only plain matrices, not expressions may be resized; therefore the only useful resize method is /** Only plain matrices, not expressions may be resized; therefore the only useful resize method is
* Matrix::resize(). The present method only asserts that the new size equals the old size, and does * Matrix::resize(). The present method only asserts that the new size equals the old size, and does
@ -232,9 +158,6 @@ template<typename Derived> class MatrixBase
*/ */
// typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType_ColMajor; // typedef typename ei_plain_matrix_type<Derived>::type PlainMatrixType_ColMajor;
/** \internal the return type of coeff()
*/
typedef typename ei_meta_if<_HasDirectAccess, const Scalar&, Scalar>::ret CoeffReturnType;
/** \internal Represents a matrix with all coefficients equal to one another*/ /** \internal Represents a matrix with all coefficients equal to one another*/
typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType; typedef CwiseNullaryOp<ei_scalar_constant_op<Scalar>,Derived> ConstantReturnType;
@ -282,11 +205,6 @@ template<typename Derived> class MatrixBase
Derived& operator=(const ReturnByValue<OtherDerived>& func); Derived& operator=(const ReturnByValue<OtherDerived>& func);
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
using DenseBase<Derived>::lazyAssign;
/** Copies \a other into *this without evaluating other. \returns a reference to *this. */
// template<typename OtherDerived>
// Derived& lazyAssign(const MatrixBase<OtherDerived>& other);
template<typename ProductDerived, typename Lhs, typename Rhs> template<typename ProductDerived, typename Lhs, typename Rhs>
Derived& lazyAssign(const ProductBase<ProductDerived, Lhs,Rhs>& other); Derived& lazyAssign(const ProductBase<ProductDerived, Lhs,Rhs>& other);
@ -426,14 +344,6 @@ template<typename Derived> class MatrixBase
Scalar mean() const; Scalar mean() const;
Scalar trace() const; Scalar trace() const;
#ifndef EIGEN_PARSED_BY_DOXYGEN
using AnyMatrixBase<Derived>::derived;
inline Derived& const_cast_derived() const
{ return *static_cast<Derived*>(const_cast<MatrixBase*>(this)); }
#endif // not EIGEN_PARSED_BY_DOXYGEN
inline const WithFormat<Derived> format(const IOFormat& fmt) const;
/////////// Array module /////////// /////////// Array module ///////////
const VectorwiseOp<Derived,Horizontal> rowwise() const; const VectorwiseOp<Derived,Horizontal> rowwise() const;

View File

@ -174,7 +174,7 @@ void fitHyperplane(int numPoints,
// let's compute the constant coefficient such that the // let's compute the constant coefficient such that the
// plane pass trough the mean point: // plane pass trough the mean point:
result->offset() = - (result->normal().cwise()* mean).sum(); result->offset() = - (result->normal().cwiseProduct(mean)).sum();
} }

View File

@ -324,14 +324,14 @@ SparseMatrixBase<Derived>::operator+=(const SparseMatrixBase<OtherDerived>& othe
// { // {
// return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); // return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived());
// } // }
//
// template<typename ExpressionType> template<typename Derived>
// template<typename OtherDerived> template<typename OtherDerived>
// EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
// SparseCwise<ExpressionType>::operator*(const MatrixBase<OtherDerived> &other) const SparseMatrixBase<Derived>::cwiseProduct(const MatrixBase<OtherDerived> &other) const
// { {
// return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(_expression(), other.derived()); return EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE(derived(), other.derived());
// } }
// template<typename ExpressionType> // template<typename ExpressionType>
// template<typename OtherDerived> // template<typename OtherDerived>

View File

@ -121,24 +121,24 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Sparse>::InnerIterator
const ViewOp m_functor; const ViewOp m_functor;
}; };
// template<typename Derived> template<typename Derived>
// EIGEN_STRONG_INLINE Derived& EIGEN_STRONG_INLINE Derived&
// SparseMatrixBase<Derived>::operator*=(const Scalar& other) SparseMatrixBase<Derived>::operator*=(const Scalar& other)
// { {
// for (int j=0; j<outerSize(); ++j) for (int j=0; j<outerSize(); ++j)
// for (typename Derived::InnerIterator i(derived(),j); i; ++i) for (typename Derived::InnerIterator i(derived(),j); i; ++i)
// i.valueRef() *= other; i.valueRef() *= other;
// return derived(); return derived();
// } }
//
// template<typename Derived> template<typename Derived>
// EIGEN_STRONG_INLINE Derived& EIGEN_STRONG_INLINE Derived&
// SparseMatrixBase<Derived>::operator/=(const Scalar& other) SparseMatrixBase<Derived>::operator/=(const Scalar& other)
// { {
// for (int j=0; j<outerSize(); ++j) for (int j=0; j<outerSize(); ++j)
// for (typename Derived::InnerIterator i(derived(),j); i; ++i) for (typename Derived::InnerIterator i(derived(),j); i; ++i)
// i.valueRef() /= other; i.valueRef() /= other;
// return derived(); return derived();
// } }
#endif // EIGEN_SPARSE_CWISE_UNARY_OP_H #endif // EIGEN_SPARSE_CWISE_UNARY_OP_H

View File

@ -133,7 +133,7 @@ class ei_sparse_diagonal_product_inner_iterator_selector
public: public:
inline ei_sparse_diagonal_product_inner_iterator_selector( inline ei_sparse_diagonal_product_inner_iterator_selector(
const SparseDiagonalProductType& expr, int outer) const SparseDiagonalProductType& expr, int outer)
: Base(expr.rhs().innerVector(outer) .cwise()* expr.lhs().diagonal(), 0) : Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0)
{} {}
}; };
@ -165,7 +165,7 @@ class ei_sparse_diagonal_product_inner_iterator_selector
public: public:
inline ei_sparse_diagonal_product_inner_iterator_selector( inline ei_sparse_diagonal_product_inner_iterator_selector(
const SparseDiagonalProductType& expr, int outer) const SparseDiagonalProductType& expr, int outer)
: Base(expr.lhs().innerVector(outer) .cwise()* expr.rhs().diagonal().transpose().nestByValue(), 0) : Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose().nestByValue()), 0)
{} {}
}; };

View File

@ -109,9 +109,19 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
Transpose<Derived> Transpose<Derived>
>::ret AdjointReturnType; >::ret AdjointReturnType;
// typedef Matrix<typename ei_traits<Derived>::Scalar,
// ei_traits<Derived>::RowsAtCompileTime,
// ei_traits<Derived>::ColsAtCompileTime,
// AutoAlign | (ei_traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
// ei_traits<Derived>::MaxRowsAtCompileTime,
// ei_traits<Derived>::MaxColsAtCompileTime
// > PlainMatrixType;
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
#include "../Core/CwiseUnaryOps.h" #include "../plugins/CommonCwiseUnaryOps.h"
#include "../Core/CwiseBinaryOps.h" #include "../plugins/CommonCwiseBinaryOps.h"
#include "../plugins/MatrixCwiseUnaryOps.h"
#include "../plugins/MatrixCwiseBinaryOps.h"
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
#ifndef EIGEN_PARSED_BY_DOXYGEN #ifndef EIGEN_PARSED_BY_DOXYGEN
@ -307,8 +317,24 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
// template<typename Lhs,typename Rhs> // template<typename Lhs,typename Rhs>
// Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other); // Derived& operator+=(const Flagged<Product<Lhs,Rhs,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>& other);
// Derived& operator*=(const Scalar& other); Derived& operator*=(const Scalar& other);
// Derived& operator/=(const Scalar& other); Derived& operator/=(const Scalar& other);
#define EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE \
CwiseBinaryOp< \
ei_scalar_product_op< \
typename ei_scalar_product_traits< \
typename ei_traits<Derived>::Scalar, \
typename ei_traits<OtherDerived>::Scalar \
>::ReturnType \
>, \
Derived, \
OtherDerived \
>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_SPARSE_CWISE_PRODUCT_RETURN_TYPE
cwiseProduct(const MatrixBase<OtherDerived> &other) const;
// const SparseCwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived> // const SparseCwiseUnaryOp<ei_scalar_multiple_op<typename ei_traits<Derived>::Scalar>, Derived>
// operator*(const Scalar& scalar) const; // operator*(const Scalar& scalar) const;

View File

@ -1,4 +1,29 @@
/** \returns an expression of the coefficient wise product of \c *this and \a other
*
* \sa MatrixBase::cwiseProduct
*/
#define EIGEN_CWISE_PRODUCT_RETURN_TYPE \
CwiseBinaryOp< \
ei_scalar_product_op< \
typename ei_scalar_product_traits< \
typename ei_traits<Derived>::Scalar, \
typename ei_traits<OtherDerived>::Scalar \
>::ReturnType \
>, \
Derived, \
OtherDerived \
>
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE
operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
{
return EIGEN_CWISE_PRODUCT_RETURN_TYPE(derived(), other.derived());
}
#undef EIGEN_CWISE_PRODUCT_RETURN_TYPE
/** \returns an expression of the coefficient-wise \< operator of *this and \a other /** \returns an expression of the coefficient-wise \< operator of *this and \a other
* *
* Example: \include Cwise_less.cpp * Example: \include Cwise_less.cpp
@ -16,13 +41,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less)
* \sa all(), any(), operator>=(), operator<() * \sa all(), any(), operator>=(), operator<()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal) EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
// template<typename ExpressionType>
// template<typename OtherDerived>
// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
// operator<=(const MatrixBase<OtherDerived> &other) const
// {
// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived());
// }
/** \returns an expression of the coefficient-wise \> operator of *this and \a other /** \returns an expression of the coefficient-wise \> operator of *this and \a other
* *
@ -32,13 +50,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
* \sa all(), any(), operator>=(), operator<() * \sa all(), any(), operator>=(), operator<()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater) EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
// template<typename ExpressionType>
// template<typename OtherDerived>
// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
// operator>(const MatrixBase<OtherDerived> &other) const
// {
// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived());
// }
/** \returns an expression of the coefficient-wise \>= operator of *this and \a other /** \returns an expression of the coefficient-wise \>= operator of *this and \a other
* *
@ -48,13 +59,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
* \sa all(), any(), operator>(), operator<=() * \sa all(), any(), operator>(), operator<=()
*/ */
EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal) EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
// template<typename ExpressionType>
// template<typename OtherDerived>
// inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
// operator>=(const MatrixBase<OtherDerived> &other) const
// {
// return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived());
// }
/** \returns an expression of the coefficient-wise == operator of *this and \a other /** \returns an expression of the coefficient-wise == operator of *this and \a other
* *
@ -106,7 +110,6 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to)
* *
* \sa operator<(const MatrixBase<OtherDerived> &) const * \sa operator<(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
operator<(Scalar s) const operator<(Scalar s) const
{ {
@ -118,7 +121,6 @@ operator<(Scalar s) const
* *
* \sa operator<=(const MatrixBase<OtherDerived> &) const * \sa operator<=(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
operator<=(Scalar s) const operator<=(Scalar s) const
{ {
@ -130,7 +132,6 @@ operator<=(Scalar s) const
* *
* \sa operator>(const MatrixBase<OtherDerived> &) const * \sa operator>(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
operator>(Scalar s) const operator>(Scalar s) const
{ {
@ -142,7 +143,6 @@ operator>(Scalar s) const
* *
* \sa operator>=(const MatrixBase<OtherDerived> &) const * \sa operator>=(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
operator>=(Scalar s) const operator>=(Scalar s) const
{ {
@ -159,7 +159,6 @@ operator>=(Scalar s) const
* *
* \sa operator==(const MatrixBase<OtherDerived> &) const * \sa operator==(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
operator==(Scalar s) const operator==(Scalar s) const
{ {
@ -176,7 +175,6 @@ operator==(Scalar s) const
* *
* \sa operator!=(const MatrixBase<OtherDerived> &) const * \sa operator!=(const MatrixBase<OtherDerived> &) const
*/ */
template<typename ExpressionType>
inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to) inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
operator!=(Scalar s) const operator!=(Scalar s) const
{ {
@ -201,6 +199,12 @@ operator+(const Scalar& scalar) const
return CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>(derived(), ei_scalar_add_op<Scalar>(scalar)); return CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>(derived(), ei_scalar_add_op<Scalar>(scalar));
} }
friend inline const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
operator+(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other)
{
return other + scalar;
}
/** Adds the given \a scalar to each coeff of this expression. /** Adds the given \a scalar to each coeff of this expression.
* *
* Example: \include Cwise_plus_equal.cpp * Example: \include Cwise_plus_equal.cpp
@ -208,10 +212,9 @@ operator+(const Scalar& scalar) const
* *
* \sa operator+(), operator-=() * \sa operator+(), operator-=()
*/ */
// template<typename ExpressionType> // inline Derived& operator+=(const Scalar& scalar)
// inline ExpressionType& operator+=(const Scalar& scalar)
// { // {
// return m_matrix.const_cast_derived() = *this + scalar; // return derived() = *this + scalar;
// } // }
/** \returns an expression of \c *this with each coeff decremented by the constant \a scalar /** \returns an expression of \c *this with each coeff decremented by the constant \a scalar
@ -221,12 +224,17 @@ operator+(const Scalar& scalar) const
* *
* \sa operator+(), operator-=() * \sa operator+(), operator-=()
*/ */
// template<typename ExpressionType> inline const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
// inline const typename ScalarAddReturnType operator-(const Scalar& scalar) const
// operator-(const Scalar& scalar) const {
// { return *this + (-scalar);
// return *this + (-scalar); }
// }
friend inline const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
operator-(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other)
{
return other + (-scalar);
}
/** Substracts the given \a scalar from each coeff of this expression. /** Substracts the given \a scalar from each coeff of this expression.
* *
@ -235,9 +243,7 @@ operator+(const Scalar& scalar) const
* *
* \sa operator+=(), operator-() * \sa operator+=(), operator-()
*/ */
// inline Derived& operator-=(const Scalar& scalar)
// template<typename ExpressionType>
// inline ExpressionType& operator-=(const Scalar& scalar)
// { // {
// return m_matrix.const_cast_derived() = *this - scalar; // return derived() = *this - scalar;
// } // }

View File

@ -146,3 +146,17 @@ cube() const
{ {
return derived(); return derived();
} }
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(METHOD_NAME,FUNCTOR) \
inline const CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >,Derived> \
METHOD_NAME(Scalar s) const { \
return CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >,Derived> \
(derived(), std::bind1st(FUNCTOR<Scalar>(), s)); \
}
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==, std::equal_to);
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=, std::not_equal_to);
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<, std::less);
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=, std::less_equal);
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>, std::greater);
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=, std::greater_equal);

View File

@ -58,18 +58,6 @@ typedef CwiseUnaryView<ei_scalar_imag_op<Scalar>, Derived> NonConstImagReturnTyp
EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived> EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived>
operator-() const { return derived(); } operator-() const { return derived(); }
EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other)
{
SelfCwiseBinaryOp<ei_scalar_product_op<Scalar>, Derived> tmp(derived());
tmp = PlainMatrixType::Constant(rows(),cols(),other);
return derived();
}
EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other)
{
SelfCwiseBinaryOp<typename ei_meta_if<NumTraits<Scalar>::HasFloatingPoint,ei_scalar_product_op<Scalar>,ei_scalar_quotient_op<Scalar> >::ret, Derived> tmp(derived());
tmp = PlainMatrixType::Constant(rows(),cols(), NumTraits<Scalar>::HasFloatingPoint ? Scalar(1)/other : other);
return derived();
}
/** \returns an expression of \c *this scaled by the scalar factor \a scalar */ /** \returns an expression of \c *this scaled by the scalar factor \a scalar */
EIGEN_STRONG_INLINE const ScalarMultipleReturnType EIGEN_STRONG_INLINE const ScalarMultipleReturnType

View File

@ -22,7 +22,6 @@
// License and a copy of the GNU General Public License along with // License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>. // Eigen. If not, see <http://www.gnu.org/licenses/>.
#define EIGEN2_SUPPORT
#include "main.h" #include "main.h"
#include <Eigen/Array> #include <Eigen/Array>
@ -51,15 +50,15 @@ template<typename MatrixType> void array(const MatrixType& m)
s2 = ei_random<Scalar>(); s2 = ei_random<Scalar>();
// scalar addition // scalar addition
VERIFY_IS_APPROX(m1.cwise() + s1, s1 + m1.cwise()); VERIFY_IS_APPROX(m1.array() + s1, s1 + m1.array());
VERIFY_IS_APPROX(m1.cwise() + s1, MatrixType::Constant(rows,cols,s1) + m1); VERIFY_IS_APPROX((m1.array() + s1).asMatrix(), MatrixType::Constant(rows,cols,s1) + m1);
VERIFY_IS_APPROX((m1*Scalar(2)).cwise() - s2, (m1+m1) - MatrixType::Constant(rows,cols,s2) ); VERIFY_IS_APPROX(((m1*Scalar(2)).array() - s2).asMatrix(), (m1+m1) - MatrixType::Constant(rows,cols,s2) );
m3 = m1; m3 = m1;
m3.cwise() += s2; m3.array() += s2;
VERIFY_IS_APPROX(m3, m1.cwise() + s2); VERIFY_IS_APPROX(m3, (m1.array() + s2).asMatrix());
m3 = m1; m3 = m1;
m3.cwise() -= s1; m3.array() -= s1;
VERIFY_IS_APPROX(m3, m1.cwise() - s1); VERIFY_IS_APPROX(m3, (m1.array() - s1).asMatrix());
// reductions // reductions
VERIFY_IS_APPROX(m1.colwise().sum().sum(), m1.sum()); VERIFY_IS_APPROX(m1.colwise().sum().sum(), m1.sum());
@ -95,53 +94,54 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
m2 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols),
m3(rows, cols); m3(rows, cols);
VERIFY(((m1.cwise() + Scalar(1)).cwise() > m1).all()); VERIFY(((m1.array() + Scalar(1)) > m1.array()).all());
VERIFY(((m1.cwise() - Scalar(1)).cwise() < m1).all()); VERIFY(((m1.array() - Scalar(1)) < m1.array()).all());
if (rows*cols>1) if (rows*cols>1)
{ {
m3 = m1; m3 = m1;
m3(r,c) += 1; m3(r,c) += 1;
VERIFY(! (m1.cwise() < m3).all() ); VERIFY(! (m1.array() < m3.array()).all() );
VERIFY(! (m1.cwise() > m3).all() ); VERIFY(! (m1.array() > m3.array()).all() );
} }
// comparisons to scalar // comparisons to scalar
VERIFY( (m1.cwise() != (m1(r,c)+1) ).any() ); VERIFY( (m1.array() != (m1(r,c)+1) ).any() );
VERIFY( (m1.cwise() > (m1(r,c)-1) ).any() ); VERIFY( (m1.array() > (m1(r,c)-1) ).any() );
VERIFY( (m1.cwise() < (m1(r,c)+1) ).any() ); VERIFY( (m1.array() < (m1(r,c)+1) ).any() );
VERIFY( (m1.cwise() == m1(r,c) ).any() ); VERIFY( (m1.array() == m1(r,c) ).any() );
// test Select // test Select
VERIFY_IS_APPROX( (m1.cwise()<m2).select(m1,m2), m1.cwise().min(m2) ); VERIFY_IS_APPROX( (m1.array()<m2.array()).select(m1,m2), m1.cwiseMin(m2) );
VERIFY_IS_APPROX( (m1.cwise()>m2).select(m1,m2), m1.cwise().max(m2) ); VERIFY_IS_APPROX( (m1.array()>m2.array()).select(m1,m2), m1.cwiseMax(m2) );
Scalar mid = (m1.cwise().abs().minCoeff() + m1.cwise().abs().maxCoeff())/Scalar(2); Scalar mid = (m1.cwiseAbs().minCoeff() + m1.cwiseAbs().maxCoeff())/Scalar(2);
for (int j=0; j<cols; ++j) for (int j=0; j<cols; ++j)
for (int i=0; i<rows; ++i) for (int i=0; i<rows; ++i)
m3(i,j) = ei_abs(m1(i,j))<mid ? 0 : m1(i,j); m3(i,j) = ei_abs(m1(i,j))<mid ? 0 : m1(i,j);
VERIFY_IS_APPROX( (m1.cwise().abs().cwise()<MatrixType::Constant(rows,cols,mid)) VERIFY_IS_APPROX( (m1.array().abs()<MatrixType::Constant(rows,cols,mid).array())
.select(MatrixType::Zero(rows,cols),m1), m3); .select(MatrixType::Zero(rows,cols),m1), m3);
// shorter versions: // shorter versions:
VERIFY_IS_APPROX( (m1.cwise().abs().cwise()<MatrixType::Constant(rows,cols,mid)) VERIFY_IS_APPROX( (m1.array().abs()<MatrixType::Constant(rows,cols,mid).array())
.select(0,m1), m3); .select(0,m1), m3);
VERIFY_IS_APPROX( (m1.cwise().abs().cwise()>=MatrixType::Constant(rows,cols,mid)) VERIFY_IS_APPROX( (m1.array().abs()>=MatrixType::Constant(rows,cols,mid).array())
.select(m1,0), m3); .select(m1,0), m3);
// even shorter version: // even shorter version:
VERIFY_IS_APPROX( (m1.cwise().abs().cwise()<mid).select(0,m1), m3); VERIFY_IS_APPROX( (m1.array().abs()<mid).select(0,m1), m3);
// count // count
VERIFY(((m1.cwise().abs().cwise()+1).cwise()>RealScalar(0.1)).count() == rows*cols); VERIFY(((m1.array().abs()+1)>RealScalar(0.1)).count() == rows*cols);
VERIFY_IS_APPROX(((m1.cwise().abs().cwise()+1).cwise()>RealScalar(0.1)).colwise().count(), RowVectorXi::Constant(cols,rows)); // TODO allows colwise/rowwise for array
VERIFY_IS_APPROX(((m1.cwise().abs().cwise()+1).cwise()>RealScalar(0.1)).rowwise().count(), VectorXi::Constant(rows, cols)); 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));
} }
template<typename VectorType> void lpNorm(const VectorType& v) template<typename VectorType> void lpNorm(const VectorType& v)
{ {
VectorType u = VectorType::Random(v.size()); VectorType u = VectorType::Random(v.size());
VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwise().abs().maxCoeff()); VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwiseAbs().maxCoeff());
VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwise().abs().sum()); VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwiseAbs().sum());
VERIFY_IS_APPROX(u.template lpNorm<2>(), ei_sqrt(u.cwise().abs().cwise().square().sum())); VERIFY_IS_APPROX(u.template lpNorm<2>(), ei_sqrt(u.array().abs().square().sum()));
VERIFY_IS_APPROX(ei_pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.cwise().abs().cwise().pow(5).sum()); VERIFY_IS_APPROX(ei_pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.array().abs().pow(5).sum());
} }
void test_array() void test_array()

View File

@ -58,30 +58,30 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
VERIFY_IS_APPROX((-m1+m2)*s1, -s1*m1+s1*m2); VERIFY_IS_APPROX((-m1+m2)*s1, -s1*m1+s1*m2);
m3 = m2; m3 += m1; m3 = m2; m3 += m1;
VERIFY_IS_APPROX(m3, m1+m2); VERIFY_IS_APPROX(m3, m1+m2);
m3 = m2; m3 -= m1; // m3 = m2; m3 -= m1;
VERIFY_IS_APPROX(m3, m2-m1); // VERIFY_IS_APPROX(m3, m2-m1);
m3 = m2; m3 *= s1; // m3 = m2; m3 *= s1;
VERIFY_IS_APPROX(m3, s1*m2); // VERIFY_IS_APPROX(m3, s1*m2);
if(NumTraits<Scalar>::HasFloatingPoint) // if(NumTraits<Scalar>::HasFloatingPoint)
{ // {
m3 = m2; m3 /= s1; // m3 = m2; m3 /= s1;
VERIFY_IS_APPROX(m3, m2/s1); // VERIFY_IS_APPROX(m3, m2/s1);
} // }
// again, test operator() to check const-qualification // // again, test operator() to check const-qualification
VERIFY_IS_APPROX((-m1)(r,c), -(m1(r,c))); // VERIFY_IS_APPROX((-m1)(r,c), -(m1(r,c)));
VERIFY_IS_APPROX((m1-m2)(r,c), (m1(r,c))-(m2(r,c))); // VERIFY_IS_APPROX((m1-m2)(r,c), (m1(r,c))-(m2(r,c)));
VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c))); // VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
VERIFY_IS_APPROX((s1*m1)(r,c), s1*(m1(r,c))); // VERIFY_IS_APPROX((s1*m1)(r,c), s1*(m1(r,c)));
VERIFY_IS_APPROX((m1*s1)(r,c), (m1(r,c))*s1); // VERIFY_IS_APPROX((m1*s1)(r,c), (m1(r,c))*s1);
if(NumTraits<Scalar>::HasFloatingPoint) // if(NumTraits<Scalar>::HasFloatingPoint)
VERIFY_IS_APPROX((m1/s1)(r,c), (m1(r,c))/s1); // VERIFY_IS_APPROX((m1/s1)(r,c), (m1(r,c))/s1);
//
// use .block to disable vectorization and compare to the vectorized version // // use .block to disable vectorization and compare to the vectorized version
VERIFY_IS_APPROX(m1+m1.block(0,0,rows,cols), m1+m1); // VERIFY_IS_APPROX(m1+m1.block(0,0,rows,cols), m1+m1);
VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), m1.cwiseProduct(m1)); // VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), m1.cwiseProduct(m1));
VERIFY_IS_APPROX(m1 - m1.block(0,0,rows,cols), m1 - m1); // VERIFY_IS_APPROX(m1 - m1.block(0,0,rows,cols), m1 - m1);
VERIFY_IS_APPROX(m1.block(0,0,rows,cols) * s1, m1 * s1); // VERIFY_IS_APPROX(m1.block(0,0,rows,cols) * s1, m1 * s1);
} }
void test_linearstructure() void test_linearstructure()

View File

@ -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)*s1, s1*m1+s1*m2);
VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c))); VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
VERIFY_IS_APPROX(m1.cwise() * m1.block(0,0,rows,cols), m1.array()*m1); VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), (m1.array()*m1.array()));
if (MatrixType::RowsAtCompileTime<EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD) { if (MatrixType::RowsAtCompileTime<EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD) {
// If the matrices are too large, we have better to use the optimized GEMM // If the matrices are too large, we have better to use the optimized GEMM
// routines which allocates temporaries. However, on some platforms // routines which allocates temporaries. However, on some platforms

View File

@ -51,7 +51,7 @@ void makeNoisyCohyperplanarPoints(int numPoints,
{ {
cur_point = VectorType::Random(size)/*.normalized()*/; cur_point = VectorType::Random(size)/*.normalized()*/;
// project cur_point onto the hyperplane // project cur_point onto the hyperplane
Scalar x = - (hyperplane->coeffs().start(size).cwise()*cur_point).sum(); Scalar x = - (hyperplane->coeffs().start(size).cwiseProduct(cur_point)).sum();
cur_point *= hyperplane->coeffs().coeff(size) / x; cur_point *= hyperplane->coeffs().coeff(size) / x;
} while( cur_point.norm() < 0.5 } while( cur_point.norm() < 0.5
|| cur_point.norm() > 2.0 ); || cur_point.norm() > 2.0 );

View File

@ -246,7 +246,7 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
VERIFY_IS_APPROX(m1+m2, refM1+refM2); VERIFY_IS_APPROX(m1+m2, refM1+refM2);
VERIFY_IS_APPROX(m1+m2+m3, refM1+refM2+refM3); VERIFY_IS_APPROX(m1+m2+m3, refM1+refM2+refM3);
VERIFY_IS_APPROX(m3.cwise()*(m1+m2), refM3.cwise()*(refM1+refM2)); VERIFY_IS_APPROX(m3.cwiseProduct(m1+m2), refM3.cwiseProduct(refM1+refM2));
VERIFY_IS_APPROX(m1*s1-m2, refM1*s1-refM2); VERIFY_IS_APPROX(m1*s1-m2, refM1*s1-refM2);
VERIFY_IS_APPROX(m1*=s1, refM1*=s1); VERIFY_IS_APPROX(m1*=s1, refM1*=s1);
@ -259,7 +259,7 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
refM4.setRandom(); refM4.setRandom();
// sparse cwise* dense // sparse cwise* dense
VERIFY_IS_APPROX(m3.cwise()*refM4, refM3.cwise()*refM4); VERIFY_IS_APPROX(m3.cwiseProduct(refM4), refM3.cwiseProduct(refM4));
// VERIFY_IS_APPROX(m3.cwise()/refM4, refM3.cwise()/refM4); // VERIFY_IS_APPROX(m3.cwise()/refM4, refM3.cwise()/refM4);
} }