From 9d8876ce82c51f7898ddf73984fcfbb413ef851f Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 10 Apr 2008 09:01:28 +0000 Subject: * rename XprCopy -> Nested * rename OperatorEquals -> Assign * move Util.h and FwDecl.h to a util/ subdir --- Eigen/Core | 15 +- Eigen/src/Core/Assign.h | 246 +++++++++++++++++++++++++++ Eigen/src/Core/Block.h | 2 +- Eigen/src/Core/CMakeLists.txt | 2 + Eigen/src/Core/CwiseBinaryOp.h | 4 +- Eigen/src/Core/CwiseUnaryOp.h | 2 +- Eigen/src/Core/DiagonalCoeffs.h | 2 +- Eigen/src/Core/DiagonalMatrix.h | 2 +- Eigen/src/Core/Dot.h | 40 ++--- Eigen/src/Core/ForwardDeclarations.h | 125 -------------- Eigen/src/Core/Fuzzy.h | 18 +- Eigen/src/Core/Lazy.h | 2 +- Eigen/src/Core/Minor.h | 2 +- Eigen/src/Core/OperatorEquals.h | 246 --------------------------- Eigen/src/Core/Product.h | 30 ++-- Eigen/src/Core/Redux.h | 16 +- Eigen/src/Core/Transpose.h | 2 +- Eigen/src/Core/Util.h | 264 ----------------------------- Eigen/src/Core/util/CMakeLists.txt | 6 + Eigen/src/Core/util/ForwardDeclarations.h | 125 ++++++++++++++ Eigen/src/Core/util/Util.h | 273 ++++++++++++++++++++++++++++++ bench/benchmark.cpp | 8 +- 22 files changed, 722 insertions(+), 710 deletions(-) create mode 100644 Eigen/src/Core/Assign.h delete mode 100644 Eigen/src/Core/ForwardDeclarations.h delete mode 100644 Eigen/src/Core/OperatorEquals.h delete mode 100644 Eigen/src/Core/Util.h create mode 100644 Eigen/src/Core/util/CMakeLists.txt create mode 100644 Eigen/src/Core/util/ForwardDeclarations.h create mode 100644 Eigen/src/Core/util/Util.h diff --git a/Eigen/Core b/Eigen/Core index dc28951f0..404eb89de 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -7,26 +7,17 @@ #include #include -#ifdef EIGEN_VECTORIZE -#ifdef EIGEN_INTEL_PLATFORM -#include -#include -#else -#undef EIGEN_VECTORIZE -#endif -#endif - namespace Eigen { -#include "src/Core/Util.h" -#include "src/Core/ForwardDeclarations.h" +#include "src/Core/util/Util.h" +#include "src/Core/util/ForwardDeclarations.h" #include "src/Core/NumTraits.h" #include "src/Core/MathFunctions.h" #include "src/Core/PacketMath.h" #include "src/Core/Functors.h" #include "src/Core/MatrixBase.h" #include "src/Core/Coeffs.h" -#include "src/Core/OperatorEquals.h" +#include "src/Core/Assign.h" #include "src/Core/MatrixStorage.h" #include "src/Core/Matrix.h" #include "src/Core/Lazy.h" diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h new file mode 100644 index 000000000..f33f491bf --- /dev/null +++ b/Eigen/src/Core/Assign.h @@ -0,0 +1,246 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2007 Michael Olbrich +// 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_ASSIGN_H +#define EIGEN_ASSIGN_H + +template +struct ei_matrix_operator_equals_unroller +{ + enum { + col = (UnrollCount-1) / Derived1::RowsAtCompileTime, + row = (UnrollCount-1) % Derived1::RowsAtCompileTime + }; + + static void run(Derived1 &dst, const Derived2 &src) + { + ei_matrix_operator_equals_unroller::run(dst, src); + dst.coeffRef(row, col) = src.coeff(row, col); + } +}; + +template +struct ei_matrix_operator_equals_unroller +{ + static void run(Derived1 &dst, const Derived2 &src) + { + dst.coeffRef(0, 0) = src.coeff(0, 0); + } +}; + +// prevent buggy user code from causing an infinite recursion +template +struct ei_matrix_operator_equals_unroller +{ + static void run(Derived1 &, const Derived2 &) {} +}; + +template +struct ei_matrix_operator_equals_unroller +{ + static void run(Derived1 &, const Derived2 &) {} +}; + +//---- + +template +struct ei_matrix_operator_equals_packet_unroller +{ + enum { + row = Derived1::Flags&RowMajorBit ? Index / Derived1::ColsAtCompileTime : Index % Derived1::RowsAtCompileTime, + col = Derived1::Flags&RowMajorBit ? Index % Derived1::ColsAtCompileTime : Index / Derived1::RowsAtCompileTime + }; + + static void run(Derived1 &dst, const Derived2 &src) + { + ei_matrix_operator_equals_packet_unroller::size>::run(dst, src); + dst.writePacketCoeff(row, col, src.packetCoeff(row, col)); + } +}; + +template +struct ei_matrix_operator_equals_packet_unroller +{ + static void run(Derived1 &dst, const Derived2 &src) + { + dst.writePacketCoeff(0, 0, src.packetCoeff(0, 0)); + } +}; + +template +struct ei_matrix_operator_equals_packet_unroller +{ + static void run(Derived1 &, const Derived2 &) { ei_internal_assert(false && "ei_matrix_operator_equals_packet_unroller"); } +}; + +//---- + +template +struct ei_vector_operator_equals_unroller +{ + enum { index = UnrollCount - 1 }; + + static void run(Derived1 &dst, const Derived2 &src) + { + ei_vector_operator_equals_unroller::run(dst, src); + dst.coeffRef(index) = src.coeff(index); + } +}; + +// prevent buggy user code from causing an infinite recursion +template +struct ei_vector_operator_equals_unroller +{ + static void run(Derived1 &, const Derived2 &) {} +}; + +template +struct ei_vector_operator_equals_unroller +{ + static void run(Derived1 &dst, const Derived2 &src) + { + dst.coeffRef(0) = src.coeff(0); + } +}; + +template +struct ei_vector_operator_equals_unroller +{ + static void run(Derived1 &, const Derived2 &) {} +}; + +template +struct ei_operator_equals_impl; + +template +template +Derived& MatrixBase + ::lazyAssign(const MatrixBase& other) +{ + ei_operator_equals_impl::execute(derived(),other.derived()); + return derived(); +} + +template +template +Derived& MatrixBase + ::operator=(const MatrixBase& other) +{ + if(OtherDerived::Flags & EvalBeforeAssigningBit) + { + return lazyAssign(other.derived().eval()); + } + else + return lazyAssign(other.derived()); +} + +template +struct ei_operator_equals_impl +{ + static void execute(Derived & dst, const OtherDerived & src) + { + const bool unroll = Derived::SizeAtCompileTime * OtherDerived::CoeffReadCost <= EIGEN_UNROLLING_LIMIT; + if(Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) + // copying a vector expression into a vector + { + ei_assert(dst.size() == src.size()); + if(unroll) + ei_vector_operator_equals_unroller + ::run(dst.derived(), src.derived()); + else + for(int i = 0; i < dst.size(); i++) + dst.coeffRef(i) = src.coeff(i); + } + else // copying a matrix expression into a matrix + { + ei_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + if(unroll) + { + ei_matrix_operator_equals_unroller + ::run(dst.derived(), src.derived()); + } + else + { + if(Derived::ColsAtCompileTime == Dynamic || Derived::RowsAtCompileTime != Dynamic) + { + // traverse in column-major order + for(int j = 0; j < dst.cols(); j++) + for(int i = 0; i < dst.rows(); i++) + dst.coeffRef(i, j) = src.coeff(i, j); + } + else + { + // traverse in row-major order + // in order to allow the compiler to unroll the inner loop + for(int i = 0; i < dst.rows(); i++) + for(int j = 0; j < dst.cols(); j++) + dst.coeffRef(i, j) = src.coeff(i, j); + } + } + } + } +}; + +template +struct ei_operator_equals_impl +{ + static void execute(Derived & dst, const OtherDerived & src) + { + const bool unroll = Derived::SizeAtCompileTime * OtherDerived::CoeffReadCost <= EIGEN_UNROLLING_LIMIT; + ei_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); + if(unroll) + { + ei_matrix_operator_equals_packet_unroller + =ei_packet_traits::size + ? Derived::SizeAtCompileTime-ei_packet_traits::size + : Dynamic>::run(dst.const_cast_derived(), src.derived()); + } + else + { + if(OtherDerived::Flags&RowMajorBit) + { + for(int i = 0; i < dst.rows(); i++) + for(int j = 0; j < dst.cols(); j+=ei_packet_traits::size) + dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); + } + else + { + for(int j = 0; j < dst.cols(); j++) + for(int i = 0; i < dst.rows(); i+=ei_packet_traits::size) + dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); + } + } + } +}; + +#endif // EIGEN_ASSIGN_H diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index f0c1d11c0..c8f4ac6b1 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -143,7 +143,7 @@ template class Block protected: - const typename MatrixType::XprCopy m_matrix; + const typename MatrixType::Nested m_matrix; ei_int_if_dynamic m_startRow; ei_int_if_dynamic m_startCol; ei_int_if_dynamic m_blockRows; diff --git a/Eigen/src/Core/CMakeLists.txt b/Eigen/src/Core/CMakeLists.txt index 963cd50e6..a59a0fd67 100644 --- a/Eigen/src/Core/CMakeLists.txt +++ b/Eigen/src/Core/CMakeLists.txt @@ -4,3 +4,5 @@ INSTALL(FILES ${Eigen_Core_SRCS} DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Core ) + +ADD_SUBDIRECTORY(util) diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 174b448fc..0cddc5a30 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -97,8 +97,8 @@ class CwiseBinaryOp : ei_no_assignment_operator, } protected: - const typename Lhs::XprCopy m_lhs; - const typename Rhs::XprCopy m_rhs; + const typename Lhs::Nested m_lhs; + const typename Rhs::Nested m_rhs; const BinaryOp m_functor; }; diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index cbe545a92..2a6858703 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -83,7 +83,7 @@ class CwiseUnaryOp : ei_no_assignment_operator, } protected: - const typename MatrixType::XprCopy m_matrix; + const typename MatrixType::Nested m_matrix; const UnaryOp m_functor; }; diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index 7f8fea162..3e4ebded8 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -87,7 +87,7 @@ template class DiagonalCoeffs protected: - const typename MatrixType::XprCopy m_matrix; + const typename MatrixType::Nested m_matrix; }; /** \returns an expression of the main diagonal of the matrix \c *this diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 6a243a402..0fae56805 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -77,7 +77,7 @@ class DiagonalMatrix : ei_no_assignment_operator, } protected: - const typename CoeffsVectorType::XprCopy m_coeffs; + const typename CoeffsVectorType::Nested m_coeffs; }; /** \returns an expression of a diagonal matrix with *this as vector of diagonal coefficients diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 1d768b259..ae42bfa1b 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -72,31 +72,31 @@ template typename ei_traits::Scalar MatrixBase::dot(const MatrixBase& other) const { - typedef typename Derived::XprCopy XprCopy; - typedef typename OtherDerived::XprCopy OtherXprCopy; - typedef typename ei_unref::type _XprCopy; - typedef typename ei_unref::type _OtherXprCopy; - XprCopy xprCopy(derived()); - OtherXprCopy otherXprCopy(other.derived()); + typedef typename Derived::Nested Nested; + typedef typename OtherDerived::Nested OtherNested; + typedef typename ei_unref::type _Nested; + typedef typename ei_unref::type _OtherNested; + Nested nested(derived()); + OtherNested otherNested(other.derived()); - ei_assert(_XprCopy::IsVectorAtCompileTime - && _OtherXprCopy::IsVectorAtCompileTime - && xprCopy.size() == otherXprCopy.size()); + ei_assert(_Nested::IsVectorAtCompileTime + && _OtherNested::IsVectorAtCompileTime + && nested.size() == otherNested.size()); Scalar res; const bool unroll = SizeAtCompileTime - * (_XprCopy::CoeffReadCost + _OtherXprCopy::CoeffReadCost + NumTraits::MulCost) + * (_Nested::CoeffReadCost + _OtherNested::CoeffReadCost + NumTraits::MulCost) + (SizeAtCompileTime - 1) * NumTraits::AddCost <= EIGEN_UNROLLING_LIMIT; if(unroll) ei_dot_unroller - ::run(xprCopy, otherXprCopy, res); + _Nested, _OtherNested> + ::run(nested, otherNested, res); else { - res = xprCopy.coeff(0) * ei_conj(otherXprCopy.coeff(0)); + res = nested.coeff(0) * ei_conj(otherNested.coeff(0)); for(int i = 1; i < size(); i++) - res += xprCopy.coeff(i)* ei_conj(otherXprCopy.coeff(i)); + res += nested.coeff(i)* ei_conj(otherNested.coeff(i)); } return res; } @@ -149,9 +149,9 @@ template bool MatrixBase::isOrtho (const MatrixBase& other, RealScalar prec) const { - typename ei_xpr_copy::type xprCopy(derived()); - typename ei_xpr_copy::type otherXprCopy(other.derived()); - return ei_abs2(xprCopy.dot(otherXprCopy)) <= prec * prec * xprCopy.norm2() * otherXprCopy.norm2(); + typename ei_nested::type nested(derived()); + typename ei_nested::type otherNested(other.derived()); + return ei_abs2(nested.dot(otherNested)) <= prec * prec * nested.norm2() * otherNested.norm2(); } /** \returns true if *this is approximately an unitary matrix, @@ -168,13 +168,13 @@ bool MatrixBase::isOrtho template bool MatrixBase::isOrtho(RealScalar prec) const { - typename Derived::XprCopy xprCopy(derived()); + typename Derived::Nested nested(derived()); for(int i = 0; i < cols(); i++) { - if(!ei_isApprox(xprCopy.col(i).norm2(), static_cast(1), prec)) + if(!ei_isApprox(nested.col(i).norm2(), static_cast(1), prec)) return false; for(int j = 0; j < i; j++) - if(!ei_isMuchSmallerThan(xprCopy.col(i).dot(xprCopy.col(j)), static_cast(1), prec)) + if(!ei_isMuchSmallerThan(nested.col(i).dot(nested.col(j)), static_cast(1), prec)) return false; } return true; diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h deleted file mode 100644 index d9699301d..000000000 --- a/Eigen/src/Core/ForwardDeclarations.h +++ /dev/null @@ -1,125 +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_FORWARDDECLARATIONS_H -#define EIGEN_FORWARDDECLARATIONS_H - -template struct ei_traits; -template struct ei_product_eval_mode; -template struct NumTraits; - -template class Matrix; -template class Lazy; -template class Temporary; -template class Minor; -template class Block; -template class Transpose; -template class Conjugate; -template class CwiseBinaryOp; -template class CwiseUnaryOp; -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 EvalOMP; -template class PartialRedux; - -template struct ei_scalar_sum_op; -template struct ei_scalar_difference_op; -template struct ei_scalar_product_op; -template struct ei_scalar_quotient_op; -template struct ei_scalar_opposite_op; -template struct ei_scalar_conjugate_op; -template struct ei_scalar_abs_op; -template struct ei_scalar_abs2_op; -template struct ei_scalar_sqrt_op; -template struct ei_scalar_exp_op; -template struct ei_scalar_log_op; -template struct ei_scalar_cos_op; -template struct ei_scalar_sin_op; -template struct ei_scalar_pow_op; -template struct ei_scalar_cast_op; -template struct ei_scalar_multiple_op; -template struct ei_scalar_quotient1_op; -template struct ei_scalar_min_op; -template struct ei_scalar_max_op; - -template struct ei_eval -{ - typedef Matrix::Scalar, - ei_traits::RowsAtCompileTime, - ei_traits::ColsAtCompileTime, - ei_traits::Flags & ~(EvalBeforeNestingBit | EvalBeforeAssigningBit), - ei_traits::MaxRowsAtCompileTime, - ei_traits::MaxColsAtCompileTime> type; -}; - -template struct ei_unref { typedef T type; }; -template struct ei_unref { typedef T type; }; - -template struct ei_is_temporary -{ - enum { ret = 0 }; -}; - -template struct ei_is_temporary > -{ - enum { ret = 1 }; -}; - -template struct ei_xpr_copy -{ - typedef typename ei_meta_if< - ei_is_temporary::ret, - T, - typename ei_meta_if< - ei_traits::Flags & EvalBeforeNestingBit - || (n+1) * NumTraits::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, - typename ei_eval::type, - const T& - >::ret - >::ret type; -}; - -template struct ei_functor_traits -{ - enum - { - Cost = 10, - IsVectorizable = false - }; -}; - -template struct ei_packet_traits -{ - typedef T type; - enum {size=1}; -}; - -#endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index 5dd0265ba..8438193d8 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -55,11 +55,11 @@ bool MatrixBase::isApprox( } else { - typename Derived::XprCopy xprCopy(derived()); - typename OtherDerived::XprCopy otherXprCopy(other.derived()); + typename Derived::Nested nested(derived()); + typename OtherDerived::Nested otherNested(other.derived()); for(int i = 0; i < cols(); i++) - if((xprCopy.col(i) - otherXprCopy.col(i)).norm2() - > std::min(xprCopy.col(i).norm2(), otherXprCopy.col(i).norm2()) * prec * prec) + if((nested.col(i) - otherNested.col(i)).norm2() + > std::min(nested.col(i).norm2(), otherNested.col(i).norm2()) * prec * prec) return false; return true; } @@ -87,9 +87,9 @@ bool MatrixBase::isMuchSmallerThan( } else { - typename Derived::XprCopy xprCopy(*this); + typename Derived::Nested nested(*this); for(int i = 0; i < cols(); i++) - if(xprCopy.col(i).norm2() > ei_abs2(other * prec)) + if(nested.col(i).norm2() > ei_abs2(other * prec)) return false; return true; } @@ -119,10 +119,10 @@ bool MatrixBase::isMuchSmallerThan( } else { - typename Derived::XprCopy xprCopy(*this); - typename OtherDerived::XprCopy otherXprCopy(other); + typename Derived::Nested nested(*this); + typename OtherDerived::Nested otherNested(other); for(int i = 0; i < cols(); i++) - if(xprCopy.col(i).norm2() > otherXprCopy.col(i).norm2() * prec * prec) + if(nested.col(i).norm2() > otherNested.col(i).norm2() * prec * prec) return false; return true; } diff --git a/Eigen/src/Core/Lazy.h b/Eigen/src/Core/Lazy.h index aacc61695..0c65cdeba 100644 --- a/Eigen/src/Core/Lazy.h +++ b/Eigen/src/Core/Lazy.h @@ -73,7 +73,7 @@ template class Lazy } protected: - const typename ExpressionType::XprCopy m_expression; + const typename ExpressionType::Nested m_expression; }; /** \returns an expression of the lazy version of *this. diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index 1b060928f..5c9afc162 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -88,7 +88,7 @@ template class Minor } protected: - const typename MatrixType::XprCopy m_matrix; + const typename MatrixType::Nested m_matrix; const int m_row, m_col; }; diff --git a/Eigen/src/Core/OperatorEquals.h b/Eigen/src/Core/OperatorEquals.h deleted file mode 100644 index 213c5f660..000000000 --- a/Eigen/src/Core/OperatorEquals.h +++ /dev/null @@ -1,246 +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) 2007 Michael Olbrich -// 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_OPERATOREQUALS_H -#define EIGEN_OPERATOREQUALS_H - -template -struct ei_matrix_operator_equals_unroller -{ - enum { - col = (UnrollCount-1) / Derived1::RowsAtCompileTime, - row = (UnrollCount-1) % Derived1::RowsAtCompileTime - }; - - static void run(Derived1 &dst, const Derived2 &src) - { - ei_matrix_operator_equals_unroller::run(dst, src); - dst.coeffRef(row, col) = src.coeff(row, col); - } -}; - -template -struct ei_matrix_operator_equals_unroller -{ - static void run(Derived1 &dst, const Derived2 &src) - { - dst.coeffRef(0, 0) = src.coeff(0, 0); - } -}; - -// prevent buggy user code from causing an infinite recursion -template -struct ei_matrix_operator_equals_unroller -{ - static void run(Derived1 &, const Derived2 &) {} -}; - -template -struct ei_matrix_operator_equals_unroller -{ - static void run(Derived1 &, const Derived2 &) {} -}; - -//---- - -template -struct ei_matrix_operator_equals_packet_unroller -{ - enum { - row = Derived1::Flags&RowMajorBit ? Index / Derived1::ColsAtCompileTime : Index % Derived1::RowsAtCompileTime, - col = Derived1::Flags&RowMajorBit ? Index % Derived1::ColsAtCompileTime : Index / Derived1::RowsAtCompileTime - }; - - static void run(Derived1 &dst, const Derived2 &src) - { - ei_matrix_operator_equals_packet_unroller::size>::run(dst, src); - dst.writePacketCoeff(row, col, src.packetCoeff(row, col)); - } -}; - -template -struct ei_matrix_operator_equals_packet_unroller -{ - static void run(Derived1 &dst, const Derived2 &src) - { - dst.writePacketCoeff(0, 0, src.packetCoeff(0, 0)); - } -}; - -template -struct ei_matrix_operator_equals_packet_unroller -{ - static void run(Derived1 &, const Derived2 &) { ei_internal_assert(false && "ei_matrix_operator_equals_packet_unroller"); } -}; - -//---- - -template -struct ei_vector_operator_equals_unroller -{ - enum { index = UnrollCount - 1 }; - - static void run(Derived1 &dst, const Derived2 &src) - { - ei_vector_operator_equals_unroller::run(dst, src); - dst.coeffRef(index) = src.coeff(index); - } -}; - -// prevent buggy user code from causing an infinite recursion -template -struct ei_vector_operator_equals_unroller -{ - static void run(Derived1 &, const Derived2 &) {} -}; - -template -struct ei_vector_operator_equals_unroller -{ - static void run(Derived1 &dst, const Derived2 &src) - { - dst.coeffRef(0) = src.coeff(0); - } -}; - -template -struct ei_vector_operator_equals_unroller -{ - static void run(Derived1 &, const Derived2 &) {} -}; - -template -struct ei_operator_equals_impl; - -template -template -Derived& MatrixBase - ::lazyAssign(const MatrixBase& other) -{ - ei_operator_equals_impl::execute(derived(),other.derived()); - return derived(); -} - -template -template -Derived& MatrixBase - ::operator=(const MatrixBase& other) -{ - if(OtherDerived::Flags & EvalBeforeAssigningBit) - { - return lazyAssign(other.derived().eval()); - } - else - return lazyAssign(other.derived()); -} - -template -struct ei_operator_equals_impl -{ - static void execute(Derived & dst, const OtherDerived & src) - { - const bool unroll = Derived::SizeAtCompileTime * OtherDerived::CoeffReadCost <= EIGEN_UNROLLING_LIMIT; - if(Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) - // copying a vector expression into a vector - { - ei_assert(dst.size() == src.size()); - if(unroll) - ei_vector_operator_equals_unroller - ::run(dst.derived(), src.derived()); - else - for(int i = 0; i < dst.size(); i++) - dst.coeffRef(i) = src.coeff(i); - } - else // copying a matrix expression into a matrix - { - ei_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - if(unroll) - { - ei_matrix_operator_equals_unroller - ::run(dst.derived(), src.derived()); - } - else - { - if(Derived::ColsAtCompileTime == Dynamic || Derived::RowsAtCompileTime != Dynamic) - { - // traverse in column-major order - for(int j = 0; j < dst.cols(); j++) - for(int i = 0; i < dst.rows(); i++) - dst.coeffRef(i, j) = src.coeff(i, j); - } - else - { - // traverse in row-major order - // in order to allow the compiler to unroll the inner loop - for(int i = 0; i < dst.rows(); i++) - for(int j = 0; j < dst.cols(); j++) - dst.coeffRef(i, j) = src.coeff(i, j); - } - } - } - } -}; - -template -struct ei_operator_equals_impl -{ - static void execute(Derived & dst, const OtherDerived & src) - { - const bool unroll = Derived::SizeAtCompileTime * OtherDerived::CoeffReadCost <= EIGEN_UNROLLING_LIMIT; - ei_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); - if(unroll) - { - ei_matrix_operator_equals_packet_unroller - =ei_packet_traits::size - ? Derived::SizeAtCompileTime-ei_packet_traits::size - : Dynamic>::run(dst.const_cast_derived(), src.derived()); - } - else - { - if(OtherDerived::Flags&RowMajorBit) - { - for(int i = 0; i < dst.rows(); i++) - for(int j = 0; j < dst.cols(); j+=ei_packet_traits::size) - dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); - } - else - { - for(int j = 0; j < dst.cols(); j++) - for(int i = 0; i < dst.rows(); i+=ei_packet_traits::size) - dst.writePacketCoeff(i, j, src.packetCoeff(i, j)); - } - } - } -}; - -#endif // EIGEN_OPERATOREQUALS_H diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 142955108..9e7127720 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -116,15 +116,15 @@ template struct ei_traits > { typedef typename Lhs::Scalar Scalar; - typedef typename ei_xpr_copy::type LhsXprCopy; - typedef typename ei_xpr_copy::type RhsXprCopy; - typedef typename ei_unref::type _LhsXprCopy; - typedef typename ei_unref::type _RhsXprCopy; + typedef typename ei_nested::type LhsNested; + typedef typename ei_nested::type RhsNested; + typedef typename ei_unref::type _LhsNested; + typedef typename ei_unref::type _RhsNested; enum { - LhsCoeffReadCost = _LhsXprCopy::CoeffReadCost, - RhsCoeffReadCost = _RhsXprCopy::CoeffReadCost, - LhsFlags = _LhsXprCopy::Flags, - RhsFlags = _RhsXprCopy::Flags, + LhsCoeffReadCost = _LhsNested::CoeffReadCost, + RhsCoeffReadCost = _RhsNested::CoeffReadCost, + LhsFlags = _LhsNested::Flags, + RhsFlags = _RhsNested::Flags, RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Rhs::ColsAtCompileTime, MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, @@ -153,10 +153,10 @@ template class Product : ei_no_assignm public: EIGEN_GENERIC_PUBLIC_INTERFACE(Product) - typedef typename ei_traits::LhsXprCopy LhsXprCopy; - typedef typename ei_traits::RhsXprCopy RhsXprCopy; - typedef typename ei_traits::_LhsXprCopy _LhsXprCopy; - typedef typename ei_traits::_RhsXprCopy _RhsXprCopy; + typedef typename ei_traits::LhsNested LhsNested; + typedef typename ei_traits::RhsNested RhsNested; + typedef typename ei_traits::_LhsNested _LhsNested; + typedef typename ei_traits::_RhsNested _RhsNested; Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) @@ -181,7 +181,7 @@ template class Product : ei_no_assignm { ei_product_unroller + _LhsNested, _RhsNested> ::run(row, col, m_lhs, m_rhs, res); } else @@ -224,8 +224,8 @@ template class Product : ei_no_assignm } protected: - const LhsXprCopy m_lhs; - const RhsXprCopy m_rhs; + const LhsNested m_lhs; + const RhsNested m_rhs; }; /** \returns the matrix product of \c *this and \a other. diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 12ceedd76..6e740fc7d 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -87,18 +87,18 @@ struct ei_traits > typedef typename ei_result_of< BinaryOp(typename MatrixType::Scalar) >::type Scalar; - typedef typename ei_xpr_copy::type MatrixTypeXprCopy; - typedef typename ei_unref::type _MatrixTypeXprCopy; + typedef typename ei_nested::type MatrixTypeNested; + typedef typename ei_unref::type _MatrixTypeNested; enum { RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime, ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime, Flags = ((RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) - ? (unsigned int)_MatrixTypeXprCopy::Flags - : (unsigned int)_MatrixTypeXprCopy::Flags & ~LargeBit) & ~VectorizableBit, + ? (unsigned int)_MatrixTypeNested::Flags + : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & ~VectorizableBit, TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, - CoeffReadCost = TraversalSize * _MatrixTypeXprCopy::CoeffReadCost + CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost + (TraversalSize - 1) * ei_functor_traits::Cost }; }; @@ -110,8 +110,8 @@ class PartialRedux : ei_no_assignment_operator, public: EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux) - typedef typename ei_traits::MatrixTypeXprCopy MatrixTypeXprCopy; - typedef typename ei_traits::_MatrixTypeXprCopy _MatrixTypeXprCopy; + typedef typename ei_traits::MatrixTypeNested MatrixTypeNested; + typedef typename ei_traits::_MatrixTypeNested _MatrixTypeNested; PartialRedux(const MatrixType& mat, const BinaryOp& func = BinaryOp()) : m_matrix(mat), m_functor(func) {} @@ -130,7 +130,7 @@ class PartialRedux : ei_no_assignment_operator, } protected: - const MatrixTypeXprCopy m_matrix; + const MatrixTypeNested m_matrix; const BinaryOp m_functor; }; diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 6710f3092..424557754 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -88,7 +88,7 @@ template class Transpose } protected: - const typename MatrixType::XprCopy m_matrix; + const typename MatrixType::Nested m_matrix; }; /** \returns an expression of the transpose of *this. diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h deleted file mode 100644 index e2c95bc53..000000000 --- a/Eigen/src/Core/Util.h +++ /dev/null @@ -1,264 +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) 2008 Gael Guennebaud -// 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_UTIL_H -#define EIGEN_UTIL_H - -#ifdef EIGEN_DONT_USE_UNROLLED_LOOPS -#define EIGEN_UNROLLING_LIMIT 0 -#endif - -/** Defines the maximal loop size to enable meta unrolling of loops */ -#ifndef EIGEN_UNROLLING_LIMIT -#define EIGEN_UNROLLING_LIMIT 400 -#endif - -#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR -#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajorBit -#else -#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER 0 -#endif - -#undef minor - -#define USING_PART_OF_NAMESPACE_EIGEN \ -EIGEN_USING_MATRIX_TYPEDEFS \ -using Eigen::Matrix; \ -using Eigen::MatrixBase; - -#ifdef NDEBUG -#define EIGEN_NO_DEBUG -#endif - -#ifndef ei_assert -#ifdef EIGEN_NO_DEBUG -#define ei_assert(x) -#else -#define ei_assert(x) assert(x) -#endif -#endif - -#ifdef EIGEN_INTERNAL_DEBUGGING -#define ei_internal_assert(x) ei_assert(x); -#else -#define ei_internal_assert(x) -#endif - -#ifdef EIGEN_NO_DEBUG -#define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x -#else -#define EIGEN_ONLY_USED_FOR_DEBUG(x) -#endif - -// FIXME with the always_inline attribute, -// gcc 3.4.x reports the following compilation error: -// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval Eigen::MatrixBase::eval() const' -// : function body not available -#if (defined __GNUC__) && (__GNUC__!=3) -#define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) -#else -#define EIGEN_ALWAYS_INLINE -#endif - -#if (defined __GNUC__) -#define EIGEN_ALIGN_128 __attribute__ ((aligned(16))) -#else -#define EIGEN_ALIGN_128 -#endif - -#define EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ -template \ -Derived& operator Op(const MatrixBase& other) \ -{ \ - return Eigen::MatrixBase::operator Op(other); \ -} \ -Derived& operator Op(const Derived& other) \ -{ \ - return Eigen::MatrixBase::operator Op(other); \ -} - -#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ -template \ -Derived& operator Op(const Other& scalar) \ -{ \ - return Eigen::MatrixBase::operator Op(scalar); \ -} - -#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ -EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \ -EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \ -EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ -EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ -EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) - -#define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ -typedef BaseClass Base; \ -typedef typename Eigen::ei_traits::Scalar Scalar; \ -typedef typename Base::PacketScalar PacketScalar; \ -typedef typename Eigen::ei_xpr_copy::type XprCopy; \ -typedef typename Eigen::ei_eval::type Eval; \ -enum { RowsAtCompileTime = Base::RowsAtCompileTime, \ - ColsAtCompileTime = Base::ColsAtCompileTime, \ - MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime, \ - MaxColsAtCompileTime = Base::MaxColsAtCompileTime, \ - SizeAtCompileTime = Base::SizeAtCompileTime, \ - MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime, \ - Flags = Base::Flags, \ - CoeffReadCost = Base::CoeffReadCost }; - -#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ -_EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) \ -friend class Eigen::MatrixBase; - -#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) - -const int Dynamic = 10000; - -// matrix/expression flags -const unsigned int RowMajorBit = 0x1; -const unsigned int EvalBeforeNestingBit = 0x2; -const unsigned int EvalBeforeAssigningBit = 0x4; -const unsigned int LargeBit = 0x8; -#ifdef EIGEN_VECTORIZE -const unsigned int VectorizableBit = 0x10; -#else -const unsigned int VectorizableBit = 0x0; -#endif - - -enum { ConditionalJumpCost = 5 }; - -enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; - -enum DirectionType { Vertical, Horizontal }; - -enum ProductEvaluationMode { UnrolledDotProduct, CacheOptimal }; - -// just a workaround because GCC seems to not really like empty structs -#ifdef __GNUG__ - struct ei_empty_struct{char _ei_dummy_;}; - #define EIGEN_EMPTY_STRUCT : Eigen::ei_empty_struct -#else - #define EIGEN_EMPTY_STRUCT -#endif - -//classes inheriting ei_no_assignment_operator don't generate a default operator=. -class ei_no_assignment_operator -{ - private: - ei_no_assignment_operator& operator=(const ei_no_assignment_operator&); -}; - -template class ei_int_if_dynamic EIGEN_EMPTY_STRUCT -{ - public: - ei_int_if_dynamic() {} - explicit ei_int_if_dynamic(int) {} - static int value() { return Value; } - void setValue(int) {} -}; - -template<> class ei_int_if_dynamic -{ - int m_value; - ei_int_if_dynamic() {} - public: - explicit ei_int_if_dynamic(int value) : m_value(value) {} - int value() const { return m_value; } - void setValue(int value) { m_value = value; } -}; - - -template -struct ei_meta_if { typedef Then ret; }; - -template -struct ei_meta_if { typedef Else ret; }; - -template struct ei_is_same_type { enum { ret = 0 }; }; -template struct ei_is_same_type { enum { ret = 1 }; }; - - -/** \internal - * Convenient struct to get the result type of a unary or binary functor. - * - * It supports both the current STL mechanism (using the result_type member) as well as - * upcoming next STL generation (using a templated result member). - * If none of these members is provided, then the type of the first argument is returned. - */ -template struct ei_result_of {}; - -struct ei_has_none {int a[1];}; -struct ei_has_std_result_type {int a[2];}; -struct ei_has_tr1_result {int a[3];}; - -template -struct ei_unary_result_of_select {typedef ArgType type;}; - -template -struct ei_unary_result_of_select {typedef typename Func::result_type type;}; - -template -struct ei_unary_result_of_select {typedef typename Func::template result::type type;}; - -template -struct ei_result_of { - template - static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); - template - static ei_has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); - static ei_has_none testFunctor(...); - - // note that the following indirection is needed for gcc-3.3 - enum {FunctorType = sizeof(testFunctor(static_cast(0)))}; - typedef typename ei_unary_result_of_select::type type; -}; - -template -struct ei_binary_result_of_select {typedef ArgType0 type;}; - -template -struct ei_binary_result_of_select -{typedef typename Func::result_type type;}; - -template -struct ei_binary_result_of_select -{typedef typename Func::template result::type type;}; - -template -struct ei_result_of { - template - static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); - template - static ei_has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); - static ei_has_none testFunctor(...); - - // note that the following indirection is needed for gcc-3.3 - enum {FunctorType = sizeof(testFunctor(static_cast(0)))}; - typedef typename ei_binary_result_of_select::type type; -}; - -#endif // EIGEN_UTIL_H diff --git a/Eigen/src/Core/util/CMakeLists.txt b/Eigen/src/Core/util/CMakeLists.txt new file mode 100644 index 000000000..9ab9fc8b0 --- /dev/null +++ b/Eigen/src/Core/util/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB Eigen_Core_util_SRCS "*.h") + +INSTALL(FILES + ${Eigen_Core_SRCS} + DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Core/util + ) diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h new file mode 100644 index 000000000..a7f269cb4 --- /dev/null +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -0,0 +1,125 @@ +// 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_FORWARDDECLARATIONS_H +#define EIGEN_FORWARDDECLARATIONS_H + +template struct ei_traits; +template struct ei_product_eval_mode; +template struct NumTraits; + +template class Matrix; +template class Lazy; +template class Temporary; +template class Minor; +template class Block; +template class Transpose; +template class Conjugate; +template class CwiseBinaryOp; +template class CwiseUnaryOp; +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 EvalOMP; +template class PartialRedux; + +template struct ei_scalar_sum_op; +template struct ei_scalar_difference_op; +template struct ei_scalar_product_op; +template struct ei_scalar_quotient_op; +template struct ei_scalar_opposite_op; +template struct ei_scalar_conjugate_op; +template struct ei_scalar_abs_op; +template struct ei_scalar_abs2_op; +template struct ei_scalar_sqrt_op; +template struct ei_scalar_exp_op; +template struct ei_scalar_log_op; +template struct ei_scalar_cos_op; +template struct ei_scalar_sin_op; +template struct ei_scalar_pow_op; +template struct ei_scalar_cast_op; +template struct ei_scalar_multiple_op; +template struct ei_scalar_quotient1_op; +template struct ei_scalar_min_op; +template struct ei_scalar_max_op; + +template struct ei_eval +{ + typedef Matrix::Scalar, + ei_traits::RowsAtCompileTime, + ei_traits::ColsAtCompileTime, + ei_traits::Flags & ~(EvalBeforeNestingBit | EvalBeforeAssigningBit), + ei_traits::MaxRowsAtCompileTime, + ei_traits::MaxColsAtCompileTime> type; +}; + +template struct ei_unref { typedef T type; }; +template struct ei_unref { typedef T type; }; + +template struct ei_is_temporary +{ + enum { ret = 0 }; +}; + +template struct ei_is_temporary > +{ + enum { ret = 1 }; +}; + +template struct ei_nested +{ + typedef typename ei_meta_if< + ei_is_temporary::ret, + T, + typename ei_meta_if< + ei_traits::Flags & EvalBeforeNestingBit + || (n+1) * NumTraits::Scalar>::ReadCost < (n-1) * T::CoeffReadCost, + typename ei_eval::type, + const T& + >::ret + >::ret type; +}; + +template struct ei_functor_traits +{ + enum + { + Cost = 10, + IsVectorizable = false + }; +}; + +template struct ei_packet_traits +{ + typedef T type; + enum {size=1}; +}; + +#endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/Eigen/src/Core/util/Util.h b/Eigen/src/Core/util/Util.h new file mode 100644 index 000000000..de45927ce --- /dev/null +++ b/Eigen/src/Core/util/Util.h @@ -0,0 +1,273 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud +// 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_UTIL_H +#define EIGEN_UTIL_H + +#ifdef EIGEN_VECTORIZE +#ifdef EIGEN_INTEL_PLATFORM +#include +#include +#else +#undef EIGEN_VECTORIZE +#endif +#endif + +#ifdef EIGEN_DONT_USE_UNROLLED_LOOPS +#define EIGEN_UNROLLING_LIMIT 0 +#endif + +/** Defines the maximal loop size to enable meta unrolling of loops */ +#ifndef EIGEN_UNROLLING_LIMIT +#define EIGEN_UNROLLING_LIMIT 400 +#endif + +#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR +#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajorBit +#else +#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER 0 +#endif + +#undef minor + +#define USING_PART_OF_NAMESPACE_EIGEN \ +EIGEN_USING_MATRIX_TYPEDEFS \ +using Eigen::Matrix; \ +using Eigen::MatrixBase; + +#ifdef NDEBUG +#define EIGEN_NO_DEBUG +#endif + +#ifndef ei_assert +#ifdef EIGEN_NO_DEBUG +#define ei_assert(x) +#else +#define ei_assert(x) assert(x) +#endif +#endif + +#ifdef EIGEN_INTERNAL_DEBUGGING +#define ei_internal_assert(x) ei_assert(x); +#else +#define ei_internal_assert(x) +#endif + +#ifdef EIGEN_NO_DEBUG +#define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x +#else +#define EIGEN_ONLY_USED_FOR_DEBUG(x) +#endif + +// FIXME with the always_inline attribute, +// gcc 3.4.x reports the following compilation error: +// Eval.h:91: sorry, unimplemented: inlining failed in call to 'const Eigen::Eval Eigen::MatrixBase::eval() const' +// : function body not available +#if (defined __GNUC__) && (__GNUC__!=3) +#define EIGEN_ALWAYS_INLINE __attribute__((always_inline)) +#else +#define EIGEN_ALWAYS_INLINE +#endif + +#if (defined __GNUC__) +#define EIGEN_ALIGN_128 __attribute__ ((aligned(16))) +#else +#define EIGEN_ALIGN_128 +#endif + +#define EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \ +template \ +Derived& operator Op(const MatrixBase& other) \ +{ \ + return Eigen::MatrixBase::operator Op(other); \ +} \ +Derived& operator Op(const Derived& other) \ +{ \ + return Eigen::MatrixBase::operator Op(other); \ +} + +#define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ +template \ +Derived& operator Op(const Other& scalar) \ +{ \ + return Eigen::MatrixBase::operator Op(scalar); \ +} + +#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ +EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \ +EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \ +EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ +EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ +EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) + +#define _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \ +typedef BaseClass Base; \ +typedef typename Eigen::ei_traits::Scalar Scalar; \ +typedef typename Base::PacketScalar PacketScalar; \ +typedef typename Eigen::ei_nested::type Nested; \ +typedef typename Eigen::ei_eval::type Eval; \ +enum { RowsAtCompileTime = Base::RowsAtCompileTime, \ + ColsAtCompileTime = Base::ColsAtCompileTime, \ + MaxRowsAtCompileTime = Base::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = Base::MaxColsAtCompileTime, \ + SizeAtCompileTime = Base::SizeAtCompileTime, \ + MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ + IsVectorAtCompileTime = Base::IsVectorAtCompileTime, \ + Flags = Base::Flags, \ + CoeffReadCost = Base::CoeffReadCost }; + +#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ +_EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase) \ +friend class Eigen::MatrixBase; + +#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) + +const int Dynamic = 10000; + +// matrix/expression flags +const unsigned int RowMajorBit = 0x1; +const unsigned int EvalBeforeNestingBit = 0x2; +const unsigned int EvalBeforeAssigningBit = 0x4; +const unsigned int LargeBit = 0x8; +#ifdef EIGEN_VECTORIZE +const unsigned int VectorizableBit = 0x10; +#else +const unsigned int VectorizableBit = 0x0; +#endif + + +enum { ConditionalJumpCost = 5 }; + +enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; + +enum DirectionType { Vertical, Horizontal }; + +enum ProductEvaluationMode { UnrolledDotProduct, CacheOptimal }; + +// just a workaround because GCC seems to not really like empty structs +#ifdef __GNUG__ + struct ei_empty_struct{char _ei_dummy_;}; + #define EIGEN_EMPTY_STRUCT : Eigen::ei_empty_struct +#else + #define EIGEN_EMPTY_STRUCT +#endif + +//classes inheriting ei_no_assignment_operator don't generate a default operator=. +class ei_no_assignment_operator +{ + private: + ei_no_assignment_operator& operator=(const ei_no_assignment_operator&); +}; + +template class ei_int_if_dynamic EIGEN_EMPTY_STRUCT +{ + public: + ei_int_if_dynamic() {} + explicit ei_int_if_dynamic(int) {} + static int value() { return Value; } + void setValue(int) {} +}; + +template<> class ei_int_if_dynamic +{ + int m_value; + ei_int_if_dynamic() {} + public: + explicit ei_int_if_dynamic(int value) : m_value(value) {} + int value() const { return m_value; } + void setValue(int value) { m_value = value; } +}; + + +template +struct ei_meta_if { typedef Then ret; }; + +template +struct ei_meta_if { typedef Else ret; }; + +template struct ei_is_same_type { enum { ret = 0 }; }; +template struct ei_is_same_type { enum { ret = 1 }; }; + + +/** \internal + * Convenient struct to get the result type of a unary or binary functor. + * + * It supports both the current STL mechanism (using the result_type member) as well as + * upcoming next STL generation (using a templated result member). + * If none of these members is provided, then the type of the first argument is returned. + */ +template struct ei_result_of {}; + +struct ei_has_none {int a[1];}; +struct ei_has_std_result_type {int a[2];}; +struct ei_has_tr1_result {int a[3];}; + +template +struct ei_unary_result_of_select {typedef ArgType type;}; + +template +struct ei_unary_result_of_select {typedef typename Func::result_type type;}; + +template +struct ei_unary_result_of_select {typedef typename Func::template result::type type;}; + +template +struct ei_result_of { + template + static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); + template + static ei_has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); + static ei_has_none testFunctor(...); + + // note that the following indirection is needed for gcc-3.3 + enum {FunctorType = sizeof(testFunctor(static_cast(0)))}; + typedef typename ei_unary_result_of_select::type type; +}; + +template +struct ei_binary_result_of_select {typedef ArgType0 type;}; + +template +struct ei_binary_result_of_select +{typedef typename Func::result_type type;}; + +template +struct ei_binary_result_of_select +{typedef typename Func::template result::type type;}; + +template +struct ei_result_of { + template + static ei_has_std_result_type testFunctor(T const *, typename T::result_type const * = 0); + template + static ei_has_tr1_result testFunctor(T const *, typename T::template result::type const * = 0); + static ei_has_none testFunctor(...); + + // note that the following indirection is needed for gcc-3.3 + enum {FunctorType = sizeof(testFunctor(static_cast(0)))}; + typedef typename ei_binary_result_of_select::type type; +}; + +#endif // EIGEN_UTIL_H diff --git a/bench/benchmark.cpp b/bench/benchmark.cpp index 4ff678d8a..99fd097ba 100644 --- a/bench/benchmark.cpp +++ b/bench/benchmark.cpp @@ -12,10 +12,14 @@ USING_PART_OF_NAMESPACE_EIGEN #define REPEAT 40000000 #endif +#ifndef SCALAR +#define SCALAR double +#endif + int main(int argc, char *argv[]) { - Matrix I; - Matrix m; + Matrix I; + Matrix m; for(int i = 0; i < MATSIZE; i++) for(int j = 0; j < MATSIZE; j++) { -- cgit v1.2.3