mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-09 18:29:03 +08:00
rename CopyHelper into OperatorEquals, get rid of the auxiliary _copy_helper() method,
and make sure copies are always done in column-dominant order
This commit is contained in:
parent
2b20814ced
commit
0a7086f1ec
@ -31,9 +31,6 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
|
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
|
||||||
ColsAtCompileTime = Derived::ColsAtCompileTime;
|
ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||||
|
|
||||||
template<typename OtherDerived>
|
|
||||||
void _copy_helper(const MatrixBase<Scalar, OtherDerived>& other);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int SizeAtCompileTime
|
static const int SizeAtCompileTime
|
||||||
= RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic
|
= RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic
|
||||||
@ -51,20 +48,13 @@ template<typename Scalar, typename Derived> class MatrixBase
|
|||||||
{ return static_cast<const Derived *>(this)->_ref(); }
|
{ return static_cast<const Derived *>(this)->_ref(); }
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
Derived& operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
Derived& operator=(const MatrixBase<Scalar, OtherDerived>& other);
|
||||||
{
|
|
||||||
assert(rows() == other.rows() && cols() == other.cols());
|
|
||||||
_copy_helper(other);
|
|
||||||
return *static_cast<Derived*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//special case of the above template operator=, in order to prevent the compiler
|
//special case of the above template operator=, in order to prevent the compiler
|
||||||
//from generating a default operator= (issue hit with g++ 4.1)
|
//from generating a default operator= (issue hit with g++ 4.1)
|
||||||
Derived& operator=(const MatrixBase& other)
|
Derived& operator=(const MatrixBase& other)
|
||||||
{
|
{
|
||||||
assert(rows() == other.rows() && cols() == other.cols());
|
return this->operator=<Derived>(other);
|
||||||
_copy_helper(other);
|
|
||||||
return *static_cast<Derived*>(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename NewScalar> Cast<NewScalar, Derived> cast() const;
|
template<typename NewScalar> Cast<NewScalar, Derived> cast() const;
|
||||||
|
@ -24,10 +24,10 @@
|
|||||||
// License. This exception does not invalidate any other reasons why a work
|
// License. This exception does not invalidate any other reasons why a work
|
||||||
// based on this file might be covered by the GNU General Public License.
|
// based on this file might be covered by the GNU General Public License.
|
||||||
|
|
||||||
#ifndef EIGEN_COPYHELPER_H
|
#ifndef EIGEN_OPERATOREQUALS_H
|
||||||
#define EIGEN_COPYHELPER_H
|
#define EIGEN_OPERATOREQUALS_H
|
||||||
|
|
||||||
template<int UnrollCount, int Rows> struct CopyHelperUnroller
|
template<int UnrollCount, int Rows> struct OperatorEqualsUnroller
|
||||||
{
|
{
|
||||||
static const int col = (UnrollCount-1) / Rows;
|
static const int col = (UnrollCount-1) / Rows;
|
||||||
static const int row = (UnrollCount-1) % Rows;
|
static const int row = (UnrollCount-1) % Rows;
|
||||||
@ -35,13 +35,13 @@ template<int UnrollCount, int Rows> struct CopyHelperUnroller
|
|||||||
template <typename Derived1, typename Derived2>
|
template <typename Derived1, typename Derived2>
|
||||||
static void run(Derived1 &dst, const Derived2 &src)
|
static void run(Derived1 &dst, const Derived2 &src)
|
||||||
{
|
{
|
||||||
CopyHelperUnroller<UnrollCount-1, Rows>::run(dst, src);
|
OperatorEqualsUnroller<UnrollCount-1, Rows>::run(dst, src);
|
||||||
dst.write(row, col) = src.read(row, col);
|
dst.write(row, col) = src.read(row, col);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// prevent buggy user code from causing an infinite recursion
|
// prevent buggy user code from causing an infinite recursion
|
||||||
template<int UnrollCount> struct CopyHelperUnroller<UnrollCount, 0>
|
template<int UnrollCount> struct OperatorEqualsUnroller<UnrollCount, 0>
|
||||||
{
|
{
|
||||||
template <typename Derived1, typename Derived2>
|
template <typename Derived1, typename Derived2>
|
||||||
static void run(Derived1 &dst, const Derived2 &src)
|
static void run(Derived1 &dst, const Derived2 &src)
|
||||||
@ -51,7 +51,7 @@ template<int UnrollCount> struct CopyHelperUnroller<UnrollCount, 0>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int Rows> struct CopyHelperUnroller<1, Rows>
|
template<int Rows> struct OperatorEqualsUnroller<1, Rows>
|
||||||
{
|
{
|
||||||
template <typename Derived1, typename Derived2>
|
template <typename Derived1, typename Derived2>
|
||||||
static void run(Derived1 &dst, const Derived2 &src)
|
static void run(Derived1 &dst, const Derived2 &src)
|
||||||
@ -60,7 +60,7 @@ template<int Rows> struct CopyHelperUnroller<1, Rows>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int Rows> struct CopyHelperUnroller<Dynamic, Rows>
|
template<int Rows> struct OperatorEqualsUnroller<Dynamic, Rows>
|
||||||
{
|
{
|
||||||
template <typename Derived1, typename Derived2>
|
template <typename Derived1, typename Derived2>
|
||||||
static void run(Derived1 &dst, const Derived2 &src)
|
static void run(Derived1 &dst, const Derived2 &src)
|
||||||
@ -72,14 +72,17 @@ template<int Rows> struct CopyHelperUnroller<Dynamic, Rows>
|
|||||||
|
|
||||||
template<typename Scalar, typename Derived>
|
template<typename Scalar, typename Derived>
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
void MatrixBase<Scalar, Derived>::_copy_helper(const MatrixBase<Scalar, OtherDerived>& other)
|
Derived& MatrixBase<Scalar, Derived>
|
||||||
|
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
||||||
{
|
{
|
||||||
|
assert(rows() == other.rows() && cols() == other.cols());
|
||||||
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
|
if(EIGEN_UNROLLED_LOOPS && SizeAtCompileTime != Dynamic && SizeAtCompileTime <= 25)
|
||||||
CopyHelperUnroller<SizeAtCompileTime, RowsAtCompileTime>::run(*this, other);
|
OperatorEqualsUnroller<SizeAtCompileTime, RowsAtCompileTime>::run(*this, other);
|
||||||
else
|
else
|
||||||
for(int i = 0; i < rows(); i++)
|
for(int j = 0; j < cols(); j++) //traverse in column-dominant order
|
||||||
for(int j = 0; j < cols(); j++)
|
for(int i = 0; i < rows(); i++)
|
||||||
write(i, j) = other.read(i, j);
|
write(i, j) = other.read(i, j);
|
||||||
|
return *static_cast<Derived*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EIGEN_COPYHELPER_H
|
#endif // EIGEN_OPERATOREQUALS_H
|
Loading…
x
Reference in New Issue
Block a user