From 9385793f71f2a606b0527df8ea1d2153c3e70e11 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 24 Apr 2008 18:35:39 +0000 Subject: [PATCH] Fix a couple of issue with the vectorization. In particular, default ei_p* functions are provided to handle not suported types seemlessly. Added a generic null-ary expression with null-ary functors. They replace Zero, Ones, Identity and Random. --- Eigen/Core | 5 +- Eigen/src/Core/Block.h | 2 +- Eigen/src/Core/DiagonalCoeffs.h | 2 +- Eigen/src/Core/DiagonalMatrix.h | 2 +- Eigen/src/Core/Functors.h | 40 +++++ Eigen/src/Core/Identity.h | 161 -------------------- Eigen/src/Core/MatrixBase.h | 41 +++-- Eigen/src/Core/Ones.h | 172 --------------------- Eigen/src/Core/PacketMath.h | 33 ++++- Eigen/src/Core/Product.h | 4 +- Eigen/src/Core/Random.h | 158 -------------------- Eigen/src/Core/Zero.h | 173 ---------------------- Eigen/src/Core/util/Constants.h | 1 + Eigen/src/Core/util/ForwardDeclarations.h | 9 +- Eigen/src/Core/util/Meta.h | 2 +- 15 files changed, 109 insertions(+), 696 deletions(-) delete mode 100644 Eigen/src/Core/Identity.h delete mode 100644 Eigen/src/Core/Ones.h delete mode 100644 Eigen/src/Core/Random.h delete mode 100644 Eigen/src/Core/Zero.h diff --git a/Eigen/Core b/Eigen/Core index 24dc37145..950328aaa 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -36,17 +36,14 @@ namespace Eigen { #include "src/Core/Temporary.h" #include "src/Core/CwiseBinaryOp.h" #include "src/Core/CwiseUnaryOp.h" +#include "src/Core/CwiseNullaryOp.h" #include "src/Core/Product.h" #include "src/Core/Block.h" #include "src/Core/Minor.h" #include "src/Core/Transpose.h" #include "src/Core/Dot.h" -#include "src/Core/Random.h" -#include "src/Core/Zero.h" -#include "src/Core/Ones.h" #include "src/Core/DiagonalMatrix.h" #include "src/Core/DiagonalCoeffs.h" -#include "src/Core/Identity.h" #include "src/Core/Redux.h" #include "src/Core/Visitor.h" #include "src/Core/Fuzzy.h" diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 2c9f429a2..26e8fd50b 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -71,7 +71,7 @@ struct ei_traits > || (ColsAtCompileTime != Dynamic && MatrixType::ColsAtCompileTime == Dynamic)) ? ~LargeBit : ~(unsigned int)0, - Flags = MatrixType::Flags & FlagsMaskLargeBit & ~VectorizableBit, + Flags = MatrixType::Flags & FlagsMaskLargeBit & ~(VectorizableBit | Like1DArrayBit), CoeffReadCost = MatrixType::CoeffReadCost }; }; diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index 3e4ebded8..dc35de4d8 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -54,7 +54,7 @@ struct ei_traits > MaxColsAtCompileTime = 1, Flags = (RowsAtCompileTime == Dynamic && ColsAtCompileTime == Dynamic ? (unsigned int)MatrixType::Flags - : (unsigned int)MatrixType::Flags &~ LargeBit) & ~VectorizableBit, + : (unsigned int)MatrixType::Flags &~ LargeBit) & ~(VectorizableBit | Like1DArrayBit), CoeffReadCost = MatrixType::CoeffReadCost }; }; diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 0fae56805..2c8f6cdf7 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -47,7 +47,7 @@ struct ei_traits > ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime, MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime, MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime, - Flags = CoeffsVectorType::Flags & ~VectorizableBit, + Flags = CoeffsVectorType::Flags & ~(VectorizableBit | Like1DArrayBit), CoeffReadCost = CoeffsVectorType::CoeffReadCost }; }; diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index d0f5151bc..bb4b8bb54 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -340,6 +340,46 @@ template struct ei_functor_traits > { enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; +// nullary functors + +template::size)>1?true:false) > struct ei_scalar_constant_op; + +template +struct ei_scalar_constant_op { + typedef typename ei_packet_traits::type PacketScalar; + ei_scalar_constant_op(const Scalar& other) : m_other(ei_pset1(other)) { } + Scalar operator() (int, int) const { return ei_pfirst(m_other); } + PacketScalar packetOp() const + { return m_other; } + const PacketScalar m_other; +}; +template +struct ei_scalar_constant_op { + ei_scalar_constant_op(const Scalar& other) : m_other(other) { } + Scalar operator() (int, int) const { return m_other; } + const Scalar m_other; +}; +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = ei_packet_traits::size>1, IsRepeatable = true }; }; + + +template struct ei_scalar_random_op EIGEN_EMPTY_STRUCT { + ei_scalar_random_op(void) {} + Scalar operator() (int, int) const { return ei_random(); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false, IsRepeatable = false }; }; + + +template struct ei_scalar_identity_op EIGEN_EMPTY_STRUCT { + ei_scalar_identity_op(void) {} + Scalar operator() (int row, int col) const { return row==col ? Scalar(1) : Scalar(0); } +}; +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::AddCost, IsVectorizable = false, IsRepeatable = true }; }; // default ei_functor_traits for STL functors: diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h deleted file mode 100644 index 0783983c1..000000000 --- a/Eigen/src/Core/Identity.h +++ /dev/null @@ -1,161 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_IDENTITY_H -#define EIGEN_IDENTITY_H - -/** \class Identity - * - * \brief Expression of the identity matrix of some size. - * - * \sa MatrixBase::identity(), MatrixBase::identity(int,int), MatrixBase::setIdentity() - */ -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Flags = MatrixType::Flags & ~VectorizableBit, - CoeffReadCost = NumTraits::ReadCost - }; -}; - -template class Identity : ei_no_assignment_operator, - public MatrixBase > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(Identity) - - Identity(int rows, int cols) : m_rows(rows), m_cols(cols) - { - ei_assert(rows > 0 - && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols > 0 - && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); - } - - private: - - int _rows() const { return m_rows.value(); } - int _cols() const { return m_cols.value(); } - - const Scalar _coeff(int row, int col) const - { - return row == col ? static_cast(1) : static_cast(0); - } - - protected: - - const ei_int_if_dynamic m_rows; - const ei_int_if_dynamic m_cols; -}; - -/** \returns an expression of the identity matrix (not necessarily square). - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so identity() should be used - * instead. - * - * Example: \include MatrixBase_identity_int_int.cpp - * Output: \verbinclude MatrixBase_identity_int_int.out - * - * \sa identity(), setIdentity(), isIdentity() - */ -template -const Identity MatrixBase::identity(int rows, int cols) -{ - return Identity(rows, cols); -} - -/** \returns an expression of the identity matrix (not necessarily square). - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variant taking size arguments. - * - * Example: \include MatrixBase_identity.cpp - * Output: \verbinclude MatrixBase_identity.out - * - * \sa identity(int,int), setIdentity(), isIdentity() - */ -template -const Identity MatrixBase::identity() -{ - return Identity(RowsAtCompileTime, ColsAtCompileTime); -} - -/** \returns true if *this is approximately equal to the identity matrix - * (not necessarily square), - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isIdentity.cpp - * Output: \verbinclude MatrixBase_isIdentity.out - * - * \sa class Identity, identity(), identity(int,int), setIdentity() - */ -template -bool MatrixBase::isIdentity -(typename NumTraits::Real prec) const -{ - for(int j = 0; j < cols(); j++) - { - for(int i = 0; i < rows(); i++) - { - if(i == j) - { - if(!ei_isApprox(coeff(i, j), static_cast(1), prec)) - return false; - } - else - { - if(!ei_isMuchSmallerThan(coeff(i, j), static_cast(1), prec)) - return false; - } - } - } - return true; -} - -/** Writes the identity expression (not necessarily square) into *this. - * - * Example: \include MatrixBase_setIdentity.cpp - * Output: \verbinclude MatrixBase_setIdentity.out - * - * \sa class Identity, identity(), identity(int,int), isIdentity() - */ -template -Derived& MatrixBase::setIdentity() -{ - return *this = Identity(rows(), cols()); -} - - -#endif // EIGEN_IDENTITY_H diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index d0faa88bf..3247ec4bf 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -339,20 +339,38 @@ template class MatrixBase /// \name Generating special matrices //@{ - static const Random random(int rows, int cols); - static const Random random(int size); - static const Random random(); - static const Zero zero(int rows, int cols); - static const Zero zero(int size); - static const Zero zero(); - static const Ones ones(int rows, int cols); - static const Ones ones(int size); - static const Ones ones(); - static const Identity identity(); - static const Identity identity(int rows, int cols); + static const CwiseNullaryOp,Derived> + constant(int rows, int cols, const Scalar& value); + static const CwiseNullaryOp,Derived> + constant(int size, const Scalar& value); + static const CwiseNullaryOp,Derived> + constant(const Scalar& value); + + template + static const CwiseNullaryOp + cwiseCreate(int rows, int cols, const CustomZeroaryOp& func); + template + static const CwiseNullaryOp + cwiseCreate(int size, const CustomZeroaryOp& func); + template + static const CwiseNullaryOp + cwiseCreate(const CustomZeroaryOp& func); + + static const CwiseNullaryOp,Derived> random(int rows, int cols); + static const CwiseNullaryOp,Derived> random(int size); + static const CwiseNullaryOp,Derived> random(); + static const CwiseNullaryOp,Derived> zero(int rows, int cols); + static const CwiseNullaryOp,Derived> zero(int size); + static const CwiseNullaryOp,Derived> zero(); + static const CwiseNullaryOp,Derived> ones(int rows, int cols); + static const CwiseNullaryOp,Derived> ones(int size); + static const CwiseNullaryOp,Derived> ones(); + static const CwiseNullaryOp,Derived> identity(); + static const CwiseNullaryOp,Derived> identity(int rows, int cols); const DiagonalMatrix asDiagonal() const; + Derived& setConstant(const Scalar& value); Derived& setZero(); Derived& setOnes(); Derived& setRandom(); @@ -370,6 +388,7 @@ template class MatrixBase bool isMuchSmallerThan(const MatrixBase& other, RealScalar prec = precision()) const; + bool isEqualToConstant(const Scalar& value, RealScalar prec = precision()) const; bool isZero(RealScalar prec = precision()) const; bool isOnes(RealScalar prec = precision()) const; bool isIdentity(RealScalar prec = precision()) const; diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h deleted file mode 100644 index bcc71764c..000000000 --- a/Eigen/src/Core/Ones.h +++ /dev/null @@ -1,172 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_ONES_H -#define EIGEN_ONES_H - -/** \class Ones - * - * \brief Expression of a matrix where all coefficients equal one. - * - * \sa MatrixBase::ones(), MatrixBase::ones(int), MatrixBase::ones(int,int), - * MatrixBase::setOnes(), MatrixBase::isOnes() - */ -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Flags = MatrixType::Flags & ~VectorizableBit, - CoeffReadCost = NumTraits::ReadCost - }; -}; - -template class Ones : ei_no_assignment_operator, - public MatrixBase > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(Ones) - - private: - - int _rows() const { return m_rows.value(); } - int _cols() const { return m_cols.value(); } - - const Scalar _coeff(int, int) const - { - return static_cast(1); - } - - public: - Ones(int rows, int cols) : m_rows(rows), m_cols(cols) - { - ei_assert(rows > 0 - && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols > 0 - && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); - } - - protected: - const ei_int_if_dynamic m_rows; - const ei_int_if_dynamic m_cols; -}; - -/** \returns an expression of a matrix where all coefficients equal one. - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so ones() should be used - * instead. - * - * Example: \include MatrixBase_ones_int_int.cpp - * Output: \verbinclude MatrixBase_ones_int_int.out - * - * \sa ones(), ones(int), isOnes(), class Ones - */ -template -const Ones MatrixBase::ones(int rows, int cols) -{ - return Ones(rows, cols); -} - -/** \returns an expression of a vector where all coefficients equal one. - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so ones() should be used - * instead. - * - * Example: \include MatrixBase_ones_int.cpp - * Output: \verbinclude MatrixBase_ones_int.out - * - * \sa ones(), ones(int,int), isOnes(), class Ones - */ -template -const Ones MatrixBase::ones(int size) -{ - ei_assert(IsVectorAtCompileTime); - if(RowsAtCompileTime == 1) return Ones(1, size); - else return Ones(size, 1); -} - -/** \returns an expression of a fixed-size matrix or vector where all coefficients equal one. - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_ones.cpp - * Output: \verbinclude MatrixBase_ones.out - * - * \sa ones(int), ones(int,int), isOnes(), class Ones - */ -template -const Ones MatrixBase::ones() -{ - return Ones(RowsAtCompileTime, ColsAtCompileTime); -} - -/** \returns true if *this is approximately equal to the matrix where all coefficients - * are equal to 1, within the precision given by \a prec. - * - * Example: \include MatrixBase_isOnes.cpp - * Output: \verbinclude MatrixBase_isOnes.out - * - * \sa class Ones, ones() - */ -template -bool MatrixBase::isOnes -(typename NumTraits::Real prec) const -{ - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if(!ei_isApprox(coeff(i, j), static_cast(1), prec)) - return false; - return true; -} - -/** Sets all coefficients in this expression to one. - * - * Example: \include MatrixBase_setOnes.cpp - * Output: \verbinclude MatrixBase_setOnes.out - * - * \sa class Ones, ones() - */ -template -Derived& MatrixBase::setOnes() -{ - return *this = Ones(rows(), cols()); -} - -#endif // EIGEN_ONES_H diff --git a/Eigen/src/Core/PacketMath.h b/Eigen/src/Core/PacketMath.h index cc925b50c..8956c27b0 100644 --- a/Eigen/src/Core/PacketMath.h +++ b/Eigen/src/Core/PacketMath.h @@ -25,6 +25,21 @@ #ifndef EIGEN_PACKET_MATH_H #define EIGEN_PACKET_MATH_H +// Default implementation for types not supported by the vectorization. +// In practice these functions are provided to make easier the writting +// of generic vectorized code. However, at runtime, they should never be +// called, TODO so sould we raise an assertion or not ? +template inline Scalar ei_padd(const Scalar& a, const Scalar& b) { return a + b; } +template inline Scalar ei_psub(const Scalar& a, const Scalar& b) { return a - b; } +template inline Scalar ei_pmul(const Scalar& a, const Scalar& b) { return a * b; } +template inline Scalar ei_pmin(const Scalar& a, const Scalar& b) { return std::min(a,b); } +template inline Scalar ei_pmax(const Scalar& a, const Scalar& b) { return std::max(a,b); } +template inline Scalar ei_pload(const Scalar* from) { return *from; } +template inline Scalar ei_pload1(const Scalar* from) { return *from; } +template inline Scalar ei_pset1(const Scalar& from) { return from; } +template inline void ei_pstore(Scalar* to, const Scalar& from) { (*to) = from; } +template inline Scalar ei_pfirst(const Scalar& a) { return a; } + #ifdef EIGEN_VECTORIZE_SSE template<> struct ei_packet_traits { typedef __m128 type; enum {size=4}; }; @@ -41,10 +56,17 @@ inline __m128i ei_psub(const __m128i& a, const __m128i& b) { return _mm_sub_epi3 inline __m128 ei_pmul(const __m128& a, const __m128& b) { return _mm_mul_ps(a,b); } inline __m128d ei_pmul(const __m128d& a, const __m128d& b) { return _mm_mul_pd(a,b); } -inline __m128i ei_pmul(const __m128i& a, const __m128i& b) { return _mm_mul_epu32(a,b); } +inline __m128i ei_pmul(const __m128i& a, const __m128i& b) +{ + return _mm_or_si128( + _mm_mul_epu32(a,b), + _mm_slli_si128( + _mm_mul_epu32(_mm_srli_si128(a,32),_mm_srli_si128(b,32)), 32)); +} inline __m128 ei_pmin(const __m128& a, const __m128& b) { return _mm_min_ps(a,b); } inline __m128d ei_pmin(const __m128d& a, const __m128d& b) { return _mm_min_pd(a,b); } +// FIXME this vectorized min operator is likely to be slower than the standard one inline __m128i ei_pmin(const __m128i& a, const __m128i& b) { __m128i mask = _mm_cmplt_epi32(a,b); @@ -53,6 +75,7 @@ inline __m128i ei_pmin(const __m128i& a, const __m128i& b) inline __m128 ei_pmax(const __m128& a, const __m128& b) { return _mm_max_ps(a,b); } inline __m128d ei_pmax(const __m128d& a, const __m128d& b) { return _mm_max_pd(a,b); } +// FIXME this vectorized max operator is likely to be slower than the standard one inline __m128i ei_pmax(const __m128i& a, const __m128i& b) { __m128i mask = _mm_cmpgt_epi32(a,b); @@ -61,7 +84,7 @@ inline __m128i ei_pmax(const __m128i& a, const __m128i& b) inline __m128 ei_pload(const float* from) { return _mm_load_ps(from); } inline __m128d ei_pload(const double* from) { return _mm_load_pd(from); } -inline __m128i ei_pload(const __m128i* from) { return _mm_load_si128(from); } +inline __m128i ei_pload(const int* from) { return _mm_load_si128(reinterpret_cast(from)); } inline __m128 ei_pload1(const float* from) { return _mm_load1_ps(from); } inline __m128d ei_pload1(const double* from) { return _mm_load1_pd(from); } @@ -71,9 +94,9 @@ inline __m128 ei_pset1(const float& from) { return _mm_set1_ps(from); } inline __m128d ei_pset1(const double& from) { return _mm_set1_pd(from); } inline __m128i ei_pset1(const int& from) { return _mm_set1_epi32(from); } -inline void ei_pstore(float* to, const __m128& from) { _mm_store_ps(to, from); } -inline void ei_pstore(double* to, const __m128d& from) { _mm_store_pd(to, from); } -inline void ei_pstore(__m128i* to, const __m128i& from) { _mm_store_si128(to, from); } +inline void ei_pstore(float* to, const __m128& from) { _mm_store_ps(to, from); } +inline void ei_pstore(double* to, const __m128d& from) { _mm_store_pd(to, from); } +inline void ei_pstore(int* to, const __m128i& from) { _mm_store_si128(reinterpret_cast<__m128i*>(to), from); } inline float ei_pfirst(const __m128& a) { return _mm_cvtss_f32(a); } inline double ei_pfirst(const __m128d& a) { return _mm_cvtsd_f64(a); } diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index a49609f5c..590e03599 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -213,7 +213,7 @@ template class Product : ei_no_assignm ei_packet_product_unroller + _LhsNested, _RhsNested, PacketScalar> ::run(row, col, m_lhs, m_rhs, res); } else @@ -282,7 +282,7 @@ void Product::_cacheOptimalEval(DestDerived& res) const const int cols4 = m_lhs.cols() & 0xfffffffC; #ifdef EIGEN_VECTORIZE if( (Flags & VectorizableBit) && (!(Lhs::Flags & RowMajorBit)) ) - { + { for(int k=0; kcols(); k++) { int j=0; diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h deleted file mode 100644 index 4d6a21da4..000000000 --- a/Eigen/src/Core/Random.h +++ /dev/null @@ -1,158 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_RANDOM_H -#define EIGEN_RANDOM_H - -/** \class Random - * - * \brief Expression of a random matrix or vector. - * - * \sa MatrixBase::random(), MatrixBase::random(int), MatrixBase::random(int,int), - * MatrixBase::setRandom() - */ -template -struct ei_traits > -{ - typedef typename ei_traits::Scalar Scalar; - enum { - RowsAtCompileTime = ei_traits::RowsAtCompileTime, - ColsAtCompileTime = ei_traits::ColsAtCompileTime, - MaxRowsAtCompileTime = ei_traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = ei_traits::MaxColsAtCompileTime, - Flags = (ei_traits::Flags | EvalBeforeNestingBit) & ~VectorizableBit, - CoeffReadCost = 2 * NumTraits::MulCost // FIXME: arbitrary value - }; -}; - -template class Random : ei_no_assignment_operator, - public MatrixBase > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(Random) - - private: - - int _rows() const { return m_rows.value(); } - int _cols() const { return m_cols.value(); } - - const Scalar _coeff(int, int) const - { - return ei_random(); - } - - public: - - Random(int rows, int cols) : m_rows(rows), m_cols(cols) - { - ei_assert(rows > 0 - && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols > 0 - && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); - } - - protected: - const ei_int_if_dynamic m_rows; - const ei_int_if_dynamic m_cols; -}; - -/** \returns a random matrix (not an expression, the matrix is immediately evaluated). - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so ei_random() should be used - * instead. - * - * Example: \include MatrixBase_random_int_int.cpp - * Output: \verbinclude MatrixBase_random_int_int.out - * - * \sa ei_random(), ei_random(int) - */ -template -const Random -MatrixBase::random(int rows, int cols) -{ - return Random(rows, cols); -} - -/** \returns a random vector (not an expression, the vector is immediately evaluated). - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so ei_random() should be used - * instead. - * - * Example: \include MatrixBase_random_int.cpp - * Output: \verbinclude MatrixBase_random_int.out - * - * \sa ei_random(), ei_random(int,int) - */ -template -const Random -MatrixBase::random(int size) -{ - ei_assert(IsVectorAtCompileTime); - if(RowsAtCompileTime == 1) return Random(1, size); - else return Random(size, 1); -} - -/** \returns a fixed-size random matrix or vector - * (not an expression, the matrix is immediately evaluated). - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_random.cpp - * Output: \verbinclude MatrixBase_random.out - * - * \sa ei_random(int), ei_random(int,int) - */ -template -const Random -MatrixBase::random() -{ - return Random(RowsAtCompileTime, ColsAtCompileTime); -} - -/** Sets all coefficients in this expression to random values. - * - * Example: \include MatrixBase_setRandom.cpp - * Output: \verbinclude MatrixBase_setRandom.out - * - * \sa class Random, ei_random() - */ -template -Derived& MatrixBase::setRandom() -{ - return *this = Random(rows(), cols()); -} - -#endif // EIGEN_RANDOM_H diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h deleted file mode 100644 index 1daffd1c4..000000000 --- a/Eigen/src/Core/Zero.h +++ /dev/null @@ -1,173 +0,0 @@ -// This file is part of Eigen, a lightweight C++ template library -// for linear algebra. Eigen itself is part of the KDE project. -// -// Copyright (C) 2006-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_ZERO_H -#define EIGEN_ZERO_H - -/** \class Zero - * - * \brief Expression of a zero matrix or vector. - * - * \sa MatrixBase::zero(), MatrixBase::zero(int), MatrixBase::zero(int,int), - * MatrixBase::setZero(), MatrixBase::isZero() - */ -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Flags = MatrixType::Flags & ~VectorizableBit, - CoeffReadCost = NumTraits::ReadCost - }; -}; - -template class Zero : ei_no_assignment_operator, - public MatrixBase > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(Zero) - - private: - - int _rows() const { return m_rows.value(); } - int _cols() const { return m_cols.value(); } - - Scalar _coeff(int, int) const - { - return static_cast(0); - } - - public: - - Zero(int rows, int cols) : m_rows(rows), m_cols(cols) - { - ei_assert(rows > 0 - && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == rows) - && cols > 0 - && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == cols)); - } - - protected: - const ei_int_if_dynamic m_rows; - const ei_int_if_dynamic m_cols; -}; - -/** \returns an expression of a zero matrix. - * - * The parameters \a rows and \a cols are the number of rows and of columns of - * the returned matrix. Must be compatible with this MatrixBase type. - * - * This variant is meant to be used for dynamic-size matrix types. For fixed-size types, - * it is redundant to pass \a rows and \a cols as arguments, so zero() should be used - * instead. - * - * Example: \include MatrixBase_zero_int_int.cpp - * Output: \verbinclude MatrixBase_zero_int_int.out - * - * \sa zero(), zero(int) - */ -template -const Zero MatrixBase::zero(int rows, int cols) -{ - return Zero(rows, cols); -} - -/** \returns an expression of a zero vector. - * - * The parameter \a size is the size of the returned vector. - * Must be compatible with this MatrixBase type. - * - * \only_for_vectors - * - * This variant is meant to be used for dynamic-size vector types. For fixed-size types, - * it is redundant to pass \a size as argument, so zero() should be used - * instead. - * - * Example: \include MatrixBase_zero_int.cpp - * Output: \verbinclude MatrixBase_zero_int.out - * - * \sa zero(), zero(int,int) - */ -template -const Zero MatrixBase::zero(int size) -{ - ei_assert(IsVectorAtCompileTime); - if(RowsAtCompileTime == 1) return Zero(1, size); - else return Zero(size, 1); -} - -/** \returns an expression of a fixed-size zero matrix or vector. - * - * This variant is only for fixed-size MatrixBase types. For dynamic-size types, you - * need to use the variants taking size arguments. - * - * Example: \include MatrixBase_zero.cpp - * Output: \verbinclude MatrixBase_zero.out - * - * \sa zero(int), zero(int,int) - */ -template -const Zero MatrixBase::zero() -{ - return Zero(RowsAtCompileTime, ColsAtCompileTime); -} - -/** \returns true if *this is approximately equal to the zero matrix, - * within the precision given by \a prec. - * - * Example: \include MatrixBase_isZero.cpp - * Output: \verbinclude MatrixBase_isZero.out - * - * \sa class Zero, zero() - */ -template -bool MatrixBase::isZero -(typename NumTraits::Real prec) const -{ - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if(!ei_isMuchSmallerThan(coeff(i, j), static_cast(1), prec)) - return false; - return true; -} - -/** Sets all coefficients in this expression to zero. - * - * Example: \include MatrixBase_setZero.cpp - * Output: \verbinclude MatrixBase_setZero.out - * - * \sa class Zero, zero() - */ -template -Derived& MatrixBase::setZero() -{ - return *this = Zero(rows(), cols()); -} - -#endif // EIGEN_ZERO_H diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index c71b12334..97d8c346a 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -38,6 +38,7 @@ const unsigned int VectorizableBit = 0x10; #else const unsigned int VectorizableBit = 0x0; #endif +const unsigned int Like1DArrayBit = 0x20; enum { ConditionalJumpCost = 5 }; enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 0bdfb4ea1..adbbdeff8 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -40,15 +40,12 @@ template class Minor; template class Block; template class Transpose; template class Conjugate; -template class CwiseBinaryOp; -template class CwiseUnaryOp; +template class CwiseNullaryOp; +template class CwiseUnaryOp; +template class CwiseBinaryOp; template::value> class Product; -template class Random; -template class Zero; -template class Ones; template class DiagonalMatrix; template class DiagonalCoeffs; -template class Identity; template class Map; template class Eval; template class PartialRedux; diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index ce0c4a21b..3c8f9ad9a 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -158,7 +158,7 @@ class ei_corrected_matrix_flags ? Cols%ei_packet_traits::size==0 : Rows%ei_packet_traits::size==0 ), - _flags1 = SuggestedFlags & ~(EvalBeforeNestingBit | EvalBeforeAssigningBit) + _flags1 = (SuggestedFlags & ~(EvalBeforeNestingBit | EvalBeforeAssigningBit)) | Like1DArrayBit }; public: