Blaze 3.9
SVecSerialExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SVECSERIALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SVECSERIALEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
53#include <blaze/util/Assert.h>
55#include <blaze/util/mpl/If.h>
56#include <blaze/util/Types.h>
57
58
59namespace blaze {
60
61//=================================================================================================
62//
63// CLASS SVECSERIALEXPR
64//
65//=================================================================================================
66
67//*************************************************************************************************
74template< typename VT // Type of the sparse vector
75 , bool TF > // Transpose flag
77 : public VecSerialExpr< SparseVector< SVecSerialExpr<VT,TF>, TF > >
78 , private Computation
79{
80 public:
81 //**Type definitions****************************************************************************
84
87
92
95
97 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
98 //**********************************************************************************************
99
100 //**Compilation flags***************************************************************************
102 static constexpr bool smpAssignable = VT::smpAssignable;
103 //**********************************************************************************************
104
105 //**Constructor*********************************************************************************
110 explicit inline SVecSerialExpr( const VT& sv ) noexcept
111 : sv_( sv ) // Sparse vector of the serial evaluation expression
112 {}
113 //**********************************************************************************************
114
115 //**Subscript operator**************************************************************************
121 inline ReturnType operator[]( size_t index ) const {
122 BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
123 return sv_[index];
124 }
125 //**********************************************************************************************
126
127 //**At function*********************************************************************************
134 inline ReturnType at( size_t index ) const {
135 if( index >= sv_.size() ) {
136 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
137 }
138 return (*this)[index];
139 }
140 //**********************************************************************************************
141
142 //**Size function*******************************************************************************
147 inline size_t size() const noexcept {
148 return sv_.size();
149 }
150 //**********************************************************************************************
151
152 //**NonZeros function***************************************************************************
157 inline size_t nonZeros() const {
158 return sv_.nonZeros();
159 }
160 //**********************************************************************************************
161
162 //**Operand access******************************************************************************
167 inline Operand operand() const noexcept {
168 return sv_;
169 }
170 //**********************************************************************************************
171
172 //**Conversion operator*************************************************************************
177 inline operator Operand() const noexcept {
178 return sv_;
179 }
180 //**********************************************************************************************
181
182 //**********************************************************************************************
188 template< typename T >
189 inline bool canAlias( const T* alias ) const noexcept {
190 return sv_.canAlias( alias );
191 }
192 //**********************************************************************************************
193
194 //**********************************************************************************************
200 template< typename T >
201 inline bool isAliased( const T* alias ) const noexcept {
202 return sv_.isAliased( alias );
203 }
204 //**********************************************************************************************
205
206 //**********************************************************************************************
211 inline bool canSMPAssign() const noexcept {
212 return sv_.canSMPAssign();
213 }
214 //**********************************************************************************************
215
216 private:
217 //**Member variables****************************************************************************
219 //**********************************************************************************************
220
221 //**Assignment to dense vectors*****************************************************************
233 template< typename VT2 > // Type of the target dense vector
234 friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
235 {
237
238 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
239
240 assign( *lhs, rhs.sv_ );
241 }
243 //**********************************************************************************************
244
245 //**Assignment to sparse vectors****************************************************************
257 template< typename VT2 > // Type of the target sparse vector
258 friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
259 {
261
262 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
263
264 assign( *lhs, rhs.sv_ );
265 }
267 //**********************************************************************************************
268
269 //**Addition assignment to dense vectors********************************************************
281 template< typename VT2 > // Type of the target dense vector
282 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
283 {
285
286 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
287
288 addAssign( *lhs, rhs.sv_ );
289 }
291 //**********************************************************************************************
292
293 //**Addition assignment to sparse vectors*******************************************************
305 template< typename VT2 > // Type of the target sparse vector
306 friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
307 {
309
310 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
311
312 addAssign( *lhs, rhs.sv_ );
313 }
315 //**********************************************************************************************
316
317 //**Subtraction assignment to dense vectors*****************************************************
330 template< typename VT2 > // Type of the target dense vector
331 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
332 {
334
335 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
336
337 subAssign( *lhs, rhs.sv_ );
338 }
340 //**********************************************************************************************
341
342 //**Subtraction assignment to sparse vectors****************************************************
355 template< typename VT2 > // Type of the target sparse vector
356 friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
357 {
359
360 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
361
362 subAssign( *lhs, rhs.sv_ );
363 }
365 //**********************************************************************************************
366
367 //**Multiplication assignment to dense vectors**************************************************
380 template< typename VT2 > // Type of the target dense vector
381 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
382 {
384
385 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
386
387 multAssign( *lhs, rhs.sv_ );
388 }
390 //**********************************************************************************************
391
392 //**Multiplication assignment to sparse vectors*************************************************
405 template< typename VT2 > // Type of the target sparse vector
406 friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
407 {
409
410 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
411
412 multAssign( *lhs, rhs.sv_ );
413 }
415 //**********************************************************************************************
416
417 //**SMP assignment to dense vectors*************************************************************
429 template< typename VT2 > // Type of the target dense vector
430 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
431 {
433
434 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
435
436 assign( *lhs, rhs.sv_ );
437 }
439 //**********************************************************************************************
440
441 //**SMP assignment to sparse vectors************************************************************
453 template< typename VT2 > // Type of the target sparse vector
454 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
455 {
457
458 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
459
460 assign( *lhs, rhs.sv_ );
461 }
463 //**********************************************************************************************
464
465 //**SMP addition assignment to dense vectors****************************************************
478 template< typename VT2 > // Type of the target dense vector
479 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
480 {
482
483 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
484
485 addAssign( *lhs, rhs.sv_ );
486 }
488 //**********************************************************************************************
489
490 //**SMP addition assignment to sparse vectors***************************************************
503 template< typename VT2 > // Type of the target sparse vector
504 friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
505 {
507
508 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
509
510 addAssign( *lhs, rhs.sv_ );
511 }
513 //**********************************************************************************************
514
515 //**SMP subtraction assignment to dense vectors*************************************************
528 template< typename VT2 > // Type of the target dense vector
529 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
530 {
532
533 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
534
535 subAssign( *lhs, rhs.sv_ );
536 }
538 //**********************************************************************************************
539
540 //**SMP subtraction assignment to sparse vectors************************************************
553 template< typename VT2 > // Type of the target sparse vector
554 friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
555 {
557
558 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
559
560 subAssign( *lhs, rhs.sv_ );
561 }
563 //**********************************************************************************************
564
565 //**SMP multiplication assignment to dense vectors**********************************************
578 template< typename VT2 > // Type of the target dense vector
579 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
580 {
582
583 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
584
585 multAssign( *lhs, rhs.sv_ );
586 }
588 //**********************************************************************************************
589
590 //**SMP multiplication assignment to sparse vectors*********************************************
603 template< typename VT2 > // Type of the target sparse vector
604 friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
605 {
607
608 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
609
610 multAssign( *lhs, rhs.sv_ );
611 }
613 //**********************************************************************************************
614
615 //**Compile time checks*************************************************************************
620 //**********************************************************************************************
621};
622//*************************************************************************************************
623
624
625
626
627//=================================================================================================
628//
629// GLOBAL FUNCTIONS
630//
631//=================================================================================================
632
633//*************************************************************************************************
650template< typename VT // Type of the dense vector
651 , bool TF > // Transpose flag
652inline decltype(auto) serial( const SparseVector<VT,TF>& sv )
653{
655
656 using ReturnType = const SVecSerialExpr<VT,TF>;
657 return ReturnType( *sv );
658}
659//*************************************************************************************************
660
661} // namespace blaze
662
663#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::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 If class template.
Header file for the IsExpression type trait class.
Deactivation of problematic macros.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Expression object for the forced serial evaluation of sparse vectors.
Definition: SVecSerialExpr.h:79
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the sparse vector expression.
Definition: SVecSerialExpr.h:97
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSerialExpr.h:121
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecSerialExpr.h:167
SVecSerialExpr(const VT &sv) noexcept
Constructor for the SVecSerialExpr class.
Definition: SVecSerialExpr.h:110
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecSerialExpr.h:102
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSerialExpr.h:189
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecSerialExpr.h:211
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSerialExpr.h:201
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: SVecSerialExpr.h:88
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecSerialExpr.h:91
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSerialExpr.h:147
Operand sv_
Sparse vector of the serial evaluation expression.
Definition: SVecSerialExpr.h:218
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSerialExpr.h:94
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSerialExpr.h:134
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSerialExpr.h:157
ElementType_t< VT > ElementType
Resulting element type.
Definition: SVecSerialExpr.h:90
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSerialExpr.h:89
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
Header file for the Computation base class.
Header file for the SparseVector base class.
Header file for the VecSerialExpr base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#define BLAZE_CONSTRAINT_MUST_BE_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
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
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 compute expression templates.
Definition: Computation.h:68
Base class for all vector serial evaluation expression templates.
Definition: VecSerialExpr.h:69
Header file for basic type definitions.