some cleaning/renaming is Triangular/SelfadjointView

This commit is contained in:
Gael Guennebaud 2009-07-14 22:38:21 +02:00
parent a2cf7ba955
commit 279cedc1ce
3 changed files with 68 additions and 54 deletions

View File

@ -182,6 +182,7 @@ namespace Eigen {
#include "src/Core/SolveTriangular.h"
#include "src/Core/products/SelfadjointRank2Update.h"
#include "src/Core/products/TriangularMatrixVector.h"
#include "src/Core/BandMatrix.h"
} // namespace Eigen

View File

@ -126,6 +126,40 @@ template<typename MatrixType, unsigned int UpLo> class SelfAdjointView
const typename MatrixType::Nested m_matrix;
};
template<typename Derived1, typename Derived2, int UnrollCount, bool ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, SelfAdjoint, UnrollCount, ClearOpposite>
{
enum {
col = (UnrollCount-1) / Derived1::RowsAtCompileTime,
row = (UnrollCount-1) % Derived1::RowsAtCompileTime
};
inline static void run(Derived1 &dst, const Derived2 &src)
{
ei_triangular_assignment_selector<Derived1, Derived2, SelfAdjoint, UnrollCount-1, ClearOpposite>::run(dst, src);
if(row == col)
dst.coeffRef(row, col) = ei_real(src.coeff(row, col));
else if(row < col)
dst.coeffRef(col, row) = ei_conj(dst.coeffRef(row, col) = src.coeff(row, col));
}
};
// selfadjoint to dense matrix
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, SelfAdjoint, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
for(int j = 0; j < dst.cols(); ++j)
{
for(int i = 0; i < j; ++i)
dst.coeffRef(j, i) = ei_conj(dst.coeffRef(i, j) = src.coeff(i, j));
dst.coeffRef(j, j) = ei_real(src.coeff(j, j));
}
}
};
/***************************************************************************
* Wrapper to ei_product_selfadjoint_vector
***************************************************************************/

View File

