diff options
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/Assign.h | 11 | ||||
-rw-r--r-- | Eigen/src/Core/BandMatrix.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryView.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/DenseStorageBase.h | 11 | ||||
-rw-r--r-- | Eigen/src/Core/Diagonal.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/Map.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/MapBase.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 23 | ||||
-rw-r--r-- | Eigen/src/Core/Redux.h | 10 | ||||
-rw-r--r-- | Eigen/src/Core/SolveTriangular.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/TriangularMatrix.h | 18 | ||||
-rw-r--r-- | Eigen/src/Core/Visitor.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/products/CoeffBasedProduct.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/products/SelfadjointProduct.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/products/TriangularMatrixMatrix.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/products/TriangularSolverMatrix.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/util/Constants.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/util/Macros.h | 26 | ||||
-rw-r--r-- | Eigen/src/Core/util/StaticAssert.h | 3 | ||||
-rw-r--r-- | Eigen/src/Core/util/XprHelper.h | 30 |
21 files changed, 143 insertions, 78 deletions
diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 494df7bd5..e025fa355 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -65,7 +65,8 @@ private: && (DstIsAligned || MaxSizeAtCompileTime == Dynamic), /* If the destination isn't aligned, we have to do runtime checks and we don't unroll, so it's only good for large enough sizes. */ - MaySliceVectorize = MightVectorize && DstHasDirectAccess && int(InnerMaxSize)>=3*PacketSize + MaySliceVectorize = MightVectorize && DstHasDirectAccess + && (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=3*PacketSize) /* slice vectorization can be slow, so we only want it if the slices are big, which is indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block in a fixed-size matrix */ @@ -86,8 +87,12 @@ public: private: enum { UnrollingLimit = EIGEN_UNROLLING_LIMIT * (Vectorized ? int(PacketSize) : 1), - MayUnrollCompletely = int(Derived::SizeAtCompileTime) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit), - MayUnrollInner = int(InnerSize) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit) + MayUnrollCompletely = int(Derived::SizeAtCompileTime) != Dynamic + && int(OtherDerived::CoeffReadCost) != Dynamic + && int(Derived::SizeAtCompileTime) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit), + MayUnrollInner = int(InnerSize) != Dynamic + && int(OtherDerived::CoeffReadCost) != Dynamic + && int(InnerSize) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit) }; public: diff --git a/Eigen/src/Core/BandMatrix.h b/Eigen/src/Core/BandMatrix.h index fbe7e394b..fa0a24762 100644 --- a/Eigen/src/Core/BandMatrix.h +++ b/Eigen/src/Core/BandMatrix.h @@ -138,9 +138,8 @@ class BandMatrix : public EigenBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Opt DiagonalSize = (RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic) ? Dynamic : (ActualIndex<0 - // we handled Dynamic already, so can use EIGEN_ENUM_MIN safely here. - ? EIGEN_ENUM_MIN(ColsAtCompileTime, RowsAtCompileTime + ActualIndex) - : EIGEN_ENUM_MIN(RowsAtCompileTime, ColsAtCompileTime - ActualIndex)) + ? EIGEN_SIZE_MIN(ColsAtCompileTime, RowsAtCompileTime + ActualIndex) + : EIGEN_SIZE_MIN(RowsAtCompileTime, ColsAtCompileTime - ActualIndex)) }; typedef Block<DataType,1, DiagonalSize> BuildType; typedef typename ei_meta_if<Conjugate, diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 11a23c66a..953fc89a6 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -50,9 +50,12 @@ struct ei_traits<CwiseUnaryView<ViewOp, MatrixType> > Flags = (ei_traits<_MatrixTypeNested>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)), CoeffReadCost = ei_traits<_MatrixTypeNested>::CoeffReadCost + ei_functor_traits<ViewOp>::Cost, MatrixTypeInnerStride = ei_inner_stride_at_compile_time<MatrixType>::ret, + // need to cast the sizeof's from size_t to int explicitly, otherwise: + // "error: no integral type can represent all of the enumerator values InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic - ? Dynamic - : MatrixTypeInnerStride * sizeof(typename ei_traits<MatrixType>::Scalar) / sizeof(Scalar), + ? int(Dynamic) + : int(MatrixTypeInnerStride) + * int(sizeof(typename ei_traits<MatrixType>::Scalar) / sizeof(Scalar)), OuterStrideAtCompileTime = ei_outer_stride_at_compile_time<MatrixType>::ret }; }; diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h index 15f3988ea..6df7e4b18 100644 --- a/Eigen/src/Core/DenseStorageBase.h +++ b/Eigen/src/Core/DenseStorageBase.h @@ -512,15 +512,12 @@ class DenseStorageBase : public ei_dense_xpr_base<Derived>::type { EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor) && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0) - && (RowsAtCompileTime >= MaxRowsAtCompileTime) - && (ColsAtCompileTime >= MaxColsAtCompileTime) - && (MaxRowsAtCompileTime >= 0) - && (MaxColsAtCompileTime >= 0) - && (RowsAtCompileTime <= Dynamic) - && (ColsAtCompileTime <= Dynamic) + && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0)) + && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0)) + && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0)) + && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0)) && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic) && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic) - && ((MaxRowsAtCompileTime==Dynamic?1:MaxRowsAtCompileTime)*(MaxColsAtCompileTime==Dynamic?1:MaxColsAtCompileTime)<Dynamic) && (Options & (DontAlign|RowMajor)) == Options), INVALID_MATRIX_TEMPLATE_PARAMETERS) } diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index a4326a299..e93dabd45 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -51,13 +51,15 @@ struct ei_traits<Diagonal<MatrixType,DiagIndex> > typedef typename MatrixType::StorageKind StorageKind; enum { AbsDiagIndex = DiagIndex<0 ? -DiagIndex : DiagIndex, // only used if DiagIndex != Dynamic + // FIXME these computations are broken in the case where the matrix is rectangular and DiagIndex!=0 RowsAtCompileTime = (int(DiagIndex) == Dynamic || int(MatrixType::SizeAtCompileTime) == Dynamic) ? Dynamic - : (EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime, + : (EIGEN_SIZE_MIN(MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime) - AbsDiagIndex), ColsAtCompileTime = 1, MaxRowsAtCompileTime = int(MatrixType::MaxSizeAtCompileTime) == Dynamic ? Dynamic - : DiagIndex == Dynamic ? EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - : (EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex), + : DiagIndex == Dynamic ? EIGEN_MAXSIZE_MIN(MatrixType::MaxRowsAtCompileTime, + MatrixType::MaxColsAtCompileTime) + : (EIGEN_MAXSIZE_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) - AbsDiagIndex), MaxColsAtCompileTime = 1, Flags = (unsigned int)_MatrixTypeNested::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit) & ~RowMajorBit, CoeffReadCost = _MatrixTypeNested::CoeffReadCost, diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 6ca24b77d..a1ab29ead 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -79,10 +79,14 @@ struct ei_traits<Map<PlainObjectType, MapOptions, StrideType> > { typedef typename PlainObjectType::Scalar Scalar; enum { - InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime, - OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime, - HasNoInnerStride = InnerStrideAtCompileTime <= 1, - HasNoOuterStride = OuterStrideAtCompileTime == 0, + InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 + ? int(PlainObjectType::InnerStrideAtCompileTime) + : int(StrideType::InnerStrideAtCompileTime), + OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 + ? int(PlainObjectType::OuterStrideAtCompileTime) + : int(StrideType::OuterStrideAtCompileTime), + HasNoInnerStride = InnerStrideAtCompileTime == 1, + HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0, HasNoStride = HasNoInnerStride && HasNoOuterStride, IsAligned = int(int(MapOptions)&Aligned)==Aligned, IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic, diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 8cdd452ac..979eef707 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -185,10 +185,11 @@ template<typename Derived> class MapBase void checkSanity() const { - ei_assert( ((!(ei_traits<Derived>::Flags&AlignedBit)) - || ((size_t(m_data)&0xf)==0)) && "data is not aligned"); - ei_assert( ((!(ei_traits<Derived>::Flags&PacketAccessBit)) - || (innerStride()==1)) && "packet access incompatible with inner stride greater than 1"); + EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(ei_traits<Derived>::Flags&PacketAccessBit, + ei_inner_stride_at_compile_time<Derived>::ret==1), + PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1); + ei_assert(EIGEN_IMPLIES(ei_traits<Derived>::Flags&AlignedBit, (size_t(m_data)&0xf)==0) + && "data is not aligned"); } const Scalar* EIGEN_RESTRICT m_data; diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 633b0106e..0a81c4da0 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -98,8 +98,8 @@ template<typename Derived> class MatrixBase #ifndef EIGEN_PARSED_BY_DOXYGEN /** type of the equivalent square matrix */ - typedef Matrix<Scalar,EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime), - EIGEN_ENUM_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; + typedef Matrix<Scalar,EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime), + EIGEN_SIZE_MAX(RowsAtCompileTime,ColsAtCompileTime)> SquareMatrixType; #endif // not EIGEN_PARSED_BY_DOXYGEN /** \returns the size of the main diagonal, which is min(rows(),cols()). diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 93e978779..b9aab524b 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -61,16 +61,16 @@ template<typename Lhs, typename Rhs> struct ei_product_type enum { Rows = _Lhs::MaxRowsAtCompileTime, Cols = _Rhs::MaxColsAtCompileTime, - Depth = EIGEN_ENUM_MIN(_Lhs::MaxColsAtCompileTime,_Rhs::MaxRowsAtCompileTime) + Depth = EIGEN_MAXSIZE_MIN(_Lhs::MaxColsAtCompileTime,_Rhs::MaxRowsAtCompileTime) }; // the splitting into different lines of code here, introducing the _select enums and the typedef below, // is to work around an internal compiler error with gcc 4.1 and 4.2. private: enum { - rows_select = Rows >=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Rows==1 ? 1 : Small), - cols_select = Cols >=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Cols==1 ? 1 : Small), - depth_select = Depth>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Depth==1 ? 1 : Small) + rows_select = Rows == Dynamic || Rows >=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Rows==1 ? 1 : Small), + cols_select = Cols == Dynamic || Cols >=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Cols==1 ? 1 : Small), + depth_select = Depth == Dynamic || Depth>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD ? Large : (Depth==1 ? 1 : Small) }; typedef ei_product_type_selector<rows_select, cols_select, depth_select> product_type_selector; @@ -78,6 +78,18 @@ public: enum { value = product_type_selector::ret }; +#ifdef EIGEN_DEBUG_PRODUCT + static void debug() + { + EIGEN_DEBUG_VAR(Rows); + EIGEN_DEBUG_VAR(Cols); + EIGEN_DEBUG_VAR(Depth); + EIGEN_DEBUG_VAR(rows_select); + EIGEN_DEBUG_VAR(cols_select); + EIGEN_DEBUG_VAR(depth_select); + EIGEN_DEBUG_VAR(value); + } +#endif }; /* The following allows to select the kind of product at compile time @@ -440,6 +452,9 @@ MatrixBase<Derived>::operator*(const MatrixBase<OtherDerived> &other) const EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors), INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION) EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT) +#ifdef EIGEN_DEBUG_PRODUCT + ei_product_type<Derived,OtherDerived>::debug(); +#endif return typename ProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived()); } diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 3fd5de74c..b3e60192f 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -61,14 +61,18 @@ public: public: enum { - Cost = Derived::SizeAtCompileTime * Derived::CoeffReadCost - + (Derived::SizeAtCompileTime-1) * NumTraits<typename Derived::Scalar>::AddCost, + Cost = ( Derived::SizeAtCompileTime == Dynamic + || Derived::CoeffReadCost == Dynamic + || (Derived::SizeAtCompileTime!=1 && ei_functor_traits<Func>::Cost == Dynamic) + ) ? Dynamic + : Derived::SizeAtCompileTime * Derived::CoeffReadCost + + (Derived::SizeAtCompileTime-1) * ei_functor_traits<Func>::Cost, UnrollingLimit = EIGEN_UNROLLING_LIMIT * (int(Traversal) == int(DefaultTraversal) ? 1 : int(PacketSize)) }; public: enum { - Unrolling = Cost <= UnrollingLimit + Unrolling = Cost != Dynamic && Cost <= UnrollingLimit ? CompleteUnrolling : NoUnrolling }; diff --git a/Eigen/src/Core/SolveTriangular.h b/Eigen/src/Core/SolveTriangular.h index 083c9cea2..96141d5ce 100644 --- a/Eigen/src/Core/SolveTriangular.h +++ b/Eigen/src/Core/SolveTriangular.h @@ -34,7 +34,7 @@ class ei_trsolve_traits }; public: enum { - Unrolling = (RhsIsVectorAtCompileTime && Rhs::SizeAtCompileTime <= 8) + Unrolling = (RhsIsVectorAtCompileTime && Rhs::SizeAtCompileTime != Dynamic && Rhs::SizeAtCompileTime <= 8) ? CompleteUnrolling : NoUnrolling, RhsVectors = RhsIsVectorAtCompileTime ? 1 : Dynamic }; diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 47c11ceb6..03347b09c 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -508,8 +508,10 @@ template<typename MatrixType, unsigned int Mode> template<typename OtherDerived> void TriangularView<MatrixType, Mode>::lazyAssign(const MatrixBase<OtherDerived>& other) { - const bool unroll = MatrixType::SizeAtCompileTime * ei_traits<OtherDerived>::CoeffReadCost / 2 - <= EIGEN_UNROLLING_LIMIT; + const bool unroll = MatrixType::SizeAtCompileTime != Dynamic + && ei_traits<OtherDerived>::CoeffReadCost != Dynamic + && MatrixType::SizeAtCompileTime * ei_traits<OtherDerived>::CoeffReadCost / 2 + <= EIGEN_UNROLLING_LIMIT; ei_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols()); ei_triangular_assignment_selector @@ -542,8 +544,10 @@ template<typename MatrixType, unsigned int Mode> template<typename OtherDerived> void TriangularView<MatrixType, Mode>::lazyAssign(const TriangularBase<OtherDerived>& other) { - const bool unroll = MatrixType::SizeAtCompileTime * ei_traits<OtherDerived>::CoeffReadCost / 2 - <= EIGEN_UNROLLING_LIMIT; + const bool unroll = MatrixType::SizeAtCompileTime != Dynamic + && ei_traits<OtherDerived>::CoeffReadCost != Dynamic + && MatrixType::SizeAtCompileTime * ei_traits<OtherDerived>::CoeffReadCost / 2 + <= EIGEN_UNROLLING_LIMIT; ei_assert(m_matrix.rows() == other.rows() && m_matrix.cols() == other.cols()); ei_triangular_assignment_selector @@ -579,8 +583,10 @@ template<typename Derived> template<typename DenseDerived> void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const { - const bool unroll = DenseDerived::SizeAtCompileTime * Derived::CoeffReadCost / 2 - <= EIGEN_UNROLLING_LIMIT; + const bool unroll = DenseDerived::SizeAtCompileTime != Dynamic + && ei_traits<Derived>::CoeffReadCost != Dynamic + && DenseDerived::SizeAtCompileTime * ei_traits<Derived>::CoeffReadCost / 2 + <= EIGEN_UNROLLING_LIMIT; ei_assert(this->rows() == other.rows() && this->cols() == other.cols()); ei_triangular_assignment_selector diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 2e96cfe6b..9116b9512 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -86,9 +86,11 @@ template<typename Derived> template<typename Visitor> void DenseBase<Derived>::visit(Visitor& visitor) const { - const bool unroll = SizeAtCompileTime * CoeffReadCost - + (SizeAtCompileTime-1) * ei_functor_traits<Visitor>::Cost - <= EIGEN_UNROLLING_LIMIT; + const bool unroll = SizeAtCompileTime != Dynamic + && CoeffReadCost != Dynamic + && (SizeAtCompileTime == 1 || ei_functor_traits<Visitor>::Cost != Dynamic) + && SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * ei_functor_traits<Visitor>::Cost + <= EIGEN_UNROLLING_LIMIT; return ei_visitor_impl<Visitor, Derived, unroll ? int(SizeAtCompileTime) : Dynamic >::run(derived(), visitor); diff --git a/Eigen/src/Core/products/CoeffBasedProduct.h b/Eigen/src/Core/products/CoeffBasedProduct.h index 0c39cbd84..170641589 100644 --- a/Eigen/src/Core/products/CoeffBasedProduct.h +++ b/Eigen/src/Core/products/CoeffBasedProduct.h @@ -63,7 +63,7 @@ struct ei_traits<CoeffBasedProduct<LhsNested,RhsNested,NestingFlags> > RowsAtCompileTime = _LhsNested::RowsAtCompileTime, ColsAtCompileTime = _RhsNested::ColsAtCompileTime, - InnerSize = EIGEN_ENUM_MIN(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime), + InnerSize = EIGEN_SIZE_MIN(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime), MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime, MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime, @@ -130,7 +130,7 @@ class CoeffBasedProduct enum { PacketSize = ei_packet_traits<Scalar>::size, InnerSize = ei_traits<CoeffBasedProduct>::InnerSize, - Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT, + Unroll = CoeffReadCost != Dynamic && CoeffReadCost <= EIGEN_UNROLLING_LIMIT, CanVectorizeInner = ei_traits<CoeffBasedProduct>::CanVectorizeInner }; @@ -269,14 +269,6 @@ struct ei_product_coeff_impl<DefaultTraversal, Dynamic, Lhs, Rhs, RetScalar> } }; -// prevent buggy user code from causing an infinite recursion -template<typename Lhs, typename Rhs, typename RetScalar> -struct ei_product_coeff_impl<DefaultTraversal, -1, Lhs, Rhs, RetScalar> -{ - typedef typename Lhs::Index Index; - EIGEN_STRONG_INLINE static void run(Index, Index, const Lhs&, const Rhs&, RetScalar&) {} -}; - /******************************************* *** Scalar path with inner vectorization *** *******************************************/ diff --git a/Eigen/src/Core/products/SelfadjointProduct.h b/Eigen/src/Core/products/SelfadjointProduct.h index bf835b516..befc4ff69 100644 --- a/Eigen/src/Core/products/SelfadjointProduct.h +++ b/Eigen/src/Core/products/SelfadjointProduct.h @@ -163,7 +163,7 @@ struct ei_sybb_kernel { enum { PacketSize = ei_packet_traits<Scalar>::size, - BlockSize = EIGEN_ENUM_MAX(mr,nr) + BlockSize = EIGEN_PLAIN_ENUM_MAX(mr,nr) }; void operator()(Scalar* res, Index resStride, const Scalar* blockA, const Scalar* blockB, Index size, Index depth, Scalar* workspace) { diff --git a/Eigen/src/Core/products/TriangularMatrixMatrix.h b/Eigen/src/Core/products/TriangularMatrixMatrix.h index 25d9ffe2d..7f6177ea7 100644 --- a/Eigen/src/Core/products/TriangularMatrixMatrix.h +++ b/Eigen/src/Core/products/TriangularMatrixMatrix.h @@ -112,7 +112,7 @@ struct ei_product_triangular_matrix_matrix<Scalar,Index,Mode,true, typedef ei_product_blocking_traits<Scalar> Blocking; enum { - SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), + SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Blocking::mr,Blocking::nr), IsLower = (Mode&Lower) == Lower }; @@ -230,7 +230,7 @@ struct ei_product_triangular_matrix_matrix<Scalar,Index,Mode,false, typedef ei_product_blocking_traits<Scalar> Blocking; enum { - SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), + SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Blocking::mr,Blocking::nr), IsLower = (Mode&Lower) == Lower }; diff --git a/Eigen/src/Core/products/TriangularSolverMatrix.h b/Eigen/src/Core/products/TriangularSolverMatrix.h index 1d8022517..11e08c3b5 100644 --- a/Eigen/src/Core/products/TriangularSolverMatrix.h +++ b/Eigen/src/Core/products/TriangularSolverMatrix.h @@ -59,7 +59,7 @@ struct ei_triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStora typedef ei_product_blocking_traits<Scalar> Blocking; enum { - SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), + SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Blocking::mr,Blocking::nr), IsLower = (Mode&Lower) == Lower }; @@ -192,7 +192,7 @@ struct ei_triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStor typedef ei_product_blocking_traits<Scalar> Blocking; enum { RhsStorageOrder = TriStorageOrder, - SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), + SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Blocking::mr,Blocking::nr), IsLower = (Mode&Lower) == Lower }; diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index a586f2a5d..e4dbc4aef 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -29,19 +29,9 @@ /** This value means that a quantity is not known at compile-time, and that instead the value is * stored in some runtime variable. * - * Explanation for the choice of this value: - * - It should be positive and larger than the number of entries in any reasonable fixed-size matrix. - * This allows to simplify many compile-time conditions throughout Eigen. - * - It should be smaller than the sqrt of INT_MAX. Indeed, we often multiply a number of rows with a number - * of columns in order to compute a number of coefficients. Even if we guard that with an "if" checking whether - * the values are Dynamic, we still get a compiler warning "integer overflow". So the only way to get around - * it would be a meta-selector. Doing this everywhere would reduce code readability and lengthen compilation times. - * Also, disabling compiler warnings for integer overflow, sounds like a bad idea. - * - It should be a prime number, because for example the old value 10000 led to bugs with 100x100 matrices. - * * Changing the value of Dynamic breaks the ABI, as Dynamic is often used as a template parameter for Matrix. */ -const int Dynamic = sizeof(int) >= 4 ? 33331 : 101; +const int Dynamic = -1; /** This value means +Infinity; it is currently used only as the p parameter to MatrixBase::lpNorm<int>(). * The value Infinity there means the L-infinity norm. diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 312a14414..3a65fb807 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -306,11 +306,31 @@ using Base::const_cast_derived; -#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) -#define EIGEN_SIZE_MIN(a,b) (((int)a == 1 || (int)b == 1) ? 1 \ +#define EIGEN_PLAIN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) +#define EIGEN_PLAIN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b) + +// EIGEN_SIZE_MIN gives the min between compile-time sizes. 0 has absolute priority, followed by 1, +// followed by Dynamic, followed by other finite values. The reason for giving Dynamic the priority over +// finite values is that min(3, Dynamic) should be Dynamic, since that could be anything between 0 and 3. +#define EIGEN_SIZE_MIN(a,b) (((int)a == 0 || (int)b == 0) ? 0 \ + : ((int)a == 1 || (int)b == 1) ? 1 \ : ((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \ : ((int)a <= (int)b) ? (int)a : (int)b) -#define EIGEN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b) + +// EIGEN_MAXSIZE_MIN is a variant of EIGEN_SIZE_MIN comparing MaxSizes. The difference is that finite values +// now have priority over Dynamic, so that min(3, Dynamic) gives 3. Indeed, whatever the actual value is +// (between 0 and 3), it is not more than 3. +#define EIGEN_MAXSIZE_MIN(a,b) (((int)a == 0 || (int)b == 0) ? 0 \ + : ((int)a == 1 || (int)b == 1) ? 1 \ + : ((int)a == Dynamic && (int)b == Dynamic) ? Dynamic \ + : ((int)a == Dynamic) ? (int)b \ + : ((int)b == Dynamic) ? (int)a \ + : ((int)a <= (int)b) ? (int)a : (int)b) + +// see EIGEN_SIZE_MIN. No need for a separate variant for MaxSizes here. +#define EIGEN_SIZE_MAX(a,b) (((int)a == Dynamic || (int)b == Dynamic) ? Dynamic \ + : ((int)a >= (int)b) ? (int)a : (int)b) + #define EIGEN_LOGICAL_XOR(a,b) (((a) || (b)) && !((a) && (b))) #define EIGEN_IMPLIES(a,b) (!(a) || (b)) diff --git a/Eigen/src/Core/util/StaticAssert.h b/Eigen/src/Core/util/StaticAssert.h index cf0db2901..e9f8cfadf 100644 --- a/Eigen/src/Core/util/StaticAssert.h +++ b/Eigen/src/Core/util/StaticAssert.h @@ -84,7 +84,8 @@ THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES, YOU_ALREADY_SPECIFIED_THIS_STRIDE, INVALID_STORAGE_ORDER_FOR_THIS_VECTOR_EXPRESSION, - THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD + THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD, + PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1 }; }; diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 63e99730a..cef7874a9 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -293,9 +293,15 @@ struct ei_ref_selector */ template<typename T, int n=1, typename PlainObject = typename ei_eval<T>::type> struct ei_nested { + // this is a direct port of the logic used when Dynamic was 33331, to make an atomic commit. enum { - CostEval = (n+1) * int(NumTraits<typename ei_traits<T>::Scalar>::ReadCost), - CostNoEval = (n-1) * int(ei_traits<T>::CoeffReadCost) + _ScalarReadCost = NumTraits<typename ei_traits<T>::Scalar>::ReadCost, + ScalarReadCost = _ScalarReadCost == Dynamic ? 33331 : int(_ScalarReadCost), + _CoeffReadCost = int(ei_traits<T>::CoeffReadCost), + CoeffReadCost = _CoeffReadCost == Dynamic ? 33331 : int(_CoeffReadCost), + N = n == Dynamic ? 33331 : n, + CostEval = (N+1) * int(ScalarReadCost), + CostNoEval = (N-1) * int(CoeffReadCost) }; typedef typename ei_meta_if< @@ -304,6 +310,24 @@ template<typename T, int n=1, typename PlainObject = typename ei_eval<T>::type> PlainObject, typename ei_ref_selector<T>::type >::ret type; + +/* this is what the above logic should be updated to look like: + enum { + ScalarReadCost = NumTraits<typename ei_traits<T>::Scalar>::ReadCost, + CoeffReadCost = ei_traits<T>::CoeffReadCost, + CostEval = n == Dynamic || ScalarReadCost == Dynamic ? int(Dynamic) : (n+1) * int(ScalarReadCost), + CostNoEval = n == Dynamic || (CoeffReadCost == Dynamic && n>1) ? int(Dynamic) : (n-1) * int(CoeffReadCost) + }; + + typedef typename ei_meta_if< + ( int(ei_traits<T>::Flags) & EvalBeforeNestingBit ) || + ( int(CostNoEval) == Dynamic ? true + : int(CostEval) == Dynamic ? false + : int(CostEval) <= int(CostNoEval) ), + PlainObject, + typename ei_ref_selector<T>::type + >::ret type; +*/ }; template<unsigned int Flags> struct ei_are_flags_consistent @@ -405,7 +429,7 @@ template<typename MatrixType, typename Scalar = typename MatrixType::Scalar> struct ei_plain_diag_type { enum { diag_size = EIGEN_SIZE_MIN(MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime), - max_diag_size = EIGEN_SIZE_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) + max_diag_size = EIGEN_MAXSIZE_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime) }; typedef Matrix<Scalar, diag_size, 1, MatrixType::PlainObject::Options & ~RowMajor, max_diag_size, 1> type; }; |