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-2010 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_ARRAYWRAPPER_H
|
|
|
|
|
#define EIGEN_ARRAYWRAPPER_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-01-04 19:13:08 +01:00
|
|
|
/** \class ArrayWrapper
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2010-01-04 19:13:08 +01:00
|
|
|
*
|
|
|
|
|
* \brief Expression of a mathematical vector or matrix as an array object
|
|
|
|
|
*
|
|
|
|
|
* This class is the return type of MatrixBase::array(), and most of the time
|
|
|
|
|
* this is the only way it is use.
|
|
|
|
|
*
|
|
|
|
|
* \sa MatrixBase::array(), class MatrixWrapper
|
|
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
|
|
|
|
|
namespace internal {
|
2009-12-04 23:17:14 +01:00
|
|
|
template<typename ExpressionType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<ArrayWrapper<ExpressionType> >
|
2010-10-26 16:47:01 +02:00
|
|
|
: public traits<typename remove_all<typename ExpressionType::Nested>::type >
|
2009-12-17 19:28:54 +01:00
|
|
|
{
|
2010-04-16 10:13:32 -04:00
|
|
|
typedef ArrayXpr XprKind;
|
2009-12-17 19:28:54 +01:00
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
}
|
2009-12-04 23:17:14 +01:00
|
|
|
|
|
|
|
|
template<typename ExpressionType>
|
|
|
|
|
class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
|
|
|
|
|
{
|
|
|
|
|
public:
|
2009-12-16 17:37:21 +01:00
|
|
|
typedef ArrayBase<ArrayWrapper> Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
|
2009-12-16 17:37:21 +01:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2011-05-06 21:15:05 +02:00
|
|
|
typedef typename internal::conditional<
|
|
|
|
|
internal::is_lvalue<ExpressionType>::value,
|
|
|
|
|
Scalar,
|
|
|
|
|
const Scalar
|
|
|
|
|
>::type ScalarWithConstIfNotLvalue;
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
|
2010-02-09 16:38:36 +01:00
|
|
|
|
2012-02-03 23:18:26 +01:00
|
|
|
inline ArrayWrapper(ExpressionType& matrix) : m_expression(matrix) {}
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index rows() const { return m_expression.rows(); }
|
|
|
|
|
inline Index cols() const { return m_expression.cols(); }
|
|
|
|
|
inline Index outerStride() const { return m_expression.outerStride(); }
|
|
|
|
|
inline Index innerStride() const { return m_expression.innerStride(); }
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2013-05-16 10:18:19 +02:00
|
|
|
inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); }
|
2011-05-06 21:15:05 +02:00
|
|
|
inline const Scalar* data() const { return m_expression.data(); }
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline CoeffReturnType coeff(Index rowId, Index colId) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.coeff(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline Scalar& coeffRef(Index rowId, Index colId)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.const_cast_derived().coeffRef(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
2011-01-18 13:19:13 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.const_cast_derived().coeffRef(rowId, colId);
|
2011-01-18 13:19:13 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-03 23:18:26 +01:00
|
|
|
inline CoeffReturnType coeff(Index index) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Scalar& coeffRef(Index index)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 13:19:13 +01:00
|
|
|
inline const Scalar& coeffRef(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_expression.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline const PacketScalar packet(Index rowId, Index colId) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.template packet<LoadMode>(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
m_expression.const_cast_derived().template writePacket<LoadMode>(rowId, colId, val);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2010-05-30 16:00:58 -04:00
|
|
|
inline const PacketScalar packet(Index index) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.template packet<LoadMode>(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline void writePacket(Index index, const PacketScalar& val)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
m_expression.const_cast_derived().template writePacket<LoadMode>(index, val);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Dest>
|
|
|
|
|
inline void evalTo(Dest& dst) const { dst = m_expression; }
|
|
|
|
|
|
2011-04-22 22:36:45 +01:00
|
|
|
const typename internal::remove_all<NestedExpressionType>::type&
|
|
|
|
|
nestedExpression() const
|
|
|
|
|
{
|
|
|
|
|
return m_expression;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-30 16:28:53 +02:00
|
|
|
/** Forwards the resizing request to the nested expression
|
|
|
|
|
* \sa DenseBase::resize(Index) */
|
|
|
|
|
void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
|
|
|
|
|
/** Forwards the resizing request to the nested expression
|
|
|
|
|
* \sa DenseBase::resize(Index,Index)*/
|
|
|
|
|
void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
protected:
|
2012-02-03 23:18:26 +01:00
|
|
|
NestedExpressionType m_expression;
|
2009-12-04 23:17:14 +01:00
|
|
|
};
|
|
|
|
|
|
2010-01-04 19:13:08 +01:00
|
|
|
/** \class MatrixWrapper
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2010-01-04 19:13:08 +01:00
|
|
|
*
|
|
|
|
|
* \brief Expression of an array as a mathematical vector or matrix
|
|
|
|
|
*
|
|
|
|
|
* This class is the return type of ArrayBase::matrix(), and most of the time
|
|
|
|
|
* this is the only way it is use.
|
|
|
|
|
*
|
|
|
|
|
* \sa MatrixBase::matrix(), class ArrayWrapper
|
|
|
|
|
*/
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
2009-12-04 23:17:14 +01:00
|
|
|
template<typename ExpressionType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<MatrixWrapper<ExpressionType> >
|
2010-10-26 16:47:01 +02:00
|
|
|
: public traits<typename remove_all<typename ExpressionType::Nested>::type >
|
2009-12-17 19:28:54 +01:00
|
|
|
{
|
2010-04-16 10:13:32 -04:00
|
|
|
typedef MatrixXpr XprKind;
|
2009-12-17 19:28:54 +01:00
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
}
|
2009-12-04 23:17:14 +01:00
|
|
|
|
|
|
|
|
template<typename ExpressionType>
|
|
|
|
|
class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-01-22 10:15:41 +01:00
|
|
|
typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
|
|
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
|
2010-05-21 01:46:17 +02:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2011-05-06 21:15:05 +02:00
|
|
|
typedef typename internal::conditional<
|
|
|
|
|
internal::is_lvalue<ExpressionType>::value,
|
|
|
|
|
Scalar,
|
|
|
|
|
const Scalar
|
|
|
|
|
>::type ScalarWithConstIfNotLvalue;
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
|
2010-02-09 16:38:36 +01:00
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline MatrixWrapper(ExpressionType& a_matrix) : m_expression(a_matrix) {}
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index rows() const { return m_expression.rows(); }
|
|
|
|
|
inline Index cols() const { return m_expression.cols(); }
|
|
|
|
|
inline Index outerStride() const { return m_expression.outerStride(); }
|
|
|
|
|
inline Index innerStride() const { return m_expression.innerStride(); }
|
2009-12-04 23:17:14 +01:00
|
|
|
|
2013-05-16 10:18:19 +02:00
|
|
|
inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); }
|
2011-05-06 21:15:05 +02:00
|
|
|
inline const Scalar* data() const { return m_expression.data(); }
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline CoeffReturnType coeff(Index rowId, Index colId) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.coeff(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline Scalar& coeffRef(Index rowId, Index colId)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.const_cast_derived().coeffRef(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 16:32:45 +02:00
|
|
|
inline const Scalar& coeffRef(Index rowId, Index colId) const
|
2011-01-04 15:35:50 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.derived().coeffRef(rowId, colId);
|
2011-01-04 15:35:50 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-03 23:18:26 +01:00
|
|
|
inline CoeffReturnType coeff(Index index) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Scalar& coeffRef(Index index)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 13:19:13 +01:00
|
|
|
inline const Scalar& coeffRef(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_expression.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline const PacketScalar packet(Index rowId, Index colId) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.template packet<LoadMode>(rowId, colId);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline void writePacket(Index rowId, Index colId, const PacketScalar& val)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
m_expression.const_cast_derived().template writePacket<LoadMode>(rowId, colId, val);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2010-05-30 16:00:58 -04:00
|
|
|
inline const PacketScalar packet(Index index) const
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
|
|
|
|
return m_expression.template packet<LoadMode>(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
inline void writePacket(Index index, const PacketScalar& val)
|
2009-12-04 23:17:14 +01:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
m_expression.const_cast_derived().template writePacket<LoadMode>(index, val);
|
2009-12-04 23:17:14 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-22 22:36:45 +01:00
|
|
|
const typename internal::remove_all<NestedExpressionType>::type&
|
|
|
|
|
nestedExpression() const
|
|
|
|
|
{
|
|
|
|
|
return m_expression;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-30 16:28:53 +02:00
|
|
|
/** Forwards the resizing request to the nested expression
|
|
|
|
|
* \sa DenseBase::resize(Index) */
|
|
|
|
|
void resize(Index newSize) { m_expression.const_cast_derived().resize(newSize); }
|
|
|
|
|
/** Forwards the resizing request to the nested expression
|
|
|
|
|
* \sa DenseBase::resize(Index,Index)*/
|
|
|
|
|
void resize(Index nbRows, Index nbCols) { m_expression.const_cast_derived().resize(nbRows,nbCols); }
|
|
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
protected:
|
2012-02-03 23:18:26 +01:00
|
|
|
NestedExpressionType m_expression;
|
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_ARRAYWRAPPER_H
|