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 Iterator begin() {
157  return dv_.begin();
158  }
159  //**********************************************************************************************
160 
161  //**Begin function******************************************************************************
166  inline ConstIterator begin() const {
167  return dv_.cbegin();
168  }
169  //**********************************************************************************************
170 
171  //**Cbegin function*****************************************************************************
176  inline ConstIterator cbegin() const {
177  return dv_.cbegin();
178  }
179  //**********************************************************************************************
180 
181  //**End function********************************************************************************
186  inline Iterator end() {
187  return dv_.end();
188  }
189  //**********************************************************************************************
190 
191  //**End function********************************************************************************
196  inline ConstIterator end() const {
197  return dv_.cend();
198  }
199  //**********************************************************************************************
200 
201  //**Cend function*******************************************************************************
206  inline ConstIterator cend() const {
207  return dv_.cend();
208  }
209  //**********************************************************************************************
210 
211  //**Multiplication assignment operator**********************************************************
218  template< typename Other > // Data type of the right-hand side scalar
219  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator*=( Other rhs )
220  {
221  (~dv_) *= rhs;
222  return *this;
223  }
224  //**********************************************************************************************
225 
226  //**Division assignment operator****************************************************************
235  template< typename Other > // Data type of the right-hand side scalar
236  inline typename EnableIf< IsNumeric<Other>, DVecTransposer >::Type& operator/=( Other rhs )
237  {
238  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
239 
240  (~dv_) /= rhs;
241  return *this;
242  }
243  //**********************************************************************************************
244 
245  //**Size function*******************************************************************************
250  inline size_t size() const {
251  return dv_.size();
252  }
253  //**********************************************************************************************
254 
255  //**Reset function******************************************************************************
260  inline void reset() {
261  return dv_.reset();
262  }
263  //**********************************************************************************************
264 
265  //**CanAliased function*************************************************************************
271  template< typename Other > // Data type of the foreign expression
272  inline bool canAlias( const Other* alias ) const
273  {
274  return dv_.canAlias( alias );
275  }
276  //**********************************************************************************************
277 
278  //**IsAliased function**************************************************************************
284  template< typename Other > // Data type of the foreign expression
285  inline bool isAliased( const Other* alias ) const
286  {
287  return dv_.isAliased( alias );
288  }
289  //**********************************************************************************************
290 
291  //**IsAligned function**************************************************************************
296  inline bool isAligned() const
297  {
298  return dv_.isAligned();
299  }
300  //**********************************************************************************************
301 
302  //**CanSMPAssign function***********************************************************************
307  inline bool canSMPAssign() const
308  {
309  return dv_.canSMPAssign();
310  }
311  //**********************************************************************************************
312 
313  //**Load function*******************************************************************************
323  inline IntrinsicType load( size_t index ) const
324  {
325  return dv_.load( index );
326  }
327  //**********************************************************************************************
328 
329  //**Loadu function******************************************************************************
339  inline IntrinsicType loadu( size_t index ) const
340  {
341  return dv_.loadu( index );
342  }
343  //**********************************************************************************************
344 
345  //**Store function******************************************************************************
356  inline void store( size_t index, const IntrinsicType& value )
357  {
358  dv_.store( index, value );
359  }
360  //**********************************************************************************************
361 
362  //**Storeu function*****************************************************************************
373  inline void storeu( size_t index, const IntrinsicType& value )
374  {
375  dv_.storeu( index, value );
376  }
377  //**********************************************************************************************
378 
379  //**Stream function*****************************************************************************
390  inline void stream( size_t index, const IntrinsicType& value )
391  {
392  dv_.stream( index, value );
393  }
394  //**********************************************************************************************
395 
396  //**Transpose assignment of dense vectors*******************************************************
407  template< typename VT2 > // Type of the right-hand side dense vector
408  inline void assign( const DenseVector<VT2,TF>& rhs )
409  {
411 
412  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
413 
414  const size_t n( size() );
415 
416  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
417  const size_t iend( n & size_t(-2) );
418 
419  for( size_t i=0UL; i<iend; i+=2UL ) {
420  dv_[i ] = (~rhs)[i ];
421  dv_[i+1UL] = (~rhs)[i+1UL];
422  }
423  if( iend < n )
424  dv_[iend] = (~rhs)[iend];
425  }
426  //**********************************************************************************************
427 
428  //**Transpose assignment of sparse vectors******************************************************
439  template< typename VT2 > // Type of the right-hand side sparse vector
440  inline void assign( const SparseVector<VT2,TF>& rhs )
441  {
443 
444  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
445 
446  typedef typename VT2::ConstIterator RhsConstIterator;
447 
448  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
449  dv_[element->index()] = element->value();
450  }
451  //**********************************************************************************************
452 
453  //**Transpose addition assignment of dense vectors**********************************************
464  template< typename VT2 > // Type of the right-hand side dense vector
465  inline void addAssign( const DenseVector<VT2,TF>& rhs )
466  {
468 
469  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
470 
471  const size_t n( size() );
472 
473  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
474  const size_t iend( n & size_t(-2) );
475 
476  for( size_t i=0UL; i<iend; i+=2UL ) {
477  dv_[i ] += (~rhs)[i ];
478  dv_[i+1UL] += (~rhs)[i+1UL];
479  }
480  if( iend < n )
481  dv_[iend] += (~rhs)[iend];
482  }
483  //**********************************************************************************************
484 
485  //**Transpose addition assignment of sparse vectors*********************************************
496  template< typename VT2 > // Type of the right-hand side sparse vector
497  inline void addAssign( const SparseVector<VT2,TF>& rhs )
498  {
500 
501  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
502 
503  typedef typename VT2::ConstIterator RhsConstIterator;
504 
505  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
506  dv_[element->index()] += element->value();
507  }
508  //**********************************************************************************************
509 
510  //**Transpose subtraction assignment of dense vectors*******************************************
521  template< typename VT2 > // Type of the right-hand side dense vector
522  inline void subAssign( const DenseVector<VT2,TF>& rhs )
523  {
525 
526  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
527 
528  const size_t n( size() );
529 
530  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
531  const size_t iend( n & size_t(-2) );
532 
533  for( size_t i=0UL; i<iend; i+=2UL ) {
534  dv_[i ] -= (~rhs)[i ];
535  dv_[i+1UL] -= (~rhs)[i+1UL];
536  }
537  if( iend < n )
538  dv_[iend] -= (~rhs)[iend];
539  }
540  //**********************************************************************************************
541 
542  //**Transpose subtraction assignment of sparse vectors******************************************
553  template< typename VT2 > // Type of the right-hand side sparse vector
554  inline void subAssign( const SparseVector<VT2,TF>& rhs )
555  {
557 
558  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
559 
560  typedef typename VT2::ConstIterator RhsConstIterator;
561 
562  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
563  dv_[element->index()] -= element->value();
564  }
565  //**********************************************************************************************
566 
567  //**Transpose multiplication assignment of dense vectors****************************************
578  template< typename VT2 > // Type of the right-hand side dense vector
579  inline void multAssign( const DenseVector<VT2,TF>& rhs )
580  {
582 
583  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
584 
585  const size_t n( size() );
586 
587  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
588  const size_t iend( n & size_t(-2) );
589 
590  for( size_t i=0UL; i<iend; i+=2UL ) {
591  dv_[i ] *= (~rhs)[i ];
592  dv_[i+1UL] *= (~rhs)[i+1UL];
593  }
594  if( iend < n )
595  dv_[iend] *= (~rhs)[iend];
596  }
597  //**********************************************************************************************
598 
599  //**Transpose multiplication assignment of sparse vectors***************************************
610  template< typename VT2 > // Type of the right-hand side dense vector
611  inline void multAssign( const SparseVector<VT2,TF>& rhs )
612  {
614 
615  BLAZE_INTERNAL_ASSERT( dv_.size() == (~rhs).size(), "Invalid vector sizes" );
616 
617  typedef typename VT2::ConstIterator RhsConstIterator;
618 
619  const VT tmp( dv_ );
620  dv_.reset();
621 
622  for( RhsConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
623  dv_[element->index()] = tmp[element->index()] * element->value();
624  }
625  //**********************************************************************************************
626 
627  private:
628  //**Member variables****************************************************************************
629  VT& dv_;
630  //**********************************************************************************************
631 
632  //**Compile time checks*************************************************************************
638  //**********************************************************************************************
639 };
640 //*************************************************************************************************
641 
642 
643 
644 
645 //=================================================================================================
646 //
647 // GLOBAL OPERATORS
648 //
649 //=================================================================================================
650 
651 //*************************************************************************************************
659 template< typename VT // Type of the dense vector
660  , bool TF > // Transpose flag
661 inline void reset( DVecTransposer<VT,TF>& v )
662 {
663  v.reset();
664 }
666 //*************************************************************************************************
667 
668 
669 
670 
671 //=================================================================================================
672 //
673 // SUBVECTORTRAIT SPECIALIZATIONS
674 //
675 //=================================================================================================
676 
677 //*************************************************************************************************
679 template< typename VT, bool TF >
680 struct SubvectorTrait< DVecTransposer<VT,TF> >
681 {
683 };
685 //*************************************************************************************************
686 
687 } // namespace blaze
688 
689 #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.
Iterator begin()
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:156
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DVecTransposer.h:285
VT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DVecTransposer.h:90
#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:250
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
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: DVecTransposer.h:307
void subAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a dense vector.
Definition: DVecTransposer.h:522
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:206
void multAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a sparse vector.
Definition: DVecTransposer.h:611
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:272
ConstIterator begin() const
Returns an iterator to the first element of the dense vector.
Definition: DVecTransposer.h:166
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:296
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:2482
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:2475
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:2476
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
Header file for the EnableIf class template.
void reset()
Resets the vector elements.
Definition: DVecTransposer.h:260
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:2477
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:86
Iterator end()
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:186
void addAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose addition assignment of a sparse vector.
Definition: DVecTransposer.h:497
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:356
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:323
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:465
ConstIterator end() const
Returns an iterator just past the last element of the dense vector.
Definition: DVecTransposer.h:196
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DVecTransposer.h:84
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: DVecTransposer.h:373
void subAssign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose subtraction assignment of a sparse vector.
Definition: DVecTransposer.h:554
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
void assign(const SparseVector< VT2, TF > &rhs)
Implementation of the transpose assignment of a sparse vector.
Definition: DVecTransposer.h:440
#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:408
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator/=(Other rhs)
Division assignment operator for the division of a vector by a scalar value ( ).
Definition: DVecTransposer.h:236
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:2473
EnableIf< IsNumeric< Other >, DVecTransposer >::Type & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a vector and a scalar value ( )...
Definition: DVecTransposer.h:219
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:390
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DVecTransposer.h:339
void multAssign(const DenseVector< VT2, TF > &rhs)
Implementation of the transpose multiplication assignment of a dense vector.
Definition: DVecTransposer.h:579
#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:176
VT & dv_
The dense vector operand.
Definition: DVecTransposer.h:629