Blaze 3.9
DMatNoAliasExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATNOALIASEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATNOALIASEXPR_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>
62#include <blaze/util/mpl/If.h>
63#include <blaze/util/Types.h>
65
66
67namespace blaze {
68
69//=================================================================================================
70//
71// CLASS DMATNOALIASEXPR
72//
73//=================================================================================================
74
75//*************************************************************************************************
82template< typename MT // Type of the dense matrix
83 , bool SO > // Storage order
85 : public MatNoAliasExpr< DenseMatrix< DMatNoAliasExpr<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 public:
95 //**Type definitions****************************************************************************
98
101
107
110
112 using ConstIterator = GetConstIterator_t<MT>;
113
115 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
116 //**********************************************************************************************
117
118 //**Compilation flags***************************************************************************
120 static constexpr bool simdEnabled = MT::simdEnabled;
121
123 static constexpr bool smpAssignable = MT::smpAssignable;
124 //**********************************************************************************************
125
126 //**SIMD properties*****************************************************************************
128 static constexpr size_t SIMDSIZE = SIMDTrait<ElementType>::size;
129 //**********************************************************************************************
130
131 //**Constructor*********************************************************************************
136 explicit inline DMatNoAliasExpr( const MT& dm ) noexcept
137 : dm_( dm ) // Dense matrix of the no-alias expression
138 {}
139 //**********************************************************************************************
140
141 //**Access operator*****************************************************************************
148 inline ReturnType operator()( size_t i, size_t j ) const {
149 return dm_(i,j);
150 }
151 //**********************************************************************************************
152
153 //**At function*********************************************************************************
161 inline ReturnType at( size_t i, size_t j ) const {
162 return dm_.at(i,j);
163 }
164 //**********************************************************************************************
165
166 //**Load function*******************************************************************************
173 BLAZE_ALWAYS_INLINE auto load( size_t i, size_t j ) const noexcept {
174 return dm_.load(i,j);
175 }
176 //**********************************************************************************************
177
178 //**Low-level data access***********************************************************************
183 inline const ElementType* data() const noexcept {
184 return dm_.data();
185 }
186 //**********************************************************************************************
187
188 //**Begin function******************************************************************************
194 inline ConstIterator begin( size_t i ) const {
195 return ConstIterator( dm_.begin(i) );
196 }
197 //**********************************************************************************************
198
199 //**End function********************************************************************************
205 inline ConstIterator end( size_t i ) const {
206 return ConstIterator( dm_.end(i) );
207 }
208 //**********************************************************************************************
209
210 //**Rows function*******************************************************************************
215 inline size_t rows() const noexcept {
216 return dm_.rows();
217 }
218 //**********************************************************************************************
219
220 //**Columns function****************************************************************************
225 inline size_t columns() const noexcept {
226 return dm_.columns();
227 }
228 //**********************************************************************************************
229
230 //**Spacing function****************************************************************************
235 inline size_t spacing() const noexcept {
236 return dm_.spacing();
237 }
238 //**********************************************************************************************
239
240 //**NonZeros function***************************************************************************
245 inline size_t nonZeros() const {
246 return dm_.nonZeros();
247 }
248 //**********************************************************************************************
249
250 //**NonZeros function***************************************************************************
256 inline size_t nonZeros( size_t i ) const {
257 return dm_.nonZeros( i );
258 }
259 //**********************************************************************************************
260
261 //**Operand access******************************************************************************
266 inline Operand operand() const noexcept {
267 return dm_;
268 }
269 //**********************************************************************************************
270
271 //**********************************************************************************************
277 template< typename T >
278 inline bool canAlias( const T* alias ) const noexcept {
279 MAYBE_UNUSED( alias );
280 return false;
281 }
282 //**********************************************************************************************
283
284 //**********************************************************************************************
290 template< typename T >
291 inline bool isAliased( const T* alias ) const noexcept {
292 MAYBE_UNUSED( alias );
293 return false;
294 }
295 //**********************************************************************************************
296
297 //**********************************************************************************************
302 inline bool isAligned() const noexcept {
303 return dm_.isAligned();
304 }
305 //**********************************************************************************************
306
307 //**********************************************************************************************
312 inline bool canSMPAssign() const noexcept {
313 return dm_.canSMPAssign();
314 }
315 //**********************************************************************************************
316
317 private:
318 //**Member variables****************************************************************************
320 //**********************************************************************************************
321
322 //**Assignment to dense matrices****************************************************************
336 template< typename MT2 // Type of the target dense matrix
337 , bool SO2 > // Storage order of the target dense matrix
338 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
339 {
341
342 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
343 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
344
345 assign( *lhs, rhs.dm_ );
346 }
348 //**********************************************************************************************
349
350 //**Assignment to sparse matrices***************************************************************
364 template< typename MT2 // Type of the target sparse matrix
365 , bool SO2 > // Storage order of the target dense matrix
366 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
367 {
369
370 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
371 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
372
373 assign( *lhs, rhs.dm_ );
374 }
376 //**********************************************************************************************
377
378 //**Addition assignment to dense matrices*******************************************************
392 template< typename MT2 // Type of the target dense matrix
393 , bool SO2 > // Storage order of the target dense matrix
394 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
395 {
397
398 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
399 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
400
401 addAssign( *lhs, rhs.dm_ );
402 }
404 //**********************************************************************************************
405
406 //**Addition assignment to sparse matrices******************************************************
407 // No special implementation for the addition assignment to sparse matrices.
408 //**********************************************************************************************
409
410 //**Subtraction assignment to dense matrices****************************************************
424 template< typename MT2 // Type of the target dense matrix
425 , bool SO2 > // Storage order of the target dense matrix
426 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
427 {
429
430 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
431 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
432
433 subAssign( *lhs, rhs.dm_ );
434 }
436 //**********************************************************************************************
437
438 //**Subtraction assignment to sparse matrices***************************************************
439 // No special implementation for the subtraction assignment to sparse matrices.
440 //**********************************************************************************************
441
442 //**Schur product assignment to dense matrices**************************************************
456 template< typename MT2 // Type of the target dense matrix
457 , bool SO2 > // Storage order of the target dense matrix
458 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
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 schurAssign( *lhs, rhs.dm_ );
466 }
468 //**********************************************************************************************
469
470 //**Schur product assignment to sparse matrices*************************************************
471 // No special implementation for the Schur product assignment to sparse matrices.
472 //**********************************************************************************************
473
474 //**Multiplication assignment to dense matrices*************************************************
475 // No special implementation for the multiplication assignment to dense matrices.
476 //**********************************************************************************************
477
478 //**Multiplication assignment to sparse matrices************************************************
479 // No special implementation for the multiplication assignment to sparse matrices.
480 //**********************************************************************************************
481
482 //**SMP assignment to dense matrices************************************************************
496 template< typename MT2 // Type of the target dense matrix
497 , bool SO2 > // Storage order of the target dense matrix
498 friend inline void smpAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
499 {
501
502 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
503 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
504
505 smpAssign( *lhs, rhs.dm_ );
506 }
508 //**********************************************************************************************
509
510 //**SMP assignment to sparse matrices***********************************************************
524 template< typename MT2 // Type of the target sparse matrix
525 , bool SO2 > // Storage order of the target dense matrix
526 friend inline void smpAssign( SparseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
527 {
529
530 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
531 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
532
533 smpAssign( *lhs, rhs.dm_ );
534 }
536 //**********************************************************************************************
537
538 //**SMP addition assignment to dense matrices***************************************************
552 template< typename MT2 // Type of the target dense matrix
553 , bool SO2 > // Storage order of the target dense matrix
554 friend inline void smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
555 {
557
558 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
559 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
560
561 smpAddAssign( *lhs, rhs.dm_ );
562 }
564 //**********************************************************************************************
565
566 //**SMP addition assignment to sparse matrices**************************************************
567 // No special implementation for the SMP addition assignment to sparse matrices.
568 //**********************************************************************************************
569
570 //**SMP subtraction assignment to dense matrices************************************************
584 template< typename MT2 // Type of the target dense matrix
585 , bool SO2 > // Storage order of the target dense matrix
586 friend inline void smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
587 {
589
590 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
591 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
592
593 smpSubAssign( *lhs, rhs.dm_ );
594 }
596 //**********************************************************************************************
597
598 //**SMP subtraction assignment to sparse matrices***********************************************
599 // No special implementation for the SMP subtraction assignment to sparse matrices.
600 //**********************************************************************************************
601
602 //**SMP Schur product assignment to dense matrices**********************************************
616 template< typename MT2 // Type of the target dense matrix
617 , bool SO2 > // Storage order of the target dense matrix
618 friend inline void smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatNoAliasExpr& rhs )
619 {
621
622 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
623 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
624
625 smpSchurAssign( *lhs, rhs.dm_ );
626 }
628 //**********************************************************************************************
629
630 //**SMP Schur product assignment to sparse matrices*********************************************
631 // No special implementation for the SMP Schur product assignment to sparse matrices.
632 //**********************************************************************************************
633
634 //**SMP multiplication assignment to dense matrices*********************************************
635 // No special implementation for the SMP multiplication assignment to dense matrices.
636 //**********************************************************************************************
637
638 //**SMP multiplication assignment to sparse matrices********************************************
639 // No special implementation for the SMP multiplication assignment to sparse matrices.
640 //**********************************************************************************************
641
642 //**Compile time checks*************************************************************************
647 //**********************************************************************************************
648};
649//*************************************************************************************************
650
651
652
653
654//=================================================================================================
655//
656// GLOBAL FUNCTIONS
657//
658//=================================================================================================
659
660//*************************************************************************************************
677template< typename MT // Type of the dense matrix
678 , bool SO > // Storage order
679inline decltype(auto) noalias( const DenseMatrix<MT,SO>& dm )
680{
682
683 using ReturnType = const DMatNoAliasExpr<MT,SO>;
684 return ReturnType( *dm );
685}
686//*************************************************************************************************
687
688
689
690
691//=================================================================================================
692//
693// HASCONSTDATAACCESS SPECIALIZATIONS
694//
695//=================================================================================================
696
697//*************************************************************************************************
699template< typename MT, bool SO >
700struct HasConstDataAccess< DMatNoAliasExpr<MT,SO> >
701 : public HasConstDataAccess<MT>
702{};
704//*************************************************************************************************
705
706
707
708
709//=================================================================================================
710//
711// ISALIGNED SPECIALIZATIONS
712//
713//=================================================================================================
714
715//*************************************************************************************************
717template< typename MT, bool SO >
718struct IsAligned< DMatNoAliasExpr<MT,SO> >
719 : public IsAligned<MT>
720{};
722//*************************************************************************************************
723
724
725
726
727//=================================================================================================
728//
729// ISPADDED SPECIALIZATIONS
730//
731//=================================================================================================
732
733//*************************************************************************************************
735template< typename MT, bool SO >
736struct IsPadded< DMatNoAliasExpr<MT,SO> >
737 : public IsPadded<MT>
738{};
740//*************************************************************************************************
741
742} // namespace blaze
743
744#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 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 MAYBE_UNUSED function template.
Header file for the SIMD trait.
Expression object for the non-aliased evaluation of dense matrices.
Definition: DMatNoAliasExpr.h:87
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatNoAliasExpr.h:104
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatNoAliasExpr.h:103
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatNoAliasExpr.h:120
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatNoAliasExpr.h:102
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatNoAliasExpr.h:302
size_t nonZeros() const
Returns the number of non-zero elements in the dense matrix.
Definition: DMatNoAliasExpr.h:245
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: DMatNoAliasExpr.h:194
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatNoAliasExpr.h:148
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row/column.
Definition: DMatNoAliasExpr.h:256
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: DMatNoAliasExpr.h:205
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatNoAliasExpr.h:225
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatNoAliasExpr.h:123
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatNoAliasExpr.h:115
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatNoAliasExpr.h:312
const ElementType * data() const noexcept
Low-level data access to the matrix elements.
Definition: DMatNoAliasExpr.h:183
static constexpr size_t SIMDSIZE
The number of elements packed within a single SIMD element.
Definition: DMatNoAliasExpr.h:128
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatNoAliasExpr.h:266
Operand dm_
Dense matrix of the no-alias expression.
Definition: DMatNoAliasExpr.h:319
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatNoAliasExpr.h:106
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatNoAliasExpr.h:105
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatNoAliasExpr.h:291
BLAZE_ALWAYS_INLINE auto load(size_t i, size_t j) const noexcept
Access to the SIMD elements of the matrix.
Definition: DMatNoAliasExpr.h:173
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatNoAliasExpr.h:161
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatNoAliasExpr.h:215
GetConstIterator_t< MT > ConstIterator
Iterator over the elements of the dense matrix.
Definition: DMatNoAliasExpr.h:112
If_t< RequiresEvaluation_v< MT >, const ResultType, const DMatNoAliasExpr & > CompositeType
Data type for composite expression templates.
Definition: DMatNoAliasExpr.h:109
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatNoAliasExpr.h:278
size_t spacing() const noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DMatNoAliasExpr.h:235
DMatNoAliasExpr(const MT &dm) noexcept
Constructor for the DMatNoAliasExpr class.
Definition: DMatNoAliasExpr.h:136
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 MatNoAliasExpr base class.
Header file for the Modification base class.
decltype(auto) noalias(const DenseMatrix< MT, SO > &dm)
Forces the non-aliased evaluation of the given dense matrix expression dm.
Definition: DMatNoAliasExpr.h:679
#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
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
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-alias expression templates.
Definition: MatNoAliasExpr.h:68
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.