From 6d1f5dbaaefcb9cc198aad362146131f8eec9cd7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Jul 2013 23:48:26 +0200 Subject: [PATCH] Add no_assignment_operator to a few classes that must not be assigned, and fix a couple of warnings. --- Eigen/src/Geometry/Homogeneous.h | 2 +- Eigen/src/SparseLU/SparseLU.h | 7 ++- Eigen/src/SparseLU/SparseLU_Memory.h | 6 +- .../src/SparseLU/SparseLU_SupernodalMatrix.h | 29 ++++----- Eigen/src/SparseLU/SparseLU_column_dfs.h | 2 +- test/cholesky.cpp | 1 + test/geo_eulerangles.cpp | 8 +-- test/mapstride.cpp | 4 +- test/redux.cpp | 2 +- test/sizeof.cpp | 2 +- test/sparse.h | 16 ++--- test/sparse_basic.cpp | 63 ++++++++++--------- .../LevenbergMarquardt/LevenbergMarquardt.h | 2 +- 13 files changed, 75 insertions(+), 69 deletions(-) diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index df03feb55..00e71d190 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -59,7 +59,7 @@ template struct homogeneous_right_product_impl } // end namespace internal template class Homogeneous - : public MatrixBase > + : internal::no_assignment_operator, public MatrixBase > { public: diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index ee79c7762..dda79e5d2 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -511,7 +511,7 @@ void SparseLU::factorize(const MatrixType& matrix) m_perm_r.resize(m); m_perm_r.indices().setConstant(-1); marker.setConstant(-1); - m_detPermR = 1.0; // Record the determinant of the row permutation + m_detPermR = 1; // Record the determinant of the row permutation m_glu.supno(0) = emptyIdxLU; m_glu.xsup.setConstant(0); m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0); @@ -630,7 +630,7 @@ void SparseLU::factorize(const MatrixType& matrix) } template -struct SparseLUMatrixLReturnType +struct SparseLUMatrixLReturnType : internal::no_assignment_operator { typedef typename MappedSupernodalType::Index Index; typedef typename MappedSupernodalType::Scalar Scalar; @@ -647,7 +647,7 @@ struct SparseLUMatrixLReturnType }; template -struct SparseLUMatrixUReturnType +struct SparseLUMatrixUReturnType : internal::no_assignment_operator { typedef typename MatrixLType::Index Index; typedef typename MatrixLType::Scalar Scalar; @@ -700,6 +700,7 @@ struct SparseLUMatrixUReturnType const MatrixLType& m_mapL; const MatrixUType& m_mapU; }; + namespace internal { template diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index 6d9570d19..a5158025c 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -70,7 +70,7 @@ Index SparseLUImpl::expand(VectorType& vec, Index& length, Index if(num_expansions == 0 || keep_prev) new_len = length ; // First time allocate requested else - new_len = alpha * length ; + new_len = Index(alpha * length); VectorType old_vec; // Temporary vector to hold the previous values if (nbElts > 0 ) @@ -100,7 +100,7 @@ Index SparseLUImpl::expand(VectorType& vec, Index& length, Index do { alpha = (alpha + 1)/2; - new_len = alpha * length ; + new_len = Index(alpha * length); try { vec.resize(new_len); @@ -141,7 +141,7 @@ Index SparseLUImpl::memInit(Index m, Index n, Index annz, Index lw Index& num_expansions = glu.num_expansions; //No memory expansions so far num_expansions = 0; glu.nzumax = glu.nzlumax = (std::max)(fillratio * annz, m*n); // estimated number of nonzeros in U - glu.nzlmax = (std::max)(1., fillratio/4.) * annz; // estimated nnz in L factor + glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4; // estimated nnz in L factor // Return the estimated size to the user if necessary Index tempSpace; diff --git a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h index 3836d1096..ad6f2183f 100644 --- a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +++ b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h @@ -216,13 +216,13 @@ class MappedSuperNodalMatrix::InnerIterator protected: const MappedSuperNodalMatrix& m_matrix; // Supernodal lower triangular matrix - const Index m_outer; // Current column - const Index m_supno; // Current SuperNode number - Index m_idval; //Index to browse the values in the current column - const Index m_startidval; // Start of the column value - const Index m_endidval; // End of the column value - Index m_idrow; //Index to browse the row indices - Index m_endidrow; // End index of row indices of the current column + const Index m_outer; // Current column + const Index m_supno; // Current SuperNode number + Index m_idval; // Index to browse the values in the current column + const Index m_startidval; // Start of the column value + const Index m_endidval; // End of the column value + Index m_idrow; // Index to browse the row indices + Index m_endidrow; // End index of row indices of the current column }; /** @@ -235,17 +235,17 @@ void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) con { Index n = X.rows(); Index nrhs = X.cols(); - const Scalar * Lval = valuePtr(); // Nonzero values - Matrix work(n, nrhs); // working vector + const Scalar * Lval = valuePtr(); // Nonzero values + Matrix work(n, nrhs); // working vector work.setZero(); for (Index k = 0; k <= nsuper(); k ++) { - Index fsupc = supToCol()[k]; // First column of the current supernode - Index istart = rowIndexPtr()[fsupc]; // Pointer index to the subscript of the current column + Index fsupc = supToCol()[k]; // First column of the current supernode + Index istart = rowIndexPtr()[fsupc]; // Pointer index to the subscript of the current column Index nsupr = rowIndexPtr()[fsupc+1] - istart; // Number of rows in the current supernode - Index nsupc = supToCol()[k+1] - fsupc; // Number of columns in the current supernode - Index nrow = nsupr - nsupc; // Number of rows in the non-diagonal part of the supernode - Index irow; //Current index row + Index nsupc = supToCol()[k+1] - fsupc; // Number of columns in the current supernode + Index nrow = nsupr - nsupc; // Number of rows in the non-diagonal part of the supernode + Index irow; //Current index row if (nsupc == 1 ) { @@ -294,4 +294,5 @@ void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) con } // end namespace internal } // end namespace Eigen + #endif // EIGEN_SPARSELU_MATRIX_H diff --git a/Eigen/src/SparseLU/SparseLU_column_dfs.h b/Eigen/src/SparseLU/SparseLU_column_dfs.h index bc4cfbf37..4c04b0e44 100644 --- a/Eigen/src/SparseLU/SparseLU_column_dfs.h +++ b/Eigen/src/SparseLU/SparseLU_column_dfs.h @@ -36,7 +36,7 @@ namespace Eigen { namespace internal { template -struct column_dfs_traits +struct column_dfs_traits : no_assignment_operator { typedef typename ScalarVector::Scalar Scalar; typedef typename IndexVector::Scalar Index; diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 38862924a..378525a83 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -328,4 +328,5 @@ void test_cholesky() CALL_SUBTEST_9( LDLT(10) ); TEST_SET_BUT_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(nb_temporaries) } diff --git a/test/geo_eulerangles.cpp b/test/geo_eulerangles.cpp index 26456beee..4361625e3 100644 --- a/test/geo_eulerangles.cpp +++ b/test/geo_eulerangles.cpp @@ -41,7 +41,7 @@ template void check_all_var(const Matrix& ea) VERIFY_EULER(2,1,2, Z,Y,Z); } -template void eulerangles(void) +template void eulerangles() { typedef Matrix Matrix3; typedef Matrix Vector3; @@ -60,13 +60,13 @@ template void eulerangles(void) ea = m.eulerAngles(0,1,0); check_all_var(ea); - ea = (Array3::Random() + Array3(1,1,0))*M_PI*Array3(0.5,0.5,1); + ea = (Array3::Random() + Array3(1,1,0))*Scalar(M_PI)*Array3(0.5,0.5,1); check_all_var(ea); - ea[2] = ea[0] = internal::random(0,M_PI); + ea[2] = ea[0] = internal::random(0,Scalar(M_PI)); check_all_var(ea); - ea[0] = ea[1] = internal::random(0,M_PI); + ea[0] = ea[1] = internal::random(0,Scalar(M_PI)); check_all_var(ea); ea[1] = 0; diff --git a/test/mapstride.cpp b/test/mapstride.cpp index fe35b9d23..b1dc9de2a 100644 --- a/test/mapstride.cpp +++ b/test/mapstride.cpp @@ -116,7 +116,7 @@ template void map_class_matrix(const MatrixTy void test_mapstride() { for(int i = 0; i < g_repeat; i++) { - EIGEN_UNUSED int maxn = 30; + int maxn = 30; CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_2( map_class_vector(Vector4d()) ); @@ -142,5 +142,7 @@ void test_mapstride() CALL_SUBTEST_5( map_class_matrix(MatrixXi(internal::random(1,maxn),internal::random(1,maxn))) ); CALL_SUBTEST_6( map_class_matrix(MatrixXcd(internal::random(1,maxn),internal::random(1,maxn))) ); CALL_SUBTEST_6( map_class_matrix(MatrixXcd(internal::random(1,maxn),internal::random(1,maxn))) ); + + TEST_SET_BUT_UNUSED_VARIABLE(maxn); } } diff --git a/test/redux.cpp b/test/redux.cpp index bb65f9461..0d176e500 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -22,7 +22,7 @@ template void matrixRedux(const MatrixType& m) // The entries of m1 are uniformly distributed in [0,1], so m1.prod() is very small. This may lead to test // failures if we underflow into denormals. Thus, we scale so that entires are close to 1. - MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + Scalar(0.2) * m1; + MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + RealScalar(0.2) * m1; VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows, cols).sum(), Scalar(1)); VERIFY_IS_APPROX(MatrixType::Ones(rows, cols).sum(), Scalar(float(rows*cols))); // the float() here to shut up excessive MSVC warning about int->complex conversion being lossy diff --git a/test/sizeof.cpp b/test/sizeof.cpp index 68463c9b6..c454780a6 100644 --- a/test/sizeof.cpp +++ b/test/sizeof.cpp @@ -13,7 +13,7 @@ template void verifySizeOf(const MatrixType&) { typedef typename MatrixType::Scalar Scalar; if (MatrixType::RowsAtCompileTime!=Dynamic && MatrixType::ColsAtCompileTime!=Dynamic) - VERIFY(sizeof(MatrixType)==sizeof(Scalar)*size_t(MatrixType::SizeAtCompileTime)); + VERIFY(sizeof(MatrixType)==sizeof(Scalar)*std::ptrdiff_t(MatrixType::SizeAtCompileTime)); else VERIFY(sizeof(MatrixType)==sizeof(Scalar*) + 2 * sizeof(typename MatrixType::Index)); } diff --git a/test/sparse.h b/test/sparse.h index 7e2b98494..1a5ceb38d 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -58,8 +58,8 @@ initSparse(double density, Matrix& refMat, SparseMatrix& sparseMat, int flags = 0, - std::vector* zeroCoords = 0, - std::vector* nonzeroCoords = 0) + std::vector >* zeroCoords = 0, + std::vector >* nonzeroCoords = 0) { enum { IsRowMajor = SparseMatrix::IsRowMajor }; sparseMat.setZero(); @@ -93,11 +93,11 @@ initSparse(double density, //sparseMat.insertBackByOuterInner(j,i) = v; sparseMat.insertByOuterInner(j,i) = v; if (nonzeroCoords) - nonzeroCoords->push_back(Vector2i(ai,aj)); + nonzeroCoords->push_back(Matrix (ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(ai,aj)); + zeroCoords->push_back(Matrix (ai,aj)); } refMat(ai,aj) = v; } @@ -110,8 +110,8 @@ initSparse(double density, Matrix& refMat, DynamicSparseMatrix& sparseMat, int flags = 0, - std::vector* zeroCoords = 0, - std::vector* nonzeroCoords = 0) + std::vector >* zeroCoords = 0, + std::vector >* nonzeroCoords = 0) { enum { IsRowMajor = DynamicSparseMatrix::IsRowMajor }; sparseMat.setZero(); @@ -142,11 +142,11 @@ initSparse(double density, { sparseMat.insertBackByOuterInner(j,i) = v; if (nonzeroCoords) - nonzeroCoords->push_back(Vector2i(ai,aj)); + nonzeroCoords->push_back(Matrix (ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(ai,aj)); + zeroCoords->push_back(Matrix (ai,aj)); } refMat(ai,aj) = v; } diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 8fc1904b1..d466b51da 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -14,7 +14,8 @@ template void sparse_basic(const SparseMatrixType& ref) { typedef typename SparseMatrixType::Index Index; - + typedef Matrix Vector2; + const Index rows = ref.rows(); const Index cols = ref.cols(); typedef typename SparseMatrixType::Scalar Scalar; @@ -31,8 +32,8 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat = DenseMatrix::Zero(rows, cols); DenseVector vec1 = DenseVector::Random(rows); - std::vector zeroCoords; - std::vector nonzeroCoords; + std::vector zeroCoords; + std::vector nonzeroCoords; initSparse(density, refMat, m, 0, &zeroCoords, &nonzeroCoords); if (zeroCoords.size()==0 || nonzeroCoords.size()==0) @@ -104,11 +105,11 @@ template void sparse_basic(const SparseMatrixType& re SparseMatrixType m2(rows,cols); if(internal::random()%2) m2.reserve(VectorXi::Constant(m2.outerSize(), 2)); - for (int j=0; j(0,rows-1); + Index i = internal::random(0,rows-1); if (m1.coeff(i,j)==Scalar(0)) m2.insert(i,j) = m1(i,j) = internal::random(); } @@ -126,8 +127,8 @@ template void sparse_basic(const SparseMatrixType& re m2.reserve(VectorXi::Constant(m2.outerSize(), 2)); for (int k=0; k(0,rows-1); - int j = internal::random(0,cols-1); + Index i = internal::random(0,rows-1); + Index j = internal::random(0,cols-1); if ((m1.coeff(i,j)==Scalar(0)) && (internal::random()%2)) m2.insert(i,j) = m1(i,j) = internal::random(); else @@ -150,8 +151,8 @@ template void sparse_basic(const SparseMatrixType& re m2.reserve(r); for (int k=0; k(0,rows-1); - int j = internal::random(0,cols-1); + Index i = internal::random(0,rows-1); + Index j = internal::random(0,cols-1); if (m1.coeff(i,j)==Scalar(0)) m2.insert(i,j) = m1(i,j) = internal::random(); if(mode==3) @@ -167,8 +168,8 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse(density, refMat2, m2); - int j0 = internal::random(0,rows-1); - int j1 = internal::random(0,rows-1); + Index j0 = internal::random(0,rows-1); + Index j1 = internal::random(0,rows-1); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.row(j0)); else @@ -181,17 +182,17 @@ template void sparse_basic(const SparseMatrixType& re SparseMatrixType m3(rows,rows); m3.reserve(VectorXi::Constant(rows,rows/2)); - for(int j=0; j0) VERIFY(j==numext::real(m3.innerVector(j).lastCoeff())); } m3.makeCompressed(); - for(int j=0; j0) @@ -210,9 +211,9 @@ template void sparse_basic(const SparseMatrixType& re initSparse(density, refMat2, m2); if(internal::random(0,1)>0.5) m2.makeCompressed(); - int j0 = internal::random(0,rows-2); - int j1 = internal::random(0,rows-2); - int n0 = internal::random(1,rows-(std::max)(j0,j1)); + Index j0 = internal::random(0,rows-2); + Index j1 = internal::random(0,rows-2); + Index n0 = internal::random(1,rows-(std::max)(j0,j1)); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(j0,0,n0,cols)); else @@ -300,9 +301,9 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse(density, refMat2, m2); - int j0 = internal::random(0,rows-2); - int j1 = internal::random(0,rows-2); - int n0 = internal::random(1,rows-(std::max)(j0,j1)); + Index j0 = internal::random(0,rows-2); + Index j1 = internal::random(0,rows-2); + Index n0 = internal::random(1,rows-(std::max)(j0,j1)); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.block(j0,0,n0,cols), refMat2.block(j0,0,n0,cols)); else @@ -315,7 +316,7 @@ template void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m2.block(0,j0,rows,n0)+m2.block(0,j1,rows,n0), refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); - int i = internal::random(0,m2.outerSize()-1); + Index i = internal::random(0,m2.outerSize()-1); if(SparseMatrixType::IsRowMajor) { m2.innerVector(i) = m2.innerVector(i) * s1; refMat2.row(i) = refMat2.row(i) * s1; @@ -334,10 +335,10 @@ template void sparse_basic(const SparseMatrixType& re refM2.setZero(); int countFalseNonZero = 0; int countTrueNonZero = 0; - for (int j=0; j(0,1); if (x<0.1) @@ -378,8 +379,8 @@ template void sparse_basic(const SparseMatrixType& re refMat.setZero(); for(int i=0;i(0,rows-1); - int c = internal::random(0,cols-1); + Index r = internal::random(0,rows-1); + Index c = internal::random(0,cols-1); Scalar v = internal::random(); triplets.push_back(TripletType(r,c,v)); refMat(r,c) += v; @@ -456,8 +457,8 @@ template void sparse_basic(const SparseMatrixType& re inc.push_back(std::pair(0,3)); for(size_t i = 0; i< inc.size(); i++) { - int incRows = inc[i].first; - int incCols = inc[i].second; + Index incRows = inc[i].first; + Index incCols = inc[i].second; SparseMatrixType m1(rows, cols); DenseMatrix refMat1 = DenseMatrix::Zero(rows, cols); initSparse(density, refMat1, m1); @@ -502,7 +503,7 @@ void test_sparse_basic() CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); + CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(s), short(s))) )); + CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(s), short(s))) )); } } diff --git a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h index ad47d3d84..51dd1d3c4 100644 --- a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h +++ b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h @@ -107,7 +107,7 @@ void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, * http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm */ template -class LevenbergMarquardt +class LevenbergMarquardt : internal::no_assignment_operator { public: typedef _FunctorType FunctorType;