diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 754ce4c24..402f597d2 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -79,8 +79,6 @@ struct ProductReturnType */ template struct ei_product_mode { - typedef typename ei_blas_traits::ActualXprType ActualLhs; - typedef typename ei_blas_traits::ActualXprType ActualRhs; enum{ // workaround sun studio: LhsIsVectorAtCompileTime = ei_traits::ColsAtCompileTime==1 || ei_traits::ColsAtCompileTime==1, @@ -552,14 +550,14 @@ struct ei_cache_friendly_product_selector::_LhsNested> LhsProductTraits; typedef ei_blas_traits::_RhsNested> RhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; - typedef typename RhsProductTraits::ActualXprType ActualRhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; + typedef typename RhsProductTraits::ExtractType ActualRhsType; template inline static void run(DestDerived& res, const ProductType& product, typename ProductType::Scalar alpha) { - const ActualLhsType& actualLhs = LhsProductTraits::extract(product.lhs()); - const ActualRhsType& actualRhs = RhsProductTraits::extract(product.rhs()); + ActualLhsType actualLhs = LhsProductTraits::extract(product.lhs()); + ActualRhsType actualRhs = RhsProductTraits::extract(product.rhs()); Scalar actualAlpha = alpha * LhsProductTraits::extractScalarFactor(product.lhs()) * RhsProductTraits::extractScalarFactor(product.rhs()); @@ -613,14 +611,14 @@ struct ei_cache_friendly_product_selector::_LhsNested> LhsProductTraits; typedef ei_blas_traits::_RhsNested> RhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; - typedef typename RhsProductTraits::ActualXprType ActualRhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; + typedef typename RhsProductTraits::ExtractType ActualRhsType; template inline static void run(DestDerived& res, const ProductType& product, typename ProductType::Scalar alpha) { - const ActualLhsType& actualLhs = LhsProductTraits::extract(product.lhs()); - const ActualRhsType& actualRhs = RhsProductTraits::extract(product.rhs()); + ActualLhsType actualLhs = LhsProductTraits::extract(product.lhs()); + ActualRhsType actualRhs = RhsProductTraits::extract(product.rhs()); Scalar actualAlpha = alpha * LhsProductTraits::extractScalarFactor(product.lhs()) * RhsProductTraits::extractScalarFactor(product.rhs()); @@ -659,18 +657,19 @@ struct ei_cache_friendly_product_selector::_LhsNested> LhsProductTraits; typedef ei_blas_traits::_RhsNested> RhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; - typedef typename RhsProductTraits::ActualXprType ActualRhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; + typedef typename RhsProductTraits::ExtractType ActualRhsType; + typedef typename ei_cleantype::type _ActualRhsType; enum { - UseRhsDirectly = ((ei_packet_traits::size==1) || (ActualRhsType::Flags&ActualPacketAccessBit)) - && (!(ActualRhsType::Flags & RowMajorBit)) }; + UseRhsDirectly = ((ei_packet_traits::size==1) || (_ActualRhsType::Flags&ActualPacketAccessBit)) + && (!(_ActualRhsType::Flags & RowMajorBit)) }; template inline static void run(DestDerived& res, const ProductType& product, typename ProductType::Scalar alpha) { - const ActualLhsType& actualLhs = LhsProductTraits::extract(product.lhs()); - const ActualRhsType& actualRhs = RhsProductTraits::extract(product.rhs()); + ActualLhsType actualLhs = LhsProductTraits::extract(product.lhs()); + ActualRhsType actualRhs = RhsProductTraits::extract(product.rhs()); Scalar actualAlpha = alpha * LhsProductTraits::extractScalarFactor(product.lhs()) * RhsProductTraits::extractScalarFactor(product.rhs()); @@ -681,7 +680,7 @@ struct ei_cache_friendly_product_selector >(_rhs, actualRhs.size()) = actualRhs; + Map >(_rhs, actualRhs.size()) = actualRhs; } ei_cache_friendly_product_rowmajor_times_vector @@ -702,18 +701,19 @@ struct ei_cache_friendly_product_selector::_LhsNested> LhsProductTraits; typedef ei_blas_traits::_RhsNested> RhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; - typedef typename RhsProductTraits::ActualXprType ActualRhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; + typedef typename RhsProductTraits::ExtractType ActualRhsType; + typedef typename ei_cleantype::type _ActualLhsType; enum { - UseLhsDirectly = ((ei_packet_traits::size==1) || (ActualLhsType::Flags&ActualPacketAccessBit)) - && (ActualLhsType::Flags & RowMajorBit) }; + UseLhsDirectly = ((ei_packet_traits::size==1) || (_ActualLhsType::Flags&ActualPacketAccessBit)) + && (_ActualLhsType::Flags & RowMajorBit) }; template inline static void run(DestDerived& res, const ProductType& product, typename ProductType::Scalar alpha) { - const ActualLhsType& actualLhs = LhsProductTraits::extract(product.lhs()); - const ActualRhsType& actualRhs = RhsProductTraits::extract(product.rhs()); + ActualLhsType actualLhs = LhsProductTraits::extract(product.lhs()); + ActualRhsType actualRhs = RhsProductTraits::extract(product.rhs()); Scalar actualAlpha = alpha * LhsProductTraits::extractScalarFactor(product.lhs()) * RhsProductTraits::extractScalarFactor(product.rhs()); @@ -724,7 +724,7 @@ struct ei_cache_friendly_product_selector >(_lhs, actualLhs.size()) = actualLhs; + Map >(_lhs, actualLhs.size()) = actualLhs; } ei_cache_friendly_product_rowmajor_times_vector diff --git a/Eigen/src/Core/SolveTriangular.h b/Eigen/src/Core/SolveTriangular.h index 99cf79821..671b2458d 100644 --- a/Eigen/src/Core/SolveTriangular.h +++ b/Eigen/src/Core/SolveTriangular.h @@ -40,14 +40,14 @@ struct ei_triangular_solver_selector { typedef typename Rhs::Scalar Scalar; typedef ei_blas_traits LhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; enum { IsLowerTriangular = ((Mode&LowerTriangularBit)==LowerTriangularBit) }; static void run(const Lhs& lhs, Rhs& other) { static const int PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - const ActualLhsType& actualLhs = LhsProductTraits::extract(lhs); + ActualLhsType actualLhs = LhsProductTraits::extract(lhs); const int size = lhs.cols(); for(int pi=IsLowerTriangular ? 0 : size; @@ -94,7 +94,7 @@ struct ei_triangular_solver_selector typedef typename Rhs::Scalar Scalar; typedef typename ei_packet_traits::type Packet; typedef ei_blas_traits LhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; + typedef typename LhsProductTraits::ExtractType ActualLhsType; enum { PacketSize = ei_packet_traits::size, IsLowerTriangular = ((Mode&LowerTriangularBit)==LowerTriangularBit) @@ -103,7 +103,7 @@ struct ei_triangular_solver_selector static void run(const Lhs& lhs, Rhs& other) { static const int PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; - const ActualLhsType& actualLhs = LhsProductTraits::extract(lhs); + ActualLhsType actualLhs = LhsProductTraits::extract(lhs); const int size = lhs.cols(); for(int pi=IsLowerTriangular ? 0 : size; @@ -151,10 +151,10 @@ struct ei_triangular_solver_selector LhsProductTraits; - typedef typename LhsProductTraits::ActualXprType ActualLhsType; + typedef typename LhsProductTraits::DirectLinearAccessType ActualLhsType; static void run(const Lhs& lhs, Rhs& rhs) { - const ActualLhsType& actualLhs = LhsProductTraits::extract(lhs); + const ActualLhsType actualLhs = LhsProductTraits::extract(lhs); ei_triangular_solve_matrix ::run(lhs.rows(), rhs.cols(), &actualLhs.coeff(0,0), actualLhs.stride(), &rhs.coeffRef(0,0), rhs.stride()); } diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 65127d175..77865c410 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -116,6 +116,10 @@ template class Transpose m_matrix.const_cast_derived().template writePacket(index, x); } + /** \internal used for introspection */ + const typename ei_cleantype::type& + _expression() const { return m_matrix; } + protected: const typename MatrixType::Nested m_matrix; }; diff --git a/Eigen/src/Core/products/TriangularMatrixMatrix.h b/Eigen/src/Core/products/TriangularMatrixMatrix.h index 43a4c3d18..39a2bc4c5 100644 --- a/Eigen/src/Core/products/TriangularMatrixMatrix.h +++ b/Eigen/src/Core/products/TriangularMatrixMatrix.h @@ -344,13 +344,6 @@ struct ei_triangular_product_returntype::type _ActualRhsType; -// enum { -// LhsUpLo = LhsMode&(UpperTriangularBit|LowerTriangularBit), -// LhsIsTriangular = (LhsMode&SelfAdjointBit)==SelfAdjointBit, -// RhsUpLo = RhsMode&(UpperTriangularBit|LowerTriangularBit), -// RhsIsSelfAdjoint = (RhsMode&SelfAdjointBit)==SelfAdjointBit -// }; - template inline void _addTo(Dest& dst) const { evalTo(dst,1); } template inline void _subTo(Dest& dst) const diff --git a/Eigen/src/Core/util/BlasUtil.h b/Eigen/src/Core/util/BlasUtil.h index 339e11de7..c1b80acff 100644 --- a/Eigen/src/Core/util/BlasUtil.h +++ b/Eigen/src/Core/util/BlasUtil.h @@ -95,7 +95,9 @@ template<> struct ei_conj_helper { return std::complex(ei_real(x)*ei_real(y) - ei_imag(x)*ei_imag(y), - ei_real(x)*ei_imag(y) - ei_imag(x)*ei_real(y)); } }; -// lightweight helper class to access matrix coefficients +// Lightweight helper class to access matrix coefficients. +// Yes, this is somehow redundant with Map<>, but this version is much much lighter, +// and so I hope better compilation performance (time and code quality). template class ei_blas_data_mapper { @@ -121,12 +123,6 @@ class ei_const_blas_data_mapper int m_stride; }; -// -// template -// struct ei_L2_block_traits { -// enum {width = 8 * ei_meta_sqrt::ret }; -// }; - // Defines various constant controlling level 3 blocking template struct ei_product_blocking_traits @@ -160,71 +156,93 @@ struct ei_product_blocking_traits template struct ei_blas_traits { typedef typename ei_traits::Scalar Scalar; - typedef XprType ActualXprType; + typedef const XprType& ExtractType; + typedef XprType _ExtractType; enum { IsComplex = NumTraits::IsComplex, NeedToConjugate = false, ActualAccess = int(ei_traits::Flags)&DirectAccessBit ? HasDirectAccess : NoDirectAccess }; typedef typename ei_meta_if::ret DirectLinearAccessType; - static inline const ActualXprType& extract(const XprType& x) { return x; } + static inline ExtractType extract(const XprType& x) { return x; } static inline Scalar extractScalarFactor(const XprType&) { return Scalar(1); } }; // pop conjugate -template struct ei_blas_traits, NestedXpr> > +template +struct ei_blas_traits, NestedXpr> > : ei_blas_traits { typedef ei_blas_traits Base; typedef CwiseUnaryOp, NestedXpr> XprType; - typedef typename Base::ActualXprType ActualXprType; + typedef typename Base::ExtractType ExtractType; enum { IsComplex = NumTraits::IsComplex, NeedToConjugate = IsComplex }; - static inline const ActualXprType& extract(const XprType& x) { return Base::extract(x._expression()); } + static inline ExtractType extract(const XprType& x) { return Base::extract(x._expression()); } static inline Scalar extractScalarFactor(const XprType& x) { return ei_conj(Base::extractScalarFactor(x._expression())); } }; // pop scalar multiple -template struct ei_blas_traits, NestedXpr> > +template +struct ei_blas_traits, NestedXpr> > : ei_blas_traits { typedef ei_blas_traits Base; typedef CwiseUnaryOp, NestedXpr> XprType; - typedef typename Base::ActualXprType ActualXprType; - static inline const ActualXprType& extract(const XprType& x) { return Base::extract(x._expression()); } + typedef typename Base::ExtractType ExtractType; + static inline ExtractType extract(const XprType& x) { return Base::extract(x._expression()); } static inline Scalar extractScalarFactor(const XprType& x) { return x._functor().m_other * Base::extractScalarFactor(x._expression()); } }; // pop opposite -template struct ei_blas_traits, NestedXpr> > +template +struct ei_blas_traits, NestedXpr> > : ei_blas_traits { typedef ei_blas_traits Base; typedef CwiseUnaryOp, NestedXpr> XprType; - typedef typename Base::ActualXprType ActualXprType; - static inline const ActualXprType& extract(const XprType& x) { return Base::extract(x._expression()); } + typedef typename Base::ExtractType ExtractType; + static inline ExtractType extract(const XprType& x) { return Base::extract(x._expression()); } static inline Scalar extractScalarFactor(const XprType& x) { return - Base::extractScalarFactor(x._expression()); } }; -// pop opposite -template struct ei_blas_traits > +// pop NestByValue +template +struct ei_blas_traits > : ei_blas_traits { typedef typename NestedXpr::Scalar Scalar; typedef ei_blas_traits Base; typedef NestByValue XprType; - typedef typename Base::ActualXprType ActualXprType; - static inline const ActualXprType& extract(const XprType& x) { return Base::extract(static_cast(x)); } + typedef typename Base::ExtractType ExtractType; + static inline ExtractType extract(const XprType& x) { return Base::extract(static_cast(x)); } static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(static_cast(x)); } }; +// pop/push transpose +template +struct ei_blas_traits > + : ei_blas_traits +{ + typedef typename NestedXpr::Scalar Scalar; + typedef ei_blas_traits Base; + typedef Transpose XprType; + typedef Transpose ExtractType; + typedef typename ei_meta_if::ret DirectLinearAccessType; + static inline const ExtractType extract(const XprType& x) { return Base::extract(x._expression()); } + static inline Scalar extractScalarFactor(const XprType& x) { return Base::extractScalarFactor(x._expression()); } +}; + #endif // EIGEN_BLASUTIL_H