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  //**Subscript operator**************************************************************************
135  inline ConstReference operator[]( size_t index ) const {
136  BLAZE_USER_ASSERT( index < dv_.size(), "Invalid vector access index" );
137  return dv_[index];
138  }
139  //**********************************************************************************************
140 
141  //**Low-level data access***********************************************************************
146  inline ElementType* data() {
147  return dv_.data();
148  }
149  //**********************************************************************************************
150 
151  //**Begin function******************************************************************************
156  inline ConstIterator begin() const {
157  return dv_.cbegin();
158  }
159  //**********************************************************************************************
160 
161  //**Cbegin function*****************************************************************************
166  inline ConstIterator cbegin() const {
167  return dv_.cbegin();
168  }
169  //**********************************************************************************************
170 
171  //**End function********************************************************************************
176  inline ConstIterator end() const {
177  return dv_.cend();
178  }
179  //**********************************************************************************************
180 
181  //**Cend function*******************************************************************************
186  inline ConstIterator cend() const {
187  return dv_.cend();
188  }
189  //**********************************************************************************************
190 
191  //**Multiplication assignment operator**********************************************************
198  template< typename Other > // Data type of the right-hand side scalar
199  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator*=( Other rhs )
200  {
201  (~dv_) *= rhs;
202  return *this;
203  }
204  //**********************************************************************************************
205 
206  //**Division assignment operator****************************************************************
215  template< typename Other > // Data type of the right-hand side scalar
216  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator/=( Other rhs )
217  {
218  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
219 
220  (~dv_) /= rhs;
221  return *this;
222  }
223  //**********************************************************************************************
224 
225  //**Size function*******************************************************************************
230  inline size_t size() const {
231  return dv_.size();
232  }
233  //**********************************************************************************************
234 
235  //**Reset function******************************************************************************
240  inline void reset() {
241  return dv_.reset();
242  }
243  //**********************************************************************************************
244 
245  //**CanAliased function*************************************************************************
251  template< typename Other > // Data type of the foreign expression
252  inline bool canAlias( const Other* alias ) const
253  {
254  return dv_.canAlias( alias );
255  }
256  //**********************************************************************************************
257 
258  //**IsAliased function**************************************************************************
264  template< typename Other > // Data type of the foreign expression
265  inline bool isAliased( const Other* alias ) const
266  {
267  return dv_.isAliased( alias );
268  }
269  //**********************************************************************************************
270 
271  //**IsAligned function**************************************************************************
276  inline bool isAligned() const
277  {
278  return dv_.isAligned();
279  }
280  //**********************************************************************************************
281 
282  //**Load function*******************************************************************************
292  inline IntrinsicType load( size_t index ) const
293  {
294  return dv_.load( index );
295  }
296  //**********************************************************************************************
297 
298  //**Loadu function******************************************************************************
308  inline IntrinsicType loadu( size_t index ) const
309  {
310  return dv_.loadu( index );
311  }
312  //**********************************************************************************************
313 
314  //**Store function******************************************************************************
325  inline void store( size_t index, const IntrinsicType& value )
326  {
327  dv_.store( index, value );
328  }
329  //**********************************************************************************************
330 
331  //**Storeu function*****************************************************************************
342  inline void storeu( size_t index, const IntrinsicType& value )
343  {
344  dv_.storeu( index, value );
345  }
346  //**********************************************************************************************
347 
348  //**Stream function*****************************************************************************
359  inline void stream( size_t index, const IntrinsicType& value )
360  {
361  dv_.stream( index, value );
362  }
363  //**********************************************************************************************
364 
365  //**Transpose assignment of dense vectors*******************************************************
376  template< typename VT2 > // Type of the right-hand side dense vector
377  inline void assign( const DenseVector<VT2,TF>& rhs )
378  {
380 
381  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
382 
383  const size_t n( size() );
384 
385  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
386  const size_t iend( n & size_t(-2) );
387 
388  for( size_t i=0UL; i<iend; i+=2UL ) {
389  dv_[i ] = (~rhs)[i ];
390  dv_[i+1UL] = (~rhs)[i+1UL];
391  }
392  if( iend < n )
393  dv_[iend] = (~rhs)[iend];
394  }
395  //**********************************************************************************************
396 
397  //**Transpose assignment of sparse vectors******************************************************
408  template< typename VT2 > // Type of the right-hand side sparse vector
409  inline void assign( const SparseVector<VT2,TF>& rhs )
410  {
412 
413  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
414 
415  typedef typename VT2::ConstIterator RhsConstIterator;
416 
417  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
418  dv_[element->index()] = element->value();
419  }
420  //**********************************************************************************************
421 
422  //**Transpose addition assignment of dense vectors**********************************************
433  template< typename VT2 > // Type of the right-hand side dense vector
434  inline void addAssign( const DenseVector<VT2,TF>& rhs )
435  {
437 
438  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
439 
440  const size_t n( size() );
441 
442  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
443  const size_t iend( n & size_t(-2) );
444 
445  for( size_t i=0UL; i<iend; i+=2UL ) {
446  dv_[i ] += (~rhs)[i ];
447  dv_[i+1UL] += (~rhs)[i+1UL];
448  }
449  if( iend < n )
450  dv_[iend] += (~rhs)[iend];
451  }
452  //**********************************************************************************************
453 
454  //**Transpose addition assignment of sparse vectors*********************************************
465  template< typename VT2 > // Type of the right-hand side sparse vector
466  inline void addAssign( const SparseVector<VT2,TF>& rhs )
467  {
469 
470  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
471 
472  typedef typename VT2::ConstIterator RhsConstIterator;
473 
474  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
475  dv_[element->index()] += element->value();
476  }
477  //**********************************************************************************************
478 
479  //**Transpose subtraction assignment of dense vectors*******************************************
490  template< typename VT2 > // Type of the right-hand side dense vector
491  inline void subAssign( const DenseVector<VT2,TF>& rhs )
492  {
494 
495  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
496 
497  const size_t n( size() );
498 
499  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
500  const size_t iend( n & size_t(-2) );
501 
502  for( size_t i=0UL; i<iend; i+=2UL ) {
503  dv_[i ] -= (~rhs)[i ];
504  dv_[i+1UL] -= (~rhs)[i+1UL];
505  }
506  if( iend < n )
507  dv_[iend] -= (~rhs)[iend];
508  }
509  //**********************************************************************************************
510 
511  //**Transpose subtraction assignment of sparse vectors******************************************
522  template< typename VT2 > // Type of the right-hand side sparse vector
523  inline void subAssign( const SparseVector<VT2,TF>& rhs )
524  {
526 
527  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
528 
529  typedef typename VT2::ConstIterator RhsConstIterator;
530 
531  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
532  dv_[element->index()] -= element->value();
533  }
534  //**********************************************************************************************
535 
536  //**Transpose multiplication assignment of dense vectors****************************************
547  template< typename VT2 > // Type of the right-hand side dense vector
548  inline void multAssign( const DenseVector<VT2,TF>& rhs )
549  {
551 
552  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
553 
554  const size_t n( size() );
555 
556  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
557  const size_t iend( n & size_t(-2) );
558 
559  for( size_t i=0UL; i<iend; i+=2UL ) {
560  dv_[i ] *= (~rhs)[i ];
561  dv_[i+1UL] *= (~rhs)[i+1UL];
562  }
563  if( iend < n )
564  dv_[iend] *= (~rhs)[iend];
565  }
566  //**********************************************************************************************
567 
568  //**Transpose multiplication assignment of sparse vectors***************************************
579  template< typename VT2 > // Type of the right-hand side dense vector
580  inline void multAssign( const SparseVector<VT2,TF>& rhs )
581  {
583 
584  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
585 
586  typedef typename VT2::ConstIterator RhsConstIterator;
587 
588  const VT tmp( dv_ );
589  dv_.reset();
590 
591  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
592  dv_[element->index()] = tmp[element->index()] * element->value();
593  }
594  //**********************************************************************************************
595 
596  private:
597  //**Member variables****************************************************************************
598  VT& dv_;
599  //**********************************************************************************************
600 
601  //**Compile time checks*************************************************************************
607  //**********************************************************************************************
608 };
609 //*************************************************************************************************
610 
611 
612 
613 
614 //=================================================================================================
615 //
616 // GLOBAL OPERATORS
617 //
618 //=================================================================================================
619 
620 //*************************************************************************************************
628 template< typename VT // Type of the dense vector
629  , bool TF > // Transpose flag
630 inline void reset( DVecTransposer<VT,TF>& v )
631 {
632  v.reset();
633 }
635 //*************************************************************************************************
636 
637 
638 
639 
640 //=================================================================================================
641 //
642 // SUBVECTORTRAIT SPECIALIZATIONS
643 //
644 //=================================================================================================
645 
646 //*************************************************************************************************
648 template< typename VT, bool TF >
649 struct SubvectorTrait< DVecTransposer<VT,TF> >
650 {
652 };
654 //*************************************************************************************************
655 
656 } // namespace blaze
657 
658 #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:265
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:4599
#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:230
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:491
VT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: DVecTransposer.h:88
ConstIterator cend() const
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:186
void multAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a sparse vector.
Definition: DVecTransposer.h:580
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:135
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: DVecTransposer.h:252
ConstIterator begin() const
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:156
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
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: DVecTransposer.h:276
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:2412
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:2405
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:2406
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
Header file for the EnableIf class template.
void reset()
Resets the vector elements.
Definition: DVecTransposer.h:240
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:2407
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
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:466
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:325
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:292
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:434
ConstIterator end() const
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:176
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DVecTransposer.h:84
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2411
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:342
void subAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a sparse vector.
Definition: DVecTransposer.h:523
void assign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a sparse vector.
Definition: DVecTransposer.h:409
#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:377
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator/=(Other rhs)
Division assignment operator for the division of a vector by a scalar value ( ).
Definition: DVecTransposer.h:216
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:146
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a vector and a scalar value ( )...
Definition: DVecTransposer.h:199
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:359
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2409
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:308
void multAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a dense vector.
Definition: DVecTransposer.h:548
#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:166
VT & dv_
The dense vector operand.
Definition: DVecTransposer.h:598