From 5dda7842ca66c7a81b703734bc7bd8cef11a6d7b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 26 Feb 2013 11:42:32 +0100 Subject: Add assertion on the input matrix size in factorizations relying on permutations of 32bits int --- Eigen/src/LU/PartialPivLU.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Eigen/src/LU/PartialPivLU.h') diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h index c9ff9dd5a..4017b5699 100644 --- a/Eigen/src/LU/PartialPivLU.h +++ b/Eigen/src/LU/PartialPivLU.h @@ -386,6 +386,9 @@ void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, t template PartialPivLU& PartialPivLU::compute(const MatrixType& matrix) { + // the row permutation is stored as int indices, so just to be sure: + eigen_assert(matrix.rows()::highest()); + m_lu = matrix; eigen_assert(matrix.rows() == matrix.cols() && "PartialPivLU is only for square (and moreover invertible) matrices"); -- cgit v1.2.3 From d8f103535522dcc98c4e328e27ffea1e8450e526 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 9 Apr 2013 09:43:00 +0200 Subject: Fix a couple of int versus Index issues. --- Eigen/src/Cholesky/LLT.h | 8 ++--- Eigen/src/Core/Assign.h | 8 ++--- Eigen/src/Core/Functors.h | 4 +-- Eigen/src/Core/PermutationMatrix.h | 15 ++++---- Eigen/src/Core/products/TriangularMatrixVector.h | 2 +- Eigen/src/LU/PartialPivLU.h | 6 ++-- Eigen/src/SparseLU/SparseLU_gemm_kernel.h | 46 ++++++++++++------------ test/main.h | 2 +- 8 files changed, 46 insertions(+), 45 deletions(-) (limited to 'Eigen/src/LU/PartialPivLU.h') diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index 478fad251..db22a2f85 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -200,7 +200,7 @@ static typename MatrixType::Index llt_rank_update_lower(MatrixType& mat, const V typedef Matrix TempVectorType; typedef typename TempVectorType::SegmentReturnType TempVecSegment; - int n = mat.cols(); + Index n = mat.cols(); eigen_assert(mat.rows()==n && vec.size()==n); TempVectorType temp; @@ -212,12 +212,12 @@ static typename MatrixType::Index llt_rank_update_lower(MatrixType& mat, const V // i.e., for sigma > 0 temp = sqrt(sigma) * vec; - for(int i=0; i g; g.makeGivens(mat(i,i), -temp(i), &mat(i,i)); - int rs = n-i-1; + Index rs = n-i-1; if(rs>0) { ColXprSegment x(mat.col(i).tail(rs)); @@ -230,7 +230,7 @@ static typename MatrixType::Index llt_rank_update_lower(MatrixType& mat, const V { temp = vec; RealScalar beta = 1; - for(int j=0; j template struct assign_DefaultTraversal_InnerUnrolling { - static EIGEN_STRONG_INLINE void run(Derived1 &dst, const Derived2 &src, int outer) + static EIGEN_STRONG_INLINE void run(Derived1 &dst, const Derived2 &src, typename Derived1::Index outer) { dst.copyCoeffByOuterInner(outer, Index, src); assign_DefaultTraversal_InnerUnrolling::run(dst, src, outer); @@ -165,7 +165,7 @@ struct assign_DefaultTraversal_InnerUnrolling template struct assign_DefaultTraversal_InnerUnrolling { - static EIGEN_STRONG_INLINE void run(Derived1 &, const Derived2 &, int) {} + static EIGEN_STRONG_INLINE void run(Derived1 &, const Derived2 &, typename Derived1::Index) {} }; /*********************** @@ -218,7 +218,7 @@ struct assign_innervec_CompleteUnrolling template struct assign_innervec_InnerUnrolling { - static EIGEN_STRONG_INLINE void run(Derived1 &dst, const Derived2 &src, int outer) + static EIGEN_STRONG_INLINE void run(Derived1 &dst, const Derived2 &src, typename Derived1::Index outer) { dst.template copyPacketByOuterInner(outer, Index, src); assign_innervec_InnerUnrolling struct assign_innervec_InnerUnrolling { - static EIGEN_STRONG_INLINE void run(Derived1 &, const Derived2 &, int) {} + static EIGEN_STRONG_INLINE void run(Derived1 &, const Derived2 &, typename Derived1::Index) {} }; /*************************************************************************** diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 0ab767f30..9a84e8f26 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -560,7 +560,7 @@ struct linspaced_op_impl EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { m_base = padd(m_base, pset1(m_step)); - return m_low+i*m_step; + return m_low+Scalar(i)*m_step; } template @@ -609,7 +609,7 @@ template struct functor_traits< linspaced_o template struct linspaced_op { typedef typename packet_traits::type Packet; - linspaced_op(const Scalar& low, const Scalar& high, int num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/(num_steps-1))) {} + linspaced_op(const Scalar& low, const Scalar& high, DenseIndex num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/(num_steps-1))) {} template EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); } diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 21ecf0a58..4fc5dd318 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -541,24 +541,25 @@ struct permut_matrix_product_retval : public ReturnByValue > { typedef typename remove_all::type MatrixTypeNestedCleaned; + typedef typename MatrixType::Index Index; permut_matrix_product_retval(const PermutationType& perm, const MatrixType& matrix) : m_permutation(perm), m_matrix(matrix) {} - inline int rows() const { return m_matrix.rows(); } - inline int cols() const { return m_matrix.cols(); } + inline Index rows() const { return m_matrix.rows(); } + inline Index cols() const { return m_matrix.cols(); } template inline void evalTo(Dest& dst) const { - const int n = Side==OnTheLeft ? rows() : cols(); + const Index n = Side==OnTheLeft ? rows() : cols(); if(is_same::value && extract_data(dst) == extract_data(m_matrix)) { // apply the permutation inplace Matrix mask(m_permutation.size()); mask.fill(false); - int r = 0; + Index r = 0; while(r < m_permutation.size()) { // search for the next seed @@ -566,10 +567,10 @@ struct permut_matrix_product_retval if(r>=m_permutation.size()) break; // we got one, let's follow it until we are back to the seed - int k0 = r++; - int kPrev = k0; + Index k0 = r++; + Index kPrev = k0; mask.coeffRef(k0) = true; - for(int k=m_permutation.indices().coeff(k0); k!=k0; k=m_permutation.indices().coeff(k)) + for(Index k=m_permutation.indices().coeff(k0); k!=k0; k=m_permutation.indices().coeff(k)) { Block(dst, k) .swap(Block diff --git a/Eigen/src/Core/products/TriangularMatrixVector.h b/Eigen/src/Core/products/TriangularMatrixVector.h index 134a91d2d..c8b7d28c4 100644 --- a/Eigen/src/Core/products/TriangularMatrixVector.h +++ b/Eigen/src/Core/products/TriangularMatrixVector.h @@ -256,7 +256,7 @@ template<> struct trmv_selector if(!evalToDest) { #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN - int size = dest.size(); + Index size = dest.size(); EIGEN_DENSE_STORAGE_CTOR_PLUGIN #endif if(!alphaIsCompatible) diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h index 4017b5699..740ee694c 100644 --- a/Eigen/src/LU/PartialPivLU.h +++ b/Eigen/src/LU/PartialPivLU.h @@ -242,7 +242,7 @@ struct partial_lu_impl const Index cols = lu.cols(); const Index size = (std::min)(rows,cols); nb_transpositions = 0; - int first_zero_pivot = -1; + Index first_zero_pivot = -1; for(Index k = 0; k < size; ++k) { Index rrows = rows-k-1; @@ -253,7 +253,7 @@ struct partial_lu_impl = lu.col(k).tail(rows-k).cwiseAbs().maxCoeff(&row_of_biggest_in_col); row_of_biggest_in_col += k; - row_transpositions[k] = row_of_biggest_in_col; + row_transpositions[k] = PivIndex(row_of_biggest_in_col); if(biggest_in_corner != RealScalar(0)) { @@ -318,7 +318,7 @@ struct partial_lu_impl } nb_transpositions = 0; - int first_zero_pivot = -1; + Index first_zero_pivot = -1; for(Index k = 0; k < size; k+=blockSize) { Index bs = (std::min)(size-k,blockSize); // actual size of the block diff --git a/Eigen/src/SparseLU/SparseLU_gemm_kernel.h b/Eigen/src/SparseLU/SparseLU_gemm_kernel.h index c8edf1cac..9e4e3e72b 100644 --- a/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +++ b/Eigen/src/SparseLU/SparseLU_gemm_kernel.h @@ -21,9 +21,9 @@ namespace internal { * - lda and ldc must be multiples of the respective packet size * - C must have the same alignment as A */ -template +template EIGEN_DONT_INLINE -void sparselu_gemm(int m, int n, int d, const Scalar* A, int lda, const Scalar* B, int ldb, Scalar* C, int ldc) +void sparselu_gemm(Index m, Index n, Index d, const Scalar* A, Index lda, const Scalar* B, Index ldb, Scalar* C, Index ldc) { using namespace Eigen::internal; @@ -37,37 +37,37 @@ void sparselu_gemm(int m, int n, int d, const Scalar* A, int lda, const Scalar* BM = 4096/sizeof(Scalar), // number of rows of A-C per chunk SM = PM*PacketSize // step along M }; - int d_end = (d/RK)*RK; // number of columns of A (rows of B) suitable for full register blocking - int n_end = (n/RN)*RN; // number of columns of B-C suitable for processing RN columns at once - int i0 = internal::first_aligned(A,m); + Index d_end = (d/RK)*RK; // number of columns of A (rows of B) suitable for full register blocking + Index n_end = (n/RN)*RN; // number of columns of B-C suitable for processing RN columns at once + Index i0 = internal::first_aligned(A,m); eigen_internal_assert(((lda%PacketSize)==0) && ((ldc%PacketSize)==0) && (i0==internal::first_aligned(C,m))); // handle the non aligned rows of A and C without any optimization: - for(int i=0; i(BM, m-ib); // actual number of rows - int actual_b_end1 = (actual_b/SM)*SM; // actual number of rows suitable for peeling - int actual_b_end2 = (actual_b/PacketSize)*PacketSize; // actual number of rows suitable for vectorization + Index actual_b = std::min(BM, m-ib); // actual number of rows + Index actual_b_end1 = (actual_b/SM)*SM; // actual number of rows suitable for peeling + Index actual_b_end2 = (actual_b/PacketSize)*PacketSize; // actual number of rows suitable for vectorization // Let's process two columns of B-C at once - for(int j=0; j0) { - for(int j=0; j1 ? Aligned : 0 diff --git a/test/main.h b/test/main.h index 578284f5c..3be0f9fca 100644 --- a/test/main.h +++ b/test/main.h @@ -405,7 +405,7 @@ void set_repeat_from_string(const char *str) void set_seed_from_string(const char *str) { errno = 0; - g_seed = strtoul(str, 0, 10); + g_seed = int(strtoul(str, 0, 10)); if(errno || g_seed == 0) { std::cout << "Invalid seed value " << str << std::endl; -- cgit v1.2.3