Blaze 3.9
DMatTDMatMapExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATTDMATMAPEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATTDMATMAPEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
44#include <blaze/math/Aliases.h>
56#include <blaze/math/SIMD.h>
64#include <blaze/system/Inline.h>
65#include <blaze/util/Assert.h>
66#include <blaze/util/EnableIf.h>
69#include <blaze/util/mpl/If.h>
70#include <blaze/util/Types.h>
71
72
73namespace blaze {
74
75//=================================================================================================
76//
77// CLASS DMATTDMATMAPEXPR
78//
79//=================================================================================================
80
81//*************************************************************************************************
89template< typename MT1 // Type of the left-hand side dense matrix
90 , typename MT2 // Type of the right-hand side dense matrix
91 , typename OP > // Type of the custom operation
93 : public MatMatMapExpr< DenseMatrix< DMatTDMatMapExpr<MT1,MT2,OP>, false > >
94 , private Computation
95{
96 private:
97 //**Type definitions****************************************************************************
106 //**********************************************************************************************
107
108 //**Serial evaluation strategy******************************************************************
110
116 static constexpr bool useAssign = ( RequiresEvaluation_v<MT1> || RequiresEvaluation_v<MT2> );
117
120 template< typename MT >
121 static constexpr bool UseAssign_v = useAssign;
123 //**********************************************************************************************
124
125 //**Parallel evaluation strategy****************************************************************
127
133 template< typename MT >
134 static constexpr bool UseSMPAssign_v =
135 ( ( !MT1::smpAssignable || !MT2::smpAssignable ) && useAssign );
137 //**********************************************************************************************
138
139 public:
140 //**Type definitions****************************************************************************
143
146
151
153 using ReturnType = decltype( std::declval<OP>()( std::declval<RN1>(), std::declval<RN2>() ) );
154
157
159 using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
160
162 using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
163
165 using Operation = OP;
166
169
172 //**********************************************************************************************
173
174 //**Compilation flags***************************************************************************
176 static constexpr bool simdEnabled = false;
177
179 static constexpr bool smpAssignable = ( MT1::smpAssignable && MT2::smpAssignable );
180 //**********************************************************************************************
181
182 //**Constructor*********************************************************************************
189 inline DMatTDMatMapExpr( const MT1& lhs, const MT2& rhs, OP op ) noexcept
190 : lhs_( lhs ) // Left-hand side dense matrix of the map expression
191 , rhs_( rhs ) // Right-hand side dense matrix of the map expression
192 , op_ ( std::move(op) ) // The custom unary operation
193 {}
194 //**********************************************************************************************
195
196 //**Access operator*****************************************************************************
203 inline ReturnType operator()( size_t i, size_t j ) const {
204 BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
205 BLAZE_INTERNAL_ASSERT( j < lhs_.columns(), "Invalid column access index" );
206 return op_( lhs_(i,j), rhs_(i,j) );
207 }
208 //**********************************************************************************************
209
210 //**At function*********************************************************************************
218 inline ReturnType at( size_t i, size_t j ) const {
219 if( i >= lhs_.rows() ) {
220 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
221 }
222 if( j >= lhs_.columns() ) {
223 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
224 }
225 return (*this)(i,j);
226 }
227 //**********************************************************************************************
228
229 //**Rows function*******************************************************************************
234 inline size_t rows() const noexcept {
235 return lhs_.rows();
236 }
237 //**********************************************************************************************
238
239 //**Columns function****************************************************************************
244 inline size_t columns() const noexcept {
245 return lhs_.columns();
246 }
247 //**********************************************************************************************
248
249 //**Left operand access*************************************************************************
254 inline LeftOperand leftOperand() const noexcept {
255 return lhs_;
256 }
257 //**********************************************************************************************
258
259 //**Right operand access************************************************************************
264 inline RightOperand rightOperand() const noexcept {
265 return rhs_;
266 }
267 //**********************************************************************************************
268
269 //**Operation access****************************************************************************
274 inline Operation operation() const {
275 return op_;
276 }
277 //**********************************************************************************************
278
279 //**********************************************************************************************
285 template< typename T >
286 inline bool canAlias( const T* alias ) const noexcept {
287 return ( IsExpression_v<MT1> && lhs_.canAlias( alias ) ) ||
288 ( IsExpression_v<MT2> && rhs_.canAlias( alias ) );
289 }
290 //**********************************************************************************************
291
292 //**********************************************************************************************
298 template< typename T >
299 inline bool isAliased( const T* alias ) const noexcept {
300 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
301 }
302 //**********************************************************************************************
303
304 //**********************************************************************************************
309 inline bool isAligned() const noexcept {
310 return lhs_.isAligned() && rhs_.isAligned();
311 }
312 //**********************************************************************************************
313
314 //**********************************************************************************************
319 inline bool canSMPAssign() const noexcept {
320 return lhs_.canSMPAssign() && rhs_.canSMPAssign();
321 }
322 //**********************************************************************************************
323
324 private:
325 //**Member variables****************************************************************************
329 //**********************************************************************************************
330
331 //**Assignment to dense matrices****************************************************************
345 template< typename MT // Type of the target dense matrix
346 , bool SO > // Storage order of the target dense matrix
347 friend inline auto assign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
349 {
351
352 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
353 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
354
355 constexpr size_t block( BLOCK_SIZE );
356
357 const size_t m( rhs.rows() );
358 const size_t n( rhs.columns() );
359
360 for( size_t ii=0UL; ii<m; ii+=block ) {
361 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
362 for( size_t jj=0UL; jj<n; jj+=block ) {
363 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
364 for( size_t i=ii; i<iend; ++i ) {
365 for( size_t j=jj; j<jend; ++j ) {
366 (*lhs)(i,j) = rhs.op_( rhs.lhs_(i,j), rhs.rhs_(i,j) );
367 }
368 }
369 }
370 }
371 }
373 //**********************************************************************************************
374
375 //**Assignment to dense matrices****************************************************************
389 template< typename MT // Type of the target dense matrix
390 , bool SO > // Storage order of the target dense matrix
391 friend inline auto assign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
393 {
395
396 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
397 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
398
399 LT A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense matrix operand
400 RT B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
401
402 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
403 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
404 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
405 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
406 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
407 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
408
409 assign( *lhs, map( A, B, rhs.op_ ) );
410 }
412 //**********************************************************************************************
413
414 //**Assignment to sparse matrices***************************************************************
428 template< typename MT // Type of the target sparse matrix
429 , bool SO > // Storage order of the target sparse matrix
430 friend inline auto assign( SparseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
431 -> EnableIf_t< UseAssign_v<MT> >
432 {
434
435 using TmpType = If_t< SO, OppositeType, ResultType >;
436
443
444 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
445 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
446
447 const TmpType tmp( serial( rhs ) );
448 assign( *lhs, tmp );
449 }
451 //**********************************************************************************************
452
453 //**Addition assignment to dense matrices*******************************************************
467 template< typename MT // Type of the target dense matrix
468 , bool SO > // Storage order of the target dense matrix
469 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
470 -> DisableIf_t< UseAssign_v<MT> >
471 {
473
474 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
475 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
476
477 constexpr size_t block( BLOCK_SIZE );
478
479 const size_t m( rhs.rows() );
480 const size_t n( rhs.columns() );
481
482 for( size_t ii=0UL; ii<m; ii+=block ) {
483 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
484 for( size_t jj=0UL; jj<n; jj+=block ) {
485 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
486 for( size_t i=ii; i<iend; ++i ) {
487 for( size_t j=jj; j<jend; ++j ) {
488 (*lhs)(i,j) += rhs.op_( rhs.lhs_(i,j), rhs.rhs_(i,j) );
489 }
490 }
491 }
492 }
493 }
495 //**********************************************************************************************
496
497 //**Addition assignment to dense matrices*******************************************************
511 template< typename MT // Type of the target dense matrix
512 , bool SO > // Storage order of the target dense matrix
513 friend inline auto addAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
514 -> EnableIf_t< UseAssign_v<MT> >
515 {
517
518 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
519 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
520
521 LT A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense matrix operand
522 RT B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
523
524 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
525 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
526 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
527 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
528 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
529 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
530
531 addAssign( *lhs, map( A, B, rhs.op_ ) );
532 }
534 //**********************************************************************************************
535
536 //**Addition assignment to sparse matrices******************************************************
537 // No special implementation for the addition assignment to sparse matrices.
538 //**********************************************************************************************
539
540 //**Subtraction assignment to dense matrices****************************************************
554 template< typename MT // Type of the target dense matrix
555 , bool SO > // Storage order of the target dense matrix
556 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
557 -> DisableIf_t< UseAssign_v<MT> >
558 {
560
561 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
562 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
563
564 constexpr size_t block( BLOCK_SIZE );
565
566 const size_t m( rhs.rows() );
567 const size_t n( rhs.columns() );
568
569 for( size_t ii=0UL; ii<m; ii+=block ) {
570 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
571 for( size_t jj=0UL; jj<n; jj+=block ) {
572 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
573 for( size_t i=ii; i<iend; ++i ) {
574 for( size_t j=jj; j<jend; ++j ) {
575 (*lhs)(i,j) -= rhs.op_( rhs.lhs_(i,j), rhs.rhs_(i,j) );
576 }
577 }
578 }
579 }
580 }
582 //**********************************************************************************************
583
584 //**Subtraction assignment to dense matrices****************************************************
598 template< typename MT // Type of the target dense matrix
599 , bool SO > // Storage order of the target dense matrix
600 friend inline auto subAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
601 -> EnableIf_t< UseAssign_v<MT> >
602 {
604
605 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
606 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
607
608 LT A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense matrix operand
609 RT B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
610
611 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
612 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
613 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
614 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
615 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
616 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
617
618 subAssign( *lhs, map( A, B, rhs.op_ ) );
619 }
621 //**********************************************************************************************
622
623 //**Subtraction assignment to sparse matrices***************************************************
624 // No special implementation for the subtraction assignment to sparse matrices.
625 //**********************************************************************************************
626
627 //**Schur product assignment to dense matrices**************************************************
641 template< typename MT // Type of the target dense matrix
642 , bool SO > // Storage order of the target dense matrix
643 friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
644 -> DisableIf_t< UseAssign_v<MT> >
645 {
647
648 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
649 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
650
651 constexpr size_t block( BLOCK_SIZE );
652
653 const size_t m( rhs.rows() );
654 const size_t n( rhs.columns() );
655
656 for( size_t ii=0UL; ii<m; ii+=block ) {
657 const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
658 for( size_t jj=0UL; jj<n; jj+=block ) {
659 const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
660 for( size_t i=ii; i<iend; ++i ) {
661 for( size_t j=jj; j<jend; ++j ) {
662 (*lhs)(i,j) *= rhs.op_( rhs.lhs_(i,j), rhs.rhs_(i,j) );
663 }
664 }
665 }
666 }
667 }
669 //**********************************************************************************************
670
671 //**Schur product assignment to dense matrices**************************************************
685 template< typename MT // Type of the target dense matrix
686 , bool SO > // Storage order of the target dense matrix
687 friend inline auto schurAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
688 -> EnableIf_t< UseAssign_v<MT> >
689 {
691
692 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
693 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
694
695 LT A( serial( rhs.lhs_ ) ); // Evaluation of the left-hand side dense matrix operand
696 RT B( serial( rhs.rhs_ ) ); // Evaluation of the right-hand side dense matrix operand
697
698 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
699 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
700 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
701 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
702 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
703 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
704
705 schurAssign( *lhs, map( A, B, rhs.op_ ) );
706 }
708 //**********************************************************************************************
709
710 //**Schur product assignment to sparse matrices*************************************************
711 // No special implementation for the Schur product assignment to sparse matrices.
712 //**********************************************************************************************
713
714 //**Multiplication assignment to dense matrices*************************************************
715 // No special implementation for the multiplication assignment to dense matrices.
716 //**********************************************************************************************
717
718 //**Multiplication assignment to sparse matrices************************************************
719 // No special implementation for the multiplication assignment to sparse matrices.
720 //**********************************************************************************************
721
722 //**SMP assignment to dense matrices************************************************************
736 template< typename MT // Type of the target dense matrix
737 , bool SO > // Storage order of the target dense matrix
738 friend inline auto smpAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
739 -> EnableIf_t< UseSMPAssign_v<MT> >
740 {
742
743 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
744 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
745
746 LT A( rhs.lhs_ ); // Evaluation of the left-hand side dense matrix operand
747 RT B( rhs.rhs_ ); // Evaluation of the right-hand side dense matrix operand
748
749 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
750 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
751 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
752 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
753 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
754 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
755
756 smpAssign( *lhs, map( A, B, rhs.op_ ) );
757 }
759 //**********************************************************************************************
760
761 //**SMP assignment to sparse matrices***********************************************************
775 template< typename MT // Type of the target sparse matrix
776 , bool SO > // Storage order of the target sparse matrix
777 friend inline auto smpAssign( SparseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
778 -> EnableIf_t< UseSMPAssign_v<MT> >
779 {
781
782 using TmpType = If_t< SO, OppositeType, ResultType >;
783
790
791 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
792 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
793
794 const TmpType tmp( rhs );
795 smpAssign( *lhs, tmp );
796 }
798 //**********************************************************************************************
799
800 //**SMP addition assignment to dense matrices***************************************************
815 template< typename MT // Type of the target dense matrix
816 , bool SO > // Storage order of the target dense matrix
817 friend inline auto smpAddAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
818 -> EnableIf_t< UseSMPAssign_v<MT> >
819 {
821
822 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
823 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
824
825 LT A( rhs.lhs_ ); // Evaluation of the left-hand side dense matrix operand
826 RT B( rhs.rhs_ ); // Evaluation of the right-hand side dense matrix operand
827
828 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
829 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
830 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
831 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
832 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
833 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
834
835 smpAddAssign( *lhs, map( A, B, rhs.op_ ) );
836 }
838 //**********************************************************************************************
839
840 //**SMP addition assignment to sparse matrices**************************************************
841 // No special implementation for the SMP addition assignment to sparse matrices.
842 //**********************************************************************************************
843
844 //**SMP subtraction assignment to dense matrices************************************************
859 template< typename MT // Type of the target dense matrix
860 , bool SO > // Storage order of the target dense matrix
861 friend inline auto smpSubAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
862 -> EnableIf_t< UseSMPAssign_v<MT> >
863 {
865
866 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
867 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
868
869 LT A( rhs.lhs_ ); // Evaluation of the left-hand side dense matrix operand
870 RT B( rhs.rhs_ ); // Evaluation of the right-hand side dense matrix operand
871
872 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
873 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
874 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
875 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
876 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
877 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
878
879 smpSubAssign( *lhs, map( A, B, rhs.op_ ) );
880 }
882 //**********************************************************************************************
883
884 //**SMP subtraction assignment to sparse matrices***********************************************
885 // No special implementation for the SMP subtraction assignment to sparse matrices.
886 //**********************************************************************************************
887
888 //**SMP Schur product assignment to dense matrices**********************************************
903 template< typename MT // Type of the target dense matrix
904 , bool SO > // Storage order of the target dense matrix
905 friend inline auto smpSchurAssign( DenseMatrix<MT,SO>& lhs, const DMatTDMatMapExpr& rhs )
906 -> EnableIf_t< UseSMPAssign_v<MT> >
907 {
909
910 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
911 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
912
913 LT A( rhs.lhs_ ); // Evaluation of the left-hand side dense matrix operand
914 RT B( rhs.rhs_ ); // Evaluation of the right-hand side dense matrix operand
915
916 BLAZE_INTERNAL_ASSERT( A.rows() == rhs.lhs_.rows() , "Invalid number of rows" );
917 BLAZE_INTERNAL_ASSERT( A.columns() == rhs.lhs_.columns(), "Invalid number of columns" );
918 BLAZE_INTERNAL_ASSERT( B.rows() == rhs.rhs_.rows() , "Invalid number of rows" );
919 BLAZE_INTERNAL_ASSERT( B.columns() == rhs.rhs_.columns(), "Invalid number of columns" );
920 BLAZE_INTERNAL_ASSERT( A.rows() == (*lhs).rows() , "Invalid number of rows" );
921 BLAZE_INTERNAL_ASSERT( B.columns() == (*lhs).columns() , "Invalid number of columns" );
922
923 smpSchurAssign( *lhs, map( A, B, rhs.op_ ) );
924 }
926 //**********************************************************************************************
927
928 //**SMP Schur product assignment to sparse matrices*********************************************
929 // No special implementation for the SMP Schur product assignment to sparse matrices.
930 //**********************************************************************************************
931
932 //**SMP multiplication assignment to dense matrices*********************************************
933 // No special implementation for the SMP multiplication assignment to dense matrices.
934 //**********************************************************************************************
935
936 //**SMP multiplication assignment to sparse matrices********************************************
937 // No special implementation for the SMP multiplication assignment to sparse matrices.
938 //**********************************************************************************************
939
940 //**Compile time checks*************************************************************************
946 //**********************************************************************************************
947};
948//*************************************************************************************************
949
950
951
952
953//=================================================================================================
954//
955// GLOBAL FUNCTIONS
956//
957//=================================================================================================
958
959//*************************************************************************************************
973template< typename MT1 // Type of the left-hand side dense matrix
974 , typename MT2 // Type of the right-hand side dense matrix
975 , typename OP // Type of the custom operation
976 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* = nullptr >
977inline const DMatTDMatMapExpr<MT1,MT2,OP>
978 map_backend( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs, OP op )
979{
981
982 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
983 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
984
985 return DMatTDMatMapExpr<MT1,MT2,OP>( *lhs, *rhs, std::move(op) );
986}
988//*************************************************************************************************
989
990
991//*************************************************************************************************
1005template< typename MT1 // Type of the left-hand side dense matrix
1006 , typename MT2 // Type of the right-hand side dense matrix
1007 , typename OP // Type of the custom operation
1008 , EnableIf_t< IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* = nullptr >
1009inline decltype(auto)
1010 map_backend( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs, OP op )
1011{
1013
1014 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1015 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1016
1017 return map( trans( *lhs ), *rhs, std::move(op) );
1018}
1020//*************************************************************************************************
1021
1022
1023//*************************************************************************************************
1038template< typename MT1 // Type of the left-hand side dense matrix
1039 , typename MT2 // Type of the right-hand side dense matrix
1040 , typename OP // Type of the custom operation
1041 , EnableIf_t< IsSymmetric_v<MT2> >* = nullptr >
1042inline decltype(auto)
1043 map_backend( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs, OP op )
1044{
1046
1047 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1048 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1049
1050 return map( *lhs, trans( *rhs ), std::move(op) );
1051}
1053//*************************************************************************************************
1054
1055
1056//*************************************************************************************************
1081template< typename MT1 // Type of the left-hand side dense matrix
1082 , typename MT2 // Type of the right-hand side dense matrix
1083 , typename OP > // Type of the custom operation
1084inline decltype(auto)
1085 map( const DenseMatrix<MT1,false>& lhs, const DenseMatrix<MT2,true>& rhs, OP op )
1086{
1088
1089 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1090 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1091 }
1092
1093 return map_backend( *lhs, *rhs, std::move(op) );
1094}
1095//*************************************************************************************************
1096
1097
1098//*************************************************************************************************
1112template< typename MT1 // Type of the left-hand side dense matrix
1113 , typename MT2 // Type of the right-hand side dense matrix
1114 , typename OP // Type of the custom operation
1115 , EnableIf_t< !IsSymmetric_v<MT1> && !IsSymmetric_v<MT2> >* = nullptr >
1116inline const DMatTDMatMapExpr<MT1,MT2,OP>
1117 map_backend( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs, OP op )
1118{
1120
1121 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1122 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1123
1124 return DMatTDMatMapExpr<MT1,MT2,OP>( *lhs, *rhs, std::move(op) );
1125}
1127//*************************************************************************************************
1128
1129
1130//*************************************************************************************************
1144template< typename MT1 // Type of the left-hand side dense matrix
1145 , typename MT2 // Type of the right-hand side dense matrix
1146 , typename OP // Type of the custom operation
1147 , EnableIf_t< !IsSymmetric_v<MT1> && IsSymmetric_v<MT2> >* = nullptr >
1148inline decltype(auto)
1149 map_backend( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs, OP op )
1150{
1152
1153 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1154 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1155
1156 return map( *lhs, trans( *rhs ), std::move(op) );
1157}
1159//*************************************************************************************************
1160
1161
1162//*************************************************************************************************
1177template< typename MT1 // Type of the left-hand side dense matrix
1178 , typename MT2 // Type of the right-hand side dense matrix
1179 , typename OP // Type of the custom operation
1180 , EnableIf_t< IsSymmetric_v<MT1> >* = nullptr >
1181inline decltype(auto)
1182 map_backend( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs, OP op )
1183{
1185
1186 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == (*rhs).rows() , "Invalid number of rows" );
1187 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).columns(), "Invalid number of columns" );
1188
1189 return map( trans( *lhs ), *rhs, std::move(op) );
1190}
1192//*************************************************************************************************
1193
1194
1195//*************************************************************************************************
1220template< typename MT1 // Type of the left-hand side dense matrix
1221 , typename MT2 // Type of the right-hand side dense matrix
1222 , typename OP > // Type of the custom operation
1223inline decltype(auto)
1224 map( const DenseMatrix<MT1,true>& lhs, const DenseMatrix<MT2,false>& rhs, OP op )
1225{
1227
1228 if( (*lhs).rows() != (*rhs).rows() || (*lhs).columns() != (*rhs).columns() ) {
1229 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1230 }
1231
1232 return map_backend( *lhs, *rhs, std::move(op) );
1233}
1234//*************************************************************************************************
1235
1236
1237
1238
1239//=================================================================================================
1240//
1241// ISALIGNED SPECIALIZATIONS
1242//
1243//=================================================================================================
1244
1245//*************************************************************************************************
1247template< typename MT1, typename MT2, typename OP >
1248struct IsAligned< DMatTDMatMapExpr<MT1,MT2,OP> >
1249 : public BoolConstant< IsAligned_v<MT1> && IsAligned_v<MT2> >
1250{};
1252//*************************************************************************************************
1253
1254
1255
1256
1257//=================================================================================================
1258//
1259// ISPADDED SPECIALIZATIONS
1260//
1261//=================================================================================================
1262
1263//*************************************************************************************************
1265template< typename MT1, typename MT2, typename OP >
1266struct IsPadded< DMatTDMatMapExpr<MT1,MT2,OP> >
1267 : public BoolConstant< IsPadded_v<MT1> && IsPadded_v<MT2> >
1268{};
1270//*************************************************************************************************
1271
1272} // namespace blaze
1273
1274#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for kernel specific block sizes.
Constraints on the storage order of matrix types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsAligned type trait.
Header file for the IsExpression type trait class.
Header file for the IsPadded type trait.
Header file for the IsSymmetric type trait.
Header file for the map trait.
Constraints on the storage order of matrix types.
Header file for all SIMD functionality.
Expression object for the dense matrix/tranpose dense matrix map() function.
Definition: DMatTDMatMapExpr.h:95
RightOperand rhs_
Right-hand side dense matrix of the map expression.
Definition: DMatTDMatMapExpr.h:327
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatTDMatMapExpr.h:309
DMatTDMatMapExpr(const MT1 &lhs, const MT2 &rhs, OP op) noexcept
Constructor for the DMatTDMatMapExpr class.
Definition: DMatTDMatMapExpr.h:189
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: DMatTDMatMapExpr.h:150
ReturnType_t< MT2 > RN2
Return type of the right-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:103
CompositeType_t< MT1 > CT1
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:104
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:162
Operation operation() const
Returns a copy of the custom operation.
Definition: DMatTDMatMapExpr.h:274
RightOperand rightOperand() const noexcept
Returns the right-hand side dense matrix operand.
Definition: DMatTDMatMapExpr.h:264
LeftOperand leftOperand() const noexcept
Returns the left-hand side dense matrix operand.
Definition: DMatTDMatMapExpr.h:254
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatTDMatMapExpr.h:299
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:159
ReturnType_t< MT1 > RN1
Return type of the left-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:102
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatTDMatMapExpr.h:244
If_t< useAssign, const ResultType, const DMatTDMatMapExpr & > CompositeType
Data type for composite expression templates.
Definition: DMatTDMatMapExpr.h:156
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatTDMatMapExpr.h:148
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatTDMatMapExpr.h:179
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatTDMatMapExpr.h:218
ElementType_t< MT1 > ET1
Element type of the left-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:100
ResultType_t< MT2 > RT2
Result type of the right-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:99
If_t< RequiresEvaluation_v< MT2 >, const RT2, CT2 > RT
Type for the assignment of the right-hand side dense matrix operand.
Definition: DMatTDMatMapExpr.h:171
Operation op_
The custom unary operation.
Definition: DMatTDMatMapExpr.h:328
OP Operation
Data type of the custom unary operation.
Definition: DMatTDMatMapExpr.h:165
MapTrait_t< RT1, RT2, OP > ResultType
Result type for expression template evaluations.
Definition: DMatTDMatMapExpr.h:147
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatTDMatMapExpr.h:286
decltype(std::declval< OP >()(std::declval< RN1 >(), std::declval< RN2 >())) ReturnType
Return type for expression template evaluations.
Definition: DMatTDMatMapExpr.h:153
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatTDMatMapExpr.h:319
LeftOperand lhs_
Left-hand side dense matrix of the map expression.
Definition: DMatTDMatMapExpr.h:326
If_t< RequiresEvaluation_v< MT1 >, const RT1, CT1 > LT
Type for the assignment of the left-hand side dense matrix operand.
Definition: DMatTDMatMapExpr.h:168
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatTDMatMapExpr.h:234
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the map expression.
Definition: DMatTDMatMapExpr.h:116
CompositeType_t< MT2 > CT2
Composite type of the right-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:105
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatTDMatMapExpr.h:176
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatTDMatMapExpr.h:149
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatTDMatMapExpr.h:203
ElementType_t< MT2 > ET2
Element type of the right-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:101
ResultType_t< MT1 > RT1
Result type of the left-hand side dense matrix expression.
Definition: DMatTDMatMapExpr.h:98
Base class for dense matrices.
Definition: DenseMatrix.h:82
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatMatMapExpr base class.
decltype(auto) map(const DenseMatrix< MT1, true > &lhs, const DenseMatrix< MT2, false > &rhs, OP op)
Evaluates the given binary operation on each single element of the column-major dense matrix lhs and ...
Definition: DMatTDMatMapExpr.h:1224
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.
Definition: StorageOrder.h:84
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_DIFFERENT_STORAGE_ORDER(T1, T2)
Constraint on the data type.
Definition: StorageOrder.h:106
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
typename MapTrait< Args... >::Type MapTrait_t
Auxiliary alias declaration for the MapTrait class template.
Definition: MapTrait.h:131
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.
Definition: IntegralConstant.h:110
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all binary matrix map expression templates.
Definition: MatMatMapExpr.h:68
System settings for the inline keywords.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.