2009-12-04 23:17:14 +01:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-12-04 23:17:14 +01: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-12-04 23:17:14 +01:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_ARRAYBASE_H
|
|
|
|
|
#define EIGEN_ARRAYBASE_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
template <typename ExpressionType>
|
|
|
|
|
class MatrixWrapper;
|
|
|
|
|
|
2010-06-19 23:00:22 +02:00
|
|
|
/** \class ArrayBase
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2009-12-04 23:17:14 +01:00
|
|
|
*
|
|
|
|
|
* \brief Base class for all 1D and 2D array, and related expressions
|
|
|
|
|
*
|
|
|
|
|
* An array is similar to a dense vector or matrix. While matrices are mathematical
|
|
|
|
|
* objects with well defined linear algebra operators, an array is just a collection
|
2021-09-22 16:15:06 +00:00
|
|
|
* of scalar values arranged in a one or two dimensional fashion. As the main consequence,
|
2010-01-04 19:00:16 +01:00
|
|
|
* all operations applied to an array are performed coefficient wise. Furthermore,
|
|
|
|
|
* arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
|
2009-12-04 23:17:14 +01:00
|
|
|
* constructors allowing to easily write generic code working for both scalar values
|
|
|
|
|
* and arrays.
|
|
|
|
|
*
|
|
|
|
|
* This class is the base that is inherited by all array expression types.
|
|
|
|
|
*
|
2011-02-13 22:50:57 +00:00
|
|
|
* \tparam Derived is the derived type, e.g., an array or an expression type.
|
|
|
|
|
*
|
|
|
|
|
* This class can be extended with the help of the plugin mechanism described on the page
|
2016-08-30 11:10:08 +02:00
|
|
|
* \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
|
2009-12-04 23:17:14 +01:00
|
|
|
*
|
2010-08-22 18:28:19 +01:00
|
|
|
* \sa class MatrixBase, \ref TopicClassHierarchy
|
2009-12-04 23:17:14 +01:00
|
|
|
*/
|
|
|
|
|
template <typename Derived>
|
|
|
|
|
class ArrayBase : public DenseBase<Derived> {
|
|
|
|
|
public:
|
|
|
|
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
/** The base class for a given storage type. */
|
|
|
|
|
typedef ArrayBase StorageBaseType;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2010-04-28 18:51:38 -04:00
|
|
|
typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::traits<Derived>::StorageKind StorageKind;
|
|
|
|
|
typedef typename internal::traits<Derived>::Scalar Scalar;
|
|
|
|
|
typedef typename internal::packet_traits<Scalar>::type PacketScalar;
|
2010-05-30 16:00:58 -04:00
|
|
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
typedef DenseBase<Derived> Base;
|
|
|
|
|
using Base::ColsAtCompileTime;
|
|
|
|
|
using Base::Flags;
|
|
|
|
|
using Base::IsVectorAtCompileTime;
|
|
|
|
|
using Base::MaxColsAtCompileTime;
|
|
|
|
|
using Base::MaxRowsAtCompileTime;
|
|
|
|
|
using Base::MaxSizeAtCompileTime;
|
|
|
|
|
using Base::RowsAtCompileTime;
|
|
|
|
|
using Base::SizeAtCompileTime;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
using Base::coeff;
|
|
|
|
|
using Base::coeffRef;
|
|
|
|
|
using Base::cols;
|
2009-12-16 19:18:40 +01:00
|
|
|
using Base::const_cast_derived;
|
2009-12-04 23:17:14 +01:00
|
|
|
using Base::derived;
|
2009-12-17 19:28:54 +01:00
|
|
|
using Base::lazyAssign;
|
2009-12-04 23:17:14 +01:00
|
|
|
using Base::rows;
|
|
|
|
|
using Base::size;
|
2017-01-02 22:27:07 +01:00
|
|
|
using Base::operator-;
|
2009-12-16 17:37:21 +01:00
|
|
|
using Base::operator=;
|
2009-12-17 19:28:54 +01:00
|
|
|
using Base::operator+=;
|
|
|
|
|
using Base::operator-=;
|
|
|
|
|
using Base::operator*=;
|
|
|
|
|
using Base::operator/=;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
typedef typename Base::CoeffReturnType CoeffReturnType;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2015-06-22 10:52:08 +02:00
|
|
|
typedef typename Base::PlainObject PlainObject;
|
2009-12-04 23:17:14 +01:00
|
|
|
|
|
|
|
|
/** \internal Represents a matrix with all coefficients equal to one another*/
|
2015-06-22 10:52:08 +02:00
|
|
|
typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> ConstantReturnType;
|
2009-12-04 23:17:14 +01:00
|
|
|
#endif // not EIGEN_PARSED_BY_DOXYGEN
|
|
|
|
|
|
|
|
|
|
#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
|
2016-09-16 10:40:50 +02:00
|
|
|
#define EIGEN_DOC_UNARY_ADDONS(X, Y)
|
2023-08-21 16:26:11 +00:00
|
|
|
#include "../plugins/MatrixCwiseUnaryOps.inc"
|
|
|
|
|
#include "../plugins/ArrayCwiseUnaryOps.inc"
|
|
|
|
|
#include "../plugins/CommonCwiseBinaryOps.inc"
|
|
|
|
|
#include "../plugins/MatrixCwiseBinaryOps.inc"
|
|
|
|
|
#include "../plugins/ArrayCwiseBinaryOps.inc"
|
2009-12-16 19:18:40 +01:00
|
|
|
#ifdef EIGEN_ARRAYBASE_PLUGIN
|
|
|
|
|
#include EIGEN_ARRAYBASE_PLUGIN
|
|
|
|
|
#endif
|
2009-12-04 23:17:14 +01:00
|
|
|
#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
|
2016-09-16 10:40:50 +02:00
|
|
|
#undef EIGEN_DOC_UNARY_ADDONS
|
2009-12-04 23:17:14 +01:00
|
|
|
|
|
|
|
|
/** Special case of the template operator=, in order to prevent the compiler
|
|
|
|
|
* from generating a default operator= (issue hit with g++ 4.1)
|
|
|
|
|
*/
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const ArrayBase& other) {
|
2014-06-20 15:39:38 +02:00
|
|
|
internal::call_assignment(derived(), other.derived());
|
2014-09-28 09:16:13 +02:00
|
|
|
return derived();
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2014-09-19 13:25:28 +02:00
|
|
|
/** Set all the entries to \a value.
|
|
|
|
|
* \sa DenseBase::setConstant(), DenseBase::fill() */
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Scalar& value) {
|
2014-09-19 13:25:28 +02:00
|
|
|
Base::setConstant(value);
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2025-02-01 00:00:31 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const Scalar& other) {
|
|
|
|
|
internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
|
|
|
|
|
internal::add_assign_op<Scalar, Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const Scalar& other) {
|
|
|
|
|
internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
|
|
|
|
|
internal::sub_assign_op<Scalar, Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2025-02-01 00:00:31 +00:00
|
|
|
/** replaces \c *this by \c *this + \a other.
|
|
|
|
|
*
|
|
|
|
|
* \returns a reference to \c *this
|
|
|
|
|
*/
|
2009-12-04 23:17:14 +01:00
|
|
|
template <typename OtherDerived>
|
2025-02-01 00:00:31 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const ArrayBase<OtherDerived>& other) {
|
|
|
|
|
call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** replaces \c *this by \c *this - \a other.
|
|
|
|
|
*
|
|
|
|
|
* \returns a reference to \c *this
|
|
|
|
|
*/
|
2009-12-04 23:17:14 +01:00
|
|
|
template <typename OtherDerived>
|
2025-02-01 00:00:31 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const ArrayBase<OtherDerived>& other) {
|
|
|
|
|
call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2025-02-01 00:00:31 +00:00
|
|
|
/** replaces \c *this by \c *this * \a other coefficient wise.
|
|
|
|
|
*
|
|
|
|
|
* \returns a reference to \c *this
|
|
|
|
|
*/
|
2009-12-04 23:17:14 +01:00
|
|
|
template <typename OtherDerived>
|
2025-02-01 00:00:31 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const ArrayBase<OtherDerived>& other) {
|
|
|
|
|
call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar, typename OtherDerived::Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2025-02-01 00:00:31 +00:00
|
|
|
/** replaces \c *this by \c *this / \a other coefficient wise.
|
|
|
|
|
*
|
|
|
|
|
* \returns a reference to \c *this
|
|
|
|
|
*/
|
2010-01-05 15:41:01 +01:00
|
|
|
template <typename OtherDerived>
|
2025-02-01 00:00:31 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const ArrayBase<OtherDerived>& other) {
|
|
|
|
|
call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar, typename OtherDerived::Scalar>());
|
|
|
|
|
return derived();
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
public:
|
2026-02-24 19:59:10 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr ArrayBase<Derived>& array() { return *this; }
|
|
|
|
|
EIGEN_DEVICE_FUNC constexpr const ArrayBase<Derived>& array() const { return *this; }
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2012-12-24 13:33:22 +01:00
|
|
|
/** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array
|
2010-06-28 18:38:28 +01:00
|
|
|
* \sa MatrixBase::array() */
|
2026-02-24 19:59:10 -08:00
|
|
|
EIGEN_DEVICE_FUNC constexpr MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
|
|
|
|
|
EIGEN_DEVICE_FUNC constexpr const MatrixWrapper<const Derived> matrix() const {
|
2014-09-23 14:28:23 +02:00
|
|
|
return MatrixWrapper<const Derived>(derived());
|
|
|
|
|
}
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
protected:
|
2024-11-06 01:09:38 +00:00
|
|
|
EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
|
|
|
|
|
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
private:
|
2010-05-30 16:00:58 -04:00
|
|
|
explicit ArrayBase(Index);
|
|
|
|
|
ArrayBase(Index, Index);
|
2009-12-04 23:17:14 +01:00
|
|
|
template <typename OtherDerived>
|
|
|
|
|
explicit ArrayBase(const ArrayBase<OtherDerived>&);
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2010-08-16 11:07:17 +02:00
|
|
|
protected:
|
|
|
|
|
// mixing arrays and matrices is not legal
|
2011-02-04 13:55:12 +01:00
|
|
|
template <typename OtherDerived>
|
|
|
|
|
Derived& operator+=(const MatrixBase<OtherDerived>&) {
|
2012-01-31 13:05:44 +01:00
|
|
|
EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
|
|
|
|
|
YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2010-08-16 11:07:17 +02:00
|
|
|
// mixing arrays and matrices is not legal
|
2011-02-04 13:55:12 +01:00
|
|
|
template <typename OtherDerived>
|
2012-01-31 13:05:44 +01:00
|
|
|
Derived& operator-=(const MatrixBase<OtherDerived>&) {
|
|
|
|
|
EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
|
|
|
|
|
YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2009-12-04 23:17:14 +01:00
|
|
|
};
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
#endif // EIGEN_ARRAYBASE_H
|