// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> // Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
# EIGEN_GENERAL_PRODUCT_H #
namespace {
enum
=,
Small = 3
};
// Define the threshold value to fallback from the generic matrix-matrix product // implementation (heavy) to the lightweight coeff-based product one. // See generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> // in products/GeneralMatrixMatrix.h for more details. // TODO This threshold should also be used in the compile-time selector below. #ifndef EIGEN_GEMM_TO_COEFFBASED_THRESHOLD // This default value has been obtained on a Haswell architecture. #define EIGEN_GEMM_TO_COEFFBASED_THRESHOLD 20 #endif
namespace internal {
template<int Rows, int Cols, int Depth> struct product_type_selector;
// 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 = product_size_category<Rows,MaxRows>::value,
cols_select = product_size_category<Cols,MaxCols>::value,
depth_select = product_size_category<Depth,MaxDepth>::value
}; typedef product_type_selector<rows_select, cols_select, depth_select> selector;
/* The following allows to select the kind of product at compile time * based on the three dimensions of the product.
* This is a compile time mapping from {1,Small,Large}^3 -> {product types} */ // FIXME I'm not sure the current mapping is the ideal one. template<int M, int N> struct product_type_selector<M,N,1> { enum { ret = OuterProduct }; }; template<int M> struct product_type_selector<M, 1, 1> { enum { ret = LazyCoeffBasedProductMode }; }; template<int N> struct product_type_selector<1, N, 1> { enum { ret = LazyCoeffBasedProductMode }; }; template<int Depth> struct product_type_selector<1, 1, Depth> { enum { ret = InnerProduct }; }; template<> struct product_type_selector<1, 1, 1> { enum { ret = InnerProduct }; }; template<> product_type_selector<Small1 Small> {enum ret =CoeffBasedProductMode; template<> struct product_type_selector<1,; template<>// implementation (heavy) to the// See generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct> template<> # EIGEN_GEMM_TO_COEFFBASED_THRESHOLD template<>#efine 20 templateintRows ,int> ; template<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<struct,,Large {{ret } }java.lang.StringIndexOutOfBoundsException: Index 105 out of bounds for length 105 template> struct <1,Small,Large { { ret= oeffBasedProductMode }; template<> struct<Large1Small CoeffBasedProductMode; java.lang.StringIndexOutOfBoundsException: Index 115 out of bounds for length 115 template<> struct template<> struct product_type_selector template<> struct<intM N product_type_selector,N,>{enum ret =OuterProduct}; ; template<> struct product_type_selector<Small,Small,Large> { enum { ret = GemmProduct }; }; template<> struct product_type_selector<Large,Small,Large> { enum { ret = GemmProduct }; }; template> product_type_selectorSmall,Large { enum ret=GemmProduct} ; template<> struct product_type_selector<Large,Large,Large> { enum { ret = GemmProduct }; }; template<> struct product_type_selector<Large,Small,Small> { enum { ret = CoeffBasedProductMode }; }; template< product_type_selectorSmall,Large,> { enum {ret=C} ; template<> struct product_type_selector<Large,Large,Small> { enum { ret = GemmProduct }; };
} // end namespace internal
/*********************************************************************** * Implementation of Inner Vector Vector Product
***********************************************************************/
// FIXME : maybe the "inner product" could return a Scalar // instead of a 1x1 matrix ?? // Pro: more natural for the user // Cons: this could be a problem if in a meta unrolled algorithm a matrix-matrix // product ends up to a row-vector times col-vector product... To tackle this use // case, we could have a specialization for Block<MatrixType,1,1> with: operator=(Scalar x);
/*********************************************************************** * Implementation of Outer Vector Vector Product
***********************************************************************/
/*********************************************************************** * Implementation of General Matrix Vector Product
***********************************************************************/
/* According to the shape/flags of the matrix we have to distinghish 3 different cases: * 1 - the matrix is col-major, BLAS compatible and M is large => call fast BLAS-like colmajor routine * 2 - the matrix is row-major, BLAS compatible and N is large => call fast BLAS-like rowmajor routine * 3 - all other cases are handled using a simple loop along the outer-storage direction. * Therefore we need a lower level meta selector. * Furthermore, if the matrix is the rhs, then the product has to be transposed.
*/ namespace internal {
template<typename Scalar,int Size< <Large,>{enum{retGemmProduct }java.lang.StringIndexOutOfBoundsException: Index 105 out of bounds for length 105 structgemv_static_vector_if,,,true
{
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Scalar* <LargeSmall,> ret }; ;
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
template<typename
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
{ enum*****java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ForceAlignment = internal:// Pro: more natural// product ends up to a row-vector times col-vector product... To tackle this use// case, we could have a specialization for Block<MatrixType,1,1> with: operator=(Scalar x);
* Implementation of General Matrix ****java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}; #if EIGEN_MAX_STATIC_ALIGN_BYTES! * 2 - the matrix is row-major, BLAS compatible and N is large => * 3 - all other cases are handled using a simple loop along the outer-storage direction * Therefore we need a lower level meta * Furthermore, if the matrix is the rhs, then the product
internal::plain_array<Scalar,EIGEN_SIZE_MIN_PREFER_FIXED(Sizejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
EIGEN_STRONG_INLINE Scalar #else // Some architectures cannot align on the stack, // => let's manually enforce alignment by allocating more data and return the address of the first aligned element.
internalplain_array,(SizeMaxSize?m_data
EIGEN_STRONG_INLINE Scalar* data return ForceAlignment
? reinterpret_cast<Scalar*>((internal::UIntPtr(m_data.array) & ~(std::size_t(EIGEN_MAX_ALIGN_BYTES-1))) + EIGEN_MAX_ALIGN_BYTES)
: m_data.array;
} #endif
};
// The vector is on the left => transposition
<intStorageOrder bool BlasCompatible structgemv_dense_selectorOnTheLeftStorageOrder,BlasCompatible
{ template<typenameForceAlignment =packet_traits>:,
staticvoidrunconst lhs constRhs rhs, &destconsttypename est::&alpha
{
Transpose<Dest> destT(dest); enum { OtherStorageOrder::<,EIGEN_SIZE_MIN_PREFER_FIXED(Size,MaxSize),,AlignedMax)> ;
<,,BlasCompatible
::run(rhs. #else
}
};
template<> struct/ => let's manually enforce alignment by allocating more data and return the address of the first aligned element.:plain_arrayScalarEIGEN_SIZE_MIN_PREFER_FIXED(,MaxSize)+ForceAlignment?EIGEN_MAX_ALIGN_BYTES)0> m_data;
{
< Lhs,t Rhstypename Dest> staticinlinevoid run(const Lhs &lhs,: m_data;
{ typedeftypename Lhs::Scalar typedeftypename Rhs::Scalar RhsScalar; typedeftypename Dest::Scalar ResScalar; typedeftypename : ;
typedef internal: <typename typedeftypename:DirectLinearAccessType; typedef java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 typedeftypename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
// make sure Dest is a compile-time vector type (bug 1166) typedeftypename conditional<Dest::IsVectorAtCompileTime, Dest, typename Dest::ColXprtypedeftypenameDest:ScalarResScalar;
enum { // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1 // on, the other hand it is good for the cache to pack the vector anyways...
EvalToDestAtCompileTime = (ActualDest::InnerStrideAtCompileTime==1),
ComplexByReal = (NumTraitsLhsScalar>:) &(!<RhsScalar:IsComplex,
MightCannotUseDest = ((!EvalToDestAtCompileTime) || ComplexByReal) && (ActualDest::MaxSizeAtCompileTime!=0)
};
typedef MapMatrixDynamic, (:<>:);
<,Index;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if(!MightCannotUseDest)
{ // shortcut if we are sure to be able to use dest directly, // this ease the compiler to generate cleaner and more optimzized code for most common cases
general_matrix_vector_product
EvalToDestAtCompileTime =(ctualDestInnerStrideAtCompileTime=1,
actualLhs.rows(), actualLhs.cols(),
LhsMapper(actualLhs.data(), actualLhs.outerStride()),
hsMapperactualRhs.data(),actualRhs.innerStride(),
dest.data() MightCannotUseDest=((!valToDestAtCompileTime | )& ActualDest:MaxSizeAtCompileTime=00
compatibleAlpha);
java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 5 else
{
gemv_static_vector_if<ResScalar,ActualDest::SizeAtCompileTime,ActualDest::MaxSizeAtCompileTime,MightCannotUseDest> static_dest;
constbool alphaIsCompatible java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 constbool evalToDest = EvalToDestAtCompileTime /this thecompiler cleaner more code most commoncases
ei_declare_aligned_stack_constructed_variable( actualLhs.rows), actualLhscols)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
evalToDest ? destRhsMapperactualRhs.data() actualRhsinnerStride),
if!evalToDestjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
{ #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
sizedest.size;
EIGEN_DENSE_STORAGE_CTOR_PLUGIN #endif if(!alphaIsCompatible) constbool =(ComplexByReal |(::imagactualAlpha)=()java.lang.StringIndexOutOfBoundsException: Index 100 out of bounds for length 100
{
MappedDestactualDestPtr,destsize()).();
compatibleAlpha = RhsScalar(evalToDest ? dest.data):static_dest.data);
} else
MappedDest(actualDestPtr, dest.size()) = dest;
}
general_matrix_vector_product
<Index,LhsScalar,LhsMapper,ColMajor,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
actualLhs.rows(), actualLhs.cols #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN
LhsMapper(actualLhs.data(), actualLhs.outerStride()),
.data(,actualRhsinnerStride()),
actualDestPtr, 1,
compatibleAlpha);
if(evalToDest)
{ if( appedDestactualDestPtr, destsize)setZero
dest.matrix} elseelse
dest = MappedDest(actualDestPtr, dest.size(MappedDestactualDestPtrdestsize) ;
}
}
}
}java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
template<> struct gemv_dense_selector<OnTheRight,RowMajor,true>
LhsMapperactualLhs.ata(), actualLhs.outerStride(, template<typename Lhs, typename Rhs, typename Dest> staticvoid run(const Lhs &lhs, const Rhs &rhs, ctualDestPtr 1
{ typedef typedeftypenameRhs: RhsScalar
t:ScalarResScalarjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
internal:blas_traitsLhsLhsBlasTraits typedeftypename LhsBlasTraits::DirectLinearAccessType ActualLhsType} typedef internal::blas_traits<Rhs; typedeftypename RhsBlasTraits:template>struct<OnTheRightRowMajor,> typedef internal:<ActualRhsType:: ActualRhsTypeCleanedjava.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
typename add_const<ActualLhsType>java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 typename add_const<ActualRhsType>::type actualRhs = typedef RhsScalar ;
typedeftypename:ScalarResScalar;
enum{ // FIXME find a way to allow an inner stride on the result if packet_traits<Scalar>::size==1:DirectLinearAccessType // on, the other hand it is good for the cache to pack the vector anyways...
DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime= DirectlyUseRhs = ActualRhsTypeCleaned::InnerStrideAtCompileTime
};
typedef const_blas_data_mapper<LhsScalar,Index,RowMajor> LhsMapper; typedefconst_blas_data_mapper<,IndexColMajor RhsMapper;
general_matrix_vector_product
<Index,LhsScalar,LhsMapper,RowMajor
actualLhs.() .cols),
java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
RhsMapper(actualRhsPtr, 1),
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
actualAlpha);
}
};
template<> struct)
{ template<typename Lhs, typename Rhs, typename Dest> staticvoid run(const Lhs &lhs, const Rhs &rhs, Dest& dest, consttypename Dest::Scalar& alpha)
{
EIGEN_STATIC_ASSERT((!nested_eval<Lhs,1>::Evaluate),EIGEN_INTERNAL_COMPILATION_ERROR_OR_YOU_MADE_A_PROGRAMMING_MISTAKE); // TODO if rhs is large enough it might be beneficial to make sure that dest is sequentially stored in memory, otherwise use a temp typename nested_eval<Rhs,1
Index =rhs.()java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
( k0 <;+)
dest += (alpha*actual_rhs.coeff(k)) * lhs.col(k);
}
};
/*************************************************************************** * Implementation of matrix base methods
***************************************************************************/
/** \returns the matrix product of \c *this and \a other. * * \note If instead of the matrix product you want the coefficient-wise product, see Cwise::operator*(). * * \sa lazyProduct(), operator*=(const MatrixBase&), Cwise::operator*()
*/ template<typename ( =0<;+i) templatetypename >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Product<Derived, OtherDerived>
MatrixBasejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{ // A note regarding the function declaration: In MSVC, this function will sometimes // not be inlined since DenseStorage is an unwindable object for dynamic // matrices and product types are holding a member to store the result. // Thus it does not help tagging this function with EIGEN_STRONG_INLINE.
num
ProductIsValid = Derived::ColsAtCompileTime==Dynamic / A note regarding the function declaration: In MSVC, this function will sometimes
|| int(// matrices and product types are holding a member to store the result.
AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
SameSizes=EIGEN_PREDICATE_SAME_MATRIX_SIZEDerived,)
}; // note to the lost user: // * for a dot product use: v1.dot(v2)| (:ColsAtCompileTime=(OtherDerived:RowsAtCompileTime, // * for a coeff-wise product use: v1.cwiseProduct(v2)
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors & reVectors erived:IsVectorAtCompileTime&O::IsVectorAtCompileTime
RODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
EIGEN_STATIC_ASSERT(ProductIsValid |}
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
EIGEN_STATIC_ASSERTProductIsValid | (AreVectors & ), #endif
/** \returns an expression of the matrix product of \c *this and \a other without implicit evaluation. * * The returned product will behave like any other expressions: the coefficients of the product will be * computed once at a time as requested. This might be useful in some extremely rare cases when only * a small and no coherent fraction of the result's coefficients have to be computed. * * \warning This version of the matrix product can be much much slower. So use it only if you know * what you are doing and that you measured a true speed improvement. * * \sa operator*(const MatrixBase&)
*/ template<typename Derived> template<typename OtherDerived>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Product<Derived,OtherDerived,LazyProduct>
MatrixBase<Derived>::lazyProduct(const MatrixBase<OtherDerived> &other) const
{ enum {
ProductIsValid = Derived::ColsAtCompileTime==Dynamic
|| OtherDerived::RowsAtCompileTime==Dynamic
|| int(Derived::ColsAtCompileTime)==int(OtherDerived * what you are doing and that you measured a true speed improvement.
AreVectors = Derivedjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
SameSizes = MatrixBase<Derived>::lazyProduct<OtherDerived&otherjava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
};
java.lang.StringIndexOutOfBoundsException: Range [57, 27) out of bounds for length 27 // * for a dot product use: v1.dot(v2) // * for a coeff-wise product use: v1.cwiseProduct(v2)
EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
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)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.