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/system/Inline.h>
50 #include <blaze/util/Assert.h>
51 #include <blaze/util/EnableIf.h>
52 #include <blaze/util/Types.h>
54 
55 
56 namespace blaze {
57 
58 //=================================================================================================
59 //
60 // CLASS DVECTRANSPOSER
61 //
62 //=================================================================================================
63 
64 //*************************************************************************************************
70 template< typename VT // Type of the dense vector
71  , bool TF > // Transpose flag
72 class DVecTransposer : public DenseVector< DVecTransposer<VT,TF>, TF >
73 {
74  private:
75  //**Type definitions****************************************************************************
77  //**********************************************************************************************
78 
79  public:
80  //**Type definitions****************************************************************************
82  typedef typename VT::TransposeType ResultType;
83  typedef typename VT::ResultType TransposeType;
84  typedef typename VT::ElementType ElementType;
85  typedef typename IT::Type IntrinsicType;
86  typedef typename VT::ReturnType ReturnType;
87  typedef const This& CompositeType;
88  typedef typename VT::Reference Reference;
90  typedef typename VT::Iterator Iterator;
91  typedef typename VT::ConstIterator ConstIterator;
92  //**********************************************************************************************
93 
94  //**Compilation flags***************************************************************************
96 
99  enum { vectorizable = VT::vectorizable };
100 
102 
105  enum { smpAssignable = VT::smpAssignable };
106  //**********************************************************************************************
107 
108  //**Constructor*********************************************************************************
113  explicit inline DVecTransposer( VT& dv )
114  : dv_( dv ) // The dense vector operand
115  {}
116  //**********************************************************************************************
117 
118  //**Subscript operator**************************************************************************
124  inline Reference operator[]( size_t index ) {
125  BLAZE_USER_ASSERT( index < dv_.size(), "Invalid vector access index" );
126  return dv_[index];
127  }
128  //**********************************************************************************************
129 
130  //**Subscript operator**************************************************************************
136  inline ConstReference operator[]( size_t index ) const {
137  BLAZE_USER_ASSERT( index < dv_.size(), "Invalid vector access index" );
138  return dv_[index];
139  }
140  //**********************************************************************************************
141 
142  //**Low-level data access***********************************************************************
147  inline ElementType* data() {
148  return dv_.data();
149  }
150  //**********************************************************************************************
151 
152  //**Begin function******************************************************************************
157  inline Iterator begin() {
158  return dv_.begin();
159  }
160  //**********************************************************************************************
161 
162  //**Begin function******************************************************************************
167  inline ConstIterator begin() const {
168  return dv_.cbegin();
169  }
170  //**********************************************************************************************
171 
172  //**Cbegin function*****************************************************************************
177  inline ConstIterator cbegin() const {
178  return dv_.cbegin();
179  }
180  //**********************************************************************************************
181 
182  //**End function********************************************************************************
187  inline Iterator end() {
188  return dv_.end();
189  }
190  //**********************************************************************************************
191 
192  //**End function********************************************************************************
197  inline ConstIterator end() const {
198  return dv_.cend();
199  }
200  //**********************************************************************************************
201 
202  //**Cend function*******************************************************************************
207  inline ConstIterator cend() const {
208  return dv_.cend();
209  }
210  //**********************************************************************************************
211 
212  //**Multiplication assignment operator**********************************************************
219  template< typename Other > // Data type of the right-hand side scalar
220  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator*=( Other rhs )
221  {
222  (~dv_) *= rhs;
223  return *this;
224  }
225  //**********************************************************************************************
226 
227  //**Division assignment operator****************************************************************
236  template< typename Other > // Data type of the right-hand side scalar
237  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator/=( Other rhs )
238  {
239  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
240 
241  (~dv_) /= rhs;
242  return *this;
243  }
244  //**********************************************************************************************
245 
246  //**Size function*******************************************************************************
251  inline size_t size() const {
252  return dv_.size();
253  }
254  //**********************************************************************************************
255 
256  //**Reset function******************************************************************************
261  inline void reset() {
262  return dv_.reset();
263  }
264  //**********************************************************************************************
265 
266  //**CanAliased function*************************************************************************
272  template< typename Other > // Data type of the foreign expression
273  inline bool canAlias( const Other* alias ) const
274  {
275  return dv_.canAlias( alias );
276  }
277  //**********************************************************************************************
278 
279  //**IsAliased function**************************************************************************
285  template< typename Other > // Data type of the foreign expression
286  inline bool isAliased( const Other* alias ) const
287  {
288  return dv_.isAliased( alias );
289  }
290  //**********************************************************************************************
291 
292  //**IsAligned function**************************************************************************
297  inline bool isAligned() const
298  {
299  return dv_.isAligned();
300  }
301  //**********************************************************************************************
302 
303  //**CanSMPAssign function***********************************************************************
308  inline bool canSMPAssign() const
309  {
310  return dv_.canSMPAssign();
311  }
312  //**********************************************************************************************
313 
314  //**Load function*******************************************************************************
324  BLAZE_ALWAYS_INLINE IntrinsicType load( size_t index ) const
325  {
326  return dv_.load( index );
327  }
328  //**********************************************************************************************
329 
330  //**Loadu function******************************************************************************
340  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t index ) const
341  {
342  return dv_.loadu( index );
343  }
344  //**********************************************************************************************
345 
346  //**Store function******************************************************************************
357  BLAZE_ALWAYS_INLINE void store( size_t index, const IntrinsicType& value )
358  {
359  dv_.store( index, value );
360  }
361  //**********************************************************************************************
362 
363  //**Storeu function*****************************************************************************
374  BLAZE_ALWAYS_INLINE void storeu( size_t index, const IntrinsicType& value )
375  {
376  dv_.storeu( index, value );
377  }
378  //**********************************************************************************************
379 
380  //**Stream function*****************************************************************************
391  BLAZE_ALWAYS_INLINE void stream( size_t index, const IntrinsicType& value )
392  {
393  dv_.stream( index, value );
394  }
395  //**********************************************************************************************
396 
397  //**Transpose assignment of dense vectors*******************************************************
408  template< typename VT2 > // Type of the right-hand side dense vector
409  inline void assign( const DenseVector<VT2,TF>& rhs )
410  {
412 
413  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
414 
415  const size_t n( size() );
416 
417  const size_t ipos( n & size_t(-2) );
418  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ipos, "Invalid end calculation" );
419 
420  for( size_t i=0UL; i<ipos; i+=2UL ) {
421  dv_[i ] = (~rhs)[i ];
422  dv_[i+1UL] = (~rhs)[i+1UL];
423  }
424  if( ipos < n )
425  dv_[ipos] = (~rhs)[ipos];
426  }
427  //**********************************************************************************************
428 
429  //**Transpose assignment of sparse vectors******************************************************
440  template< typename VT2 > // Type of the right-hand side sparse vector
441  inline void assign( const SparseVector<VT2,TF>& rhs )
442  {
444 
445  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
446 
447  typedef typename VT2::ConstIterator RhsConstIterator;
448 
449  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
450  dv_[element->index()] = element->value();
451  }
452  //**********************************************************************************************
453 
454  //**Transpose addition assignment of dense vectors**********************************************
465  template< typename VT2 > // Type of the right-hand side dense vector
466  inline void addAssign( const DenseVector<VT2,TF>& rhs )
467  {
469 
470  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
471 
472  const size_t n( size() );
473 
474  const size_t ipos( n & size_t(-2) );
475  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ipos, "Invalid end calculation" );
476 
477  for( size_t i=0UL; i<ipos; i+=2UL ) {
478  dv_[i ] += (~rhs)[i ];
479  dv_[i+1UL] += (~rhs)[i+1UL];
480  }
481  if( ipos < n )
482  dv_[ipos] += (~rhs)[ipos];
483  }
484  //**********************************************************************************************
485 
486  //**Transpose addition assignment of sparse vectors*********************************************
497  template< typename VT2 > // Type of the right-hand side sparse vector
498  inline void addAssign( const SparseVector<VT2,TF>& rhs )
499  {
501 
502  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
503 
504  typedef typename VT2::ConstIterator RhsConstIterator;
505 
506  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
507  dv_[element->index()] += element->value();
508  }
509  //**********************************************************************************************
510 
511  //**Transpose subtraction assignment of dense vectors*******************************************
522  template< typename VT2 > // Type of the right-hand side dense vector
523  inline void subAssign( const DenseVector<VT2,TF>& rhs )
524  {
526 
527  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
528 
529  const size_t n( size() );
530 
531  const size_t ipos( n & size_t(-2) );
532  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ipos, "Invalid end calculation" );
533 
534  for( size_t i=0UL; i<ipos; i+=2UL ) {
535  dv_[i ] -= (~rhs)[i ];
536  dv_[i+1UL] -= (~rhs)[i+1UL];
537  }
538  if( ipos < n )
539  dv_[ipos] -= (~rhs)[ipos];
540  }
541  //**********************************************************************************************
542 
543  //**Transpose subtraction assignment of sparse vectors******************************************
554  template< typename VT2 > // Type of the right-hand side sparse vector
555  inline void subAssign( const SparseVector<VT2,TF>& rhs )
556  {
558 
559  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
560 
561  typedef typename VT2::ConstIterator RhsConstIterator;
562 
563  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
564  dv_[element->index()] -= element->value();
565  }
566  //**********************************************************************************************
567 
568  //**Transpose multiplication assignment of dense vectors****************************************
579  template< typename VT2 > // Type of the right-hand side dense vector
580  inline void multAssign( const DenseVector<VT2,TF>& rhs )
581  {
583 
584  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
585 
586  const size_t n( size() );
587 
588  const size_t ipos( n & size_t(-2) );
589  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ipos, "Invalid end calculation" );
590 
591  for( size_t i=0UL; i<ipos; i+=2UL ) {
592  dv_[i ] *= (~rhs)[i ];
593  dv_[i+1UL] *= (~rhs)[i+1UL];
594  }
595  if( ipos < n )
596  dv_[ipos] *= (~rhs)[ipos];
597  }
598  //**********************************************************************************************
599 
600  //**Transpose multiplication assignment of sparse vectors***************************************
611  template< typename VT2 > // Type of the right-hand side dense vector
612  inline void multAssign( const SparseVector<VT2,TF>& rhs )
613  {
615 
616  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
617 
618  typedef typename VT2::ConstIterator RhsConstIterator;
619 
620  const VT tmp( dv_ );
621  dv_.reset();
622 
623  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
624  dv_[element->index()] = tmp[element->index()] * element->value();
625  }
626  //**********************************************************************************************
627 
628  private:
629  //**Member variables****************************************************************************
630  VT& dv_;
631  //**********************************************************************************************
632 
633  //**Compile time checks*************************************************************************
639  //**********************************************************************************************
640 };
641 //*************************************************************************************************
642 
643 
644 
645 
646 //=================================================================================================
647 //
648 // GLOBAL OPERATORS
649 //
650 //=================================================================================================
651 
652 //*************************************************************************************************
660 template< typename VT // Type of the dense vector
661  , bool TF > // Transpose flag
662 inline void reset( DVecTransposer<VT,TF>& v )
663 {
664  v.reset();
665 }
667 //*************************************************************************************************
668 
669 
670 
671 
672 //=================================================================================================
673 //
674 // SUBVECTORTRAIT SPECIALIZATIONS
675 //
676 //=================================================================================================
677 
678 //*************************************************************************************************
680 template< typename VT, bool TF >
681 struct SubvectorTrait< DVecTransposer<VT,TF> >
682 {
684 };
686 //*************************************************************************************************
687 
688 } // namespace blaze
689 
690 #endif
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: DVecTransposer.h:124
Constraint on the data type.
Iterator begin()
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:157
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DVecTransposer.h:286
VT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DVecTransposer.h:91
#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:251
Header file for basic type definitions.
VT::Iterator Iterator
Iterator over non-constant elements.
Definition: DVecTransposer.h:90
#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
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: DVecTransposer.h:308
void subAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a dense vector.
Definition: DVecTransposer.h:523
BLAZE_ALWAYS_INLINE IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:324
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
VT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: DVecTransposer.h:89
ConstIterator cend() const
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:207
void multAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a sparse vector.
Definition: DVecTransposer.h:612
Header file for the DenseVector base class.
ConstReference operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecTransposer.h:136
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: DVecTransposer.h:273
ConstIterator begin() const
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:167
VT::ElementType ElementType
Type of the vector elements.
Definition: DVecTransposer.h:84
Header file for the intrinsic trait.
BLAZE_ALWAYS_INLINE void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: DVecTransposer.h:391
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:72
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DVecTransposer.h:83
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: DVecTransposer.h:297
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecTransposer.h:86
IntrinsicTrait< typename VT::ElementType > IT
Intrinsic trait for the vector element type.
Definition: DVecTransposer.h:76
DVecTransposer(VT &dv)
Constructor for the DVecTransposer class.
Definition: DVecTransposer.h:113
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
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:2504
Constraint on the data type.
VT::Reference Reference
Reference to a non-constant matrix value.
Definition: DVecTransposer.h:88
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
BLAZE_ALWAYS_INLINE IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:340
Header file for the EnableIf class template.
void reset()
Resets the vector elements.
Definition: DVecTransposer.h:261
Header file for the IsNumeric type trait.
DVecTransposer< VT, TF > This
Type of this DVecTransposer instance.
Definition: DVecTransposer.h:81
BLAZE_ALWAYS_INLINE void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:374
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
Header file for run time assertion macros.
const This & CompositeType
Data type for composite expression templates.
Definition: DVecTransposer.h:87
Iterator end()
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:187
void addAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose addition assignment of a sparse vector.
Definition: DVecTransposer.h:498
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:466
ConstIterator end() const
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:197
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DVecTransposer.h:85
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
void subAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a sparse vector.
Definition: DVecTransposer.h:555
void assign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a sparse vector.
Definition: DVecTransposer.h:441
#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:82
void assign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a dense vector.
Definition: DVecTransposer.h:409
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator/=(Other rhs)
Division assignment operator for the division of a vector by a scalar value ( ).
Definition: DVecTransposer.h:237
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
ElementType * data()
Low-level data access to the vector elements.
Definition: DVecTransposer.h:147
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a vector and a scalar value ( )...
Definition: DVecTransposer.h:220
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
BLAZE_ALWAYS_INLINE void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:357
System settings for the inline keywords.
void multAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a dense vector.
Definition: DVecTransposer.h:580
#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
ConstIterator cbegin() const
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:177
VT & dv_
The dense vector operand.
Definition: DVecTransposer.h:630