2009-09-16 14:35:42 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-09-16 14:35:42 +02:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2009-09-16 14:35:42 +02:00
|
|
|
|
2010-02-20 15:26:02 +01:00
|
|
|
#ifndef EIGEN_EIGENBASE_H
|
|
|
|
|
#define EIGEN_EIGENBASE_H
|
2009-09-16 14:35:42 +02:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
2009-09-16 14:35:42 +02:00
|
|
|
|
2015-02-13 18:57:41 +01:00
|
|
|
/** \class EigenBase
|
2017-06-09 14:01:44 +02:00
|
|
|
* \ingroup Core_Module
|
2015-02-13 18:57:41 +01:00
|
|
|
*
|
|
|
|
|
* Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T).
|
2009-09-16 14:35:42 +02:00
|
|
|
*
|
2010-02-20 15:26:02 +01:00
|
|
|
* In other words, an EigenBase object is an object that can be copied into a MatrixBase.
|
2009-09-16 14:35:42 +02:00
|
|
|
*
|
|
|
|
|
* Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc.
|
|
|
|
|
*
|
|
|
|
|
* Notice that this class is trivial, it is only used to disambiguate overloaded functions.
|
2010-08-22 18:28:19 +01:00
|
|
|
*
|
2015-12-30 16:45:44 +01:00
|
|
|
* \sa \blank \ref TopicClassHierarchy
|
2009-09-16 14:35:42 +02:00
|
|
|
*/
|
2010-02-20 15:26:02 +01:00
|
|
|
template<typename Derived> struct EigenBase
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
// typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
|
2015-02-13 18:57:41 +01:00
|
|
|
|
|
|
|
|
/** \brief The interface type of indices
|
|
|
|
|
* \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
|
|
|
|
|
* \deprecated Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead.
|
|
|
|
|
* \sa StorageIndex, \ref TopicPreprocessorDirectives.
|
|
|
|
|
*/
|
2019-04-23 17:23:19 -07:00
|
|
|
EIGEN_DEPRECATED typedef Eigen::Index Index;
|
2009-09-16 14:35:42 +02:00
|
|
|
|
2015-02-13 18:57:41 +01:00
|
|
|
// FIXME is it needed?
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
2010-05-30 16:00:58 -04:00
|
|
|
|
2009-12-16 19:18:40 +01:00
|
|
|
/** \returns a reference to the derived object */
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2009-09-16 14:35:42 +02:00
|
|
|
Derived& derived() { return *static_cast<Derived*>(this); }
|
2009-12-16 19:18:40 +01:00
|
|
|
/** \returns a const reference to the derived object */
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2009-09-16 14:35:42 +02:00
|
|
|
const Derived& derived() const { return *static_cast<const Derived*>(this); }
|
|
|
|
|
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2009-12-16 19:18:40 +01:00
|
|
|
inline Derived& const_cast_derived() const
|
2010-02-20 15:26:02 +01:00
|
|
|
{ return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-12-22 17:45:37 -05:00
|
|
|
inline const Derived& const_derived() const
|
|
|
|
|
{ return *static_cast<const Derived*>(this); }
|
2009-12-16 19:18:40 +01:00
|
|
|
|
2009-09-16 14:35:42 +02:00
|
|
|
/** \returns the number of rows. \sa cols(), RowsAtCompileTime */
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-02-13 18:57:41 +01:00
|
|
|
inline Index rows() const { return derived().rows(); }
|
2009-09-16 14:35:42 +02:00
|
|
|
/** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-02-13 18:57:41 +01:00
|
|
|
inline Index cols() const { return derived().cols(); }
|
2010-05-08 13:45:31 -04:00
|
|
|
/** \returns the number of coefficients, which is rows()*cols().
|
|
|
|
|
* \sa rows(), cols(), SizeAtCompileTime. */
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-02-13 18:57:41 +01:00
|
|
|
inline Index size() const { return rows() * cols(); }
|
2009-09-16 14:35:42 +02:00
|
|
|
|
|
|
|
|
/** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */
|
2013-02-07 19:06:14 +01:00
|
|
|
template<typename Dest>
|
|
|
|
|
EIGEN_DEVICE_FUNC
|
|
|
|
|
inline void evalTo(Dest& dst) const
|
2009-09-16 14:35:42 +02:00
|
|
|
{ derived().evalTo(dst); }
|
|
|
|
|
|
|
|
|
|
/** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */
|
2013-02-07 19:06:14 +01:00
|
|
|
template<typename Dest>
|
|
|
|
|
EIGEN_DEVICE_FUNC
|
|
|
|
|
inline void addTo(Dest& dst) const
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
|
|
|
|
// This is the default implementation,
|
|
|
|
|
// derived class can reimplement it in a more optimized way.
|
2010-02-20 15:53:57 +01:00
|
|
|
typename Dest::PlainObject res(rows(),cols());
|
2010-02-15 11:01:55 +01:00
|
|
|
evalTo(res);
|
2009-09-16 14:35:42 +02:00
|
|
|
dst += res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */
|
2013-02-07 19:06:14 +01:00
|
|
|
template<typename Dest>
|
|
|
|
|
EIGEN_DEVICE_FUNC
|
|
|
|
|
inline void subTo(Dest& dst) const
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
|
|
|
|
// This is the default implementation,
|
|
|
|
|
// derived class can reimplement it in a more optimized way.
|
2010-02-20 15:53:57 +01:00
|
|
|
typename Dest::PlainObject res(rows(),cols());
|
2010-02-15 11:01:55 +01:00
|
|
|
evalTo(res);
|
2009-09-16 14:35:42 +02:00
|
|
|
dst -= res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */
|
2013-02-07 19:06:14 +01:00
|
|
|
template<typename Dest>
|
|
|
|
|
EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
|
|
|
|
// This is the default implementation,
|
|
|
|
|
// derived class can reimplement it in a more optimized way.
|
|
|
|
|
dst = dst * this->derived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */
|
2013-02-07 19:06:14 +01:00
|
|
|
template<typename Dest>
|
|
|
|
|
EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
|
|
|
|
// This is the default implementation,
|
|
|
|
|
// derived class can reimplement it in a more optimized way.
|
|
|
|
|
dst = this->derived() * dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* Implementation of matrix base methods
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2010-01-16 15:43:11 +01:00
|
|
|
/** \brief Copies the generic expression \a other into *this.
|
|
|
|
|
*
|
2010-02-15 11:01:55 +01:00
|
|
|
* \details The expression must provide a (templated) evalTo(Derived& dst) const
|
|
|
|
|
* function which does the actual job. In practice, this allows any user to write
|
|
|
|
|
* its own special matrix without having to modify MatrixBase
|
2010-01-16 15:43:11 +01:00
|
|
|
*
|
|
|
|
|
* \returns a reference to *this.
|
|
|
|
|
*/
|
2009-09-16 14:35:42 +02:00
|
|
|
template<typename Derived>
|
|
|
|
|
template<typename OtherDerived>
|
2017-02-27 16:45:31 -08:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-02-20 15:26:02 +01:00
|
|
|
Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other)
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
2014-08-01 16:23:30 +02:00
|
|
|
call_assignment(derived(), other.derived());
|
2009-09-16 14:35:42 +02:00
|
|
|
return derived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
template<typename OtherDerived>
|
2017-02-27 16:45:31 -08:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-02-20 15:26:02 +01:00
|
|
|
Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other)
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
|
2009-09-16 14:35:42 +02:00
|
|
|
return derived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
|
template<typename OtherDerived>
|
2017-02-27 16:45:31 -08:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-02-20 15:26:02 +01:00
|
|
|
Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
|
2009-09-16 14:35:42 +02:00
|
|
|
{
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
|
2009-09-16 14:35:42 +02:00
|
|
|
return derived();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2010-02-20 15:26:02 +01:00
|
|
|
#endif // EIGEN_EIGENBASE_H
|