22 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATDMATMULTEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_TSMATDMATMULTEXPR_H_
89 template<
typename MT1
91 class TSMatDMatMultExpr :
public DenseMatrix< TSMatDMatMultExpr<MT1,MT2>, true >
92 ,
private MatMatMultExpr
97 typedef typename MT1::ResultType
RT1;
98 typedef typename MT2::ResultType
RT2;
99 typedef typename MT1::ElementType
ET1;
100 typedef typename MT2::ElementType
ET2;
101 typedef typename MT1::CompositeType
CT1;
102 typedef typename MT2::CompositeType
CT2;
130 enum { vectorizable = 0 };
160 if(
lhs_.columns() != 0UL ) {
162 for(
size_t k=1UL; k<
lhs_.columns(); ++k ) {
190 return rhs_.columns();
220 template<
typename T >
222 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
232 template<
typename T >
234 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
258 template<
typename MT
282 const size_t block( SO ? 8UL : 256UL );
284 for(
size_t jj=0UL; jj<B.columns(); jj+=block ) {
285 const size_t jend( ( jj+block > B.columns() )?( B.columns() ):( jj+block ) );
286 for(
size_t i=0UL; i<A.columns(); ++i ) {
287 const ConstIterator end( A.end(i) );
288 ConstIterator element( A.begin(i) );
289 for( ; element!=end; ++element ) {
290 for(
size_t j=jj; j<jend; ++j ) {
291 if(
isDefault( (~lhs)(element->index(),j) ) )
292 (~lhs)(element->index(),j) = element->value() * B(i,j);
294 (~lhs)(element->index(),j) += element->value() * B(i,j);
317 template<
typename MT
339 const size_t block( SO ? 8UL : 256UL );
341 for(
size_t jj=0UL; jj<B.columns(); jj+=block ) {
342 const size_t jend( ( jj+block > B.columns() )?( B.columns() ):( jj+block ) );
343 for(
size_t i=0UL; i<A.rows(); ++i ) {
344 for(
size_t j=jj; j<jend; ++j ) {
345 reset( (~lhs)(i,j) );
348 for(
size_t i=0UL; i<A.columns(); ++i )
350 const ConstIterator end( A.end(i) );
351 ConstIterator element( A.begin(i) );
353 const size_t nonzeros( A.nonZeros(i) );
355 BLAZE_INTERNAL_ASSERT( ( nonzeros - ( nonzeros % 4UL ) ) == ( nonzeros &
size_t(-4) ),
"Invalid end calculation" );
356 const size_t kend( nonzeros &
size_t(-4) );
358 for(
size_t k=0UL; k<kend; k+=4UL ) {
359 const size_t i1( element->index() );
360 const ET1 v1( element->value() );
362 const size_t i2( element->index() );
363 const ET1 v2( element->value() );
365 const size_t i3( element->index() );
366 const ET1 v3( element->value() );
368 const size_t i4( element->index() );
369 const ET1 v4( element->value() );
372 for(
size_t j=jj; j<jend; ++j ) {
373 (~lhs)(i1,j) += v1 * B(i,j);
374 (~lhs)(i2,j) += v2 * B(i,j);
375 (~lhs)(i3,j) += v3 * B(i,j);
376 (~lhs)(i4,j) += v4 * B(i,j);
380 for( ; element!=end; ++element ) {
381 for(
size_t j=jj; j<jend; ++j ) {
382 (~lhs)(element->index(),j) += element->value() * B(i,j);
403 template<
typename MT
409 typedef typename SelectType< SO, ResultType, OppositeType >::Type TmpType;
421 const TmpType tmp( rhs );
440 template<
typename MT
449 typedef typename RemoveReference<LT>::Type::ConstIterator ConstIterator;
461 const size_t block( SO ? 8UL : 256UL );
463 for(
size_t jj=0UL; jj<B.columns(); jj+=block ) {
464 const size_t jend( ( jj+block > B.columns() )?( B.columns() ):( jj+block ) );
465 for(
size_t i=0UL; i<A.columns(); ++i )
467 const ConstIterator end( A.end(i) );
468 ConstIterator element( A.begin(i) );
470 const size_t nonzeros( A.nonZeros(i) );
472 BLAZE_INTERNAL_ASSERT( ( nonzeros - ( nonzeros % 4UL ) ) == ( nonzeros &
size_t(-4) ),
"Invalid end calculation" );
473 const size_t kend( nonzeros &
size_t(-4) );
475 for(
size_t k=0UL; k<kend; k+=4UL ) {
476 const size_t i1( element->index() );
477 const ET1 v1( element->value() );
479 const size_t i2( element->index() );
480 const ET1 v2( element->value() );
482 const size_t i3( element->index() );
483 const ET1 v3( element->value() );
485 const size_t i4( element->index() );
486 const ET1 v4( element->value() );
489 for(
size_t j=jj; j<jend; ++j ) {
490 (~lhs)(i1,j) += v1 * B(i,j);
491 (~lhs)(i2,j) += v2 * B(i,j);
492 (~lhs)(i3,j) += v3 * B(i,j);
493 (~lhs)(i4,j) += v4 * B(i,j);
497 for( ; element!=end; ++element ) {
498 for(
size_t j=jj; j<jend; ++j ) {
499 (~lhs)(element->index(),j) += element->value() * B(i,j);
525 template<
typename MT
534 typedef typename RemoveReference<LT>::Type::ConstIterator ConstIterator;
546 const size_t block( SO ? 8UL : 256UL );
548 for(
size_t jj=0UL; jj<B.columns(); jj+=block ) {
549 const size_t jend( ( jj+block > B.columns() )?( B.columns() ):( jj+block ) );
550 for(
size_t i=0UL; i<A.columns(); ++i )
552 const ConstIterator end( A.end(i) );
553 ConstIterator element( A.begin(i) );
555 const size_t nonzeros( A.nonZeros(i) );
557 BLAZE_INTERNAL_ASSERT( ( nonzeros - ( nonzeros % 4UL ) ) == ( nonzeros &
size_t(-4) ),
"Invalid end calculation" );
558 const size_t kend( nonzeros &
size_t(-4) );
560 for(
size_t k=0UL; k<kend; k+=4UL ) {
561 const size_t i1( element->index() );
562 const ET1 v1( element->value() );
564 const size_t i2( element->index() );
565 const ET1 v2( element->value() );
567 const size_t i3( element->index() );
568 const ET1 v3( element->value() );
570 const size_t i4( element->index() );
571 const ET1 v4( element->value() );
574 for(
size_t j=jj; j<jend; ++j ) {
575 (~lhs)(i1,j) -= v1 * B(i,j);
576 (~lhs)(i2,j) -= v2 * B(i,j);
577 (~lhs)(i3,j) -= v3 * B(i,j);
578 (~lhs)(i4,j) -= v4 * B(i,j);
582 for( ; element!=end; ++element ) {
583 for(
size_t j=jj; j<jend; ++j ) {
584 (~lhs)(element->index(),j) -= element->value() * B(i,j);
656 template<
typename T1
658 inline const TSMatDMatMultExpr<T1,T2>
664 throw std::invalid_argument(
"Matrix sizes do not match" );
681 template<
typename MT1,
typename MT2,
typename VT >
682 struct TDMatDVecMultExprTrait< TSMatDMatMultExpr<MT1,MT2>, VT >
686 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
687 IsDenseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
688 IsDenseVector<VT>::value && !IsTransposeVector<VT>::value
689 ,
typename TSMatDVecMultExprTrait< MT1, typename DMatDVecMultExprTrait<MT2,VT>::Type >::Type
690 , INVALID_TYPE >::Type Type;
699 template<
typename MT1,
typename MT2,
typename VT >
700 struct TDMatSVecMultExprTrait< TSMatDMatMultExpr<MT1,MT2>, VT >
704 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
705 IsDenseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
706 IsSparseVector<VT>::value && !IsTransposeVector<VT>::value
707 ,
typename TSMatDVecMultExprTrait< MT1, typename DMatSVecMultExprTrait<MT2,VT>::Type >::Type
708 , INVALID_TYPE >::Type Type;
717 template<
typename VT,
typename MT1,
typename MT2 >
718 struct TDVecTDMatMultExprTrait< VT, TSMatDMatMultExpr<MT1,MT2> >
722 typedef typename SelectType< IsDenseVector<VT>::value && IsTransposeVector<VT>::value &&
723 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
724 IsDenseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
725 ,
typename TDVecDMatMultExprTrait< typename TDVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
726 , INVALID_TYPE >::Type Type;
735 template<
typename VT,
typename MT1,
typename MT2 >
736 struct TSVecTDMatMultExprTrait< VT, TSMatDMatMultExpr<MT1,MT2> >
740 typedef typename SelectType< IsSparseVector<VT>::value && IsTransposeVector<VT>::value &&
741 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
742 IsDenseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
743 ,
typename TDVecDMatMultExprTrait< typename TDVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
744 , INVALID_TYPE >::Type Type;
753 template<
typename MT1,
typename MT2 >
754 struct RowExprTrait< TSMatDMatMultExpr<MT1,MT2> >
758 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
767 template<
typename MT1,
typename MT2 >
768 struct ColumnExprTrait< TSMatDMatMultExpr<MT1,MT2> >
772 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;