aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-05-31 18:11:48 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-05-31 18:11:48 +0000
commit310f7aa09622e8e549b4e14cc3659e22bb02d915 (patch)
tree1d1c22bf1801a731b8d4bf7cb84443376660ea08 /Eigen
parenta2f71f9d7e1e443814fe60726d99a4b0508baefa (diff)
moved purely "array" related stuff to a new module Array.
This include: - cwise Pow,Sin,Cos,Exp... - cwise Greater and other comparison operators - .any(), .all() and partial reduction - random
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/Array17
-rw-r--r--Eigen/Core1
-rw-r--r--Eigen/src/Array/AllAndAny.h124
-rw-r--r--Eigen/src/Array/ArrayBase.h (renamed from Eigen/src/Core/ArrayBase.h)2
-rw-r--r--Eigen/src/Array/CMakeLists.txt6
-rw-r--r--Eigen/src/Array/CwiseOperators.h153
-rw-r--r--Eigen/src/Array/Functors.h205
-rw-r--r--Eigen/src/Array/PartialRedux.h126
-rw-r--r--Eigen/src/Array/Random.h111
-rw-r--r--Eigen/src/Core/CwiseBinaryOp.h72
-rw-r--r--Eigen/src/Core/CwiseNullaryOp.h77
-rw-r--r--Eigen/src/Core/CwiseUnaryOp.h49
-rw-r--r--Eigen/src/Core/Functors.h187
-rw-r--r--Eigen/src/Core/MatrixBase.h98
-rw-r--r--Eigen/src/Core/Redux.h197
-rw-r--r--Eigen/src/Core/util/ForwardDeclarations.h3
16 files changed, 797 insertions, 631 deletions
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 <g.gael@free.fr>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#ifndef EIGEN_ALLANDANY_H
+#define EIGEN_ALLANDANY_H
+
+template<typename Derived, int UnrollCount>
+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<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
+ }
+};
+
+template<typename Derived>
+struct ei_all_unroller<Derived, 1>
+{
+ inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
+};
+
+template<typename Derived>
+struct ei_all_unroller<Derived, Dynamic>
+{
+ inline static bool run(const Derived &) { return false; }
+};
+
+template<typename Derived, int UnrollCount>
+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<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
+ }
+};
+
+template<typename Derived>
+struct ei_any_unroller<Derived, 1>
+{
+ inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
+};
+
+template<typename Derived>
+struct ei_any_unroller<Derived, Dynamic>
+{
+ inline static bool run(const Derived &) { return false; }
+};
+
+/** \returns true if all coefficients are true
+ *
+ * \sa MatrixBase::any()
+ */
+template<typename Derived>
+bool MatrixBase<Derived>::all(void) const
+{
+ const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
+ <= EIGEN_UNROLLING_LIMIT;
+ if(unroll)
+ return ei_all_unroller<Derived,
+ unroll ? int(SizeAtCompileTime) : Dynamic
+ >::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<typename Derived>
+bool MatrixBase<Derived>::any(void) const
+{
+ const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
+ <= EIGEN_UNROLLING_LIMIT;
+ if(unroll)
+ return ei_any_unroller<Derived,
+ unroll ? int(SizeAtCompileTime) : Dynamic
+ >::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
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<typename Derived> class ArrayBase<Derived,false> {};
-
template<typename Derived> class ArrayBase<Derived,true>
{
inline const Derived& derived() const { return *static_cast<const Derived*>(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 <g.gael@free.fr>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#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<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_sqrt_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwiseSqrt() const
+{
+ return derived();
+}
+
+/** \returns an expression of the coefficient-wise exponential of *this. */
+template<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_exp_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwiseExp() const
+{
+ return derived();
+}
+
+/** \returns an expression of the coefficient-wise logarithm of *this. */
+template<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_log_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwiseLog() const
+{
+ return derived();
+}
+
+/** \returns an expression of the coefficient-wise cosine of *this. */
+template<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_cos_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwiseCos() const
+{
+ return derived();
+}
+
+/** \returns an expression of the coefficient-wise sine of *this. */
+template<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwiseSin() const
+{
+ return derived();
+}
+
+/** \returns an expression of the coefficient-wise power of *this to the given exponent. */
+template<typename Derived>
+inline const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::cwisePow(const Scalar& exponent) const
+{
+ return CwiseUnaryOp<ei_scalar_pow_op<Scalar>, Derived>
+ (derived(), ei_scalar_pow_op<Scalar>(exponent));
+}
+
+// -- binary operators --
+
+/** \returns an expression of the coefficient-wise \< operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseLessThan(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::less<Scalar>());
+}
+
+/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::less_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseLessEqual(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::less_equal<Scalar>());
+}
+
+/** \returns an expression of the coefficient-wise \> operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::greater<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseGreaterThan(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::greater<Scalar>());
+}
+
+/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::greater_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseGreaterEqual(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::greater_equal<Scalar>());
+}
+
+/** \returns an expression of the coefficient-wise == operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseEqualTo(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::equal_to<Scalar>());
+}
+
+/** \returns an expression of the coefficient-wise != operator of *this and \a other
+ *
+ * \sa class CwiseBinaryOp
+ */
+template<typename Derived>
+template<typename OtherDerived>
+inline const CwiseBinaryOp<std::not_equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+MatrixBase<Derived>::cwiseNotEqualTo(const MatrixBase<OtherDerived> &other) const
+{
+ return cwise(other, std::not_equal_to<Scalar>());
+}
+
+#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 <g.gael@free.fr>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#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<typename Scalar> struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT {
+ inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_sqrt_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+/** \internal
+ * \brief Template functor to compute the exponential of a scalar
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cwiseExp()
+ */
+template<typename Scalar> struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT {
+ inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_exp_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+/** \internal
+ * \brief Template functor to compute the logarithm of a scalar
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cwiseLog()
+ */
+template<typename Scalar> struct ei_scalar_log_op EIGEN_EMPTY_STRUCT {
+ inline const Scalar operator() (const Scalar& a) const { return ei_log(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_log_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+/** \internal
+ * \brief Template functor to compute the cosine of a scalar
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cwiseCos()
+ */
+template<typename Scalar> struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT {
+ inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_cos_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+/** \internal
+ * \brief Template functor to compute the sine of a scalar
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cwiseSin()
+ */
+template<typename Scalar> struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT {
+ inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_sin_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+/** \internal
+ * \brief Template functor to raise a scalar to a power
+ *
+ * \sa class CwiseUnaryOp, MatrixBase::cwisePow
+ */
+template<typename Scalar>
+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<typename Scalar>
+struct ei_functor_traits<ei_scalar_pow_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
+
+// default ei_functor_traits for STL functors:
+
+template<typename T>
+struct ei_functor_traits<std::multiplies<T> >
+{ enum { Cost = NumTraits<T>::MulCost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::divides<T> >
+{ enum { Cost = NumTraits<T>::MulCost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::plus<T> >
+{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::minus<T> >
+{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::negate<T> >
+{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::logical_or<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::logical_and<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::logical_not<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::greater<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::less<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::greater_equal<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::less_equal<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::equal_to<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::not_equal_to<T> >
+{ enum { Cost = 1, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::binder2nd<T> >
+{ enum { Cost = ei_functor_traits<T>::Cost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::binder1st<T> >
+{ enum { Cost = ei_functor_traits<T>::Cost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::unary_negate<T> >
+{ enum { Cost = 1 + ei_functor_traits<T>::Cost, IsVectorizable = false }; };
+
+template<typename T>
+struct ei_functor_traits<std::binary_negate<T> >
+{ enum { Cost = 1 + ei_functor_traits<T>::Cost, IsVectorizable = false }; };
+
+#ifdef EIGEN_STDEXT_SUPPORT
+
+template<typename T0,typename T1>
+struct ei_functor_traits<std::project1st<T0,T1> >
+{ enum { Cost = 0, IsVectorizable = false }; };
+
+template<typename T0,typename T1>
+struct ei_functor_traits<std::project2nd<T0,T1> >
+{ enum { Cost = 0, IsVectorizable = false }; };
+
+template<typename T0,typename T1>
+struct ei_functor_traits<std::select2nd<std::pair<T0,T1> > >
+{ enum { Cost = 0, IsVectorizable = false }; };
+
+template<typename T0,typename T1>
+struct ei_functor_traits<std::select1st<std::pair<T0,T1> > >
+{ enum { Cost = 0, IsVectorizable = false }; };
+
+template<typename T0,typename T1>
+struct ei_functor_traits<std::unary_compose<T0,T1> >
+{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost, IsVectorizable = false }; };
+
+template<typename T0,typename T1,typename T2>
+struct ei_functor_traits<std::binary_compose<T0,T1,T2> >
+{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost + ei_functor_traits<T2>::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 <g.gael@free.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#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<int Direction, typename BinaryOp, typename MatrixType>
+struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
+{
+ typedef typename ei_result_of<
+ BinaryOp(typename MatrixType::Scalar)
+ >::type Scalar;
+ typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
+ typedef typename ei_unref<MatrixTypeNested>::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<BinaryOp>::Cost
+ };
+};
+
+template<int Direction, typename BinaryOp, typename MatrixType>
+class PartialRedux : ei_no_assignment_operator,
+ public MatrixBase<PartialRedux<Direction, BinaryOp, MatrixType> >
+{
+ public:
+
+ EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux)
+ typedef typename ei_traits<PartialRedux>::MatrixTypeNested MatrixTypeNested;
+ typedef typename ei_traits<PartialRedux>::_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<typename Derived>
+template<typename BinaryOp>
+const PartialRedux<Vertical, BinaryOp, Derived>
+MatrixBase<Derived>::verticalRedux(const BinaryOp& func) const
+{
+ return PartialRedux<Vertical, BinaryOp, Derived>(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<typename Derived>
+template<typename BinaryOp>
+const PartialRedux<Horizontal, BinaryOp, Derived>
+MatrixBase<Derived>::horizontalRedux(const BinaryOp& func) const
+{
+ return PartialRedux<Horizontal, BinaryOp, Derived>(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 <g.gael@free.fr>
+//
+// 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 <http://www.gnu.org/licenses/>.
+
+#ifndef EIGEN_RANDOM_H
+#define EIGEN_RANDOM_H
+
+template<typename Scalar> struct ei_scalar_random_op EIGEN_EMPTY_STRUCT {
+ inline ei_scalar_random_op(void) {}
+ inline const Scalar operator() (int, int) const { return ei_random<Scalar>(); }
+};
+template<typename Scalar>
+struct ei_functor_traits<ei_scalar_random_op<Scalar> >
+{ enum { Cost = 5 * NumTraits<Scalar>::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<typename Derived>
+inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::random(int rows, int cols)
+{
+ return create(rows, cols, ei_scalar_random_op<Scalar>());
+}
+
+/** \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<typename Derived>
+inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::random(int size)
+{
+ return create(size, ei_scalar_random_op<Scalar>());
+}
+
+/** \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<typename Derived>
+inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
+MatrixBase<Derived>::random()
+{
+ return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>());
+}
+
+/** 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<typename Derived>
+inline Derived& MatrixBase<Derived>::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<Derived>::cwise(const MatrixBase<OtherDerived> &other, const CustomBi
return CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived>(derived(), other.derived(), func);
}
-/** \returns an expression of the coefficient-wise \< operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseLessThan(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::less<Scalar>());
-}
-
-/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::less_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseLessEqual(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::less_equal<Scalar>());
-}
-
-/** \returns an expression of the coefficient-wise \> operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::greater<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseGreaterThan(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::greater<Scalar>());
-}
-
-/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::greater_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseGreaterEqual(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::greater_equal<Scalar>());
-}
-
-/** \returns an expression of the coefficient-wise == operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseEqualTo(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::equal_to<Scalar>());
-}
-
-/** \returns an expression of the coefficient-wise != operator of *this and \a other
- *
- * \sa class CwiseBinaryOp
- */
-template<typename Derived>
-template<typename OtherDerived>
-inline const CwiseBinaryOp<std::not_equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
-MatrixBase<Derived>::cwiseNotEqualTo(const MatrixBase<OtherDerived> &other) const
-{
- return cwise(other, std::not_equal_to<Scalar>());
-}
-
#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<Derived>::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<typename Derived>
-inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::random(int rows, int cols)
-{
- return create(rows, cols, ei_scalar_random_op<Scalar>());
-}
-
-/** \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<typename Derived>
-inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::random(int size)
-{
- return create(size, ei_scalar_random_op<Scalar>());
-}
-
-/** \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<typename Derived>
-inline const CwiseNullaryOp<ei_scalar_random_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::random()
-{
- return create(RowsAtCompileTime, ColsAtCompileTime, ei_scalar_random_op<Scalar>());
-}
-
-/** 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<typename Derived>
-inline Derived& MatrixBase<Derived>::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<Derived>::operator/=(const Scalar& other)
return *this = *this / other;
}
-/** \returns an expression of the coefficient-wise square root of *this. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_sqrt_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwiseSqrt() const
-{
- return derived();
-}
-
-/** \returns an expression of the coefficient-wise exponential of *this. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_exp_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwiseExp() const
-{
- return derived();
-}
-
-/** \returns an expression of the coefficient-wise logarithm of *this. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_log_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwiseLog() const
-{
- return derived();
-}
-
-/** \returns an expression of the coefficient-wise cosine of *this. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_cos_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwiseCos() const
-{
- return derived();
-}
-
-/** \returns an expression of the coefficient-wise sine of *this. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwiseSin() const
-{
- return derived();
-}
-
-/** \returns an expression of the coefficient-wise power of *this to the given exponent. */
-template<typename Derived>
-inline const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
-MatrixBase<Derived>::cwisePow(const Scalar& exponent) const
-{
- return CwiseUnaryOp<ei_scalar_pow_op<Scalar>, Derived>
- (derived(), ei_scalar_pow_op<Scalar>(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<Scalar, NumTraits<Scala
: ei_scalar_quotient1_impl<Scalar, NumTraits<Scalar>::HasFloatingPoint >(other) {}
};
-/** \internal
- * \brief Template functor to compute the square root of a scalar
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwiseSqrt()
- */
-template<typename Scalar> struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT {
- inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_sqrt_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
-/** \internal
- * \brief Template functor to compute the exponential of a scalar
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwiseExp()
- */
-template<typename Scalar> struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT {
- inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_exp_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
-/** \internal
- * \brief Template functor to compute the logarithm of a scalar
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwiseLog()
- */
-template<typename Scalar> struct ei_scalar_log_op EIGEN_EMPTY_STRUCT {
- inline const Scalar operator() (const Scalar& a) const { return ei_log(a); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_log_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
-/** \internal
- * \brief Template functor to compute the cosine of a scalar
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwiseCos()
- */
-template<typename Scalar> struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT {
- inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_cos_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
-/** \internal
- * \brief Template functor to compute the sine of a scalar
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwiseSin()
- */
-template<typename Scalar> struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT {
- inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_sin_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
-/** \internal
- * \brief Template functor to raise a scalar to a power
- *
- * \sa class CwiseUnaryOp, MatrixBase::cwisePow
- */
-template<typename Scalar>
-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<typename Scalar>
-struct ei_functor_traits<ei_scalar_pow_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false }; };
-
// nullary functors
template<typename Scalar, bool IsVectorizable = (int(ei_packet_traits<Scalar>::size)>1?true:false) > struct ei_scalar_constant_op;
@@ -364,16 +289,6 @@ template<typename Scalar>
struct ei_functor_traits<ei_scalar_constant_op<Scalar> >
{ enum { Cost = 1, IsVectorizable = ei_packet_traits<Scalar>::size>1, IsRepeatable = true }; };
-
-template<typename Scalar> struct ei_scalar_random_op EIGEN_EMPTY_STRUCT {
- inline ei_scalar_random_op(void) {}
- inline const Scalar operator() (int, int) const { return ei_random<Scalar>(); }
-};
-template<typename Scalar>
-struct ei_functor_traits<ei_scalar_random_op<Scalar> >
-{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, IsVectorizable = false, IsRepeatable = false }; };
-
-
template<typename Scalar> 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<typename Scalar>
struct ei_functor_traits<ei_scalar_identity_op<Scalar> >
{ enum { Cost = NumTraits<Scalar>::AddCost, IsVectorizable = false, IsRepeatable = true }; };
-// default ei_functor_traits for STL functors:
-
-template<typename T>
-struct ei_functor_traits<std::multiplies<T> >
-{ enum { Cost = NumTraits<T>::MulCost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::divides<T> >
-{ enum { Cost = NumTraits<T>::MulCost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::plus<T> >
-{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::minus<T> >
-{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::negate<T> >
-{ enum { Cost = NumTraits<T>::AddCost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::logical_or<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::logical_and<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::logical_not<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::greater<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::less<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::greater_equal<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::less_equal<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::equal_to<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::not_equal_to<T> >
-{ enum { Cost = 1, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::binder2nd<T> >
-{ enum { Cost = ei_functor_traits<T>::Cost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::binder1st<T> >
-{ enum { Cost = ei_functor_traits<T>::Cost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::unary_negate<T> >
-{ enum { Cost = 1 + ei_functor_traits<T>::Cost, IsVectorizable = false }; };
-
-template<typename T>
-struct ei_functor_traits<std::binary_negate<T> >
-{ enum { Cost = 1 + ei_functor_traits<T>::Cost, IsVectorizable = false }; };
-
-#ifdef EIGEN_STDEXT_SUPPORT
-
-template<typename T0,typename T1>
-struct ei_functor_traits<std::project1st<T0,T1> >
-{ enum { Cost = 0, IsVectorizable = false }; };
-
-template<typename T0,typename T1>
-struct ei_functor_traits<std::project2nd<T0,T1> >
-{ enum { Cost = 0, IsVectorizable = false }; };
-
-template<typename T0,typename T1>
-struct ei_functor_traits<std::select2nd<std::pair<T0,T1> > >
-{ enum { Cost = 0, IsVectorizable = false }; };
-
-template<typename T0,typename T1>
-struct ei_functor_traits<std::select1st<std::pair<T0,T1> > >
-{ enum { Cost = 0, IsVectorizable = false }; };
-
-template<typename T0,typename T1>
-struct ei_functor_traits<std::unary_compose<T0,T1> >
-{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost, IsVectorizable = false }; };
-
-template<typename T0,typename T1,typename T2>
-struct ei_functor_traits<std::binary_compose<T0,T1,T2> >
-{ enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost + ei_functor_traits<T2>::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<typename Derived> class MatrixBase : public ArrayBase<Derived>
static const CwiseNullaryOp<CustomNullaryOp, Derived>
create(const CustomNullaryOp& func);
- static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int rows, int cols);
- static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int size);
- static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random();
static const ConstantReturnType zero(int rows, int cols);
static const ConstantReturnType zero(int size);
static const ConstantReturnType zero();
@@ -497,39 +494,8 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
const CwiseBinaryOp<ei_scalar_max_op<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
cwiseMax(const MatrixBase<OtherDerived> &other) const;
- template<typename OtherDerived>
- const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseLessThan(const MatrixBase<OtherDerived> &other) const;
-
- template<typename OtherDerived>
- const CwiseBinaryOp<std::less_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseLessEqual(const MatrixBase<OtherDerived> &other) const;
-
- template<typename OtherDerived>
- const CwiseBinaryOp<std::greater<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseGreaterThan(const MatrixBase<OtherDerived> &other) const;
-
- template<typename OtherDerived>
- const CwiseBinaryOp<std::greater_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseGreaterEqual(const MatrixBase<OtherDerived> &other) const;
-
- template<typename OtherDerived>
- const CwiseBinaryOp<std::equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseEqualTo(const MatrixBase<OtherDerived> &other) const;
-
- template<typename OtherDerived>
- const CwiseBinaryOp<std::not_equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
- cwiseNotEqualTo(const MatrixBase<OtherDerived> &other) const;
-
const CwiseUnaryOp<ei_scalar_abs_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseAbs() const;
const CwiseUnaryOp<ei_scalar_abs2_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseAbs2() const;
- const CwiseUnaryOp<ei_scalar_sqrt_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSqrt() const;
- const CwiseUnaryOp<ei_scalar_exp_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseExp() const;
- const CwiseUnaryOp<ei_scalar_log_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseLog() const;
- const CwiseUnaryOp<ei_scalar_cos_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseCos() const;
- const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSin() const;
- const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
- cwisePow(const Scalar& exponent) const;
template<typename CustomUnaryOp>
const CwiseUnaryOp<CustomUnaryOp, Derived> cwise(const CustomUnaryOp& func = CustomUnaryOp()) const;
@@ -550,17 +516,6 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
typename ei_traits<Derived>::Scalar minCoeff(int* row, int* col = 0) const;
typename ei_traits<Derived>::Scalar maxCoeff(int* row, int* col = 0) const;
- bool all(void) const;
- bool any(void) const;
-
- template<typename BinaryOp>
- const PartialRedux<Vertical, BinaryOp, Derived>
- verticalRedux(const BinaryOp& func) const;
-
- template<typename BinaryOp>
- const PartialRedux<Horizontal, BinaryOp, Derived>
- horizontalRedux(const BinaryOp& func) const;
-
template<typename BinaryOp>
typename ei_result_of<BinaryOp(typename ei_traits<Derived>::Scalar)>::type
redux(const BinaryOp& func) const;
@@ -577,6 +532,59 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
{ return *static_cast<Derived*>(const_cast<MatrixBase*>(this)); }
//@}
+ /** \name Array module
+ *
+ * \code #include <Eigen/Array> \endcode
+ */
+ //@{
+ const CwiseUnaryOp<ei_scalar_sqrt_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSqrt() const;
+ const CwiseUnaryOp<ei_scalar_exp_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseExp() const;
+ const CwiseUnaryOp<ei_scalar_log_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseLog() const;
+ const CwiseUnaryOp<ei_scalar_cos_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseCos() const;
+ const CwiseUnaryOp<ei_scalar_sin_op<typename ei_traits<Derived>::Scalar>, Derived> cwiseSin() const;
+ const CwiseUnaryOp<ei_scalar_pow_op<typename ei_traits<Derived>::Scalar>, Derived>
+ cwisePow(const Scalar& exponent) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::less<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseLessThan(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::less_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseLessEqual(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::greater<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseGreaterThan(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::greater_equal<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseGreaterEqual(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseEqualTo(const MatrixBase<OtherDerived> &other) const;
+
+ template<typename OtherDerived>
+ const CwiseBinaryOp<std::not_equal_to<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>
+ cwiseNotEqualTo(const MatrixBase<OtherDerived> &other) const;
+
+ bool all(void) const;
+ bool any(void) const;
+
+ template<typename BinaryOp>
+ const PartialRedux<Vertical, BinaryOp, Derived>
+ verticalRedux(const BinaryOp& func) const;
+
+ template<typename BinaryOp>
+ const PartialRedux<Horizontal, BinaryOp, Derived>
+ horizontalRedux(const BinaryOp& func) const;
+
+ static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int rows, int cols);
+ static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random(int size);
+ static const CwiseNullaryOp<ei_scalar_random_op<Scalar>,Derived> random();
+ //@}
+
/** \name LU module
*
* \code #include <Eigen/LU> \endcode
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<BinaryOp, Derived, Start, Dynamic>
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<int Direction, typename BinaryOp, typename MatrixType>
-struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
-{
- typedef typename ei_result_of<
- BinaryOp(typename MatrixType::Scalar)
- >::type Scalar;
- typedef typename ei_nested<MatrixType>::type MatrixTypeNested;
- typedef typename ei_unref<MatrixTypeNested>::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<BinaryOp>::Cost
- };
-};
-
-template<int Direction, typename BinaryOp, typename MatrixType>
-class PartialRedux : ei_no_assignment_operator,
- public MatrixBase<PartialRedux<Direction, BinaryOp, MatrixType> >
-{
- public:
-
- EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux)
- typedef typename ei_traits<PartialRedux>::MatrixTypeNested MatrixTypeNested;
- typedef typename ei_traits<PartialRedux>::_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<typename Derived>
-template<typename BinaryOp>
-const PartialRedux<Vertical, BinaryOp, Derived>
-MatrixBase<Derived>::verticalRedux(const BinaryOp& func) const
-{
- return PartialRedux<Vertical, BinaryOp, Derived>(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<typename Derived>
-template<typename BinaryOp>
-const PartialRedux<Horizontal, BinaryOp, Derived>
-MatrixBase<Derived>::horizontalRedux(const BinaryOp& func) const
-{
- return PartialRedux<Horizontal, BinaryOp, Derived>(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<Derived>::maxCoeff() const
return this->redux(Eigen::ei_scalar_max_op<Scalar>());
}
-
-
-template<typename Derived, int UnrollCount>
-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<Derived, UnrollCount-1>::run(mat) && mat.coeff(row, col);
- }
-};
-
-template<typename Derived>
-struct ei_all_unroller<Derived, 1>
-{
- inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
-};
-
-template<typename Derived>
-struct ei_all_unroller<Derived, Dynamic>
-{
- inline static bool run(const Derived &) { return false; }
-};
-
-template<typename Derived, int UnrollCount>
-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<Derived, UnrollCount-1>::run(mat) || mat.coeff(row, col);
- }
-};
-
-template<typename Derived>
-struct ei_any_unroller<Derived, 1>
-{
- inline static bool run(const Derived &mat) { return mat.coeff(0, 0); }
-};
-
-template<typename Derived>
-struct ei_any_unroller<Derived, Dynamic>
-{
- inline static bool run(const Derived &) { return false; }
-};
-
-/** \returns true if all coefficients are true
- *
- * \sa MatrixBase::any()
- */
-template<typename Derived>
-bool MatrixBase<Derived>::all(void) const
-{
- const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
- <= EIGEN_UNROLLING_LIMIT;
- if(unroll)
- return ei_all_unroller<Derived,
- unroll ? int(SizeAtCompileTime) : Dynamic
- >::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<typename Derived>
-bool MatrixBase<Derived>::any(void) const
-{
- const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
- <= EIGEN_UNROLLING_LIMIT;
- if(unroll)
- return ei_any_unroller<Derived,
- unroll ? int(SizeAtCompileTime) : Dynamic
- >::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<typename MatrixType> class Map;
template<int Direction, typename UnaryOp, typename MatrixType> class PartialRedux;
template<typename MatrixType, unsigned int Mode> class Part;
template<typename MatrixType, unsigned int Mode> class Extract;
-template<typename Derived, bool HasArrayFlag = int(ei_traits<Derived>::Flags) & ArrayBit> class ArrayBase;
+template<typename Derived, bool HasArrayFlag = int(ei_traits<Derived>::Flags) & ArrayBit> class ArrayBase {};
template<typename Scalar> struct ei_scalar_sum_op;
@@ -72,6 +72,7 @@ template<typename Scalar, bool IsVectorizable> struct ei_scalar_multiple_op;
template<typename Scalar> struct ei_scalar_quotient1_op;
template<typename Scalar> struct ei_scalar_min_op;
template<typename Scalar> struct ei_scalar_max_op;
+template<typename Scalar> struct ei_scalar_random_op;
template<typename ExpressionType, bool CheckExistence = true> class Inverse;
template<typename MatrixType> class QR;