2007-10-12 05:15:25 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra. Eigen itself is part of the KDE project.
|
2007-10-01 17:07:38 +00:00
|
|
|
//
|
|
|
|
|
// Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
|
2007-10-07 16:40:49 +00:00
|
|
|
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
2007-10-01 17:07:38 +00:00
|
|
|
//
|
2007-10-12 05:15:25 +00:00
|
|
|
// Eigen is free software; you can redistribute it and/or modify it under the
|
2007-10-01 17:07:38 +00:00
|
|
|
// terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
// Foundation; either version 2 or (at your option) any later version.
|
|
|
|
|
//
|
2007-10-12 05:15:25 +00:00
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
2007-10-01 17:07:38 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
// details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
2007-10-12 05:15:25 +00:00
|
|
|
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
2007-10-01 17:07:38 +00:00
|
|
|
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
//
|
|
|
|
|
// As a special exception, if other files instantiate templates or use macros
|
|
|
|
|
// or functions from this file, or you compile this file and link it
|
|
|
|
|
// with other works to produce a work based on this file, this file does not
|
|
|
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
|
|
|
|
// 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.
|
|
|
|
|
|
2007-12-11 10:19:49 +00:00
|
|
|
#ifndef EIGEN_OPERATOREQUALS_H
|
|
|
|
|
#define EIGEN_OPERATOREQUALS_H
|
2007-10-01 17:07:38 +00:00
|
|
|
|
2008-01-06 13:57:29 +00:00
|
|
|
template<typename Derived1, typename Derived2, int UnrollCount>
|
2007-12-24 11:14:25 +00:00
|
|
|
struct MatrixOperatorEqualsUnroller
|
2007-10-01 17:07:38 +00:00
|
|
|
{
|
2008-01-06 16:35:21 +00:00
|
|
|
static const int col = (UnrollCount-1) / Derived1::Traits::RowsAtCompileTime;
|
|
|
|
|
static const int row = (UnrollCount-1) % Derived1::Traits::RowsAtCompileTime;
|
2007-10-01 17:07:38 +00:00
|
|
|
|
2007-10-08 07:17:54 +00:00
|
|
|
static void run(Derived1 &dst, const Derived2 &src)
|
|
|
|
|
{
|
2008-01-06 13:57:29 +00:00
|
|
|
MatrixOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1>::run(dst, src);
|
2007-12-17 07:25:11 +00:00
|
|
|
dst.coeffRef(row, col) = src.coeff(row, col);
|
2007-10-08 07:17:54 +00:00
|
|
|
}
|
2007-10-01 17:07:38 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-06 13:57:29 +00:00
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 1>
|
2007-10-01 17:07:38 +00:00
|
|
|
{
|
2007-10-08 07:17:54 +00:00
|
|
|
static void run(Derived1 &dst, const Derived2 &src)
|
|
|
|
|
{
|
2007-12-17 07:25:11 +00:00
|
|
|
dst.coeffRef(0, 0) = src.coeff(0, 0);
|
2007-10-08 07:17:54 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2008-01-05 10:57:14 +00:00
|
|
|
// prevent buggy user code from causing an infinite recursion
|
2008-01-06 13:57:29 +00:00
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, 0>
|
2008-01-05 10:57:14 +00:00
|
|
|
{
|
|
|
|
|
static void run(Derived1 &, const Derived2 &) {}
|
|
|
|
|
};
|
|
|
|
|
|
2008-01-06 13:57:29 +00:00
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct MatrixOperatorEqualsUnroller<Derived1, Derived2, Dynamic>
|
2007-12-24 11:14:25 +00:00
|
|
|
{
|
|
|
|
|
static void run(Derived1 &, const Derived2 &) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived1, typename Derived2, int UnrollCount>
|
|
|
|
|
struct VectorOperatorEqualsUnroller
|
|
|
|
|
{
|
|
|
|
|
static const int index = UnrollCount - 1;
|
|
|
|
|
|
|
|
|
|
static void run(Derived1 &dst, const Derived2 &src)
|
|
|
|
|
{
|
|
|
|
|
VectorOperatorEqualsUnroller<Derived1, Derived2, UnrollCount-1>::run(dst, src);
|
|
|
|
|
dst.coeffRef(index) = src.coeff(index);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// prevent buggy user code from causing an infinite recursion
|
|
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct VectorOperatorEqualsUnroller<Derived1, Derived2, 0>
|
|
|
|
|
{
|
|
|
|
|
static void run(Derived1 &, const Derived2 &) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct VectorOperatorEqualsUnroller<Derived1, Derived2, 1>
|
|
|
|
|
{
|
|
|
|
|
static void run(Derived1 &dst, const Derived2 &src)
|
|
|
|
|
{
|
|
|
|
|
dst.coeffRef(0) = src.coeff(0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename Derived1, typename Derived2>
|
|
|
|
|
struct VectorOperatorEqualsUnroller<Derived1, Derived2, Dynamic>
|
2007-10-08 07:17:54 +00:00
|
|
|
{
|
2007-12-11 15:25:43 +00:00
|
|
|
static void run(Derived1 &, const Derived2 &) {}
|
2007-10-01 17:07:38 +00:00
|
|
|
};
|
|
|
|
|
|
2007-10-07 16:40:49 +00:00
|
|
|
template<typename Scalar, typename Derived>
|
|
|
|
|
template<typename OtherDerived>
|
2007-12-11 10:19:49 +00:00
|
|
|
Derived& MatrixBase<Scalar, Derived>
|
|
|
|
|
::operator=(const MatrixBase<Scalar, OtherDerived>& other)
|
2007-10-07 16:40:49 +00:00
|
|
|
{
|
2008-01-06 13:17:07 +00:00
|
|
|
if(Traits::IsVectorAtCompileTime && OtherDerived::Traits::IsVectorAtCompileTime)
|
2008-01-05 10:57:14 +00:00
|
|
|
// copying a vector expression into a vector
|
2007-12-24 11:14:25 +00:00
|
|
|
{
|
|
|
|
|
assert(size() == other.size());
|
2008-01-06 13:17:07 +00:00
|
|
|
if(EIGEN_UNROLLED_LOOPS && Traits::SizeAtCompileTime != Dynamic && Traits::SizeAtCompileTime <= 25)
|
2007-12-24 11:14:25 +00:00
|
|
|
VectorOperatorEqualsUnroller
|
2008-01-06 13:17:07 +00:00
|
|
|
<Derived, OtherDerived, Traits::SizeAtCompileTime>::run
|
2007-12-24 11:14:25 +00:00
|
|
|
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
|
|
|
|
|
else
|
|
|
|
|
for(int i = 0; i < size(); i++)
|
|
|
|
|
coeffRef(i) = other.coeff(i);
|
|
|
|
|
return *static_cast<Derived*>(this);
|
|
|
|
|
}
|
2008-01-05 10:57:14 +00:00
|
|
|
else // copying a matrix expression into a matrix
|
2007-12-24 11:14:25 +00:00
|
|
|
{
|
|
|
|
|
assert(rows() == other.rows() && cols() == other.cols());
|
2008-01-06 13:17:07 +00:00
|
|
|
if(EIGEN_UNROLLED_LOOPS && Traits::SizeAtCompileTime != Dynamic && Traits::SizeAtCompileTime <= 25)
|
2007-12-24 11:14:25 +00:00
|
|
|
MatrixOperatorEqualsUnroller
|
2008-01-06 13:57:29 +00:00
|
|
|
<Derived, OtherDerived, Traits::SizeAtCompileTime>::run
|
2007-12-24 11:14:25 +00:00
|
|
|
(*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other));
|
|
|
|
|
else
|
2008-01-06 13:57:29 +00:00
|
|
|
for(int j = 0; j < cols(); j++)
|
2007-12-24 11:14:25 +00:00
|
|
|
for(int i = 0; i < rows(); i++)
|
2008-01-06 13:57:29 +00:00
|
|
|
coeffRef(i, j) = other.coeff(i, j);
|
2007-12-24 11:14:25 +00:00
|
|
|
return *static_cast<Derived*>(this);
|
|
|
|
|
}
|
2007-10-07 16:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-11 10:19:49 +00:00
|
|
|
#endif // EIGEN_OPERATOREQUALS_H
|