22 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATSMATMULTEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_DMATSMATMULTEXPR_H_
86 template<
typename MT1
94 typedef typename MT1::ResultType
RT1;
95 typedef typename MT2::ResultType
RT2;
96 typedef typename MT1::CompositeType
CT1;
97 typedef typename MT2::CompositeType
CT2;
125 enum { vectorizable = 0 };
155 if(
lhs_.columns() != 0UL ) {
157 for(
size_t k=1UL; k<
lhs_.columns(); ++k ) {
185 return rhs_.columns();
215 template<
typename T >
217 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
227 template<
typename T >
229 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
253 template<
typename MT >
274 for(
size_t i=0UL; i<A.rows(); ++i ) {
275 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
276 reset( (~lhs)(i,j) );
278 for(
size_t j=0UL; j<B.rows(); ++j ) {
279 ConstIterator element( B.begin(j) );
280 const ConstIterator end( B.end(j) );
281 for( ; element!=end; ++element ) {
282 if(
isDefault( (~lhs)(i,element->index()) ) )
283 (~lhs)(i,element->index()) = A(i,j) * element->value();
285 (~lhs)(i,element->index()) += A(i,j) * element->value();
307 template<
typename MT >
330 for(
size_t i=0UL; i<B.rows(); ++i ) {
331 for(
size_t jj=0UL; jj<A.rows(); jj+=8UL ) {
332 const size_t jend( ( jj+8UL > A.rows() )?( A.rows() ):( jj+8UL ) );
333 ConstIterator element( B.begin(i) );
334 const ConstIterator end( B.end(i) );
335 for( ; element!=end; ++element ) {
336 for(
size_t j=jj; j<jend; ++j ) {
337 if(
isDefault( (~lhs)(j,element->index()) ) )
338 (~lhs)(j,element->index()) = A(j,i) * element->value();
340 (~lhs)(j,element->index()) += A(j,i) * element->value();
363 template<
typename MT >
364 friend inline typename DisableIf< IsResizable<typename MT::ElementType> >::Type
372 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
384 BLAZE_INTERNAL_ASSERT( ( A.rows() - ( A.rows() % 4UL ) ) == ( A.rows() & size_t(-4) ),
"Invalid end calculation" );
385 const size_t last( A.rows() & size_t(-4) );
387 for(
size_t i=0UL; i<last; i+=4UL ) {
388 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
389 reset( (~lhs)(i ,j) );
390 reset( (~lhs)(i+1UL,j) );
391 reset( (~lhs)(i+2UL,j) );
392 reset( (~lhs)(i+3UL,j) );
394 for(
size_t j=0UL; j<B.rows(); ++j ) {
395 ConstIterator element( B.begin(j) );
396 const ConstIterator end( B.end(j) );
397 for( ; element!=end; ++element ) {
398 (~lhs)(i ,element->index()) += A(i ,j) * element->value();
399 (~lhs)(i+1UL,element->index()) += A(i+1UL,j) * element->value();
400 (~lhs)(i+2UL,element->index()) += A(i+2UL,j) * element->value();
401 (~lhs)(i+3UL,element->index()) += A(i+3UL,j) * element->value();
406 for(
size_t i=last; i<A.rows(); ++i ) {
407 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
408 reset( (~lhs)(i,j) );
410 for(
size_t j=0UL; j<B.rows(); ++j ) {
411 ConstIterator element( B.begin(j) );
412 const ConstIterator end( B.end(j) );
413 for( ; element!=end; ++element ) {
414 (~lhs)(i,element->index()) += A(i,j) * element->value();
436 template<
typename MT >
437 friend inline typename DisableIf< IsResizable<typename MT::ElementType> >::Type
445 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
459 for(
size_t i=0UL; i<B.rows(); ++i ) {
460 for(
size_t jj=0UL; jj<A.rows(); jj+=8UL ) {
461 const size_t jend( ( jj+8UL > A.rows() )?( A.rows() ):( jj+8UL ) );
462 ConstIterator element( B.begin(i) );
463 const ConstIterator end( B.end(i) );
464 for( ; element!=end; ++element ) {
465 for(
size_t j=jj; j<jend; ++j ) {
466 (~lhs)(j,element->index()) += A(j,i) * element->value();
487 template<
typename MT
493 typedef typename SelectType< SO, OppositeType, ResultType >::Type TmpType;
505 const TmpType tmp( rhs );
524 template<
typename MT >
532 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
544 const size_t last( A.rows() & size_t(-4) );
546 for(
size_t i=0UL; i<last; i+=4UL ) {
547 for(
size_t j=0UL; j<B.rows(); ++j ) {
548 ConstIterator element( B.begin(j) );
549 const ConstIterator end( B.end(j) );
550 for( ; element!=end; ++element ) {
551 (~lhs)(i ,element->index()) += A(i ,j) * element->value();
552 (~lhs)(i+1UL,element->index()) += A(i+1UL,j) * element->value();
553 (~lhs)(i+2UL,element->index()) += A(i+2UL,j) * element->value();
554 (~lhs)(i+3UL,element->index()) += A(i+3UL,j) * element->value();
559 for(
size_t i=last; i<A.rows(); ++i ) {
560 for(
size_t j=0UL; j<B.rows(); ++j ) {
561 ConstIterator element( B.begin(j) );
562 const ConstIterator end( B.end(j) );
563 for( ; element!=end; ++element ) {
564 (~lhs)(i,element->index()) += A(i,j) * element->value();
585 template<
typename MT >
593 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
605 for(
size_t i=0UL; i<B.rows(); ++i ) {
606 for(
size_t jj=0UL; jj<A.rows(); jj+=8UL ) {
607 const size_t jend( ( jj+8UL > A.rows() )?( A.rows() ):( jj+8UL ) );
608 ConstIterator element( B.begin(i) );
609 const ConstIterator end( B.end(i) );
610 for( ; element!=end; ++element ) {
611 for(
size_t j=jj; j<jend; ++j ) {
612 (~lhs)(j,element->index()) += A(j,i) * element->value();
638 template<
typename MT >
646 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
658 const size_t last( A.rows() & size_t(-4) );
660 for(
size_t i=0UL; i<last; i+=4UL ) {
661 for(
size_t j=0UL; j<B.rows(); ++j ) {
662 ConstIterator element( B.begin(j) );
663 const ConstIterator end( B.end(j) );
664 for( ; element!=end; ++element ) {
665 (~lhs)(i ,element->index()) -= A(i ,j) * element->value();
666 (~lhs)(i+1UL,element->index()) -= A(i+1UL,j) * element->value();
667 (~lhs)(i+2UL,element->index()) -= A(i+2UL,j) * element->value();
668 (~lhs)(i+3UL,element->index()) -= A(i+3UL,j) * element->value();
673 for(
size_t i=last; i<A.rows(); ++i ) {
674 for(
size_t j=0UL; j<B.rows(); ++j ) {
675 ConstIterator element( B.begin(j) );
676 const ConstIterator end( B.end(j) );
677 for( ; element!=end; ++element ) {
678 (~lhs)(i,element->index()) -= A(i,j) * element->value();
699 template<
typename MT >
707 typedef typename RemoveReference<RT>::Type::ConstIterator ConstIterator;
719 for(
size_t i=0UL; i<B.rows(); ++i ) {
720 for(
size_t jj=0UL; jj<A.rows(); jj+=8UL ) {
721 const size_t jend( ( jj+8UL > A.rows() )?( A.rows() ):( jj+8UL ) );
722 ConstIterator element( B.begin(i) );
723 const ConstIterator end( B.end(i) );
724 for( ; element!=end; ++element ) {
725 for(
size_t j=jj; j<jend; ++j ) {
726 (~lhs)(j,element->index()) -= A(j,i) * element->value();
796 template<
typename T1
798 inline const DMatSMatMultExpr<T1,T2>
804 throw std::invalid_argument(
"Matrix sizes do not match" );
821 template<
typename MT1,
typename MT2,
typename VT >
822 struct DMatDVecMultExprTrait< DMatSMatMultExpr<MT1,MT2>, VT >
826 typedef typename SelectType< IsDenseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
827 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
828 IsDenseVector<VT>::value && !IsTransposeVector<VT>::value
829 ,
typename DMatDVecMultExprTrait< MT1, typename SMatDVecMultExprTrait<MT2,VT>::Type >::Type
830 , INVALID_TYPE >::Type Type;
839 template<
typename MT1,
typename MT2,
typename VT >
840 struct DMatSVecMultExprTrait< DMatSMatMultExpr<MT1,MT2>, VT >
844 typedef typename SelectType< IsDenseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
845 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
846 IsSparseVector<VT>::value && !IsTransposeVector<VT>::value
847 ,
typename DMatSVecMultExprTrait< MT1, typename SMatSVecMultExprTrait<MT2,VT>::Type >::Type
848 , INVALID_TYPE >::Type Type;
857 template<
typename VT,
typename MT1,
typename MT2 >
858 struct TDVecDMatMultExprTrait< VT, DMatSMatMultExpr<MT1,MT2> >
862 typedef typename SelectType< IsDenseVector<VT>::value && IsTransposeVector<VT>::value &&
863 IsDenseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
864 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
865 ,
typename TDVecSMatMultExprTrait< typename TDVecDMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
866 , INVALID_TYPE >::Type Type;
875 template<
typename VT,
typename MT1,
typename MT2 >
876 struct TSVecDMatMultExprTrait< VT, DMatSMatMultExpr<MT1,MT2> >
880 typedef typename SelectType< IsSparseVector<VT>::value && IsTransposeVector<VT>::value &&
881 IsDenseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
882 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
883 ,
typename TDVecSMatMultExprTrait< typename TDVecDMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
884 , INVALID_TYPE >::Type Type;
893 template<
typename MT1,
typename MT2 >
894 struct RowExprTrait< DMatSMatMultExpr<MT1,MT2> >
898 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
907 template<
typename MT1,
typename MT2 >
908 struct ColumnExprTrait< DMatSMatMultExpr<MT1,MT2> >
912 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;