All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATTRANSEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_DMATTRANSEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
43 #include <blaze/util/Assert.h>
45 #include <blaze/util/EmptyType.h>
46 #include <blaze/util/EnableIf.h>
48 #include <blaze/util/SelectType.h>
49 #include <blaze/util/Types.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // CLASS DMATTRANSEXPR
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
67 template< typename MT // Type of the dense matrix
68  , bool SO > // Storage order
69 class DMatTransExpr : public DenseMatrix< DMatTransExpr<MT,SO>, SO >
70  , private MatTransExpr
71  , private SelectType< IsComputation<MT>::value, Computation, EmptyType >::Type
72 {
73  private:
74  //**Type definitions****************************************************************************
75  typedef typename MT::ResultType RT;
76  typedef typename MT::CompositeType CT;
77  //**********************************************************************************************
78 
79  //**********************************************************************************************
81 
87  enum { useAssign = RequiresEvaluation<MT>::value };
88  //**********************************************************************************************
89 
90  //**********************************************************************************************
92 
93  template< typename MT2 >
94  struct UseAssign {
95  enum { value = useAssign };
96  };
98  //**********************************************************************************************
99 
100  public:
101  //**Type definitions****************************************************************************
103  typedef typename MT::TransposeType ResultType;
104  typedef typename ResultType::OppositeType OppositeType;
105  typedef typename MT::ResultType TransposeType;
106  typedef typename MT::ElementType ElementType;
107  typedef typename MT::ReturnType ReturnType;
108 
111 
113  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
114  //**********************************************************************************************
115 
116  //**Compilation flags***************************************************************************
118  enum { vectorizable = 0 };
119  //**********************************************************************************************
120 
121  //**Constructor*********************************************************************************
126  explicit inline DMatTransExpr( const MT& dm )
127  : dm_( dm ) // Dense matrix of the transposition expression
128  {}
129  //**********************************************************************************************
130 
131  //**Access operator*****************************************************************************
138  inline ReturnType operator()( size_t i, size_t j ) const {
139  BLAZE_INTERNAL_ASSERT( i < dm_.columns(), "Invalid row access index" );
140  BLAZE_INTERNAL_ASSERT( j < dm_.rows() , "Invalid column access index" );
141  return dm_(j,i);
142  }
143  //**********************************************************************************************
144 
145  //**Low-level data access***********************************************************************
150  inline const ElementType* data() const {
151  return dm_.data();
152  }
153  //**********************************************************************************************
154 
155  //**Rows function*******************************************************************************
160  inline size_t rows() const {
161  return dm_.columns();
162  }
163  //**********************************************************************************************
164 
165  //**Columns function****************************************************************************
170  inline size_t columns() const {
171  return dm_.rows();
172  }
173  //**********************************************************************************************
174 
175  //**Spacing function****************************************************************************
180  inline size_t spacing() const {
181  return dm_.spacing();
182  }
183  //**********************************************************************************************
184 
185  //**Operand access******************************************************************************
190  inline Operand operand() const {
191  return dm_;
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
201  template< typename T >
202  inline bool canAlias( const T* alias ) const {
203  return dm_.canAlias( alias );
204  }
205  //**********************************************************************************************
206 
207  //**********************************************************************************************
213  template< typename T >
214  inline bool isAliased( const T* alias ) const {
215  return dm_.isAliased( alias );
216  }
217  //**********************************************************************************************
218 
219  private:
220  //**Member variables****************************************************************************
222  //**********************************************************************************************
223 
224  //**Assignment to dense matrices****************************************************************
238  template< typename MT2 // Type of the target dense matrix
239  , bool SO2 > // Storage order of the target dense matrix
240  friend inline typename EnableIf< UseAssign<MT2> >::Type
241  assign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
242  {
244 
245  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
246  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
247 
248  DMatTransposer<MT2,!SO2> tmp( ~lhs );
249  assign( tmp, rhs.dm_ );
250  }
252  //**********************************************************************************************
253 
254  //**Assignment to sparse matrices***************************************************************
268  template< typename MT2 // Type of the target sparse matrix
269  , bool SO2 > // Storage order of the target sparse matrix
270  friend inline typename EnableIf< UseAssign<MT2> >::Type
271  assign( SparseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
272  {
274 
276 
282  BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE( typename TmpType::CompositeType );
283 
284  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
285  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
286 
287  const TmpType tmp( rhs );
288  assign( ~lhs, tmp );
289  }
291  //**********************************************************************************************
292 
293  //**Addition assignment to dense matrices*******************************************************
307  template< typename MT2 // Type of the target dense matrix
308  , bool SO2 > // Storage order of the target dense matrix
309  friend inline typename EnableIf< UseAssign<MT2> >::Type
310  addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
311  {
313 
314  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
315  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
316 
317  DMatTransposer<MT2,!SO2> tmp( ~lhs );
318  addAssign( tmp, rhs.dm_ );
319  }
321  //**********************************************************************************************
322 
323  //**Addition assignment to sparse matrices******************************************************
324  // No special implementation for the addition assignment to sparse matrices.
325  //**********************************************************************************************
326 
327  //**Subtraction assignment to dense matrices****************************************************
341  template< typename MT2 // Type of the target dense matrix
342  , bool SO2 > // Storage order of the target dense matrix
343  friend inline typename EnableIf< UseAssign<MT2> >::Type
344  subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatTransExpr& rhs )
345  {
347 
348  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
349  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
350 
351  DMatTransposer<MT2,!SO2> tmp( ~lhs );
352  subAssign( tmp, rhs.dm_ );
353  }
355  //**********************************************************************************************
356 
357  //**Subtraction assignment to sparse matrices***************************************************
358  // No special implementation for the subtraction assignment to sparse matrices.
359  //**********************************************************************************************
360 
361  //**Multiplication assignment to dense matrices*************************************************
362  // No special implementation for the multiplication assignment to dense matrices.
363  //**********************************************************************************************
364 
365  //**Multiplication assignment to sparse matrices************************************************
366  // No special implementation for the multiplication assignment to sparse matrices.
367  //**********************************************************************************************
368 
369  //**Trans function******************************************************************************
385  template< typename MT2 // Type of the dense matrix
386  , bool SO2 > // Storage order of the dense matrix
387  friend inline Operand trans( const DMatTransExpr<MT2,SO2>& dm )
388  {
390 
391  return dm.dm_;
392  }
394  //**********************************************************************************************
395 
396  //**Compile time checks*************************************************************************
401  //**********************************************************************************************
402 };
403 //*************************************************************************************************
404 
405 
406 
407 
408 //=================================================================================================
409 //
410 // GLOBAL OPERATORS
411 //
412 //=================================================================================================
413 
414 //*************************************************************************************************
430 template< typename MT // Type of the dense matrix
431  , bool SO > // Storage order
433 {
435 
436  return DMatTransExpr<MT,!SO>( ~dm );
437 }
438 //*************************************************************************************************
439 
440 
441 
442 
443 //=================================================================================================
444 //
445 // EXPRESSION TRAIT SPECIALIZATIONS
446 //
447 //=================================================================================================
448 
449 //*************************************************************************************************
451 template< typename MT, bool SO >
452 struct RowExprTrait< DMatTransExpr<MT,SO> >
453 {
454  public:
455  //**********************************************************************************************
456  typedef typename TransExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
457  //**********************************************************************************************
458 };
460 //*************************************************************************************************
461 
462 
463 //*************************************************************************************************
465 template< typename MT, bool SO >
466 struct ColumnExprTrait< DMatTransExpr<MT,SO> >
467 {
468  public:
469  //**********************************************************************************************
470  typedef typename TransExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
471  //**********************************************************************************************
472 };
474 //*************************************************************************************************
475 
476 } // namespace blaze
477 
478 #endif