All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATTRANSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATTRANSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
57 #include <blaze/util/Assert.h>
59 #include <blaze/util/EmptyType.h>
60 #include <blaze/util/EnableIf.h>
62 #include <blaze/util/SelectType.h>
63 #include <blaze/util/Types.h>
64 
65 
66 namespace blaze {
67 
68 //=================================================================================================
69 //
70 // CLASS DMATTRANSEXPR
71 //
72 //=================================================================================================
73 
74 //*************************************************************************************************
81 template< typename MT // Type of the dense matrix
82  , bool SO > // Storage order
83 class DMatTransExpr : public DenseMatrix< DMatTransExpr<MT,SO>, SO >
84  , private MatTransExpr
85  , private SelectType< IsComputation<MT>::value, Computation, EmptyType >::Type
86 {
87  private:
88  //**Type definitions****************************************************************************
89  typedef typename MT::ResultType RT;
90  typedef typename MT::CompositeType CT;
91  //**********************************************************************************************
92 
93  //**********************************************************************************************
95 
101  enum { useAssign = RequiresEvaluation<MT>::value };
102  //**********************************************************************************************
103 
104  //**********************************************************************************************
106  template< typename MT2 >
108  struct UseAssign {
109  enum { value = useAssign };
110  };
112  //**********************************************************************************************
113 
114  public:
115  //**Type definitions****************************************************************************
117  typedef typename MT::TransposeType ResultType;
119  typedef typename MT::ResultType TransposeType;
120  typedef typename MT::ElementType ElementType;
121  typedef typename MT::ReturnType ReturnType;
122 
125 
127  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
128  //**********************************************************************************************
129 
130  //**Compilation flags***************************************************************************
132  enum { vectorizable = 0 };
133  //**********************************************************************************************
134 
135  //**Constructor*********************************************************************************
140  explicit inline DMatTransExpr( const MT& dm )
141  : dm_( dm ) // Dense matrix of the transposition expression
142  {}
143  //**********************************************************************************************
144 
145  //**Access operator*****************************************************************************
152  inline ReturnType operator()( size_t i, size_t j ) const {
153  BLAZE_INTERNAL_ASSERT( i < dm_.columns(), "Invalid row access index" );
154  BLAZE_INTERNAL_ASSERT( j < dm_.rows() , "Invalid column access index" );
155  return dm_(j,i);
156  }
157  //**********************************************************************************************
158 
159  //**Low-level data access***********************************************************************
164  inline const ElementType* data() const {
165  return dm_.data();
166  }
167  //**********************************************************************************************
168 
169  //**Rows function*******************************************************************************
174  inline size_t rows() const {
175  return dm_.columns();
176  }
177  //**********************************************************************************************
178 
179  //**Columns function****************************************************************************
184  inline size_t columns() const {
185  return dm_.rows();
186  }
187  //**********************************************************************************************
188 
189  //**Spacing function****************************************************************************
194  inline size_t spacing() const {
195  return dm_.spacing();
196  }
197  //**********************************************************************************************
198 
199  //**Operand access******************************************************************************
204  inline Operand operand() const {
205  return dm_;
206  }
207  //**********************************************************************************************
208 
209  //**********************************************************************************************
215  template< typename T >
216  inline bool canAlias( const T* alias ) const {
217  return dm_.canAlias( alias );
218  }
219  //**********************************************************************************************
220 
221  //**********************************************************************************************
227  template< typename T >
228  inline bool isAliased( const T* alias ) const {
229  return dm_.isAliased( alias );
230  }
231  //**********************************************************************************************
232 
233  private:
234  //**Member variables****************************************************************************
236  //**********************************************************************************************
237 
238  //**Assignment to dense matrices****************************************************************
252  template< typename MT2 // Type of the target dense matrix
253  , bool SO2 > // Storage order of the target dense matrix
254  friend inline typename EnableIf< UseAssign<MT2> >::Type
255  assign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
256  {
258 
259  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
260  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
261 
262  DMatTransposer<MT2,!SO2> tmp( ~lhs );
263  assign( tmp, rhs.dm_ );
264  }
266  //**********************************************************************************************
267 
268  //**Assignment to sparse matrices***************************************************************
282  template< typename MT2 // Type of the target sparse matrix
283  , bool SO2 > // Storage order of the target sparse matrix
284  friend inline typename EnableIf< UseAssign<MT2> >::Type
285  assign( SparseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
286  {
288 
290 
297 
298  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
299  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
300 
301  const TmpType tmp( rhs );
302  assign( ~lhs, tmp );
303  }
305  //**********************************************************************************************
306 
307  //**Addition assignment to dense matrices*******************************************************
321  template< typename MT2 // Type of the target dense matrix
322  , bool SO2 > // Storage order of the target dense matrix
323  friend inline typename EnableIf< UseAssign<MT2> >::Type
324  addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
325  {
327 
328  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
329  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
330 
331  DMatTransposer<MT2,!SO2> tmp( ~lhs );
332  addAssign( tmp, rhs.dm_ );
333  }
335  //**********************************************************************************************
336 
337  //**Addition assignment to sparse matrices******************************************************
338  // No special implementation for the addition assignment to sparse matrices.
339  //**********************************************************************************************
340 
341  //**Subtraction assignment to dense matrices****************************************************
355  template< typename MT2 // Type of the target dense matrix
356  , bool SO2 > // Storage order of the target dense matrix
357  friend inline typename EnableIf< UseAssign<MT2> >::Type
358  subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
359  {
361 
362  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
363  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
364 
365  DMatTransposer<MT2,!SO2> tmp( ~lhs );
366  subAssign( tmp, rhs.dm_ );
367  }
369  //**********************************************************************************************
370 
371  //**Subtraction assignment to sparse matrices***************************************************
372  // No special implementation for the subtraction assignment to sparse matrices.
373  //**********************************************************************************************
374 
375  //**Multiplication assignment to dense matrices*************************************************
376  // No special implementation for the multiplication assignment to dense matrices.
377  //**********************************************************************************************
378 
379  //**Multiplication assignment to sparse matrices************************************************
380  // No special implementation for the multiplication assignment to sparse matrices.
381  //**********************************************************************************************
382 
383  //**Trans function******************************************************************************
399  template< typename MT2 // Type of the dense matrix
400  , bool SO2 > // Storage order of the dense matrix
401  friend inline Operand trans( const DMatTransExpr<MT2,SO2>& dm )
402  {
404 
405  return dm.dm_;
406  }
408  //**********************************************************************************************
409 
410  //**Compile time checks*************************************************************************
415  //**********************************************************************************************
416 };
417 //*************************************************************************************************
418 
419 
420 
421 
422 //=================================================================================================
423 //
424 // GLOBAL OPERATORS
425 //
426 //=================================================================================================
427 
428 //*************************************************************************************************
444 template< typename MT // Type of the dense matrix
445  , bool SO > // Storage order
447 {
449 
450  return DMatTransExpr<MT,!SO>( ~dm );
451 }
452 //*************************************************************************************************
453 
454 
455 
456 
457 //=================================================================================================
458 //
459 // EXPRESSION TRAIT SPECIALIZATIONS
460 //
461 //=================================================================================================
462 
463 //*************************************************************************************************
465 template< typename MT, bool SO >
466 struct SubmatrixExprTrait< DMatTransExpr<MT,SO> >
467 {
468  public:
469  //**********************************************************************************************
470  typedef typename TransExprTrait< typename SubmatrixExprTrait<const MT>::Type >::Type Type;
471  //**********************************************************************************************
472 };
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
479 template< typename MT, bool SO >
480 struct RowExprTrait< DMatTransExpr<MT,SO> >
481 {
482  public:
483  //**********************************************************************************************
484  typedef typename TransExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
485  //**********************************************************************************************
486 };
488 //*************************************************************************************************
489 
490 
491 //*************************************************************************************************
493 template< typename MT, bool SO >
494 struct ColumnExprTrait< DMatTransExpr<MT,SO> >
495 {
496  public:
497  //**********************************************************************************************
498  typedef typename TransExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
499  //**********************************************************************************************
500 };
502 //*************************************************************************************************
503 
504 } // namespace blaze
505 
506 #endif
DMatTransExpr(const MT &dm)
Constructor for the DMatTransExpr class.
Definition: DMatTransExpr.h:140
SelectType< useAssign, const ResultType, const DMatTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: DMatTransExpr.h:124
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:446
Expression object for dense matrix transpositions.The DMatTransExpr class represents the compile time...
Definition: DMatTransExpr.h:83
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:242
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
Header file for the MatTransExpr base class.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
Header file for the ColumnExprTrait class template.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatTransExpr.h:118
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
Operand dm_
Dense matrix of the transposition expression.
Definition: DMatTransExpr.h:235
Operand operand() const
Returns the dense matrix operand.
Definition: DMatTransExpr.h:204
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
MT::TransposeType ResultType
Result type for expression template evaluations.
Definition: DMatTransExpr.h:117
Constraint on the data type.
Constraint on the data type.
MT::ElementType ElementType
Resulting element type.
Definition: DMatTransExpr.h:120
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DMatTransExpr.h:228
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: DMatTransExpr.h:127
Header file for the DenseMatrix base class.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Expression object for the transposition of a dense matrix.The DMatTransposer class is a wrapper objec...
Definition: DMatTransposer.h:71
MT::ResultType RT
Result type of the dense matrix expression.
Definition: DMatTransExpr.h:89
MT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DMatTransExpr.h:119
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
const ElementType * data() const
Low-level data access to the matrix elements.
Definition: DMatTransExpr.h:164
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2372
Constraints on the storage order of matrix types.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
Header file for the dense matrix transposer.
size_t spacing() const
Returns the spacing between the beginning of two rows/columns.
Definition: DMatTransExpr.h:194
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Header file for run time assertion macros.
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DMatTransExpr.h:174
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DMatTransExpr.h:184
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
Header file for the TransExprTrait class template.
Base class for all matrix transposition expression templates.The MatTransExpr class serves as a tag f...
Definition: MatTransExpr.h:65
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatTransExpr.h:152
#define BLAZE_CONSTRAINT_MATRICES_MUST_HAVE_SAME_STORAGE_ORDER(T1, T2)
Constraint on the data type.In case either of the two given data types T1 or T2 is not a matrix type ...
Definition: StorageOrder.h:283
Header file for the IsComputation type trait class.
MT::CompositeType CT
Composite type of the dense matrix expression.
Definition: DMatTransExpr.h:90
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
Header file for basic type definitions.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DMatTransExpr.h:121
Header file for the empty type.
DMatTransExpr< MT, SO > This
Type of this DMatTransExpr instance.
Definition: DMatTransExpr.h:116
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DMatTransExpr.h:216
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.