Blaze 3.9
Loading...
Searching...
No Matches
SVecNoAliasExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SVECNOALIASEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SVECNOALIASEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
56#include <blaze/util/Assert.h>
60#include <blaze/util/mpl/If.h>
61#include <blaze/util/Types.h>
63
64
65namespace blaze {
66
67//=================================================================================================
68//
69// CLASS SVECNOALIASEXPR
70//
71//=================================================================================================
72
73//*************************************************************************************************
80template< typename VT // Type of the sparse vector
81 , bool TF > // Transpose flag
83 : public VecNoAliasExpr< SparseVector< SVecNoAliasExpr<VT,TF>, TF > >
84 , private Modification<VT>
85{
86 private:
87 //**Type definitions****************************************************************************
89 BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT( GetConstIterator, ConstIterator, INVALID_TYPE );
90 //**********************************************************************************************
91
92 public:
93 //**Type definitions****************************************************************************
96
99
104
107
109 using ConstIterator = GetConstIterator_t<VT>;
110
112 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
113 //**********************************************************************************************
114
115 //**Compilation flags***************************************************************************
117 static constexpr bool smpAssignable = VT::smpAssignable;
118 //**********************************************************************************************
119
120 //**Constructor*********************************************************************************
125 explicit inline SVecNoAliasExpr( const VT& sv ) noexcept
126 : sv_( sv ) // Sparse vector of the no-alias expression
127 {}
128 //**********************************************************************************************
129
130 //**Subscript operator**************************************************************************
136 inline ReturnType operator[]( size_t index ) const {
137 return sv_[index];
138 }
139 //**********************************************************************************************
140
141 //**At function*********************************************************************************
148 inline ReturnType at( size_t index ) const {
149 return sv_.at( index );
150 }
151 //**********************************************************************************************
152
153 //**Begin function******************************************************************************
158 inline ConstIterator begin() const {
159 return ConstIterator( sv_.begin() );
160 }
161 //**********************************************************************************************
162
163 //**End function********************************************************************************
168 inline ConstIterator end() const {
169 return ConstIterator( sv_.end() );
170 }
171 //**********************************************************************************************
172
173 //**Size function*******************************************************************************
178 inline size_t size() const noexcept {
179 return sv_.size();
180 }
181 //**********************************************************************************************
182
183 //**NonZeros function***************************************************************************
188 inline size_t nonZeros() const {
189 return sv_.nonZeros();
190 }
191 //**********************************************************************************************
192
193 //**Find function*******************************************************************************
199 inline ConstIterator find( size_t index ) const {
201 return ConstIterator( sv_.find( index ) );
202 }
203 //**********************************************************************************************
204
205 //**LowerBound function*************************************************************************
211 inline ConstIterator lowerBound( size_t index ) const {
213 return ConstIterator( sv_.lowerBound( index ) );
214 }
215 //**********************************************************************************************
216
217 //**UpperBound function*************************************************************************
223 inline ConstIterator upperBound( size_t index ) const {
225 return ConstIterator( sv_.upperBound( index ) );
226 }
227 //**********************************************************************************************
228
229 //**Operand access******************************************************************************
234 inline Operand operand() const noexcept {
235 return sv_;
236 }
237 //**********************************************************************************************
238
239 //**********************************************************************************************
245 template< typename T >
246 inline bool canAlias( const T* alias ) const noexcept {
247 MAYBE_UNUSED( alias );
248 return false;
249 }
250 //**********************************************************************************************
251
252 //**********************************************************************************************
258 template< typename T >
259 inline bool isAliased( const T* alias ) const noexcept {
260 MAYBE_UNUSED( alias );
261 return false;
262 }
263 //**********************************************************************************************
264
265 //**********************************************************************************************
270 inline bool canSMPAssign() const noexcept {
271 return sv_.canSMPAssign();
272 }
273 //**********************************************************************************************
274
275 private:
276 //**Member variables****************************************************************************
278 //**********************************************************************************************
279
280 //**Assignment to dense vectors*****************************************************************
294 template< typename VT2 > // Type of the target dense vector
295 friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
296 {
298
299 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
300
301 assign( *lhs, rhs.sv_ );
302 }
304 //**********************************************************************************************
305
306 //**Assignment to sparse vectors****************************************************************
320 template< typename VT2 > // Type of the target sparse vector
321 friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
322 {
324
325 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
326
327 assign( *lhs, rhs.sv_ );
328 }
330 //**********************************************************************************************
331
332 //**Addition assignment to dense vectors********************************************************
346 template< typename VT2 > // Type of the target dense vector
347 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
348 {
350
351 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
352
353 addAssign( *lhs, rhs.sv_ );
354 }
356 //**********************************************************************************************
357
358 //**Addition assignment to sparse vectors*******************************************************
359 // No special implementation for the addition assignment to sparse vectors.
360 //**********************************************************************************************
361
362 //**Subtraction assignment to dense vectors*****************************************************
376 template< typename VT2 > // Type of the target dense vector
377 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
378 {
380
381 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
382
383 subAssign( *lhs, rhs.sv_ );
384 }
386 //**********************************************************************************************
387
388 //**Subtraction assignment to sparse vectors****************************************************
389 // No special implementation for the subtraction assignment to sparse vectors.
390 //**********************************************************************************************
391
392 //**Multiplication assignment to dense vectors**************************************************
406 template< typename VT2 > // Type of the target dense vector
407 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
408 {
410
411 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
412
413 multAssign( *lhs, rhs.sv_ );
414 }
416 //**********************************************************************************************
417
418 //**Multiplication assignment to sparse vectors*************************************************
419 // No special implementation for the multiplication assignment to sparse vectors.
420 //**********************************************************************************************
421
422 //**SMP assignment to dense vectors*************************************************************
436 template< typename VT2 > // Type of the target dense vector
437 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
438 {
440
441 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
442
443 smpAssign( *lhs, rhs.sv_ );
444 }
446 //**********************************************************************************************
447
448 //**SMP assignment to sparse vectors************************************************************
462 template< typename VT2 > // Type of the target sparse vector
463 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
464 {
466
467 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
468
469 smpAssign( *lhs, rhs.sv_ );
470 }
472 //**********************************************************************************************
473
474 //**SMP addition assignment to dense vectors****************************************************
488 template< typename VT2 > // Type of the target dense vector
489 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
490 {
492
493 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
494
495 smpAddAssign( *lhs, rhs.sv_ );
496 }
498 //**********************************************************************************************
499
500 //**SMP addition assignment to sparse vectors***************************************************
501 // No special implementation for the SMP addition assignment to sparse vectors.
502 //**********************************************************************************************
503
504 //**SMP subtraction assignment to dense vectors*************************************************
518 template< typename VT2 > // Type of the target dense vector
519 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
520 {
522
523 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
524
525 smpSubAssign( *lhs, rhs.sv_ );
526 }
528 //**********************************************************************************************
529
530 //**SMP subtraction assignment to sparse vectors************************************************
531 // No special implementation for the SMP subtraction assignment to sparse vectors.
532 //**********************************************************************************************
533
534 //**SMP multiplication assignment to dense vectors**********************************************
548 template< typename VT2 > // Type of the target dense vector
549 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecNoAliasExpr& rhs )
550 {
552
553 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
554
555 smpMultAssign( *lhs, rhs.sv_ );
556 }
558 //**********************************************************************************************
559
560 //**SMP multiplication assignment to sparse vectors*********************************************
561 // No special implementation for the SMP multiplication assignment to sparse vectors.
562 //**********************************************************************************************
563
564 //**Compile time checks*************************************************************************
569 //**********************************************************************************************
570};
571//*************************************************************************************************
572
573
574
575
576//=================================================================================================
577//
578// GLOBAL FUNCTIONS
579//
580//=================================================================================================
581
582//*************************************************************************************************
599template< typename VT // Type of the dense vector
600 , bool TF > // Transpose flag
601inline decltype(auto) noalias( const SparseVector<VT,TF>& sv )
602{
604
605 using ReturnType = const SVecNoAliasExpr<VT,TF>;
606 return ReturnType( *sv );
607}
608//*************************************************************************************************
609
610} // namespace blaze
611
612#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::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition Aliases.h:550
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition Aliases.h:190
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition Aliases.h:450
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.
Deactivation of problematic macros.
Header file for the MAYBE_UNUSED function template.
Base class for N-dimensional dense vectors.
Definition DenseVector.h:77
Expression object for the non-aliased evaluation of sparse vectors.
Definition SVecNoAliasExpr.h:85
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition SVecNoAliasExpr.h:168
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition SVecNoAliasExpr.h:223
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition SVecNoAliasExpr.h:199
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition SVecNoAliasExpr.h:178
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition SVecNoAliasExpr.h:148
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition SVecNoAliasExpr.h:188
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition SVecNoAliasExpr.h:136
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition SVecNoAliasExpr.h:100
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition SVecNoAliasExpr.h:246
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition SVecNoAliasExpr.h:259
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition SVecNoAliasExpr.h:211
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition SVecNoAliasExpr.h:117
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition SVecNoAliasExpr.h:103
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition SVecNoAliasExpr.h:101
Operand sv_
Sparse vector of the no-alias expression.
Definition SVecNoAliasExpr.h:277
Operand operand() const noexcept
Returns the sparse vector operand.
Definition SVecNoAliasExpr.h:234
ElementType_t< VT > ElementType
Resulting element type.
Definition SVecNoAliasExpr.h:102
GetConstIterator_t< VT > ConstIterator
Iterator over the elements of the dense vector.
Definition SVecNoAliasExpr.h:109
If_t< RequiresEvaluation_v< VT >, const ResultType, const SVecNoAliasExpr & > CompositeType
Data type for composite expression templates.
Definition SVecNoAliasExpr.h:106
SVecNoAliasExpr(const VT &sv) noexcept
Constructor for the SVecNoAliasExpr class.
Definition SVecNoAliasExpr.h:125
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the sparse vector expression.
Definition SVecNoAliasExpr.h:112
VecNoAliasExpr< SparseVector< This, TF > > BaseType
Base type of this SVecNoAliasExpr instance.
Definition SVecNoAliasExpr.h:98
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition SVecNoAliasExpr.h:270
SVecNoAliasExpr< VT, TF > This
Type of this SVecNoAliasExpr instance.
Definition SVecNoAliasExpr.h:95
BLAZE_CREATE_GET_TYPE_MEMBER_TYPE_TRAIT(GetConstIterator, ConstIterator, INVALID_TYPE)
Definition of the GetConstIterator type trait.
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition SVecNoAliasExpr.h:158
Base class for sparse vectors.
Definition SparseVector.h:72
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the Modification base class.
Header file for the SparseVector base class.
Header file for the VecNoAliasExpr 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_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition SparseVector.h:61
#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 smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition DenseVector.h:192
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
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition FunctionTrace.h:94
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition If.h:108
Header file for the exception macros of the math module.
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Base class for all modification expression templates.
Definition Modification.h:76
Base class for all vector no-alias expression templates.
Definition VecNoAliasExpr.h:68
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.