Blaze 3.9
SMatNoAliasExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATNOALIASEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATNOALIASEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
54#include <blaze/util/Assert.h>
58#include <blaze/util/mpl/If.h>
59#include <blaze/util/Types.h>
61
62
63namespace blaze {
64
65//=================================================================================================
66//
67// CLASS SMATNOALIASEXPR
68//
69//=================================================================================================
70
71//*************************************************************************************************
78template< typename MT // Type of the sparse matrix
79 , bool SO > // Storage order
81 : public MatNoAliasExpr< SparseMatrix< SMatNoAliasExpr<MT,SO>, SO > >
82 , private Modification<MT>
83{
84 private:
85 //**Type definitions****************************************************************************
87 BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
88 //**********************************************************************************************
89
90 public:
91 //**Type definitions****************************************************************************
94
97
103
106
108 using ConstIterator = GetConstIterator_t<MT>;
109
111 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
112 //**********************************************************************************************
113
114 //**Compilation flags***************************************************************************
116 static constexpr bool smpAssignable = MT::smpAssignable;
117 //**********************************************************************************************
118
119 //**Constructor*********************************************************************************
124 explicit inline SMatNoAliasExpr( const MT& sm ) noexcept
125 : sm_( sm ) // Sparse matrix of the no-alias expression
126 {}
127 //**********************************************************************************************
128
129 //**Access operator*****************************************************************************
136 inline ReturnType operator()( size_t i, size_t j ) const {
137 return sm_(i,j);
138 }
139 //**********************************************************************************************
140
141 //**At function*********************************************************************************
149 inline ReturnType at( size_t i, size_t j ) const {
150 return sm_.at(i,j);
151 }
152 //**********************************************************************************************
153
154 //**Begin function******************************************************************************
160 inline ConstIterator begin( size_t i ) const {
161 return sm_.begin(i);
162 }
163 //**********************************************************************************************
164
165 //**End function********************************************************************************
171 inline ConstIterator end( size_t i ) const {
172 return sm_.end(i);
173 }
174 //**********************************************************************************************
175
176 //**Rows function*******************************************************************************
181 inline size_t rows() const noexcept {
182 return sm_.rows();
183 }
184 //**********************************************************************************************
185
186 //**Columns function****************************************************************************
191 inline size_t columns() const noexcept {
192 return sm_.columns();
193 }
194 //**********************************************************************************************
195
196 //**NonZeros function***************************************************************************
201 inline size_t nonZeros() const {
202 return sm_.nonZeros();
203 }
204 //**********************************************************************************************
205
206 //**NonZeros function***************************************************************************
212 inline size_t nonZeros( size_t i ) const {
213 return sm_.nonZeros(i);
214 }
215 //**********************************************************************************************
216
217 //**Find function*******************************************************************************
224 inline ConstIterator find( size_t i, size_t j ) const {
226 return sm_.find( i, j );
227 }
228 //**********************************************************************************************
229
230 //**LowerBound function*************************************************************************
237 inline ConstIterator lowerBound( size_t i, size_t j ) const {
239 return sm_.lowerBound( i, j );
240 }
241 //**********************************************************************************************
242
243 //**UpperBound function*************************************************************************
250 inline ConstIterator upperBound( size_t i, size_t j ) const {
252 return sm_.upperBound( i, j );
253 }
254 //**********************************************************************************************
255
256 //**Operand access******************************************************************************
261 inline Operand operand() const noexcept {
262 return sm_;
263 }
264 //**********************************************************************************************
265
266 //**********************************************************************************************
272 template< typename T >
273 inline bool canAlias( const T* alias ) const noexcept {
274 MAYBE_UNUSED( alias );
275 return false;
276 }
277 //**********************************************************************************************
278
279 //**********************************************************************************************
285 template< typename T >
286 inline bool isAliased( const T* alias ) const noexcept {
287 MAYBE_UNUSED( alias );
288 return false;
289 }
290 //**********************************************************************************************
291
292 //**********************************************************************************************
297 inline bool canSMPAssign() const noexcept {
298 return sm_.canSMPAssign();
299 }
300 //**********************************************************************************************
301
302 private:
303 //**Member variables****************************************************************************
305 //**********************************************************************************************
306
307 //**Assignment to dense matrices****************************************************************
321 template< typename MT2 // Type of the target dense matrix
322 , bool SO2 > // Storage order of the target dense matrix
323 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
324 {
326
327 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
328 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
329
330 assign( *lhs, rhs.sm_ );
331 }
333 //**********************************************************************************************
334
335 //**Assignment to sparse matrices***************************************************************
349 template< typename MT2 // Type of the target sparse matrix
350 , bool SO2 > // Storage order of the target sparse matrix
351 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
352 {
354
355 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
356 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
357
358 assign( *lhs, rhs.sm_ );
359 }
361 //**********************************************************************************************
362
363 //**Addition assignment to dense matrices*******************************************************
377 template< typename MT2 // Type of the target dense matrix
378 , bool SO2 > // Storage order of the target dense matrix
379 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
380 {
382
383 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
384 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
385
386 addAssign( *lhs, rhs.sm_ );
387 }
389 //**********************************************************************************************
390
391 //**Addition assignment to sparse matrices******************************************************
392 // No special implementation for the addition assignment to sparse matrices.
393 //**********************************************************************************************
394
395 //**Subtraction assignment to dense matrices****************************************************
409 template< typename MT2 // Type of the target dense matrix
410 , bool SO2 > // Storage order of the target dense matrix
411 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
412 {
414
415 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
416 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
417
418 subAssign( *lhs, rhs.sm_ );
419 }
421 //**********************************************************************************************
422
423 //**Subtraction assignment to sparse matrices***************************************************
424 // No special implementation for the subtraction assignment to sparse matrices.
425 //**********************************************************************************************
426
427 //**Schur product assignment to dense matrices**************************************************
441 template< typename MT2 // Type of the target dense matrix
442 , bool SO2 > // Storage order of the target dense matrix
443 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
444 {
446
447 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
448 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
449
450 schurAssign( *lhs, rhs.sm_ );
451 }
453 //**********************************************************************************************
454
455 //**Schur product assignment to sparse matrices*************************************************
456 // No special implementation for the Schur product assignment to sparse matrices.
457 //**********************************************************************************************
458
459 //**Multiplication assignment to dense matrices*************************************************
460 // No special implementation for the multiplication assignment to dense matrices.
461 //**********************************************************************************************
462
463 //**Multiplication assignment to sparse matrices************************************************
464 // No special implementation for the multiplication assignment to sparse matrices.
465 //**********************************************************************************************
466
467 //**SMP assignment to dense matrices************************************************************
481 template< typename MT2 // Type of the target dense matrix
482 , bool SO2 > // Storage order of the target dense matrix
483 friend inline void smpAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
484 {
486
487 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
488 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
489
490 smpAssign( *lhs, rhs.sm_ );
491 }
493 //**********************************************************************************************
494
495 //**SMP assignment to sparse matrices***********************************************************
509 template< typename MT2 // Type of the target sparse matrix
510 , bool SO2 > // Storage order of the target sparse matrix
511 friend inline void smpAssign( SparseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
512 {
514
515 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
516 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
517
518 smpAssign( *lhs, rhs.sm_ );
519 }
521 //**********************************************************************************************
522
523 //**SMP addition assignment to dense matrices***************************************************
537 template< typename MT2 // Type of the target dense matrix
538 , bool SO2 > // Storage order of the target dense matrix
539 friend inline void smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
540 {
542
543 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
544 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
545
546 smpAddAssign( *lhs, rhs.sm_ );
547 }
549 //**********************************************************************************************
550
551 //**SMP addition assignment to sparse matrices**************************************************
552 // No special implementation for the SMP addition assignment to sparse matrices.
553 //**********************************************************************************************
554
555 //**SMP subtraction assignment to dense matrices************************************************
569 template< typename MT2 // Type of the target dense matrix
570 , bool SO2 > // Storage order of the target dense matrix
571 friend inline void smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
572 {
574
575 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
576 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
577
578 smpSubAssign( *lhs, rhs.sm_ );
579 }
581 //**********************************************************************************************
582
583 //**SMP subtraction assignment to sparse matrices***********************************************
584 // No special implementation for the SMP subtraction assignment to sparse matrices.
585 //**********************************************************************************************
586
587 //**SMP Schur product assignment to dense matrices**********************************************
602 template< typename MT2 // Type of the target dense matrix
603 , bool SO2 > // Storage order of the target dense matrix
604 friend inline void smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const SMatNoAliasExpr& rhs )
605 {
607
608 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
609 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
610
611 smpSchurAssign( *lhs, rhs.sm_ );
612 }
614 //**********************************************************************************************
615
616 //**SMP Schur product assignment to sparse matrices*********************************************
617 // No special implementation for the SMP Schur product assignment to sparse matrices.
618 //**********************************************************************************************
619
620 //**SMP multiplication assignment to dense matrices*********************************************
621 // No special implementation for the SMP multiplication assignment to dense matrices.
622 //**********************************************************************************************
623
624 //**SMP multiplication assignment to sparse matrices********************************************
625 // No special implementation for the SMP multiplication assignment to sparse matrices.
626 //**********************************************************************************************
627
628 //**Compile time checks*************************************************************************
633 //**********************************************************************************************
634};
635//*************************************************************************************************
636
637
638
639
640//=================================================================================================
641//
642// GLOBAL FUNCTIONS
643//
644//=================================================================================================
645
646//*************************************************************************************************
663template< typename MT // Type of the sparse matrix
664 , bool SO > // Storage order
665inline decltype(auto) noalias( const SparseMatrix<MT,SO>& sm )
666{
668
669 using ReturnType = const SMatNoAliasExpr<MT,SO>;
670 return ReturnType( *sm );
671}
672//*************************************************************************************************
673
674} // namespace blaze
675
676#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 If class template.
Utility type for generic codes.
Header file for the IsExpression type trait class.
Header file for the MAYBE_UNUSED function template.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Expression object for the non-aliased evaluation of sparse matrices.
Definition: SMatNoAliasExpr.h:83
Operand operand() const noexcept
Returns the sparse matrix operand.
Definition: SMatNoAliasExpr.h:261
GetConstIterator_t< MT > ConstIterator
Iterator over the elements of the sparse matrix.
Definition: SMatNoAliasExpr.h:108
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: SMatNoAliasExpr.h:98
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: SMatNoAliasExpr.h:102
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatNoAliasExpr.h:116
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatNoAliasExpr.h:286
Operand sm_
Sparse matrix of the no-alias expression.
Definition: SMatNoAliasExpr.h:304
If_t< RequiresEvaluation_v< MT >, const ResultType, const SMatNoAliasExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatNoAliasExpr.h:105
SMatNoAliasExpr(const MT &sm) noexcept
Constructor for the SMatNoAliasExpr class.
Definition: SMatNoAliasExpr.h:124
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatNoAliasExpr.h:201
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatNoAliasExpr.h:212
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: SMatNoAliasExpr.h:100
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatNoAliasExpr.h:297
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatNoAliasExpr.h:136
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the sparse matrix expression.
Definition: SMatNoAliasExpr.h:111
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SMatNoAliasExpr.h:250
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatNoAliasExpr.h:191
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SMatNoAliasExpr.h:224
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SMatNoAliasExpr.h:237
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatNoAliasExpr.h:181
ElementType_t< MT > ElementType
Resulting element type.
Definition: SMatNoAliasExpr.h:101
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatNoAliasExpr.h:171
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatNoAliasExpr.h:160
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatNoAliasExpr.h:149
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatNoAliasExpr.h:99
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatNoAliasExpr.h:273
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Constraint on the data type.
Header file for the MatNoAliasExpr base class.
Header file for the Modification base class.
Header file for the SparseMatrix 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_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.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
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
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.