mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-31 01:03:38 +08:00
Next try - more Index fixes.
This commit is contained in:
parent
546b802b77
commit
f34eaa2628
@ -127,7 +127,7 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
PermutationMatrix& operator=(const Transpositions<OtherSize,OtherMaxSize>& tr)
|
PermutationMatrix& operator=(const Transpositions<OtherSize,OtherMaxSize>& tr)
|
||||||
{
|
{
|
||||||
setIdentity(tr.size());
|
setIdentity(tr.size());
|
||||||
for(int k=size()-1; k>=0; --k)
|
for(Index k=size()-1; k>=0; --k)
|
||||||
applyTranspositionOnTheRight(k,tr.coeff(k));
|
applyTranspositionOnTheRight(k,tr.coeff(k));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -144,13 +144,13 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \returns the number of rows */
|
/** \returns the number of rows */
|
||||||
inline int rows() const { return m_indices.size(); }
|
inline Index rows() const { return m_indices.size(); }
|
||||||
|
|
||||||
/** \returns the number of columns */
|
/** \returns the number of columns */
|
||||||
inline int cols() const { return m_indices.size(); }
|
inline Index cols() const { return m_indices.size(); }
|
||||||
|
|
||||||
/** \returns the size of a side of the respective square matrix, i.e., the number of indices */
|
/** \returns the size of a side of the respective square matrix, i.e., the number of indices */
|
||||||
inline int size() const { return m_indices.size(); }
|
inline Index size() const { return m_indices.size(); }
|
||||||
|
|
||||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||||
template<typename DenseDerived>
|
template<typename DenseDerived>
|
||||||
@ -178,7 +178,7 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
|
|
||||||
/** Resizes to given size.
|
/** Resizes to given size.
|
||||||
*/
|
*/
|
||||||
inline void resize(int size)
|
inline void resize(Index size)
|
||||||
{
|
{
|
||||||
m_indices.resize(size);
|
m_indices.resize(size);
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
/** Sets *this to be the identity permutation matrix */
|
/** Sets *this to be the identity permutation matrix */
|
||||||
void setIdentity()
|
void setIdentity()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < m_indices.size(); ++i)
|
for(Index i = 0; i < m_indices.size(); ++i)
|
||||||
m_indices.coeffRef(i) = i;
|
m_indices.coeffRef(i) = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,10 +207,10 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
*
|
*
|
||||||
* \sa applyTranspositionOnTheRight(int,int)
|
* \sa applyTranspositionOnTheRight(int,int)
|
||||||
*/
|
*/
|
||||||
PermutationMatrix& applyTranspositionOnTheLeft(int i, int j)
|
PermutationMatrix& applyTranspositionOnTheLeft(Index i, Index j)
|
||||||
{
|
{
|
||||||
ei_assert(i>=0 && j>=0 && i<m_indices.size() && j<m_indices.size());
|
ei_assert(i>=0 && j>=0 && i<m_indices.size() && j<m_indices.size());
|
||||||
for(int k = 0; k < m_indices.size(); ++k)
|
for(Index k = 0; k < m_indices.size(); ++k)
|
||||||
{
|
{
|
||||||
if(m_indices.coeff(k) == i) m_indices.coeffRef(k) = j;
|
if(m_indices.coeff(k) == i) m_indices.coeffRef(k) = j;
|
||||||
else if(m_indices.coeff(k) == j) m_indices.coeffRef(k) = i;
|
else if(m_indices.coeff(k) == j) m_indices.coeffRef(k) = i;
|
||||||
@ -226,7 +226,7 @@ class PermutationMatrix : public EigenBase<PermutationMatrix<SizeAtCompileTime,
|
|||||||
*
|
*
|
||||||
* \sa applyTranspositionOnTheLeft(int,int)
|
* \sa applyTranspositionOnTheLeft(int,int)
|
||||||
*/
|
*/
|
||||||
PermutationMatrix& applyTranspositionOnTheRight(int i, int j)
|
PermutationMatrix& applyTranspositionOnTheRight(Index i, Index j)
|
||||||
{
|
{
|
||||||
ei_assert(i>=0 && j>=0 && i<m_indices.size() && j<m_indices.size());
|
ei_assert(i>=0 && j>=0 && i<m_indices.size() && j<m_indices.size());
|
||||||
std::swap(m_indices.coeffRef(i), m_indices.coeffRef(j));
|
std::swap(m_indices.coeffRef(i), m_indices.coeffRef(j));
|
||||||
|
@ -106,8 +106,8 @@ template<typename MatrixType> void reverse(const MatrixType& m)
|
|||||||
|
|
||||||
Scalar x = ei_random<Scalar>();
|
Scalar x = ei_random<Scalar>();
|
||||||
|
|
||||||
int r = ei_random<int>(0, rows-1),
|
Index r = ei_random<Index>(0, rows-1),
|
||||||
c = ei_random<int>(0, cols-1);
|
c = ei_random<Index>(0, cols-1);
|
||||||
|
|
||||||
m1.reverse()(r, c) = x;
|
m1.reverse()(r, c) = x;
|
||||||
VERIFY_IS_APPROX(x, m1(rows - 1 - r, cols - 1 - c));
|
VERIFY_IS_APPROX(x, m1(rows - 1 - r, cols - 1 - c));
|
||||||
|
@ -25,17 +25,18 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
template<typename PermutationVectorType>
|
template<typename PermutationVectorType>
|
||||||
void randomPermutationVector(PermutationVectorType& v, int size)
|
void randomPermutationVector(PermutationVectorType& v, typename PermutationVectorType::Index size)
|
||||||
{
|
{
|
||||||
|
typedef typename PermutationVectorType::Index Index;
|
||||||
typedef typename PermutationVectorType::Scalar Scalar;
|
typedef typename PermutationVectorType::Scalar Scalar;
|
||||||
v.resize(size);
|
v.resize(size);
|
||||||
for(int i = 0; i < size; ++i) v(i) = Scalar(i);
|
for(Index i = 0; i < size; ++i) v(i) = Scalar(i);
|
||||||
if(size == 1) return;
|
if(size == 1) return;
|
||||||
for(int n = 0; n < 3 * size; ++n)
|
for(Index n = 0; n < 3 * size; ++n)
|
||||||
{
|
{
|
||||||
int i = ei_random<int>(0, size-1);
|
Index i = ei_random<Index>(0, size-1);
|
||||||
int j;
|
Index j;
|
||||||
do j = ei_random<int>(0, size-1); while(j==i);
|
do j = ei_random<Index>(0, size-1); while(j==i);
|
||||||
std::swap(v(i), v(j));
|
std::swap(v(i), v(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,17 +108,17 @@ template<typename MatrixType> void permutationmatrices(const MatrixType& m)
|
|||||||
if(rows>1 && cols>1)
|
if(rows>1 && cols>1)
|
||||||
{
|
{
|
||||||
lp2 = lp;
|
lp2 = lp;
|
||||||
int i = ei_random<int>(0, rows-1);
|
Index i = ei_random<Index>(0, rows-1);
|
||||||
int j;
|
Index j;
|
||||||
do j = ei_random<int>(0, rows-1); while(j==i);
|
do j = ei_random<Index>(0, rows-1); while(j==i);
|
||||||
lp2.applyTranspositionOnTheLeft(i, j);
|
lp2.applyTranspositionOnTheLeft(i, j);
|
||||||
lm = lp;
|
lm = lp;
|
||||||
lm.row(i).swap(lm.row(j));
|
lm.row(i).swap(lm.row(j));
|
||||||
VERIFY_IS_APPROX(lm, lp2.toDenseMatrix().template cast<Scalar>());
|
VERIFY_IS_APPROX(lm, lp2.toDenseMatrix().template cast<Scalar>());
|
||||||
|
|
||||||
RightPermutationType rp2 = rp;
|
RightPermutationType rp2 = rp;
|
||||||
i = ei_random<int>(0, cols-1);
|
i = ei_random<Index>(0, cols-1);
|
||||||
do j = ei_random<int>(0, cols-1); while(j==i);
|
do j = ei_random<Index>(0, cols-1); while(j==i);
|
||||||
rp2.applyTranspositionOnTheRight(i, j);
|
rp2.applyTranspositionOnTheRight(i, j);
|
||||||
rm = rp;
|
rm = rp;
|
||||||
rm.col(i).swap(rm.col(j));
|
rm.col(i).swap(rm.col(j));
|
||||||
|
@ -105,12 +105,12 @@ template<typename MatrixType> void product_extra(const MatrixType& m)
|
|||||||
(-m1.adjoint()*s2).eval() * (s1 * v1.adjoint()).eval());
|
(-m1.adjoint()*s2).eval() * (s1 * v1.adjoint()).eval());
|
||||||
|
|
||||||
// test the vector-matrix product with non aligned starts
|
// test the vector-matrix product with non aligned starts
|
||||||
int i = ei_random<int>(0,m1.rows()-2);
|
Index i = ei_random<Index>(0,m1.rows()-2);
|
||||||
int j = ei_random<int>(0,m1.cols()-2);
|
Index j = ei_random<Index>(0,m1.cols()-2);
|
||||||
int r = ei_random<int>(1,m1.rows()-i);
|
Index r = ei_random<Index>(1,m1.rows()-i);
|
||||||
int c = ei_random<int>(1,m1.cols()-j);
|
Index c = ei_random<Index>(1,m1.cols()-j);
|
||||||
int i2 = ei_random<int>(0,m1.rows()-1);
|
Index i2 = ei_random<Index>(0,m1.rows()-1);
|
||||||
int j2 = ei_random<int>(0,m1.cols()-1);
|
Index j2 = ei_random<Index>(0,m1.cols()-1);
|
||||||
|
|
||||||
VERIFY_IS_APPROX(m1.col(j2).adjoint() * m1.block(0,j,m1.rows(),c), m1.col(j2).adjoint().eval() * m1.block(0,j,m1.rows(),c).eval());
|
VERIFY_IS_APPROX(m1.col(j2).adjoint() * m1.block(0,j,m1.rows(),c), m1.col(j2).adjoint().eval() * m1.block(0,j,m1.rows(),c).eval());
|
||||||
VERIFY_IS_APPROX(m1.block(i,0,r,m1.cols()) * m1.row(i2).adjoint(), m1.block(i,0,r,m1.cols()).eval() * m1.row(i2).adjoint().eval());
|
VERIFY_IS_APPROX(m1.block(i,0,r,m1.cols()) * m1.row(i2).adjoint(), m1.block(i,0,r,m1.cols()).eval() * m1.row(i2).adjoint().eval());
|
||||||
|
@ -47,12 +47,13 @@ struct ei_increment_if_fixed_size
|
|||||||
template<int Deg, typename POLYNOMIAL, typename SOLVER>
|
template<int Deg, typename POLYNOMIAL, typename SOLVER>
|
||||||
bool aux_evalSolver( const POLYNOMIAL& pols, SOLVER& psolve )
|
bool aux_evalSolver( const POLYNOMIAL& pols, SOLVER& psolve )
|
||||||
{
|
{
|
||||||
|
typedef typename POLYNOMIAL::Index Index;
|
||||||
typedef typename POLYNOMIAL::Scalar Scalar;
|
typedef typename POLYNOMIAL::Scalar Scalar;
|
||||||
|
|
||||||
typedef typename SOLVER::RootsType RootsType;
|
typedef typename SOLVER::RootsType RootsType;
|
||||||
typedef Matrix<Scalar,Deg,1> EvalRootsType;
|
typedef Matrix<Scalar,Deg,1> EvalRootsType;
|
||||||
|
|
||||||
const int deg = pols.size()-1;
|
const Index deg = pols.size()-1;
|
||||||
|
|
||||||
psolve.compute( pols );
|
psolve.compute( pols );
|
||||||
const RootsType& roots( psolve.roots() );
|
const RootsType& roots( psolve.roots() );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user