Blaze 3.9
Loading...
Searching...
No Matches
DVecRepeatExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECREPEATEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECREPEATEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
60#include <blaze/util/mpl/If.h>
61#include <blaze/util/Types.h>
62
63
64namespace blaze {
65
66//=================================================================================================
67//
68// CLASS DVECREPEATEXPR
69//
70//=================================================================================================
71
72//*************************************************************************************************
79template< typename VT // Type of the dense vector
80 , bool TF // Transpose flag
81 , size_t... CRAs > // Compile time repeater arguments
83 : public VecRepeatExpr< DenseVector< DVecRepeatExpr<VT,TF,CRAs...>, TF >, CRAs... >
84 , private If_t< IsComputation_v<VT>, Computation, Transformation >
85 , private RepeatExprData<1UL,CRAs...>
86{
87 private:
88 //**Type definitions****************************************************************************
89 using DataType = RepeatExprData<1UL,CRAs...>;
90 //**********************************************************************************************
91
92 public:
93 //**Type definitions****************************************************************************
95 using This = DVecRepeatExpr<VT,TF,CRAs...>;
96
99
100 using ResultType = RepeatTrait_t<VT,CRAs...>;
104 using CompositeType = const ResultType;
105
107 using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
108 //**********************************************************************************************
109
110 public:
111 //**Compilation flags***************************************************************************
113 static constexpr bool simdEnabled = false;
114
116 static constexpr bool smpAssignable = false;
117 //**********************************************************************************************
118
119 //**Constructor*********************************************************************************
125 template< typename... RRAs > // Runtime repeater arguments
126 explicit inline DVecRepeatExpr( const VT& dv, RRAs... args ) noexcept
127 : DataType( args... ) // Base class initialization
128 , dv_ ( dv ) // Dense vector of the repeater expression
129 {}
130 //**********************************************************************************************
131
132 //**Subscript operator**************************************************************************
138 inline ReturnType operator[]( size_t index ) const {
139 BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
140 return dv_[index%dv_.size()];
141 }
142 //**********************************************************************************************
143
144 //**At function*********************************************************************************
151 inline ReturnType at( size_t index ) const {
152 if( index >= size() ) {
153 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
154 }
155 return (*this)[index];
156 }
157 //**********************************************************************************************
158
159 //**Size function*******************************************************************************
164 inline size_t size() const noexcept {
165 return dv_.size() * this->template repetitions<0UL>();
166 }
167 //**********************************************************************************************
168
169 //**Operand access******************************************************************************
174 inline Operand operand() const noexcept {
175 return dv_;
176 }
177 //**********************************************************************************************
178
179 //**********************************************************************************************
180 using DataType::repetitions;
181 //**********************************************************************************************
182
183 //**********************************************************************************************
189 template< typename T >
190 inline bool canAlias( const T* alias ) const noexcept {
191 return IsExpression_v<VT> && dv_.canAlias( alias );
192 }
193 //**********************************************************************************************
194
195 //**********************************************************************************************
201 template< typename T >
202 inline bool isAliased( const T* alias ) const noexcept {
203 return dv_.isAliased( alias );
204 }
205 //**********************************************************************************************
206
207 //**********************************************************************************************
212 inline bool isAligned() const noexcept {
213 return dv_.isAligned();
214 }
215 //**********************************************************************************************
216
217 //**********************************************************************************************
222 inline bool canSMPAssign() const noexcept {
223 return false;
224 }
225 //**********************************************************************************************
226
227 private:
228 //**Member variables****************************************************************************
230 //**********************************************************************************************
231
232 //**Assignment to dense vectors*****************************************************************
244 template< typename VT2 > // Type of the target dense vector
245 friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
246 {
248
249 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
250
251 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
252
253 const size_t reps( rhs.template repetitions<0UL>() );
254 const size_t size( x.size() );
255
256 for( size_t rep=0UL; rep<reps; ++rep ) {
257 subvector( *lhs, rep*size, size, unchecked ) = serial( x );
258 }
259 }
261 //**********************************************************************************************
262
263 //**Assignment to sparse vectors****************************************************************
275 template< typename VT2 > // Type of the target sparse vector
276 friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
277 {
279
280 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
281
282 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
283
284 const size_t reps( rhs.template repetitions<0UL>() );
285 const size_t size( x.size() );
286
287 (*lhs).reset();
288 (*lhs).reserve( reps*size );
289
290 for( size_t rep=0UL; rep<reps; ++rep ) {
291 for( size_t i=0UL; i<size; ++i ) {
292 (*lhs).append( rep*size+i, x[i], true );
293 }
294 }
295 }
297 //**********************************************************************************************
298
299 //**Addition assignment to dense vectors********************************************************
311 template< typename VT2 > // Type of the target dense vector
312 friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
313 {
315
316 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
317
318 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
319
320 const size_t reps( rhs.template repetitions<0UL>() );
321 const size_t size( x.size() );
322
323 for( size_t rep=0UL; rep<reps; ++rep ) {
324 subvector( *lhs, rep*size, size, unchecked ) += serial( x );
325 }
326 }
328 //**********************************************************************************************
329
330 //**Addition assignment to sparse vectors*******************************************************
331 // No special implementation for the addition assignment to sparse vectors.
332 //**********************************************************************************************
333
334 //**Subtraction assignment to dense vectors*****************************************************
346 template< typename VT2 > // Type of the target dense vector
347 friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
348 {
350
351 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
352
353 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
354
355 const size_t reps( rhs.template repetitions<0UL>() );
356 const size_t size( x.size() );
357
358 for( size_t rep=0UL; rep<reps; ++rep ) {
359 subvector( *lhs, rep*size, size, unchecked ) -= serial( x );
360 }
361 }
363 //**********************************************************************************************
364
365 //**Multiplication assignment to sparse vectors*************************************************
366 // No special implementation for the multiplication assignment to sparse vectors.
367 //**********************************************************************************************
368
369 //**Multiplication assignment to dense vectors**************************************************
381 template< typename VT2 > // Type of the target dense vector
382 friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
383 {
385
386 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
387
388 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
389
390 const size_t reps( rhs.template repetitions<0UL>() );
391 const size_t size( x.size() );
392
393 for( size_t rep=0UL; rep<reps; ++rep ) {
394 subvector( *lhs, rep*size, size, unchecked ) *= serial( x );
395 }
396 }
398 //**********************************************************************************************
399
400 //**Multiplication assignment to sparse vectors*************************************************
401 // No special implementation for the multiplication assignment to sparse vectors.
402 //**********************************************************************************************
403
404 //**Division assignment to dense vectors********************************************************
416 template< typename VT2 > // Type of the target dense vector
417 friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecRepeatExpr& rhs )
418 {
420
421 BLAZE_INTERNAL_ASSERT( (*lhs).size() == rhs.size(), "Invalid vector sizes" );
422
423 CompositeType_t<VT> x( serial( rhs.dv_ ) ); // Evaluation of the dense vector operand
424
425 const size_t reps( rhs.template repetitions<0UL>() );
426 const size_t size( x.size() );
427
428 for( size_t rep=0UL; rep<reps; ++rep ) {
429 subvector( *lhs, rep*size, size, unchecked ) /= serial( x );
430 }
431 }
433 //**********************************************************************************************
434
435 //**Division assignment to sparse vectors*******************************************************
436 // No special implementation for the division assignment to sparse vectors.
437 //**********************************************************************************************
438
439 //**Compile time checks*************************************************************************
444 //**********************************************************************************************
445};
446//*************************************************************************************************
447
448
449
450
451//=================================================================================================
452//
453// GLOBAL FUNCTIONS
454//
455//=================================================================================================
456
457//*************************************************************************************************
483template< typename VT // Type of the dense vector
484 , bool TF > // Transpose flag
485inline decltype(auto) repeat( const DenseVector<VT,TF>& dv, size_t repetitions )
486{
488
489 using ReturnType = const DVecRepeatExpr<VT,TF>;
490 return ReturnType( *dv, repetitions );
491}
492//*************************************************************************************************
493
494
495//*************************************************************************************************
520template< size_t R0 // Compile time repetitions
521 , typename VT // Type of the dense vector
522 , bool TF > // Transpose flag
523inline decltype(auto) repeat( const DenseVector<VT,TF>& dv )
524{
526
527 using ReturnType = const DVecRepeatExpr<VT,TF,R0>;
528 return ReturnType( *dv );
529}
530//*************************************************************************************************
531
532
533//*************************************************************************************************
545template< size_t R0 // Compile time repetitions
546 , typename VT // Type of the dense vector
547 , bool TF > // Transpose flag
548inline decltype(auto) repeat( const DenseVector<VT,TF>& dv, size_t repetitions )
549{
550 MAYBE_UNUSED( repetitions );
551
553
554 using ReturnType = const DVecRepeatExpr<VT,TF,R0>;
555 return ReturnType( *dv );
556}
558//*************************************************************************************************
559
560} // namespace blaze
561
562#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::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition Aliases.h:110
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
Header file for the blaze::checked and blaze::unchecked instances.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IsExpression type trait class.
Header file for the MAYBE_UNUSED function template.
Header file for the implementation of the RepeatExprData class template.
Header file for the repeat trait.
Expression object for the dense vector repeat() function.
Definition DVecRepeatExpr.h:86
static constexpr bool smpAssignable
Definition DVecRepeatExpr.h:116
TransposeType_t< ResultType > TransposeType
Definition DVecRepeatExpr.h:101
RepeatExprData< 1UL, CRAs... > DataType
The type of the RepeatExprData base class.
Definition DVecRepeatExpr.h:89
size_t size() const noexcept
Definition DVecRepeatExpr.h:164
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Definition DVecRepeatExpr.h:107
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition DVecRepeatExpr.h:190
Operand dv_
Definition DVecRepeatExpr.h:229
ReturnType_t< VT > ReturnType
Definition DVecRepeatExpr.h:103
const ResultType CompositeType
Definition DVecRepeatExpr.h:104
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition DVecRepeatExpr.h:212
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition DVecRepeatExpr.h:138
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition DVecRepeatExpr.h:222
DVecRepeatExpr< VT, TF, CRAs... > This
Type of this DVecRepeatExpr instance.
Definition DVecRepeatExpr.h:95
RepeatTrait_t< VT, CRAs... > ResultType
Definition DVecRepeatExpr.h:100
DVecRepeatExpr(const VT &dv, RRAs... args) noexcept
Constructor for the DVecRepeatExpr class.
Definition DVecRepeatExpr.h:126
VecRepeatExpr< DenseVector< This, TF >, CRAs... > BaseType
Definition DVecRepeatExpr.h:98
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition DVecRepeatExpr.h:151
Operand operand() const noexcept
Returns the dense vector operand.
Definition DVecRepeatExpr.h:174
ElementType_t< VT > ElementType
Definition DVecRepeatExpr.h:102
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition DVecRepeatExpr.h:202
static constexpr bool simdEnabled
Definition DVecRepeatExpr.h:113
Base class for N-dimensional dense vectors.
Definition DenseVector.h:77
Auxiliary class template for the data members of repeater expression classes.
Definition RepeatExprData.h:65
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 DenseVector base class.
Header file for the Transformation base class.
Header file for the VecRepeatExpr base class.
decltype(auto) repeat(const DenseMatrix< MT, SO > &dm, size_t m, size_t n)
Repeats the given dense matrix.
Definition DMatRepeatExpr.h:543
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_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition DenseVector.h:61
typename RepeatTrait< T, CRAs... >::Type RepeatTrait_t
Auxiliary alias declaration for the RepeatTrait type trait.
Definition RepeatTrait.h:151
constexpr bool IsExpression_v
Auxiliary variable template for the IsExpression type trait.
Definition IsExpression.h:114
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition Matrix.h:676
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition Assert.h:101
decltype(auto) subvector(Vector< VT, TF > &, RSAs...)
Creating a view on a specific subvector of the given vector.
Definition Subvector.h:158
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition MaybeUnused.h:81
#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
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition If.h:108
constexpr Unchecked unchecked
Global Unchecked instance.
Definition Check.h:146
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.
Header file for the serial shim.
Base class for all vector repeater expression templates.
Definition VecRepeatExpr.h:69
Header file for basic type definitions.
Subvector specialization for dense vectors.