All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecTransposer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECTRANSPOSER_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECTRANSPOSER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
49 #include <blaze/util/Assert.h>
50 #include <blaze/util/EnableIf.h>
51 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS DVECTRANSPOSER
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
69 template< typename VT // Type of the dense vector
70  , bool TF > // Transpose flag
71 class DVecTransposer : public DenseVector< DVecTransposer<VT,TF>, TF >
72 {
73  private:
74  //**Type definitions****************************************************************************
76  //**********************************************************************************************
77 
78  public:
79  //**Type definitions****************************************************************************
81  typedef typename VT::TransposeType ResultType;
82  typedef typename VT::ResultType TransposeType;
83  typedef typename VT::ElementType ElementType;
84  typedef typename IT::Type IntrinsicType;
85  typedef typename VT::ReturnType ReturnType;
86  typedef const This& CompositeType;
87  typedef typename VT::Reference Reference;
89  typedef typename VT::Iterator Iterator;
90  typedef typename VT::ConstIterator ConstIterator;
91  //**********************************************************************************************
92 
93  //**Compilation flags***************************************************************************
95 
98  enum { vectorizable = VT::vectorizable };
99 
101 
104  enum { smpAssignable = VT::smpAssignable };
105  //**********************************************************************************************
106 
107  //**Constructor*********************************************************************************
112  explicit inline DVecTransposer( VT& dv )
113  : dv_( dv ) // The dense vector operand
114  {}
115  //**********************************************************************************************
116 
117  //**Subscript operator**************************************************************************
123  inline Reference operator[]( size_t index ) {
124  BLAZE_USER_ASSERT( index < dv_.size(), "Invalid vector access index" );
125  return dv_[index];
126  }
127  //**********************************************************************************************
128 
129  //**Low-level data access***********************************************************************
134  inline ElementType* data() {
135  return dv_.data();
136  }
137  //**********************************************************************************************
138 
139  //**Multiplication assignment operator**********************************************************
146  template< typename Other > // Data type of the right-hand side scalar
147  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator*=( Other rhs )
148  {
149  (~dv_) *= rhs;
150  return *this;
151  }
152  //**********************************************************************************************
153 
154  //**Division assignment operator****************************************************************
163  template< typename Other > // Data type of the right-hand side scalar
164  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator/=( Other rhs )
165  {
166  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
167 
168  (~dv_) /= rhs;
169  return *this;
170  }
171  //**********************************************************************************************
172 
173  //**Size function*******************************************************************************
178  inline size_t size() const {
179  return dv_.size();
180  }
181  //**********************************************************************************************
182 
183  //**Reset function******************************************************************************
188  inline void reset() {
189  return dv_.reset();
190  }
191  //**********************************************************************************************
192 
193  //**CanAliased function*************************************************************************
199  template< typename Other > // Data type of the foreign expression
200  inline bool canAlias( const Other* alias ) const
201  {
202  return dv_.canAlias( alias );
203  }
204  //**********************************************************************************************
205 
206  //**IsAliased function**************************************************************************
212  template< typename Other > // Data type of the foreign expression
213  inline bool isAliased( const Other* alias ) const
214  {
215  return dv_.isAliased( alias );
216  }
217  //**********************************************************************************************
218 
219  //**Load function*******************************************************************************
229  inline IntrinsicType load( size_t index ) const
230  {
231  return dv_.load( index );
232  }
233  //**********************************************************************************************
234 
235  //**Loadu function******************************************************************************
245  inline IntrinsicType loadu( size_t index ) const
246  {
247  return dv_.loadu( index );
248  }
249  //**********************************************************************************************
250 
251  //**Store function******************************************************************************
262  inline void store( size_t index, const IntrinsicType& value )
263  {
264  dv_.store( index, value );
265  }
266  //**********************************************************************************************
267 
268  //**Storeu function*****************************************************************************
279  inline void storeu( size_t index, const IntrinsicType& value )
280  {
281  dv_.storeu( index, value );
282  }
283  //**********************************************************************************************
284 
285  //**Stream function*****************************************************************************
296  inline void stream( size_t index, const IntrinsicType& value )
297  {
298  dv_.stream( index, value );
299  }
300  //**********************************************************************************************
301 
302  //**Transpose assignment of dense vectors*******************************************************
313  template< typename VT2 > // Type of the right-hand side dense vector
314  inline void assign( const DenseVector<VT2,TF>& rhs )
315  {
317 
318  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
319 
320  const size_t n( size() );
321 
322  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
323  const size_t end( n & size_t(-2) );
324 
325  for( size_t i=0UL; i<end; i+=2UL ) {
326  dv_[i ] = (~rhs)[i ];
327  dv_[i+1UL] = (~rhs)[i+1UL];
328  }
329  if( end < n )
330  dv_[end] = (~rhs)[end];
331  }
332  //**********************************************************************************************
333 
334  //**Transpose assignment of sparse vectors******************************************************
345  template< typename VT2 > // Type of the right-hand side sparse vector
346  inline void assign( const SparseVector<VT2,TF>& rhs )
347  {
349 
350  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
351 
352  typedef typename VT2::ConstIterator RhsConstIterator;
353 
354  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
355  dv_[element->index()] = element->value();
356  }
357  //**********************************************************************************************
358 
359  //**Transpose addition assignment of dense vectors**********************************************
370  template< typename VT2 > // Type of the right-hand side dense vector
371  inline void addAssign( const DenseVector<VT2,TF>& rhs )
372  {
374 
375  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
376 
377  const size_t n( size() );
378 
379  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
380  const size_t end( n & size_t(-2) );
381 
382  for( size_t i=0UL; i<end; i+=2UL ) {
383  dv_[i ] += (~rhs)[i ];
384  dv_[i+1UL] += (~rhs)[i+1UL];
385  }
386  if( end < n )
387  dv_[end] += (~rhs)[end];
388  }
389  //**********************************************************************************************
390 
391  //**Transpose addition assignment of sparse vectors*********************************************
402  template< typename VT2 > // Type of the right-hand side sparse vector
403  inline void addAssign( const SparseVector<VT2,TF>& rhs )
404  {
406 
407  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
408 
409  typedef typename VT2::ConstIterator RhsConstIterator;
410 
411  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
412  dv_[element->index()] += element->value();
413  }
414  //**********************************************************************************************
415 
416  //**Transpose subtraction assignment of dense vectors*******************************************
427  template< typename VT2 > // Type of the right-hand side dense vector
428  inline void subAssign( const DenseVector<VT2,TF>& rhs )
429  {
431 
432  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
433 
434  const size_t n( size() );
435 
436  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
437  const size_t end( n & size_t(-2) );
438 
439  for( size_t i=0UL; i<end; i+=2UL ) {
440  dv_[i ] -= (~rhs)[i ];
441  dv_[i+1UL] -= (~rhs)[i+1UL];
442  }
443  if( end < n )
444  dv_[end] -= (~rhs)[end];
445  }
446  //**********************************************************************************************
447 
448  //**Transpose subtraction assignment of sparse vectors******************************************
459  template< typename VT2 > // Type of the right-hand side sparse vector
460  inline void subAssign( const SparseVector<VT2,TF>& rhs )
461  {
463 
464  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
465 
466  typedef typename VT2::ConstIterator RhsConstIterator;
467 
468  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
469  dv_[element->index()] -= element->value();
470  }
471  //**********************************************************************************************
472 
473  //**Transpose multiplication assignment of dense vectors****************************************
484  template< typename VT2 > // Type of the right-hand side dense vector
485  inline void multAssign( const DenseVector<VT2,TF>& rhs )
486  {
488 
489  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
490 
491  const size_t n( size() );
492 
493  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
494  const size_t end( n & size_t(-2) );
495 
496  for( size_t i=0UL; i<end; i+=2UL ) {
497  dv_[i ] *= (~rhs)[i ];
498  dv_[i+1UL] *= (~rhs)[i+1UL];
499  }
500  if( end < n )
501  dv_[end] *= (~rhs)[end];
502  }
503  //**********************************************************************************************
504 
505  //**Transpose multiplication assignment of sparse vectors***************************************
516  template< typename VT2 > // Type of the right-hand side dense vector
517  inline void multAssign( const SparseVector<VT2,TF>& rhs )
518  {
520 
521  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
522 
523  typedef typename VT2::ConstIterator RhsConstIterator;
524 
525  const VT tmp( dv_ );
526  const RhsConstIterator end( (~rhs).end() );
527 
528  dv_.reset();
529 
530  for( RhsConstIterator element=(~rhs).begin(); element!=end; ++element )
531  dv_[element->index()] = tmp[element->index()] * element->value();
532  }
533  //**********************************************************************************************
534 
535  private:
536  //**Member variables****************************************************************************
537  VT& dv_;
538  //**********************************************************************************************
539 
540  //**Compile time checks*************************************************************************
546  //**********************************************************************************************
547 };
548 //*************************************************************************************************
549 
550 
551 
552 
553 //=================================================================================================
554 //
555 // GLOBAL OPERATORS
556 //
557 //=================================================================================================
558 
559 //*************************************************************************************************
567 template< typename VT // Type of the dense vector
568  , bool TF > // Transpose flag
569 inline void reset( DVecTransposer<VT,TF>& v )
570 {
571  v.reset();
572 }
574 //*************************************************************************************************
575 
576 
577 
578 
579 //=================================================================================================
580 //
581 // SUBVECTORTRAIT SPECIALIZATIONS
582 //
583 //=================================================================================================
584 
585 //*************************************************************************************************
587 template< typename VT, bool TF >
588 struct SubvectorTrait< DVecTransposer<VT,TF> >
589 {
591 };
593 //*************************************************************************************************
594 
595 } // namespace blaze
596 
597 #endif
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: DVecTransposer.h:123
Constraint on the data type.
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DVecTransposer.h:213
VT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DVecTransposer.h:90
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecTransposer.h:178
VT::Iterator Iterator
Iterator over non-constant elements.
Definition: DVecTransposer.h:89
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
void subAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a dense vector.
Definition: DVecTransposer.h:428
VT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: DVecTransposer.h:88
void multAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a sparse vector.
Definition: DVecTransposer.h:517
Header file for the DenseVector base class.
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: DVecTransposer.h:200
VT::ElementType ElementType
Type of the vector elements.
Definition: DVecTransposer.h:83
Header file for the intrinsic trait.
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:71
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTransposer.h:82
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecTransposer.h:85
IntrinsicTrait< typename VT::ElementType > IT
Intrinsic trait for the vector element type.
Definition: DVecTransposer.h:75
DVecTransposer(VT &dv)
Constructor for the DVecTransposer class.
Definition: DVecTransposer.h:112
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
Header file for the subvector trait.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2372
Constraint on the data type.
VT::Reference Reference
Reference to a non-constant matrix value.
Definition: DVecTransposer.h:87
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2377
Header file for the EnableIf class template.
void reset()
Resets the vector elements.
Definition: DVecTransposer.h:188
Header file for the IsNumeric type trait.
DVecTransposer< VT, TF > This
Type of this DVecTransposer instance.
Definition: DVecTransposer.h:80
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
Header file for run time assertion macros.
const This & CompositeType
Data type for composite expression templates.
Definition: DVecTransposer.h:86
void addAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose addition assignment of a sparse vector.
Definition: DVecTransposer.h:403
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:262
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:229
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
void addAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose addition assignment of a dense vector.
Definition: DVecTransposer.h:371
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DVecTransposer.h:84
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2378
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:279
void subAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a sparse vector.
Definition: DVecTransposer.h:460
void assign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a sparse vector.
Definition: DVecTransposer.h:346
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: DVecTransposer.h:81
void assign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a dense vector.
Definition: DVecTransposer.h:314
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator/=(Other rhs)
Division assignment operator for the division of a vector by a scalar value ( ).
Definition: DVecTransposer.h:164
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
ElementType * data()
Low-level data access to the vector elements.
Definition: DVecTransposer.h:134
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a vector and a scalar value ( )...
Definition: DVecTransposer.h:147
Header file for basic type definitions.
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: DVecTransposer.h:296
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2376
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:245
void multAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a dense vector.
Definition: DVecTransposer.h:485
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:238
#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
VT & dv_
The dense vector operand.
Definition: DVecTransposer.h:537