diff --git a/Eigen/Array b/Eigen/Array new file mode 100644 index 000000000..9595e7db5 --- /dev/null +++ b/Eigen/Array @@ -0,0 +1,17 @@ +#ifndef EIGEN_ARRAY_MODULE_H +#define EIGEN_ARRAY_MODULE_H + +#include "Core" + +namespace Eigen { + +#include "src/Array/ArrayBase.h" +#include "src/Array/CwiseOperators.h" +#include "src/Array/Functors.h" +#include "src/Array/AllAndAny.h" +#include "src/Array/PartialRedux.h" +#include "src/Array/Random.h" + +} // namespace Eigen + +#endif // EIGEN_ARRAY_MODULE_H diff --git a/Eigen/Core b/Eigen/Core index 2c29f3602..f3e6b1fcc 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -27,7 +27,6 @@ namespace Eigen { #include "src/Core/Functors.h" #include "src/Core/MatrixBase.h" -#include "src/Core/ArrayBase.h" #include "src/Core/Coeffs.h" #include "src/Core/Assign.h" #include "src/Core/MatrixStorage.h" diff --git a/Eigen/src/Array/AllAndAny.h b/Eigen/src/Array/AllAndAny.h new file mode 100644 index 000000000..74fbf38c9 --- /dev/null +++ b/Eigen/src/Array/AllAndAny.h @@ -0,0 +1,124 @@ +// 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 +// +// 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_ALLANDANY_H +#define EIGEN_ALLANDANY_H + +template +struct ei_all_unroller +{ + enum { + col = (UnrollCount-1) / Derived::RowsAtCompileTime, + row = (UnrollCount-1) % Derived::RowsAtCompileTime + }; + + inline static bool run(const Derived &mat) + { + return ei_all_unroller::run(mat) && mat.coeff(row, col); + } +}; + +template +struct ei_all_unroller +{ + inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } +}; + +template +struct ei_all_unroller +{ + inline static bool run(const Derived &) { return false; } +}; + +template +struct ei_any_unroller +{ + enum { + col = (UnrollCount-1) / Derived::RowsAtCompileTime, + row = (UnrollCount-1) % Derived::RowsAtCompileTime + }; + + inline static bool run(const Derived &mat) + { + return ei_any_unroller::run(mat) || mat.coeff(row, col); + } +}; + +template +struct ei_any_unroller +{ + inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } +}; + +template +struct ei_any_unroller +{ + inline static bool run(const Derived &) { return false; } +}; + +/** \returns true if all coefficients are true + * + * \sa MatrixBase::any() + */ +template +bool MatrixBase::all(void) const +{ + const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) + <= EIGEN_UNROLLING_LIMIT; + if(unroll) + return ei_all_unroller::run(derived()); + else + { + for(int j = 0; j < cols(); j++) + for(int i = 0; i < rows(); i++) + if (!coeff(i, j)) return false; + return true; + } +} + +/** \returns true if at least one coefficient is true + * + * \sa MatrixBase::any() + */ +template +bool MatrixBase::any(void) const +{ + const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) + <= EIGEN_UNROLLING_LIMIT; + if(unroll) + return ei_any_unroller::run(derived()); + else + { + for(int j = 0; j < cols(); j++) + for(int i = 0; i < rows(); i++) + if (coeff(i, j)) return true; + return false; + } +} + +#endif // EIGEN_ALLANDANY_H diff --git a/Eigen/src/Core/ArrayBase.h b/Eigen/src/Array/ArrayBase.h similarity index 96% rename from Eigen/src/Core/ArrayBase.h rename to Eigen/src/Array/ArrayBase.h index 874f0754a..43d30f51d 100644 --- a/Eigen/src/Core/ArrayBase.h +++ b/Eigen/src/Array/ArrayBase.h @@ -25,8 +25,6 @@ #ifndef EIGEN_ARRAYBASE_H #define EIGEN_ARRAYBASE_H -template class ArrayBase {}; - template class ArrayBase { inline const Derived& derived() const { return *static_cast(this); } diff --git a/Eigen/src/Array/CMakeLists.txt b/Eigen/src/Array/CMakeLists.txt new file mode 100644 index 000000000..1b974a069 --- /dev/null +++ b/Eigen/src/Array/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB Eigen_ARRAY_SRCS "*.h") + +INSTALL(FILES + ${Eigen_ARRAY_SRCS} + DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/ARRAY + ) diff --git a/Eigen/src/Array/CwiseOperators.h b/Eigen/src/Array/CwiseOperators.h new file mode 100644 index 000000000..82a18d11c --- /dev/null +++ b/Eigen/src/Array/CwiseOperators.h @@ -0,0 +1,153 @@ +// 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 +// +// 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_ARRAY_CWISE_OPERATORS_H +#define EIGEN_ARRAY_CWISE_OPERATORS_H + +// -- unary operators -- + +/** \returns an expression of the coefficient-wise square root of *this. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwiseSqrt() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise exponential of *this. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwiseExp() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise logarithm of *this. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwiseLog() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise cosine of *this. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwiseCos() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise sine of *this. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwiseSin() const +{ + return derived(); +} + +/** \returns an expression of the coefficient-wise power of *this to the given exponent. */ +template +inline const CwiseUnaryOp::Scalar>, Derived> +MatrixBase::cwisePow(const Scalar& exponent) const +{ + return CwiseUnaryOp, Derived> + (derived(), ei_scalar_pow_op(exponent)); +} + +// -- binary operators -- + +/** \returns an expression of the coefficient-wise \< operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseLessThan(const MatrixBase &other) const +{ + return cwise(other, std::less()); +} + +/** \returns an expression of the coefficient-wise \<= operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseLessEqual(const MatrixBase &other) const +{ + return cwise(other, std::less_equal()); +} + +/** \returns an expression of the coefficient-wise \> operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseGreaterThan(const MatrixBase &other) const +{ + return cwise(other, std::greater()); +} + +/** \returns an expression of the coefficient-wise \>= operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseGreaterEqual(const MatrixBase &other) const +{ + return cwise(other, std::greater_equal()); +} + +/** \returns an expression of the coefficient-wise == operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseEqualTo(const MatrixBase &other) const +{ + return cwise(other, std::equal_to()); +} + +/** \returns an expression of the coefficient-wise != operator of *this and \a other + * + * \sa class CwiseBinaryOp + */ +template +template +inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> +MatrixBase::cwiseNotEqualTo(const MatrixBase &other) const +{ + return cwise(other, std::not_equal_to()); +} + +#endif // EIGEN_ARRAY_CWISE_OPERATORS_H diff --git a/Eigen/src/Array/Functors.h b/Eigen/src/Array/Functors.h new file mode 100644 index 000000000..805f2dcad --- /dev/null +++ b/Eigen/src/Array/Functors.h @@ -0,0 +1,205 @@ +// 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 +// +// 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_ARRAY_FUNCTORS_H +#define EIGEN_ARRAY_FUNCTORS_H + +/** \internal + * \brief Template functor to compute the square root of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseSqrt() + */ +template struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +/** \internal + * \brief Template functor to compute the exponential of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseExp() + */ +template struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +/** \internal + * \brief Template functor to compute the logarithm of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseLog() + */ +template struct ei_scalar_log_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_log(a); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +/** \internal + * \brief Template functor to compute the cosine of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseCos() + */ +template struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +/** \internal + * \brief Template functor to compute the sine of a scalar + * + * \sa class CwiseUnaryOp, MatrixBase::cwiseSin() + */ +template struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT { + inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +/** \internal + * \brief Template functor to raise a scalar to a power + * + * \sa class CwiseUnaryOp, MatrixBase::cwisePow + */ +template +struct ei_scalar_pow_op { + inline ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} + inline Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); } + const Scalar m_exponent; +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; + +// default ei_functor_traits for STL functors: + +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::MulCost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::MulCost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = ei_functor_traits::Cost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = ei_functor_traits::Cost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1 + ei_functor_traits::Cost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 1 + ei_functor_traits::Cost, IsVectorizable = false }; }; + +#ifdef EIGEN_STDEXT_SUPPORT + +template +struct ei_functor_traits > +{ enum { Cost = 0, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = 0, IsVectorizable = false }; }; + +template +struct ei_functor_traits > > +{ enum { Cost = 0, IsVectorizable = false }; }; + +template +struct ei_functor_traits > > +{ enum { Cost = 0, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = ei_functor_traits::Cost + ei_functor_traits::Cost, IsVectorizable = false }; }; + +template +struct ei_functor_traits > +{ enum { Cost = ei_functor_traits::Cost + ei_functor_traits::Cost + ei_functor_traits::Cost, IsVectorizable = false }; }; + +#endif // EIGEN_STDEXT_SUPPORT + +#endif // EIGEN_ARRAY_FUNCTORS_H diff --git a/Eigen/src/Array/PartialRedux.h b/Eigen/src/Array/PartialRedux.h new file mode 100644 index 000000000..6b33caaa9 --- /dev/null +++ b/Eigen/src/Array/PartialRedux.h @@ -0,0 +1,126 @@ +// 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_PARTIAL_REDUX_H +#define EIGEN_PARTIAL_REDUX_H + +/** \class PartialRedux + * + * \brief Generic expression of a partially reduxed matrix + * + * \param Direction indicates the direction of the redux (Vertical or Horizontal) + * \param BinaryOp type of the binary functor implementing the operator (must be associative) + * \param MatrixType the type of the matrix we are applying the redux operation + * + * This class represents an expression of a partial redux operator of a matrix. + * It is the return type of MatrixBase::verticalRedux(), MatrixBase::horizontalRedux(), + * and most of the time this is the only way it is used. + * + * \sa class CwiseBinaryOp + */ +template +struct ei_traits > +{ + typedef typename ei_result_of< + BinaryOp(typename MatrixType::Scalar) + >::type Scalar; + 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 = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic) + ? (unsigned int)_MatrixTypeNested::Flags + : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits, + TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, + CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost + + (TraversalSize - 1) * ei_functor_traits::Cost + }; +}; + +template +class PartialRedux : ei_no_assignment_operator, + public MatrixBase > +{ + public: + + EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux) + 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) {} + + private: + + int _rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } + int _cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } + + const Scalar _coeff(int i, int j) const + { + if (Direction==Vertical) + return m_matrix.col(j).redux(m_functor); + else + return m_matrix.row(i).redux(m_functor); + } + + protected: + const MatrixTypeNested m_matrix; + const BinaryOp m_functor; +}; + +/** \returns a row vector expression of *this vertically reduxed by \a func + * + * The template parameter \a BinaryOp is the type of the functor + * of the custom redux operator. Note that func must be an associative operator. + * + * \sa class PartialRedux, MatrixBase::horizontalRedux() + */ +template +template +const PartialRedux +MatrixBase::verticalRedux(const BinaryOp& func) const +{ + return PartialRedux(derived(), func); +} + +/** \returns a row vector expression of *this horizontally reduxed by \a func + * + * The template parameter \a BinaryOp is the type of the functor + * of the custom redux operator. Note that func must be an associative operator. + * + * \sa class PartialRedux, MatrixBase::verticalRedux() + */ +template +template +const PartialRedux +MatrixBase::horizontalRedux(const BinaryOp& func) const +{ + return PartialRedux(derived(), func); +} + +#endif // EIGEN_PARTIAL_REDUX_H diff --git a/Eigen/src/Array/Random.h b/Eigen/src/Array/Random.h new file mode 100644 index 000000000..2e19e1ff0 --- /dev/null +++ b/Eigen/src/Array/Random.h @@ -0,0 +1,111 @@ +// 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 +// +// 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 + +template struct ei_scalar_random_op EIGEN_EMPTY_STRUCT { + inline ei_scalar_random_op(void) {} + inline const Scalar operator() (int, int) const { return ei_random(); } +}; +template +struct ei_functor_traits > +{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false, IsRepeatable = false }; }; + +/** \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 +inline const CwiseNullaryOp::Scalar>, Derived> +MatrixBase::random(int rows, int cols) +{ + return create(rows, cols, ei_scalar_random_op()); +} + +/** \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 +inline const CwiseNullaryOp::Scalar>, Derived> +MatrixBase::random(int size) +{ + return create(size, ei_scalar_random_op()); +} + +/** \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 +inline const CwiseNullaryOp::Scalar>, Derived> +MatrixBase::random() +{ + return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op()); +} + +/** Sets all coefficients in this expression to random values. + * + * Example: \include MatrixBase_setRandom.cpp + * Output: \verbinclude MatrixBase_setRandom.out + * + * \sa class CwiseNullaryOp, ei_random() + */ +template +inline Derived& MatrixBase::setRandom() +{ + return *this = random(rows(), cols()); +} + +#endif // EIGEN_RANDOM_H diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index c514e2169..6b532dbd7 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -231,76 +231,4 @@ MatrixBase::cwise(const MatrixBase &other, const CustomBi return CwiseBinaryOp(derived(), other.derived(), func); } -/** \returns an expression of the coefficient-wise \< operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseLessThan(const MatrixBase &other) const -{ - return cwise(other, std::less()); -} - -/** \returns an expression of the coefficient-wise \<= operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseLessEqual(const MatrixBase &other) const -{ - return cwise(other, std::less_equal()); -} - -/** \returns an expression of the coefficient-wise \> operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseGreaterThan(const MatrixBase &other) const -{ - return cwise(other, std::greater()); -} - -/** \returns an expression of the coefficient-wise \>= operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseGreaterEqual(const MatrixBase &other) const -{ - return cwise(other, std::greater_equal()); -} - -/** \returns an expression of the coefficient-wise == operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseEqualTo(const MatrixBase &other) const -{ - return cwise(other, std::equal_to()); -} - -/** \returns an expression of the coefficient-wise != operator of *this and \a other - * - * \sa class CwiseBinaryOp - */ -template -template -inline const CwiseBinaryOp::Scalar>, Derived, OtherDerived> -MatrixBase::cwiseNotEqualTo(const MatrixBase &other) const -{ - return cwise(other, std::not_equal_to()); -} - #endif // EIGEN_CWISE_BINARY_OP_H diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 009d89dec..1e1ed78a5 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -424,83 +424,6 @@ Derived& MatrixBase::setOnes() return setConstant(Scalar(1)); } -// random: - -/** \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 -inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::random(int rows, int cols) -{ - return create(rows, cols, ei_scalar_random_op()); -} - -/** \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 -inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::random(int size) -{ - return create(size, ei_scalar_random_op()); -} - -/** \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 -inline const CwiseNullaryOp::Scalar>, Derived> -MatrixBase::random() -{ - return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op()); -} - -/** Sets all coefficients in this expression to random values. - * - * Example: \include MatrixBase_setRandom.cpp - * Output: \verbinclude MatrixBase_setRandom.out - * - * \sa class CwiseNullaryOp, ei_random() - */ -template -inline Derived& MatrixBase::setRandom() -{ - return *this = random(rows(), cols()); -} - // Identity: /** \returns an expression of the identity matrix (not necessarily square). diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index e2ae35b3d..893c8abf6 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -196,53 +196,4 @@ MatrixBase::operator/=(const Scalar& other) return *this = *this / other; } -/** \returns an expression of the coefficient-wise square root of *this. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwiseSqrt() const -{ - return derived(); -} - -/** \returns an expression of the coefficient-wise exponential of *this. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwiseExp() const -{ - return derived(); -} - -/** \returns an expression of the coefficient-wise logarithm of *this. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwiseLog() const -{ - return derived(); -} - -/** \returns an expression of the coefficient-wise cosine of *this. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwiseCos() const -{ - return derived(); -} - -/** \returns an expression of the coefficient-wise sine of *this. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwiseSin() const -{ - return derived(); -} - -/** \returns an expression of the coefficient-wise power of *this to the given exponent. */ -template -inline const CwiseUnaryOp::Scalar>, Derived> -MatrixBase::cwisePow(const Scalar& exponent) const -{ - return CwiseUnaryOp, Derived> - (derived(), ei_scalar_pow_op(exponent)); -} - #endif // EIGEN_CWISE_UNARY_OP_H diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 8472081a0..6a4a1213d 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -266,81 +266,6 @@ struct ei_scalar_quotient1_op : ei_scalar_quotient1_impl::HasFloatingPoint >(other) {} }; -/** \internal - * \brief Template functor to compute the square root of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::cwiseSqrt() - */ -template struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT { - inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); } -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - -/** \internal - * \brief Template functor to compute the exponential of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::cwiseExp() - */ -template struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT { - inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); } -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - -/** \internal - * \brief Template functor to compute the logarithm of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::cwiseLog() - */ -template struct ei_scalar_log_op EIGEN_EMPTY_STRUCT { - inline const Scalar operator() (const Scalar& a) const { return ei_log(a); } -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - -/** \internal - * \brief Template functor to compute the cosine of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::cwiseCos() - */ -template struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT { - inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); } -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - -/** \internal - * \brief Template functor to compute the sine of a scalar - * - * \sa class CwiseUnaryOp, MatrixBase::cwiseSin() - */ -template struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT { - inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); } -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - -/** \internal - * \brief Template functor to raise a scalar to a power - * - * \sa class CwiseUnaryOp, MatrixBase::cwisePow - */ -template -struct ei_scalar_pow_op { - inline ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} - inline Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); } - const Scalar m_exponent; -}; -template -struct ei_functor_traits > -{ enum { Cost = 5 * NumTraits::MulCost, IsVectorizable = false }; }; - // nullary functors template::size)>1?true:false) > struct ei_scalar_constant_op; @@ -364,16 +289,6 @@ 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 { - inline ei_scalar_random_op(void) {} - inline const 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 { inline ei_scalar_identity_op(void) {} inline const Scalar operator() (int row, int col) const { return row==col ? Scalar(1) : Scalar(0); } @@ -382,106 +297,4 @@ template struct ei_functor_traits > { enum { Cost = NumTraits::AddCost, IsVectorizable = false, IsRepeatable = true }; }; -// default ei_functor_traits for STL functors: - -template -struct ei_functor_traits > -{ enum { Cost = NumTraits::MulCost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = NumTraits::MulCost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = NumTraits::AddCost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = ei_functor_traits::Cost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = ei_functor_traits::Cost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1 + ei_functor_traits::Cost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 1 + ei_functor_traits::Cost, IsVectorizable = false }; }; - -#ifdef EIGEN_STDEXT_SUPPORT - -template -struct ei_functor_traits > -{ enum { Cost = 0, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = 0, IsVectorizable = false }; }; - -template -struct ei_functor_traits > > -{ enum { Cost = 0, IsVectorizable = false }; }; - -template -struct ei_functor_traits > > -{ enum { Cost = 0, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = ei_functor_traits::Cost + ei_functor_traits::Cost, IsVectorizable = false }; }; - -template -struct ei_functor_traits > -{ enum { Cost = ei_functor_traits::Cost + ei_functor_traits::Cost + ei_functor_traits::Cost, IsVectorizable = false }; }; - -#endif // EIGEN_STDEXT_SUPPORT - #endif // EIGEN_FUNCTORS_H diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 62e8e1057..fc1d524bd 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -395,9 +395,6 @@ template class MatrixBase : public ArrayBase static const CwiseNullaryOp create(const CustomNullaryOp& func); - static const CwiseNullaryOp,Derived> random(int rows, int cols); - static const CwiseNullaryOp,Derived> random(int size); - static const CwiseNullaryOp,Derived> random(); static const ConstantReturnType zero(int rows, int cols); static const ConstantReturnType zero(int size); static const ConstantReturnType zero(); @@ -497,6 +494,57 @@ template class MatrixBase : public ArrayBase const CwiseBinaryOp::Scalar>, Derived, OtherDerived> cwiseMax(const MatrixBase &other) const; + const CwiseUnaryOp::Scalar>, Derived> cwiseAbs() const; + const CwiseUnaryOp::Scalar>, Derived> cwiseAbs2() const; + + template + const CwiseUnaryOp cwise(const CustomUnaryOp& func = CustomUnaryOp()) const; + + template + const CwiseBinaryOp + cwise(const MatrixBase &other, const CustomBinaryOp& func = CustomBinaryOp()) const; + //@} + + /// \name Redux and visitor + //@{ + Scalar sum() const; + Scalar trace() const; + + typename ei_traits::Scalar minCoeff() const; + typename ei_traits::Scalar maxCoeff() const; + + typename ei_traits::Scalar minCoeff(int* row, int* col = 0) const; + typename ei_traits::Scalar maxCoeff(int* row, int* col = 0) const; + + template + typename ei_result_of::Scalar)>::type + redux(const BinaryOp& func) const; + + template + void visit(Visitor& func) const; + //@} + + /// \name Casting to the derived type + //@{ + inline const Derived& derived() const { return *static_cast(this); } + inline Derived& derived() { return *static_cast(this); } + inline Derived& const_cast_derived() const + { return *static_cast(const_cast(this)); } + //@} + + /** \name Array module + * + * \code #include \endcode + */ + //@{ + const CwiseUnaryOp::Scalar>, Derived> cwiseSqrt() const; + const CwiseUnaryOp::Scalar>, Derived> cwiseExp() const; + const CwiseUnaryOp::Scalar>, Derived> cwiseLog() const; + const CwiseUnaryOp::Scalar>, Derived> cwiseCos() const; + const CwiseUnaryOp::Scalar>, Derived> cwiseSin() const; + const CwiseUnaryOp::Scalar>, Derived> + cwisePow(const Scalar& exponent) const; + template const CwiseBinaryOp::Scalar>, Derived, OtherDerived> cwiseLessThan(const MatrixBase &other) const; @@ -521,35 +569,6 @@ template class MatrixBase : public ArrayBase const CwiseBinaryOp::Scalar>, Derived, OtherDerived> cwiseNotEqualTo(const MatrixBase &other) const; - const CwiseUnaryOp::Scalar>, Derived> cwiseAbs() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseAbs2() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseSqrt() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseExp() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseLog() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseCos() const; - const CwiseUnaryOp::Scalar>, Derived> cwiseSin() const; - const CwiseUnaryOp::Scalar>, Derived> - cwisePow(const Scalar& exponent) const; - - template - const CwiseUnaryOp cwise(const CustomUnaryOp& func = CustomUnaryOp()) const; - - template - const CwiseBinaryOp - cwise(const MatrixBase &other, const CustomBinaryOp& func = CustomBinaryOp()) const; - //@} - - /// \name Redux and visitor - //@{ - Scalar sum() const; - Scalar trace() const; - - typename ei_traits::Scalar minCoeff() const; - typename ei_traits::Scalar maxCoeff() const; - - typename ei_traits::Scalar minCoeff(int* row, int* col = 0) const; - typename ei_traits::Scalar maxCoeff(int* row, int* col = 0) const; - bool all(void) const; bool any(void) const; @@ -561,20 +580,9 @@ template class MatrixBase : public ArrayBase const PartialRedux horizontalRedux(const BinaryOp& func) const; - template - typename ei_result_of::Scalar)>::type - redux(const BinaryOp& func) const; - - template - void visit(Visitor& func) const; - //@} - - /// \name Casting to the derived type - //@{ - inline const Derived& derived() const { return *static_cast(this); } - inline Derived& derived() { return *static_cast(this); } - inline Derived& const_cast_derived() const - { return *static_cast(const_cast(this)); } + static const CwiseNullaryOp,Derived> random(int rows, int cols); + static const CwiseNullaryOp,Derived> random(int size); + static const CwiseNullaryOp,Derived> random(); //@} /** \name LU module diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index aaf1843d9..7c5534154 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -66,105 +66,6 @@ struct ei_redux_unroller static Scalar run(const Derived&, const BinaryOp&) { return Scalar(); } }; - -/** \class PartialRedux - * - * \brief Generic expression of a partially reduxed matrix - * - * \param Direction indicates the direction of the redux (Vertical or Horizontal) - * \param BinaryOp type of the binary functor implementing the operator (must be associative) - * \param MatrixType the type of the matrix we are applying the redux operation - * - * This class represents an expression of a partial redux operator of a matrix. - * It is the return type of MatrixBase::verticalRedux(), MatrixBase::horizontalRedux(), - * and most of the time this is the only way it is used. - * - * \sa class CwiseBinaryOp - */ -template -struct ei_traits > -{ - typedef typename ei_result_of< - BinaryOp(typename MatrixType::Scalar) - >::type Scalar; - 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 = ((int(RowsAtCompileTime) == Dynamic || int(ColsAtCompileTime) == Dynamic) - ? (unsigned int)_MatrixTypeNested::Flags - : (unsigned int)_MatrixTypeNested::Flags & ~LargeBit) & HereditaryBits, - TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime, - CoeffReadCost = TraversalSize * _MatrixTypeNested::CoeffReadCost - + (TraversalSize - 1) * ei_functor_traits::Cost - }; -}; - -template -class PartialRedux : ei_no_assignment_operator, - public MatrixBase > -{ - public: - - EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux) - 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) {} - - private: - - int _rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } - int _cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } - - const Scalar _coeff(int i, int j) const - { - if (Direction==Vertical) - return m_matrix.col(j).redux(m_functor); - else - return m_matrix.row(i).redux(m_functor); - } - - protected: - const MatrixTypeNested m_matrix; - const BinaryOp m_functor; -}; - -/** \returns a row vector expression of *this vertically reduxed by \a func - * - * The template parameter \a BinaryOp is the type of the functor - * of the custom redux operator. Note that func must be an associative operator. - * - * \sa class PartialRedux, MatrixBase::horizontalRedux() - */ -template -template -const PartialRedux -MatrixBase::verticalRedux(const BinaryOp& func) const -{ - return PartialRedux(derived(), func); -} - -/** \returns a row vector expression of *this horizontally reduxed by \a func - * - * The template parameter \a BinaryOp is the type of the functor - * of the custom redux operator. Note that func must be an associative operator. - * - * \sa class PartialRedux, MatrixBase::verticalRedux() - */ -template -template -const PartialRedux -MatrixBase::horizontalRedux(const BinaryOp& func) const -{ - return PartialRedux(derived(), func); -} - - /** \returns the result of a full redux operation on the whole matrix or vector using \a func * * The template parameter \a BinaryOp is the type of the functor \a func which must be @@ -239,102 +140,4 @@ inline MatrixBase::maxCoeff() const return this->redux(Eigen::ei_scalar_max_op()); } - - -template -struct ei_all_unroller -{ - enum { - col = (UnrollCount-1) / Derived::RowsAtCompileTime, - row = (UnrollCount-1) % Derived::RowsAtCompileTime - }; - - inline static bool run(const Derived &mat) - { - return ei_all_unroller::run(mat) && mat.coeff(row, col); - } -}; - -template -struct ei_all_unroller -{ - inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } -}; - -template -struct ei_all_unroller -{ - inline static bool run(const Derived &) { return false; } -}; - -template -struct ei_any_unroller -{ - enum { - col = (UnrollCount-1) / Derived::RowsAtCompileTime, - row = (UnrollCount-1) % Derived::RowsAtCompileTime - }; - - inline static bool run(const Derived &mat) - { - return ei_any_unroller::run(mat) || mat.coeff(row, col); - } -}; - -template -struct ei_any_unroller -{ - inline static bool run(const Derived &mat) { return mat.coeff(0, 0); } -}; - -template -struct ei_any_unroller -{ - inline static bool run(const Derived &) { return false; } -}; - -/** \returns true if all coefficients are true - * - * \sa MatrixBase::any() - */ -template -bool MatrixBase::all(void) const -{ - const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) - <= EIGEN_UNROLLING_LIMIT; - if(unroll) - return ei_all_unroller::run(derived()); - else - { - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if (!coeff(i, j)) return false; - return true; - } -} - -/** \returns true if at least one coefficient is true - * - * \sa MatrixBase::any() - */ -template -bool MatrixBase::any(void) const -{ - const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits::AddCost) - <= EIGEN_UNROLLING_LIMIT; - if(unroll) - return ei_any_unroller::run(derived()); - else - { - for(int j = 0; j < cols(); j++) - for(int i = 0; i < rows(); i++) - if (coeff(i, j)) return true; - return false; - } -} - #endif // EIGEN_REDUX_H diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index b9bc72efc..cc759ddea 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -50,7 +50,7 @@ template class Map; template class PartialRedux; template class Part; template class Extract; -template::Flags) & ArrayBit> class ArrayBase; +template::Flags) & ArrayBit> class ArrayBase {}; template struct ei_scalar_sum_op; @@ -72,6 +72,7 @@ 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_scalar_random_op; template class Inverse; template class QR; diff --git a/test/cwiseop.cpp b/test/cwiseop.cpp index b8b7c44eb..43308a8b7 100644 --- a/test/cwiseop.cpp +++ b/test/cwiseop.cpp @@ -25,6 +25,7 @@ #include "main.h" #include +#include using namespace std; diff --git a/test/main.h b/test/main.h index 3fff90b79..88e7f9123 100644 --- a/test/main.h +++ b/test/main.h @@ -137,6 +137,10 @@ namespace Eigen #define EIGEN_INTERNAL_DEBUGGING #include +namespace Eigen { +#include +} + #define VERIFY(a) do { if (!(a)) { \ std::cerr << "Test " << g_test_stack.back() << " failed in "EI_PP_MAKE_STRING(__FILE__) << " (" << EI_PP_MAKE_STRING(__LINE__) << ")" \ << std::endl << " " << EI_PP_MAKE_STRING(a) << std::endl << std::endl; \