@ -283,7 +283,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
***************************************************************************/
template<typename Derived1, typename Derived2, unsigned int Mode, int UnrollCount, bool ClearOpposite>
struct ei_part_assignment_impl
struct ei_triangular_assignment_selector
{
enum {
col = (UnrollCount-1) / Derived1::RowsAtCompileTime,
@ -292,39 +292,29 @@ struct ei_part_assignment_impl
inline static void run(Derived1 &dst, const Derived2 &src)
{
ei_part_assignment_impl<Derived1, Derived2, Mode, UnrollCount-1, ClearOpposite>::run(dst, src);
ei_triangular_assignment_selector<Derived1, Derived2, Mode, UnrollCount-1, ClearOpposite>::run(dst, src);
if(Mode == SelfAdjoint)
ei_assert( Mode == UpperTriangular || Mode == LowerTriangular
|| Mode == StrictlyUpperTriangular || Mode == StrictlyLowerTriangular
|| Mode == UnitUpperTriangular || Mode == UnitLowerTriangular);
if((Mode == UpperTriangular && row <= col)
|| (Mode == LowerTriangular && row >= col)
|| (Mode == StrictlyUpperTriangular && row < col)
|| (Mode == StrictlyLowerTriangular && row > col)
|| (Mode == UnitUpperTriangular && row < col)
|| (Mode == UnitLowerTriangular && row > col))
dst.copyCoeff(row, col, src);
else if(ClearOpposite)
{
if(row == col)
dst.coeffRef(row, col) = ei_real(src.coeff(row, col));
else if(row < col)
dst.coeffRef(col, row) = ei_conj(dst.coeffRef(row, col) = src.coeff(row, col));
}
else
{
ei_assert( Mode == UpperTriangular || Mode == LowerTriangular
|| Mode == StrictlyUpperTriangular || Mode == StrictlyLowerTriangular
|| Mode == UnitUpperTriangular || Mode == UnitLowerTriangular);
if((Mode == UpperTriangular && row <= col)
|| (Mode == LowerTriangular && row >= col)
|| (Mode == StrictlyUpperTriangular && row < col)
|| (Mode == StrictlyLowerTriangular && row > col)
|| (Mode == UnitUpperTriangular && row < col)
|| (Mode == UnitLowerTriangular && row > col))
dst.copyCoeff(row, col, src);
else if(ClearOpposite)
{
if (Mode&UnitDiagBit && row==col)
dst.coeffRef(row, col) = 1;
else
dst.coeffRef(row, col) = 0;
}
if (Mode&UnitDiagBit && row==col)
dst.coeffRef(row, col) = 1;
else
dst.coeffRef(row, col) = 0;
}
}
};
template<typename Derived1, typename Derived2, unsigned int Mode, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, Mode, 1, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, Mode, 1, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -339,13 +329,13 @@ struct ei_part_assignment_impl<Derived1, Derived2, Mode, 1, ClearOpposite>
};
// prevent buggy user code from causing an infinite recursion
template<typename Derived1, typename Derived2, unsigned int Mode, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, Mode, 0, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, Mode, 0, ClearOpposite>
{
inline static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, UpperTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, UpperTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -360,7 +350,7 @@ struct ei_part_assignment_impl<Derived1, Derived2, UpperTriangular, Dynamic, Cle
}
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, LowerTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, LowerTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -376,7 +366,7 @@ struct ei_part_assignment_impl<Derived1, Derived2, LowerTriangular, Dynamic, Cle
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, StrictlyUpperTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, StrictlyUpperTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -391,7 +381,7 @@ struct ei_part_assignment_impl<Derived1, Derived2, StrictlyUpperTriangular, Dyna
}
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, StrictlyLowerTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, StrictlyLowerTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -407,7 +397,7 @@ struct ei_part_assignment_impl<Derived1, Derived2, StrictlyLowerTriangular, Dyna
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, UnitUpperTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, UnitUpperTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -425,7 +415,7 @@ struct ei_part_assignment_impl<Derived1, Derived2, UnitUpperTriangular, Dynamic,
}
};
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, UnitLowerTriangular, Dynamic, ClearOpposite>
struct ei_triangular_assignment_selector<Derived1, Derived2, UnitLowerTriangular, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
@ -443,21 +433,6 @@ struct ei_part_assignment_impl<Derived1, Derived2, UnitLowerTriangular, Dynamic,
}
};
// selfadjoint to dense matrix
template<typename Derived1, typename Derived2, bool ClearOpposite>
struct ei_part_assignment_impl<Derived1, Derived2, SelfAdjoint, Dynamic, ClearOpposite>
{
inline static void run(Derived1 &dst, const Derived2 &src)
{
for(int j = 0; j < dst.cols(); ++j)
{
for(int i = 0; i < j; ++i)
dst.coeffRef(j, i) = ei_conj(dst.coeffRef(i, j) = src.coeff(i, j));
dst.coeffRef(j, j) = ei_real(src.coeff(j, j));
}
}
};
// FIXME should we keep that possibility
template<typename MatrixType, unsigned int Mode>
template<typename OtherDerived>
@ -484,7 +459,7 @@ void TriangularView<MatrixType, Mode>::lazyAssign(const MatrixBase<OtherDerived>
<= EIGEN_UNROLLING_LIMIT;
ei_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols());
ei_part_assignment_impl
ei_triangular_assignment_selector
<MatrixType, OtherDerived, int(Mode),
unroll ? int(MatrixType::SizeAtCompileTime) : Dynamic,
false // do not change the opposite triangular part
@ -518,7 +493,7 @@ void TriangularView<MatrixType, Mode>::lazyAssign(const TriangularBase<OtherDeri
<= EIGEN_UNROLLING_LIMIT;
ei_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols());
ei_part_assignment_impl
ei_triangular_assignment_selector
<MatrixType, OtherDerived, int(Mode),
unroll ? int(MatrixType::SizeAtCompileTime) : Dynamic,
false // preserve the opposite triangular part
@ -526,7 +501,7 @@ void TriangularView<MatrixType, Mode>::lazyAssign(const TriangularBase<OtherDeri
}
/***************************************************************************
* Implementation of MatrixBase methods
* Implementation of TriangularBase methods
***************************************************************************/
/** Assigns a triangular or selfadjoint matrix to a dense matrix.
@ -555,13 +530,17 @@ void TriangularBase<Derived>::evalToDenseLazy(MatrixBase<DenseDerived> &other) c
<= EIGEN_UNROLLING_LIMIT;
ei_assert(this->rows() == other.rows() && this->cols() == other.cols());
ei_part_assignment_impl
ei_triangular_assignment_selector
<DenseDerived, typename ei_traits<Derived>::ExpressionType, Derived::Mode,
unroll ? int(DenseDerived::SizeAtCompileTime) : Dynamic,
true // clear the opposite triangular part
>::run(other.derived(), derived()._expression());
}
/***************************************************************************
* Implementation of MatrixBase methods
***************************************************************************/
/** \deprecated use MatrixBase::triangularView() */
template<typename Derived>
template<unsigned int Mode>