11 #ifndef EIGEN_GENERAL_PRODUCT_H 12 #define EIGEN_GENERAL_PRODUCT_H 35 template<typename Lhs, typename Rhs, int ProductType = internal::product_type<Lhs,Rhs>::value>
49 enum { is_large = MaxSize ==
Dynamic ||
51 value = is_large ?
Large 62 MaxRows = _Lhs::MaxRowsAtCompileTime,
63 Rows = _Lhs::RowsAtCompileTime,
64 MaxCols = _Rhs::MaxColsAtCompileTime,
65 Cols = _Rhs::ColsAtCompileTime,
67 _Rhs::MaxRowsAtCompileTime),
69 _Rhs::RowsAtCompileTime),
87 #ifdef EIGEN_DEBUG_PRODUCT 148 template<
typename Lhs,
typename Rhs,
int ProductType>
158 template<
typename Lhs,
typename Rhs>
166 template<
typename Lhs,
typename Rhs>
175 template<
typename Lhs,
typename Rhs>
192 template<
typename Lhs,
typename Rhs>
194 :
traits<Matrix<typename scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType,1,1> >
199 template<
typename Lhs,
typename Rhs>
202 public Matrix<typename internal::scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType,1,1>
209 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
211 Base::coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
216 return Base::coeff(0,0);
227 template<
typename ProductType,
typename Dest,
typename Func>
230 typedef typename Dest::Index Index;
233 const Index cols = dest.cols();
234 for (Index j=0; j<cols; ++j)
235 func(dest.col(j), prod.rhs().coeff(j) * prod.lhs());
239 template<
typename ProductType,
typename Dest,
typename Func>
241 typedef typename Dest::Index Index;
244 const Index rows = dest.rows();
245 for (Index i=0; i<rows; ++i)
246 func(dest.row(i), prod.lhs().coeff(i) * prod.rhs());
249 template<
typename Lhs,
typename Rhs>
251 :
traits<ProductBase<GeneralProduct<Lhs,Rhs,OuterProduct>, Lhs, Rhs> >
256 template<
typename Lhs,
typename Rhs>
258 :
public ProductBase<GeneralProduct<Lhs,Rhs,OuterProduct>, Lhs, Rhs>
260 template<
typename T>
struct IsRowMajor :
internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {};
268 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
271 struct set {
template<
typename Dst,
typename Src>
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() = src; } };
272 struct add {
template<
typename Dst,
typename Src>
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() += src; } };
273 struct sub {
template<
typename Dst,
typename Src>
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() -= src; } };
277 template<
typename Dst,
typename Src>
void operator()(
const Dst& dst,
const Src& src)
const {
278 dst.const_cast_derived() += m_scale * src;
282 template<
typename Dest>
287 template<
typename Dest>
288 inline void addTo(Dest& dest)
const {
292 template<
typename Dest>
293 inline void subTo(Dest& dest)
const {
316 template<
typename Lhs,
typename Rhs>
318 :
traits<ProductBase<GeneralProduct<Lhs,Rhs,GemvProduct>, Lhs, Rhs> >
321 template<
int S
ide,
int StorageOrder,
bool BlasCompatible>
326 template<
typename Lhs,
typename Rhs>
328 :
public ProductBase<GeneralProduct<Lhs,Rhs,GemvProduct>, Lhs, Rhs>
347 eigen_assert(m_lhs.rows() == dst.rows() && m_rhs.cols() == dst.cols());
356 template<
int StorageOrder,
bool BlasCompatible>
359 template<
typename ProductType,
typename Dest>
360 static void run(
const ProductType& prod, Dest& dest,
const typename ProductType::Scalar& alpha)
366 (prod.rhs().transpose(), prod.lhs().transpose()), destT, alpha);
372 template<
typename Scalar,
int Size,
int MaxSize>
378 template<
typename Scalar,
int Size>
384 template<
typename Scalar,
int Size,
int MaxSize>
387 #if EIGEN_ALIGN_STATICALLY 399 return ForceAlignment
400 ?
reinterpret_cast<Scalar*
>((
reinterpret_cast<size_t>(m_data.
array) & ~(
size_t(15))) + 16)
408 template<
typename ProductType,
typename Dest>
409 static inline void run(
const ProductType& prod, Dest& dest,
const typename ProductType::Scalar& alpha)
411 typedef typename ProductType::Index Index;
412 typedef typename ProductType::LhsScalar LhsScalar;
413 typedef typename ProductType::RhsScalar RhsScalar;
414 typedef typename ProductType::Scalar ResScalar;
415 typedef typename ProductType::RealScalar RealScalar;
416 typedef typename ProductType::ActualLhsType ActualLhsType;
417 typedef typename ProductType::ActualRhsType ActualRhsType;
418 typedef typename ProductType::LhsBlasTraits LhsBlasTraits;
419 typedef typename ProductType::RhsBlasTraits RhsBlasTraits;
422 ActualLhsType actualLhs = LhsBlasTraits::extract(prod.lhs());
423 ActualRhsType actualRhs = RhsBlasTraits::extract(prod.rhs());
425 ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs())
426 * RhsBlasTraits::extractScalarFactor(prod.rhs());
431 EvalToDestAtCompileTime = Dest::InnerStrideAtCompileTime==1,
433 MightCannotUseDest = (Dest::InnerStrideAtCompileTime!=1) || ComplexByReal
438 bool alphaIsCompatible = (!ComplexByReal) || (
numext::imag(actualAlpha)==RealScalar(0));
439 bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible;
444 evalToDest ? dest.data() : static_dest.data());
448 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN 449 int size = dest.size();
450 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
452 if(!alphaIsCompatible)
454 MappedDest(actualDestPtr, dest.size()).setZero();
455 compatibleAlpha = RhsScalar(1);
458 MappedDest(actualDestPtr, dest.size()) = dest;
462 <Index,LhsScalar,
ColMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsBlasTraits::NeedToConjugate>::run(
463 actualLhs.rows(), actualLhs.cols(),
464 actualLhs.data(), actualLhs.outerStride(),
465 actualRhs.data(), actualRhs.innerStride(),
471 if(!alphaIsCompatible)
472 dest += actualAlpha * MappedDest(actualDestPtr, dest.size());
474 dest = MappedDest(actualDestPtr, dest.size());
481 template<
typename ProductType,
typename Dest>
482 static void run(
const ProductType& prod, Dest& dest,
const typename ProductType::Scalar& alpha)
484 typedef typename ProductType::LhsScalar LhsScalar;
485 typedef typename ProductType::RhsScalar RhsScalar;
486 typedef typename ProductType::Scalar ResScalar;
487 typedef typename ProductType::Index Index;
488 typedef typename ProductType::ActualLhsType ActualLhsType;
489 typedef typename ProductType::ActualRhsType ActualRhsType;
490 typedef typename ProductType::_ActualRhsType _ActualRhsType;
491 typedef typename ProductType::LhsBlasTraits LhsBlasTraits;
492 typedef typename ProductType::RhsBlasTraits RhsBlasTraits;
497 ResScalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs())
498 * RhsBlasTraits::extractScalarFactor(prod.rhs());
503 DirectlyUseRhs = _ActualRhsType::InnerStrideAtCompileTime==1
509 DirectlyUseRhs ?
const_cast<RhsScalar*
>(actualRhs.data()) : static_rhs.data());
513 #ifdef EIGEN_DENSE_STORAGE_CTOR_PLUGIN 514 int size = actualRhs.size();
515 EIGEN_DENSE_STORAGE_CTOR_PLUGIN
521 <Index,LhsScalar,
RowMajor,LhsBlasTraits::NeedToConjugate,RhsScalar,RhsBlasTraits::NeedToConjugate>::run(
523 actualLhs.data(), actualLhs.outerStride(),
525 dest.data(), dest.innerStride(),
532 template<
typename ProductType,
typename Dest>
533 static void run(
const ProductType& prod, Dest& dest,
const typename ProductType::Scalar& alpha)
535 typedef typename Dest::Index Index;
537 const Index size = prod.rhs().rows();
538 for(Index k=0; k<size; ++k)
539 dest += (alpha*prod.rhs().coeff(k)) * prod.lhs().col(k);
545 template<
typename ProductType,
typename Dest>
546 static void run(
const ProductType& prod, Dest& dest,
const typename ProductType::Scalar& alpha)
548 typedef typename Dest::Index Index;
550 const Index rows = prod.rows();
551 for(Index i=0; i<rows; ++i)
552 dest.coeffRef(i) += alpha * (prod.lhs().row(i).cwiseProduct(prod.rhs().transpose())).sum();
568 template<
typename Derived>
569 template<
typename OtherDerived>
578 ProductIsValid = Derived::ColsAtCompileTime==
Dynamic 579 || OtherDerived::RowsAtCompileTime==
Dynamic 580 || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
581 AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
588 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
590 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
592 #ifdef EIGEN_DEBUG_PRODUCT 609 template<
typename Derived>
610 template<
typename OtherDerived>
615 ProductIsValid = Derived::ColsAtCompileTime==
Dynamic 616 || OtherDerived::RowsAtCompileTime==
Dynamic 617 || int(Derived::ColsAtCompileTime)==int(OtherDerived::RowsAtCompileTime),
618 AreVectors = Derived::IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime,
625 INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
627 INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
635 #endif // EIGEN_PRODUCT_H
Expression of the product of two general matrices or vectors.
#define EIGEN_PRODUCT_PUBLIC_INTERFACE(Derived)
static void run(const ProductType &prod, Dest &dest, const typename ProductType::Scalar &alpha)
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
internal::plain_array< Scalar, EIGEN_SIZE_MIN_PREFER_FIXED(Size, MaxSize)+(ForceAlignment?PacketSize:0), 0 > m_data
void operator()(const Dst &dst, const Src &src) const
#define EIGEN_STRONG_INLINE
internal::traits< Derived >::Scalar Scalar
Matrix< typename internal::scalar_product_traits< typename Lhs::Scalar, typename Rhs::Scalar >::ReturnType, 1, 1 > Base
void scaleAndAddTo(Dest &dst, const Scalar &alpha) const
GeneralProduct(const Lhs &lhs, const Rhs &rhs)
#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
internal::nested< Rhs, Lhs::RowsAtCompileTime, typename internal::plain_matrix_type< Rhs >::type >::type RhsNested
const LazyProductReturnType< Derived, OtherDerived >::Type lazyProduct(const MatrixBase< OtherDerived > &other) const
A matrix or vector expression mapping an existing array of data.
Expression of the transpose of a matrix.
CoeffBasedProduct< LhsNested, RhsNested, NestByRefBit > Type
static void run(const ProductType &prod, Dest &dest, const typename ProductType::Scalar &alpha)
internal::nested< Rhs, Lhs::RowsAtCompileTime, typename internal::plain_matrix_type< Rhs >::type >::type RhsNested
internal::conditional< int(Side)==OnTheRight, _LhsNested, _RhsNested >::type MatrixType
remove_all< Lhs >::type _Lhs
iterative scaling algorithm to equilibrate rows and column norms in matrices
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
#define eigen_internal_assert(x)
void subTo(Dest &dest) const
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
const unsigned int RowMajorBit
const ImagReturnType imag() const
GeneralProduct< Lhs, Rhs, ProductType > Type
void evalTo(Dest &dest) const
remove_all< Rhs >::type _Rhs
void operator()(const Dst &dst, const Src &src) const
internal::nested< Lhs, Rhs::ColsAtCompileTime, typename internal::plain_matrix_type< Lhs >::type >::type LhsNested
void operator()(const Dst &dst, const Src &src) const
static void run(const ProductType &prod, Dest &dest, const typename ProductType::Scalar &alpha)
EIGEN_STRONG_INLINE Scalar * data()
void rhs(const real_t *x, real_t *f)
EIGEN_DONT_INLINE void outer_product_selector_run(const ProductType &prod, Dest &dest, const Func &func, const false_type &)
EIGEN_STRONG_INLINE Scalar * data()
#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0, TYPE1)
static EIGEN_STRONG_INLINE To run(const From &x)
static void run(const ProductType &prod, Dest &dest, const typename ProductType::Scalar &alpha)
void scaleAndAddTo(Dest &dest, const Scalar &alpha) const
Helper class to get the correct and optimized returned type of operator*.
void operator()(const Dst &dst, const Src &src) const
#define EIGEN_DONT_INLINE
CoeffBasedProduct< LhsNested, RhsNested, EvalBeforeAssigningBit|EvalBeforeNestingBit > Type
#define EIGEN_DEBUG_VAR(x)
internal::nested< Lhs, Rhs::ColsAtCompileTime, typename internal::plain_matrix_type< Lhs >::type >::type LhsNested
The matrix class, also used for vectors and row-vectors.
static void run(const ProductType &prod, Dest &dest, const typename ProductType::Scalar &alpha)
void addTo(Dest &dest) const
product_type_selector< rows_select, cols_select, depth_select > selector
Base class for all dense matrices, vectors, and expressions.
EIGEN_STRONG_INLINE Scalar * data()