Blaze 3.9
DMatRepeatExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATREPEATEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATREPEATEXPR_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 DMATREPEATEXPR
69//
70//=================================================================================================
71
72//*************************************************************************************************
79template< typename MT // Type of the dense matrix
80 , bool SO // Storage order
81 , size_t... CRAs > // Compile time repeater arguments
83 : public MatRepeatExpr< DenseMatrix< DMatRepeatExpr<MT,SO,CRAs...>, SO >, CRAs... >
84 , private If_t< IsComputation_v<MT>, Computation, Transformation >
85 , private RepeatExprData<2UL,CRAs...>
86{
87 private:
88 //**Type definitions****************************************************************************
89 using DataType = RepeatExprData<2UL,CRAs...>;
90 //**********************************************************************************************
91
92 public:
93 //**Type definitions****************************************************************************
95 using This = DMatRepeatExpr<MT,SO,CRAs...>;
96
99
100 using ResultType = RepeatTrait_t<MT,CRAs...>;
105 using CompositeType = const ResultType;
106
108 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
109 //**********************************************************************************************
110
111 public:
112 //**Compilation flags***************************************************************************
114 static constexpr bool simdEnabled = false;
115
117 static constexpr bool smpAssignable = false;
118 //**********************************************************************************************
119
120 //**Constructor*********************************************************************************
126 template< typename... RRAs > // Runtime repeater arguments
127 explicit inline DMatRepeatExpr( const MT& dm, RRAs... args ) noexcept
128 : DataType( args... ) // Base class initialization
129 , dm_ ( dm ) // Dense matrix of the repeater expression
130 {}
131 //**********************************************************************************************
132
133 //**Access operator*****************************************************************************
140 inline ReturnType operator()( size_t i, size_t j ) const {
141 BLAZE_INTERNAL_ASSERT( i < rows() , "Invalid row access index" );
142 BLAZE_INTERNAL_ASSERT( j < columns(), "Invalid column access index" );
143 return dm_( i%dm_.rows(), j%dm_.columns() );
144 }
145 //**********************************************************************************************
146
147 //**At function*********************************************************************************
155 inline ReturnType at( size_t i, size_t j ) const {
156 if( i >= rows() ) {
157 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
158 }
159 if( j >= columns() ) {
160 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
161 }
162 return (*this)(i,j);
163 }
164 //**********************************************************************************************
165
166 //**Rows function*******************************************************************************
171 inline size_t rows() const noexcept {
172 return dm_.rows() * this->template repetitions<0UL>();
173 }
174 //**********************************************************************************************
175
176 //**Columns function****************************************************************************
181 inline size_t columns() const noexcept {
182 return dm_.columns() * this->template repetitions<1UL>();
183 }
184 //**********************************************************************************************
185
186 //**Operand access******************************************************************************
191 inline Operand operand() const noexcept {
192 return dm_;
193 }
194 //**********************************************************************************************
195
196 //**********************************************************************************************
197 using DataType::repetitions;
198 //**********************************************************************************************
199
200 //**********************************************************************************************
206 template< typename T >
207 inline bool canAlias( const T* alias ) const noexcept {
208 return IsExpression_v<MT> && dm_.canAlias( alias );
209 }
210 //**********************************************************************************************
211
212 //**********************************************************************************************
218 template< typename T >
219 inline bool isAliased( const T* alias ) const noexcept {
220 return dm_.isAliased( alias );
221 }
222 //**********************************************************************************************
223
224 //**********************************************************************************************
229 inline bool isAligned() const noexcept {
230 return dm_.isAligned();
231 }
232 //**********************************************************************************************
233
234 //**********************************************************************************************
239 inline bool canSMPAssign() const noexcept {
240 return false;
241 }
242 //**********************************************************************************************
243
244 private:
245 //**Member variables****************************************************************************
247 size_t reps_;
248 //**********************************************************************************************
249
250 //**Assignment to row-major dense matrices******************************************************
262 template< typename MT2 // Type of the target dense matrix
263 , bool SO2 > // Storage order of the target dense matrix
264 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatRepeatExpr& rhs )
265 {
267
268 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
269 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
270
271 CompositeType_t<MT> A( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
272
273 const size_t reps0( rhs.template repetitions<0UL>() );
274 const size_t reps1( rhs.template repetitions<1UL>() );
275 const size_t M( A.rows() );
276 const size_t N( A.columns() );
277
278 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
279 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
280 submatrix( *lhs, rep0*M, rep1*N, M, N, unchecked ) = serial( A );
281 }
282 }
283 }
285 //**********************************************************************************************
286
287 //**Assignment to row-major sparse matrices*****************************************************
299 template< typename MT2 // Type of the target sparse matrix
300 , bool SO2 > // Storage order of the target sparse matrix
301 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatRepeatExpr& rhs )
302 {
304
305 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
306 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
307
308 CompositeType_t<MT> A( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
309
310 const size_t reps0( rhs.template repetitions<0UL>() );
311 const size_t reps1( rhs.template repetitions<1UL>() );
312 const size_t M( A.rows() );
313 const size_t N( A.columns() );
314
315 (*lhs).reset();
316 (*lhs).reserve( reps0*reps1*M*N );
317
318 if( SO2 == rowMajor )
319 {
320 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
321 for( size_t i=0UL; i<M; ++i ) {
322 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
323 for( size_t j=0UL; j<N; ++j ) {
324 (*lhs).append( rep0*M+i, rep1*N+j, A(i,j), true );
325 }
326 }
327 (*lhs).finalize( rep0*M+i );
328 }
329 }
330 }
331 else
332 {
333 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
334 for( size_t j=0UL; j<N; ++j ) {
335 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
336 for( size_t i=0UL; i<M; ++i ) {
337 (*lhs).append( rep0*M+i, rep1*N+j, A(i,j), true );
338 }
339 }
340 (*lhs).finalize( rep1*N+j );
341 }
342 }
343 }
344 }
346 //**********************************************************************************************
347
348 //**Addition assignment to row-major dense matrices*********************************************
360 template< typename MT2 // Type of the target dense matrix
361 , bool SO2 > // Storage order of the target dense matrix
362 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatRepeatExpr& rhs )
363 {
365
366 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
367 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
368
369 CompositeType_t<MT> A( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
370
371 const size_t reps0( rhs.template repetitions<0UL>() );
372 const size_t reps1( rhs.template repetitions<1UL>() );
373 const size_t M( A.rows() );
374 const size_t N( A.columns() );
375
376 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
377 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
378 submatrix( *lhs, rep0*M, rep1*N, M, N, unchecked ) += serial( A );
379 }
380 }
381 }
383 //**********************************************************************************************
384
385 //**Addition assignment to sparse matrices******************************************************
386 // No special implementation for the addition assignment to sparse matrices.
387 //**********************************************************************************************
388
389 //**Subtraction assignment to row-major dense matrices******************************************
401 template< typename MT2 // Type of the target dense matrix
402 , bool SO2 > // Storage order of the target dense matrix
403 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatRepeatExpr& rhs )
404 {
406
407 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
408 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
409
410 CompositeType_t<MT> A( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
411
412 const size_t reps0( rhs.template repetitions<0UL>() );
413 const size_t reps1( rhs.template repetitions<1UL>() );
414 const size_t M( A.rows() );
415 const size_t N( A.columns() );
416
417 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
418 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
419 submatrix( *lhs, rep0*M, rep1*N, M, N, unchecked ) -= serial( A );
420 }
421 }
422 }
424 //**********************************************************************************************
425
426 //**Subtraction assignment to sparse matrices***************************************************
427 // No special implementation for the subtraction assignment to sparse matrices.
428 //**********************************************************************************************
429
430 //**Schur product assignment to row-major dense matrices****************************************
442 template< typename MT2 // Type of the target dense matrix
443 , bool SO2 > // Storage order of the target dense matrix
444 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatRepeatExpr& rhs )
445 {
447
448 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
449 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
450
451 CompositeType_t<MT> A( serial( rhs.dm_ ) ); // Evaluation of the dense matrix operand
452
453 const size_t reps0( rhs.template repetitions<0UL>() );
454 const size_t reps1( rhs.template repetitions<1UL>() );
455 const size_t M( A.rows() );
456 const size_t N( A.columns() );
457
458 for( size_t rep0=0UL; rep0<reps0; ++rep0 ) {
459 for( size_t rep1=0UL; rep1<reps1; ++rep1 ) {
460 submatrix( *lhs, rep0*M, rep1*N, M, N, unchecked ) %= serial( A );
461 }
462 }
463 }
465 //**********************************************************************************************
466
467 //**Schur product assignment to sparse matrices*************************************************
468 // No special implementation for the Schur product assignment to sparse matrices.
469 //**********************************************************************************************
470
471 //**Multiplication assignment to dense matrices*************************************************
472 // No special implementation for the multiplication assignment to dense matrices.
473 //**********************************************************************************************
474
475 //**Multiplication assignment to sparse matrices************************************************
476 // No special implementation for the multiplication assignment to sparse matrices.
477 //**********************************************************************************************
478
479 //**Compile time checks*************************************************************************
484 //**********************************************************************************************
485};
486//*************************************************************************************************
487
488
489
490
491//=================================================================================================
492//
493// GLOBAL FUNCTIONS
494//
495//=================================================================================================
496
497//*************************************************************************************************
541template< typename MT // Type of the dense matrix
542 , bool SO > // Storage order
543inline decltype(auto) repeat( const DenseMatrix<MT,SO>& dm, size_t m, size_t n )
544{
546
547 using ReturnType = const DMatRepeatExpr<MT,SO>;
548 return ReturnType( *dm, m, n );
549}
550//*************************************************************************************************
551
552
553//*************************************************************************************************
595template< size_t R0 // Compile time row-wise repetitions
596 , size_t R1 // Compile time column-wise repetitions
597 , typename MT // Type of the dense matrix
598 , bool SO > // Storage order
599inline decltype(auto) repeat( const DenseMatrix<MT,SO>& dm )
600{
602
603 using ReturnType = const DMatRepeatExpr<MT,SO,R0,R1>;
604 return ReturnType( *dm );
605}
606//*************************************************************************************************
607
608
609//*************************************************************************************************
622template< size_t R0 // Compile time row-wise repetitions
623 , size_t R1 // Compile time column-wise repetitions
624 , typename MT // Type of the dense matrix
625 , bool SO > // Storage order
626inline decltype(auto) repeat( const DenseMatrix<MT,SO>& dm, size_t m, size_t n )
627{
628 MAYBE_UNUSED( m, n );
629
631
632 using ReturnType = const DMatRepeatExpr<MT,SO,R0,R1>;
633 return ReturnType( *dm );
634}
636//*************************************************************************************************
637
638} // namespace blaze
639
640#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
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 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 matrix repeat() function.
Definition: DMatRepeatExpr.h:86
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatRepeatExpr.h:104
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatRepeatExpr.h:108
RepeatTrait_t< MT, CRAs... > ResultType
Result type for expression template evaluations.
Definition: DMatRepeatExpr.h:100
size_t reps_
The number of repetitions.
Definition: DMatRepeatExpr.h:247
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatRepeatExpr.h:191
DMatRepeatExpr(const MT &dm, RRAs... args) noexcept
Constructor for the DMatRepeatExpr class.
Definition: DMatRepeatExpr.h:127
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatRepeatExpr.h:103
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatRepeatExpr.h:140
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatRepeatExpr.h:155
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatRepeatExpr.h:114
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: DMatRepeatExpr.h:102
Operand dm_
Dense matrix of the repeater expression.
Definition: DMatRepeatExpr.h:246
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatRepeatExpr.h:181
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatRepeatExpr.h:171
RepeatExprData< 2UL, CRAs... > DataType
The type of the RepeatExprData base class.
Definition: DMatRepeatExpr.h:89
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatRepeatExpr.h:117
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatRepeatExpr.h:105
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatRepeatExpr.h:207
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatRepeatExpr.h:101
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatRepeatExpr.h:229
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatRepeatExpr.h:239
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatRepeatExpr.h:219
Base class for dense matrices.
Definition: DenseMatrix.h:82
Auxiliary class template for the data members of repeater expression classes.
Definition: RepeatExprData.h:65
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatRepeatExpr base class.
Header file for the Transformation base class.
decltype(auto) repeat(const DenseMatrix< MT, SO > &dm)
Repeats the given dense matrix.
Definition: DMatRepeatExpr.h:599
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_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
typename RepeatTrait< T, CRAs... >::Type RepeatTrait_t
Auxiliary alias declaration for the RepeatTrait type trait.
Definition: RepeatTrait.h:151
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
decltype(auto) submatrix(Matrix< MT, SO > &, RSAs...)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:181
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_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
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
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.
Header file for the serial shim.
Base class for all matrix repeat expression templates.
Definition: MatRepeatExpr.h:69
Header file for basic type definitions.
Submatrix specialization for dense matrices.