2008-01-15 13:55:47 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2008-01-15 13:55:47 +00:00
|
|
|
//
|
2008-11-24 13:40:43 +00:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2008-01-15 13:55:47 +00: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/.
|
2008-01-15 13:55:47 +00:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_SWAP_H
|
|
|
|
|
#define EIGEN_SWAP_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2008-08-05 21:55:57 +00:00
|
|
|
/** \class SwapWrapper
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2008-08-05 21:55:57 +00:00
|
|
|
*
|
2008-08-07 04:31:05 +00:00
|
|
|
* \internal
|
2008-08-05 21:55:57 +00:00
|
|
|
*
|
2008-08-07 04:31:05 +00:00
|
|
|
* \brief Internal helper class for swapping two expressions
|
2008-08-05 21:55:57 +00:00
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
2008-08-05 21:55:57 +00:00
|
|
|
template<typename ExpressionType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<SwapWrapper<ExpressionType> > : traits<ExpressionType> {};
|
|
|
|
|
}
|
2008-08-05 21:55:57 +00:00
|
|
|
|
|
|
|
|
template<typename ExpressionType> class SwapWrapper
|
2010-10-25 10:15:22 -04:00
|
|
|
: public internal::dense_xpr_base<SwapWrapper<ExpressionType> >::type
|
2008-08-05 21:55:57 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::dense_xpr_base<SwapWrapper>::type Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(SwapWrapper)
|
2010-10-25 10:15:22 -04:00
|
|
|
typedef typename internal::packet_traits<Scalar>::type Packet;
|
2008-08-05 21:55:57 +00:00
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2008-08-09 04:37:09 +00:00
|
|
|
inline SwapWrapper(ExpressionType& xpr) : m_expression(xpr) {}
|
2008-08-05 21:55:57 +00:00
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index rows() const { return m_expression.rows(); }
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index cols() const { return m_expression.cols(); }
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index outerStride() const { return m_expression.outerStride(); }
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index innerStride() const { return m_expression.innerStride(); }
|
2012-02-03 23:18:26 +01:00
|
|
|
|
|
|
|
|
typedef typename internal::conditional<
|
|
|
|
|
internal::is_lvalue<ExpressionType>::value,
|
|
|
|
|
Scalar,
|
|
|
|
|
const Scalar
|
|
|
|
|
>::type ScalarWithConstIfNotLvalue;
|
|
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2012-02-03 23:18:26 +01:00
|
|
|
inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); }
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2012-02-03 23:18:26 +01:00
|
|
|
inline const Scalar* data() const { return m_expression.data(); }
|
2008-08-05 21:55:57 +00:00
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2012-06-22 16:32:45 +02:00
|
|
|
inline Scalar& coeffRef(Index rowId, Index colId)
|
2008-08-09 18:41:24 +00:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.const_cast_derived().coeffRef(rowId, colId);
|
2008-08-09 18:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Scalar& coeffRef(Index index)
|
2008-08-09 18:41:24 +00:00
|
|
|
{
|
|
|
|
|
return m_expression.const_cast_derived().coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2012-06-22 16:32:45 +02:00
|
|
|
inline Scalar& coeffRef(Index rowId, Index colId) const
|
2010-12-22 17:45:37 -05:00
|
|
|
{
|
2012-06-22 16:32:45 +02:00
|
|
|
return m_expression.coeffRef(rowId, colId);
|
2010-12-22 17:45:37 -05:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-12-22 17:45:37 -05:00
|
|
|
inline Scalar& coeffRef(Index index) const
|
|
|
|
|
{
|
|
|
|
|
return m_expression.coeffRef(index);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-05 21:55:57 +00:00
|
|
|
template<typename OtherDerived>
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2012-06-22 16:32:45 +02:00
|
|
|
void copyCoeff(Index rowId, Index colId, const DenseBase<OtherDerived>& other)
|
2008-08-05 21:55:57 +00:00
|
|
|
{
|
|
|
|
|
OtherDerived& _other = other.const_cast_derived();
|
2012-06-22 16:32:45 +02:00
|
|
|
eigen_internal_assert(rowId >= 0 && rowId < rows()
|
|
|
|
|
&& colId >= 0 && colId < cols());
|
|
|
|
|
Scalar tmp = m_expression.coeff(rowId, colId);
|
|
|
|
|
m_expression.coeffRef(rowId, colId) = _other.coeff(rowId, colId);
|
|
|
|
|
_other.coeffRef(rowId, colId) = tmp;
|
2008-08-05 21:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename OtherDerived>
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
void copyCoeff(Index index, const DenseBase<OtherDerived>& other)
|
2008-08-05 21:55:57 +00:00
|
|
|
{
|
|
|
|
|
OtherDerived& _other = other.const_cast_derived();
|
2010-10-25 10:15:22 -04:00
|
|
|
eigen_internal_assert(index >= 0 && index < m_expression.size());
|
2008-08-05 21:55:57 +00:00
|
|
|
Scalar tmp = m_expression.coeff(index);
|
|
|
|
|
m_expression.coeffRef(index) = _other.coeff(index);
|
|
|
|
|
_other.coeffRef(index) = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-09 18:41:24 +00:00
|
|
|
template<typename OtherDerived, int StoreMode, int LoadMode>
|
2012-06-22 16:32:45 +02:00
|
|
|
void copyPacket(Index rowId, Index colId, const DenseBase<OtherDerived>& other)
|
2008-08-05 21:55:57 +00:00
|
|
|
{
|
|
|
|
|
OtherDerived& _other = other.const_cast_derived();
|
2012-06-22 16:32:45 +02:00
|
|
|
eigen_internal_assert(rowId >= 0 && rowId < rows()
|
|
|
|
|
&& colId >= 0 && colId < cols());
|
|
|
|
|
Packet tmp = m_expression.template packet<StoreMode>(rowId, colId);
|
|
|
|
|
m_expression.template writePacket<StoreMode>(rowId, colId,
|
|
|
|
|
_other.template packet<LoadMode>(rowId, colId)
|
2008-08-05 21:55:57 +00:00
|
|
|
);
|
2012-06-22 16:32:45 +02:00
|
|
|
_other.template writePacket<LoadMode>(rowId, colId, tmp);
|
2008-08-05 21:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-09 18:41:24 +00:00
|
|
|
template<typename OtherDerived, int StoreMode, int LoadMode>
|
2010-05-30 16:00:58 -04:00
|
|
|
void copyPacket(Index index, const DenseBase<OtherDerived>& other)
|
2008-08-05 21:55:57 +00:00
|
|
|
{
|
|
|
|
|
OtherDerived& _other = other.const_cast_derived();
|
2010-10-25 10:15:22 -04:00
|
|
|
eigen_internal_assert(index >= 0 && index < m_expression.size());
|
2008-08-09 18:41:24 +00:00
|
|
|
Packet tmp = m_expression.template packet<StoreMode>(index);
|
|
|
|
|
m_expression.template writePacket<StoreMode>(index,
|
|
|
|
|
_other.template packet<LoadMode>(index)
|
2008-08-05 21:55:57 +00:00
|
|
|
);
|
2008-08-09 18:41:24 +00:00
|
|
|
_other.template writePacket<LoadMode>(index, tmp);
|
2008-08-05 21:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 16:26:57 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2011-04-28 15:52:15 +01:00
|
|
|
ExpressionType& expression() const { return m_expression; }
|
|
|
|
|
|
2008-08-05 21:55:57 +00:00
|
|
|
protected:
|
2008-08-09 04:37:09 +00:00
|
|
|
ExpressionType& m_expression;
|
2008-08-05 21:55:57 +00:00
|
|
|
};
|
2008-06-02 22:58:36 +00:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2008-01-15 13:55:47 +00:00
|
|
|
#endif // EIGEN_SWAP_H
|