Blaze 3.9
DMatNoSIMDExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATNOSIMDEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATNOSIMDEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
57#include <blaze/system/Inline.h>
58#include <blaze/util/Assert.h>
59#include <blaze/util/EnableIf.h>
62#include <blaze/util/mpl/If.h>
63#include <blaze/util/Types.h>
65
66
67namespace blaze {
68
69//=================================================================================================
70//
71// CLASS DMATNOSIMDEXPR
72//
73//=================================================================================================
74
75//*************************************************************************************************
82template< typename MT // Type of the dense matrix
83 , bool SO > // Storage order
85 : public MatNoSIMDExpr< DenseMatrix< DMatNoSIMDExpr<MT,SO>, SO > >
86 , private Modification<MT>
87{
88 private:
89 //**Type definitions****************************************************************************
91 BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
92 //**********************************************************************************************
93
94 //**Serial evaluation strategy******************************************************************
96
102 static constexpr bool useAssign = RequiresEvaluation_v<MT>;
103
106 template< typename MT2 >
107 static constexpr bool UseAssign_v = useAssign;
109 //**********************************************************************************************
110
111 //**Parallel evaluation strategy****************************************************************
113
119 template< typename MT2 >
120 static constexpr bool UseSMPAssign_v = ( MT2::smpAssignable && useAssign );
122 //**********************************************************************************************
123
124 public:
125 //**Type definitions****************************************************************************
128
131
137
140
142 using ConstIterator = GetConstIterator_t<MT>;
143
145 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
146 //**********************************************************************************************
147
148 //**Compilation flags***************************************************************************
150 static constexpr bool simdEnabled = false;
151
153 static constexpr bool smpAssignable = MT::smpAssignable;
154 //**********************************************************************************************
155
156 //**SIMD properties*****************************************************************************
158 static constexpr size_t SIMDSIZE = SIMDTrait<ElementType>::size;
159 //**********************************************************************************************
160
161 //**Constructor*********************************************************************************
166 explicit inline DMatNoSIMDExpr( const MT& dm ) noexcept
167 : dm_( dm ) // Dense matrix of the no-SIMD expression
168 {}
169 //**********************************************************************************************
170
171 //**Access operator*****************************************************************************
178 inline ReturnType operator()( size_t i, size_t j ) const {
179 return dm_(i,j);
180 }
181 //**********************************************************************************************
182
183 //**At function*********************************************************************************
191 inline ReturnType at( size_t i, size_t j ) const {
192 return dm_.at(i,j);
193 }
194 //**********************************************************************************************
195
196 //**Load function*******************************************************************************
203 BLAZE_ALWAYS_INLINE auto load( size_t i, size_t j ) const noexcept {
204 return dm_.load(i,j);
205 }
206 //**********************************************************************************************
207
208 //**Low-level data access***********************************************************************
213 inline const ElementType* data() const noexcept {
214 return dm_.data();
215 }
216 //**********************************************************************************************
217
218 //**Begin function******************************************************************************
224 inline ConstIterator begin( size_t i ) const {
225 return ConstIterator( dm_.begin(i) );
226 }
227 //**********************************************************************************************
228
229 //**End function********************************************************************************
235 inline ConstIterator end( size_t i ) const {
236 return ConstIterator( dm_.end(i) );
237 }
238 //**********************************************************************************************
239
240 //**Rows function*******************************************************************************
245 inline size_t rows() const noexcept {
246 return dm_.rows();
247 }
248 //**********************************************************************************************
249
250 //**Columns function****************************************************************************
255 inline size_t columns() const noexcept {
256 return dm_.columns();
257 }
258 //**********************************************************************************************
259
260 //**Spacing function****************************************************************************
265 inline size_t spacing() const noexcept {
266 return dm_.spacing();
267 }
268 //**********************************************************************************************
269
270 //**NonZeros function***************************************************************************
275 inline size_t nonZeros() const {
276 return dm_.nonZeros();
277 }
278 //**********************************************************************************************
279
280 //**NonZeros function***************************************************************************
286 inline size_t nonZeros( size_t i ) const {
287 return dm_.nonZeros( i );
288 }
289 //**********************************************************************************************
290
291 //**Operand access******************************************************************************
296 inline Operand operand() const noexcept {
297 return dm_;
298 }
299 //**********************************************************************************************
300
301 //**********************************************************************************************
307 template< typename T >
308 inline bool canAlias( const T* alias ) const noexcept {
309 return dm_.canAlias( alias );
310 }
311 //**********************************************************************************************
312
313 //**********************************************************************************************
319 template< typename T >
320 inline bool isAliased( const T* alias ) const noexcept {
321 return dm_.isAliased( alias );
322 }
323 //**********************************************************************************************
324
325 //**********************************************************************************************
330 inline bool isAligned() const noexcept {
331 return dm_.isAligned();
332 }
333 //**********************************************************************************************
334
335 //**********************************************************************************************
340 inline bool canSMPAssign() const noexcept {
341 return dm_.canSMPAssign();
342 }
343 //**********************************************************************************************
344
345 private:
346 //**Member variables****************************************************************************
348 //**********************************************************************************************
349
350 //**Assignment to dense matrices****************************************************************
364 template< typename MT2 // Type of the target dense matrix
365 , bool SO2 > // Storage order of the target dense matrix
366 friend inline auto assign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
368 {
370
371 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
372 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
373
374 assign( *lhs, rhs.dm_ );
375 }
377 //**********************************************************************************************
378
379 //**Assignment to sparse matrices***************************************************************
393 template< typename MT2 // Type of the target sparse matrix
394 , bool SO2 > // Storage order of the target dense matrix
395 friend inline auto assign( SparseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
397 {
399
400 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
401 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
402
403 assign( *lhs, rhs.dm_ );
404 }
406 //**********************************************************************************************
407
408 //**Addition assignment to dense matrices*******************************************************
422 template< typename MT2 // Type of the target dense matrix
423 , bool SO2 > // Storage order of the target dense matrix
424 friend inline auto addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
425 -> EnableIf_t< UseAssign_v<MT2> >
426 {
428
429 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
430 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
431
432 addAssign( *lhs, rhs.dm_ );
433 }
435 //**********************************************************************************************
436
437 //**Addition assignment to sparse matrices******************************************************
438 // No special implementation for the addition assignment to sparse matrices.
439 //**********************************************************************************************
440
441 //**Subtraction assignment to dense matrices****************************************************
455 template< typename MT2 // Type of the target dense matrix
456 , bool SO2 > // Storage order of the target dense matrix
457 friend inline auto subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
458 -> EnableIf_t< UseAssign_v<MT2> >
459 {
461
462 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
463 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
464
465 subAssign( *lhs, rhs.dm_ );
466 }
468 //**********************************************************************************************
469
470 //**Subtraction assignment to sparse matrices***************************************************
471 // No special implementation for the subtraction assignment to sparse matrices.
472 //**********************************************************************************************
473
474 //**Schur product assignment to dense matrices**************************************************
488 template< typename MT2 // Type of the target dense matrix
489 , bool SO2 > // Storage order of the target dense matrix
490 friend inline auto schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
491 -> EnableIf_t< UseAssign_v<MT2> >
492 {
494
495 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
496 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
497
498 schurAssign( *lhs, rhs.dm_ );
499 }
501 //**********************************************************************************************
502
503 //**Schur product assignment to sparse matrices*************************************************
504 // No special implementation for the Schur product assignment to sparse matrices.
505 //**********************************************************************************************
506
507 //**Multiplication assignment to dense matrices*************************************************
508 // No special implementation for the multiplication assignment to dense matrices.
509 //**********************************************************************************************
510
511 //**Multiplication assignment to sparse matrices************************************************
512 // No special implementation for the multiplication assignment to sparse matrices.
513 //**********************************************************************************************
514
515 //**SMP assignment to dense matrices************************************************************
529 template< typename MT2 // Type of the target dense matrix
530 , bool SO2 > // Storage order of the target dense matrix
531 friend inline auto smpAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
532 -> EnableIf_t< UseSMPAssign_v<MT2> >
533 {
535
536 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
537 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
538
539 smpAssign( *lhs, rhs.dm_ );
540 }
542 //**********************************************************************************************
543
544 //**SMP assignment to sparse matrices***********************************************************
558 template< typename MT2 // Type of the target sparse matrix
559 , bool SO2 > // Storage order of the target dense matrix
560 friend inline auto smpAssign( SparseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
561 -> EnableIf_t< UseSMPAssign_v<MT2> >
562 {
564
565 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
566 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
567
568 smpAssign( *lhs, rhs.dm_ );
569 }
571 //**********************************************************************************************
572
573 //**SMP addition assignment to dense matrices***************************************************
587 template< typename MT2 // Type of the target dense matrix
588 , bool SO2 > // Storage order of the target dense matrix
589 friend inline auto smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
590 -> EnableIf_t< UseSMPAssign_v<MT2> >
591 {
593
594 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
595 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
596
597 smpAddAssign( *lhs, rhs.dm_ );
598 }
600 //**********************************************************************************************
601
602 //**SMP addition assignment to sparse matrices**************************************************
603 // No special implementation for the SMP addition assignment to sparse matrices.
604 //**********************************************************************************************
605
606 //**SMP subtraction assignment to dense matrices************************************************
620 template< typename MT2 // Type of the target dense matrix
621 , bool SO2 > // Storage order of the target dense matrix
622 friend inline auto smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
623 -> EnableIf_t< UseSMPAssign_v<MT2> >
624 {
626
627 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
628 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
629
630 smpSubAssign( *lhs, rhs.dm_ );
631 }
633 //**********************************************************************************************
634
635 //**SMP subtraction assignment to sparse matrices***********************************************
636 // No special implementation for the SMP subtraction assignment to sparse matrices.
637 //**********************************************************************************************
638
639 //**SMP Schur product assignment to dense matrices**********************************************
653 template< typename MT2 // Type of the target dense matrix
654 , bool SO2 > // Storage order of the target dense matrix
655 friend inline auto smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoSIMDExpr& rhs )
656 -> EnableIf_t< UseSMPAssign_v<MT2> >
657 {
659
660 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
661 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
662
663 smpSchurAssign( *lhs, rhs.dm_ );
664 }
666 //**********************************************************************************************
667
668 //**SMP Schur product assignment to sparse matrices*********************************************
669 // No special implementation for the SMP Schur product assignment to sparse matrices.
670 //**********************************************************************************************
671
672 //**SMP multiplication assignment to dense matrices*********************************************
673 // No special implementation for the SMP multiplication assignment to dense matrices.
674 //**********************************************************************************************
675
676 //**SMP multiplication assignment to sparse matrices********************************************
677 // No special implementation for the SMP multiplication assignment to sparse matrices.
678 //**********************************************************************************************
679
680 //**Compile time checks*************************************************************************
685 //**********************************************************************************************
686};
687//*************************************************************************************************
688
689
690
691
692//=================================================================================================
693//
694// GLOBAL FUNCTIONS
695//
696//=================================================================================================
697
698//*************************************************************************************************
715template< typename MT // Type of the dense matrix
716 , bool SO > // Storage order
717inline decltype(auto) nosimd( const DenseMatrix<MT,SO>& dm )
718{
720
721 using ReturnType = const DMatNoSIMDExpr<MT,SO>;
722 return ReturnType( *dm );
723}
724//*************************************************************************************************
725
726
727
728
729//=================================================================================================
730//
731// HASCONSTDATAACCESS SPECIALIZATIONS
732//
733//=================================================================================================
734
735//*************************************************************************************************
737template< typename MT, bool SO >
738struct HasConstDataAccess< DMatNoSIMDExpr<MT,SO> >
739 : public HasConstDataAccess<MT>
740{};
742//*************************************************************************************************
743
744
745
746
747//=================================================================================================
748//
749// ISALIGNED SPECIALIZATIONS
750//
751//=================================================================================================
752
753//*************************************************************************************************
755template< typename MT, bool SO >
756struct IsAligned< DMatNoSIMDExpr<MT,SO> >
757 : public IsAligned<MT>
758{};
760//*************************************************************************************************
761
762
763
764
765//=================================================================================================
766//
767// ISPADDED SPECIALIZATIONS
768//
769//=================================================================================================
770
771//*************************************************************************************************
773template< typename MT, bool SO >
774struct IsPadded< DMatNoSIMDExpr<MT,SO> >
775 : public IsPadded<MT>
776{};
778//*************************************************************************************************
779
780} // namespace blaze
781
782#endif
Header file for auxiliary alias declarations.
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 the EnableIf class template.
Header file for the function trace functionality.
Header file for the GetMemberType type trait.
Header file for the HasConstDataAccess type trait.
Header file for the If class template.
Utility type for generic codes.
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 SIMD trait.
Expression object for the non-SIMD evaluation of dense matrices.
Definition: DMatNoSIMDExpr.h:87
If_t< useAssign, const ResultType, const DMatNoSIMDExpr & > CompositeType
Data type for composite expression templates.
Definition: DMatNoSIMDExpr.h:139
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatNoSIMDExpr.h:134
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatNoSIMDExpr.h:255
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatNoSIMDExpr.h:153
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatNoSIMDExpr.h:145
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatNoSIMDExpr.h:136
Operand dm_
Dense matrix of the no-SIMD expression.
Definition: DMatNoSIMDExpr.h:347
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatNoSIMDExpr.h:340
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatNoSIMDExpr.h:191
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatNoSIMDExpr.h:132
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatNoSIMDExpr.h:308
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: DMatNoSIMDExpr.h:235
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the no-SIMD expression.
Definition: DMatNoSIMDExpr.h:102
DMatNoSIMDExpr(const MT &dm) noexcept
Constructor for the DMatNoSIMDExpr class.
Definition: DMatNoSIMDExpr.h:166
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatNoSIMDExpr.h:330
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatNoSIMDExpr.h:135
BLAZE_ALWAYS_INLINE auto load(size_t i, size_t j) const noexcept
Access to the SIMD elements of the matrix.
Definition: DMatNoSIMDExpr.h:203
GetConstIterator_t< MT > ConstIterator
Iterator over the elements of the dense matrix.
Definition: DMatNoSIMDExpr.h:142
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatNoSIMDExpr.h:133
const ElementType * data() const noexcept
Low-level data access to the matrix elements.
Definition: DMatNoSIMDExpr.h:213
size_t spacing() const noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DMatNoSIMDExpr.h:265
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatNoSIMDExpr.h:296
size_t nonZeros() const
Returns the number of non-zero elements in the dense matrix.
Definition: DMatNoSIMDExpr.h:275
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatNoSIMDExpr.h:320
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatNoSIMDExpr.h:245
static constexpr size_t SIMDSIZE
The number of elements packed within a single SIMD element.
Definition: DMatNoSIMDExpr.h:158
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatNoSIMDExpr.h:150
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatNoSIMDExpr.h:178
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: DMatNoSIMDExpr.h:224
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row/column.
Definition: DMatNoSIMDExpr.h:286
Base class for dense matrices.
Definition: DenseMatrix.h:82
SIMD characteristics of data types.
Definition: SIMDTrait.h:297
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Header file for the DenseMatrix base class.
Header file for the MatNoSIMDExpr base class.
Header file for the Modification base class.
decltype(auto) nosimd(const DenseMatrix< MT, SO > &dm)
Disables the SIMD evaluation of the given dense matrix expression dm.
Definition: DMatNoSIMDExpr.h:717
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
#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
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
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
#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.
Base class for all matrix no-SIMD expression templates.
Definition: MatNoSIMDExpr.h:95
Base class for all modification expression templates.
Definition: Modification.h:76
System settings for the inline keywords.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.