Blaze 3.9
SVecEvalExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_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 SVECEVALEXPR
64//
65//=================================================================================================
66
67//*************************************************************************************************
74template< typename VT // Type of the sparse vector
75 , bool TF > // Transpose flag
77 : public VecEvalExpr< SparseVector< SVecEvalExpr<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 SVecEvalExpr( const VT& sv ) noexcept
111 : sv_( sv ) // Sparse vector of the 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 //**********************************************************************************************
178 template< typename T >
179 inline bool canAlias( const T* alias ) const noexcept {
180 return sv_.canAlias( alias );
181 }
182 //**********************************************************************************************
183
184 //**********************************************************************************************
190 template< typename T >
191 inline bool isAliased( const T* alias ) const noexcept {
192 return sv_.isAliased( alias );
193 }
194 //**********************************************************************************************
195
196 //**********************************************************************************************
201 inline bool canSMPAssign() const noexcept {
202 return sv_.canSMPAssign();
203 }
204 //**********************************************************************************************
205
206 private:
207 //**Member variables****************************************************************************
209 //**********************************************************************************************
210
211 //**Assignment to dense vectors*****************************************************************
223 template< typename VT2 > // Type of the target dense vector
224 friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
225 {
227
228 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
229
230 assign( *lhs, rhs.sv_ );
231 }
233 //**********************************************************************************************
234
235 //**Assignment to sparse vectors****************************************************************
247 template< typename VT2 > // Type of the target sparse vector
248 friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
249 {
251
252 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
253
254 assign( *lhs, rhs.sv_ );
255 }
257 //**********************************************************************************************
258
259 //**Addition assignment to dense vectors********************************************************
271 template< typename VT2 > // Type of the target dense vector
272 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
273 {
275
276 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
277
278 addAssign( *lhs, rhs.sv_ );
279 }
281 //**********************************************************************************************
282
283 //**Addition assignment to sparse vectors*******************************************************
295 template< typename VT2 > // Type of the target sparse vector
296 friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
297 {
299
300 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
301
302 addAssign( *lhs, rhs.sv_ );
303 }
305 //**********************************************************************************************
306
307 //**Subtraction assignment to dense vectors*****************************************************
319 template< typename VT2 > // Type of the target dense vector
320 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
321 {
323
324 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
325
326 subAssign( *lhs, rhs.sv_ );
327 }
329 //**********************************************************************************************
330
331 //**Subtraction assignment to sparse vectors****************************************************
343 template< typename VT2 > // Type of the target sparse vector
344 friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
345 {
347
348 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
349
350 subAssign( *lhs, rhs.sv_ );
351 }
353 //**********************************************************************************************
354
355 //**Multiplication assignment to dense vectors**************************************************
367 template< typename VT2 > // Type of the target dense vector
368 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
369 {
371
372 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
373
374 multAssign( *lhs, rhs.sv_ );
375 }
377 //**********************************************************************************************
378
379 //**Multiplication assignment to sparse vectors*************************************************
391 template< typename VT2 > // Type of the target sparse vector
392 friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
393 {
395
396 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
397
398 multAssign( *lhs, rhs.sv_ );
399 }
401 //**********************************************************************************************
402
403 //**SMP assignment to dense vectors*************************************************************
415 template< typename VT2 > // Type of the target dense vector
416 friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
417 {
419
420 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
421
422 smpAssign( *lhs, rhs.sv_ );
423 }
425 //**********************************************************************************************
426
427 //**SMP assignment to sparse vectors************************************************************
439 template< typename VT2 > // Type of the target sparse vector
440 friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
441 {
443
444 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
445
446 smpAssign( *lhs, rhs.sv_ );
447 }
449 //**********************************************************************************************
450
451 //**SMP addition assignment to dense vectors****************************************************
463 template< typename VT2 > // Type of the target dense vector
464 friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
465 {
467
468 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
469
470 smpAddAssign( *lhs, rhs.sv_ );
471 }
473 //**********************************************************************************************
474
475 //**SMP addition assignment to sparse vectors***************************************************
487 template< typename VT2 > // Type of the target sparse vector
488 friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
489 {
491
492 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
493
494 smpAddAssign( *lhs, rhs.sv_ );
495 }
497 //**********************************************************************************************
498
499 //**SMP subtraction assignment to dense vectors*************************************************
511 template< typename VT2 > // Type of the target dense vector
512 friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
513 {
515
516 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
517
518 smpSubAssign( *lhs, rhs.sv_ );
519 }
521 //**********************************************************************************************
522
523 //**SMP subtraction assignment to sparse vectors************************************************
535 template< typename VT2 > // Type of the target sparse vector
536 friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
537 {
539
540 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
541
542 smpSubAssign( *lhs, rhs.sv_ );
543 }
545 //**********************************************************************************************
546
547 //**SMP multiplication assignment to dense vectors**********************************************
559 template< typename VT2 > // Type of the target dense vector
560 friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
561 {
563
564 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
565
566 smpMultAssign( *lhs, rhs.sv_ );
567 }
569 //**********************************************************************************************
570
571 //**SMP multiplication assignment to sparse vectors*********************************************
583 template< typename VT2 > // Type of the target sparse vector
584 friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
585 {
587
588 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
589
590 smpMultAssign( *lhs, rhs.sv_ );
591 }
593 //**********************************************************************************************
594
595 //**Compile time checks*************************************************************************
600 //**********************************************************************************************
601};
602//*************************************************************************************************
603
604
605
606
607//=================================================================================================
608//
609// GLOBAL FUNCTIONS
610//
611//=================================================================================================
612
613//*************************************************************************************************
630template< typename VT // Type of the dense vector
631 , bool TF > // Transpose flag
632inline decltype(auto) eval( const SparseVector<VT,TF>& sv )
633{
635
636 using ReturnType = const SVecEvalExpr<VT,TF>;
637 return ReturnType( *sv );
638}
639//*************************************************************************************************
640
641} // namespace blaze
642
643#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 evaluation of sparse vectors.
Definition: SVecEvalExpr.h:79
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecEvalExpr.h:134
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecEvalExpr.h:94
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecEvalExpr.h:121
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecEvalExpr.h:179
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecEvalExpr.h:157
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecEvalExpr.h:201
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecEvalExpr.h:102
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecEvalExpr.h:91
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the sparse vector expression.
Definition: SVecEvalExpr.h:97
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecEvalExpr.h:191
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecEvalExpr.h:147
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: SVecEvalExpr.h:88
SVecEvalExpr(const VT &sv) noexcept
Constructor for the SVecEvalExpr class.
Definition: SVecEvalExpr.h:110
ElementType_t< VT > ElementType
Resulting element type.
Definition: SVecEvalExpr.h:90
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecEvalExpr.h:167
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecEvalExpr.h:89
Operand sv_
Sparse vector of the evaluation expression.
Definition: SVecEvalExpr.h:208
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 VecEvalExpr base class.
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:790
#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 evaluation expression templates.
Definition: VecEvalExpr.h:69
Header file for basic type definitions.