SVecTransposer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECTRANSPOSER_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECTRANSPOSER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
47 #include <blaze/math/Exception.h>
54 #include <blaze/util/Assert.h>
55 #include <blaze/util/Types.h>
56 
57 
58 namespace blaze {
59 
60 //=================================================================================================
61 //
62 // CLASS SVECTRANSPOSER
63 //
64 //=================================================================================================
65 
66 //*************************************************************************************************
72 template< typename VT // Type of the sparse vector
73  , bool TF > // Transpose flag
74 class SVecTransposer
75  : public SparseVector< SVecTransposer<VT,TF>, TF >
76 {
77  public:
78  //**Type definitions****************************************************************************
84  using CompositeType = const This&;
89  //**********************************************************************************************
90 
91  //**Compilation flags***************************************************************************
93 
96  enum : bool { smpAssignable = VT::smpAssignable };
97  //**********************************************************************************************
98 
99  //**Constructor*********************************************************************************
104  explicit inline SVecTransposer( VT& sv ) noexcept
105  : sv_( sv ) // The sparse vector operand
106  {}
107  //**********************************************************************************************
108 
109  //**Subscript operator**************************************************************************
115  inline ConstReference operator[]( size_t index ) const {
116  BLAZE_USER_ASSERT( index < sv_.size(), "Invalid vector access index" );
117  return const_cast<const VT&>( sv_ )[index];
118  }
119  //**********************************************************************************************
120 
121  //**At function*********************************************************************************
128  inline ConstReference at( size_t index ) const {
129  if( index >= sv_.size() ) {
130  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
131  }
132  return (*this)[index];
133  }
134  //**********************************************************************************************
135 
136  //**Begin function******************************************************************************
141  inline Iterator begin() {
142  return sv_.begin();
143  }
144  //**********************************************************************************************
145 
146  //**Begin function******************************************************************************
151  inline ConstIterator begin() const {
152  return sv_.cbegin();
153  }
154  //**********************************************************************************************
155 
156  //**Cbegin function*****************************************************************************
161  inline ConstIterator cbegin() const {
162  return sv_.cbegin();
163  }
164  //**********************************************************************************************
165 
166  //**End function********************************************************************************
171  inline Iterator end() {
172  return sv_.end();
173  }
174  //**********************************************************************************************
175 
176  //**End function********************************************************************************
181  inline ConstIterator end() const {
182  return sv_.cend();
183  }
184  //**********************************************************************************************
185 
186  //**Cend function*******************************************************************************
191  inline ConstIterator cend() const {
192  return sv_.cend();
193  }
194  //**********************************************************************************************
195 
196  //**Size function*******************************************************************************
201  inline size_t size() const noexcept {
202  return sv_.size();
203  }
204  //**********************************************************************************************
205 
206  //**Capacity function***************************************************************************
211  inline size_t capacity() const noexcept {
212  return sv_.capacity();
213  }
214  //**********************************************************************************************
215 
216  //**NonZeros function***************************************************************************
221  inline size_t nonZeros() const {
222  return sv_.nonZeros();
223  }
224  //**********************************************************************************************
225 
226  //**Reset function******************************************************************************
231  inline void reset() {
232  return sv_.reset();
233  }
234  //**********************************************************************************************
235 
236  //**Insert function*****************************************************************************
248  inline Iterator insert( size_t index, const ElementType& value ) {
249  return sv_.insert( index, value );
250  }
251  //**********************************************************************************************
252 
253  //**Find function*******************************************************************************
266  inline Iterator find( size_t index ) {
267  return sv_.find( index );
268  }
269  //**********************************************************************************************
270 
271  //**Reserve function****************************************************************************
280  inline void reserve( size_t nonzeros ) {
281  sv_.reserve( nonzeros );
282  }
283  //**********************************************************************************************
284 
285  //**Append function*****************************************************************************
310  inline void append( size_t index, const ElementType& value, bool check=false ) {
311  sv_.append( index, value, check );
312  }
313  //**********************************************************************************************
314 
315  //**IsIntact function***************************************************************************
320  inline bool isIntact() const noexcept
321  {
322  using blaze::isIntact;
323  return isIntact( sv_ );
324  }
325  //**********************************************************************************************
326 
327  //**CanAlias function***************************************************************************
333  template< typename Other > // Data type of the foreign expression
334  inline bool canAlias( const Other* alias ) const noexcept
335  {
336  return sv_.canAlias( alias );
337  }
338  //**********************************************************************************************
339 
340  //**IsAliased function**************************************************************************
346  template< typename Other > // Data type of the foreign expression
347  inline bool isAliased( const Other* alias ) const noexcept
348  {
349  return sv_.isAliased( alias );
350  }
351  //**********************************************************************************************
352 
353  //**CanSMPAssign function***********************************************************************
358  inline bool canSMPAssign() const noexcept
359  {
360  return sv_.canSMPAssign();
361  }
362  //**********************************************************************************************
363 
364  //**Transpose assignment of vectors*************************************************************
375  template< typename VT2 > // Type of the right-hand side vector
376  inline void assign( const Vector<VT2,TF>& rhs )
377  {
379 
380  sv_.assign( trans( ~rhs ) );
381  }
382  //**********************************************************************************************
383 
384  private:
385  //**********************************************************************************************
393  inline size_t extendCapacity() const noexcept
394  {
395  using blaze::max;
396  using blaze::min;
397 
398  size_t nonzeros( 2UL*sv_.capacity()+1UL );
399  nonzeros = max( nonzeros, 7UL );
400  nonzeros = min( nonzeros, sv_.size() );
401 
402  BLAZE_INTERNAL_ASSERT( nonzeros > sv_.capacity(), "Invalid capacity value" );
403 
404  return nonzeros;
405  }
406  //**********************************************************************************************
407 
408  //**Member variables****************************************************************************
409  VT& sv_;
410  //**********************************************************************************************
411 
412  //**Compile time checks*************************************************************************
418  //**********************************************************************************************
419 };
420 //*************************************************************************************************
421 
422 
423 
424 
425 //=================================================================================================
426 //
427 // GLOBAL OPERATORS
428 //
429 //=================================================================================================
430 
431 //*************************************************************************************************
439 template< typename VT // Type of the sparse vector
440  , bool TF > // Transpose flag
441 inline void reset( SVecTransposer<VT,TF>& v )
442 {
443  v.reset();
444 }
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
457 template< typename VT // Type of the sparse vector
458  , bool TF > // Transpose flag
459 inline bool isIntact( const SVecTransposer<VT,TF>& v ) noexcept
460 {
461  return v.isIntact();
462 }
464 //*************************************************************************************************
465 
466 
467 
468 
469 //=================================================================================================
470 //
471 // SUBVECTORTRAIT SPECIALIZATIONS
472 //
473 //=================================================================================================
474 
475 //*************************************************************************************************
477 template< typename VT, bool TF, size_t... CSAs >
478 struct SubvectorTrait< SVecTransposer<VT,TF>, CSAs... >
479 {
480  using Type = SubvectorTrait_< ResultType_< SVecTransposer<VT,TF> >, CSAs... >;
481 };
483 //*************************************************************************************************
484 
485 
486 
487 
488 //=================================================================================================
489 //
490 // ELEMENTSTRAIT SPECIALIZATIONS
491 //
492 //=================================================================================================
493 
494 //*************************************************************************************************
496 template< typename VT, bool TF, size_t... CEAs >
497 struct ElementsTrait< SVecTransposer<VT,TF>, CEAs... >
498 {
499  using Type = ElementsTrait_< ResultType_< SVecTransposer<VT,TF> >, CEAs... >;
500 };
502 //*************************************************************************************************
503 
504 } // namespace blaze
505 
506 #endif
Constraint on the data type.
Iterator find(size_t index)
Inserting an element into the sparse vector.
Definition: SVecTransposer.h:266
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: SVecTransposer.h:221
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:151
#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
Header file for basic type definitions.
Header file for the SparseVector base class.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecTransposer.h:201
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecTransposer.h:83
#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:81
size_t capacity() const noexcept
Returns the maximum capacity of the vector.
Definition: SVecTransposer.h:211
ResultType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransposer.h:81
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1903
void assign(const Vector< VT2, TF > &rhs)
Implementation of the transpose assignment of a vector.
Definition: SVecTransposer.h:376
typename ElementsTrait< VT, CEAs... >::Type ElementsTrait_
Auxiliary alias declaration for the ElementsTrait type trait.The ElementsTrait_ alias declaration pro...
Definition: ElementsTrait.h:144
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1950
ConstIterator_< VT > ConstIterator
Iterator over constant elements.
Definition: SVecTransposer.h:88
Header file for the elements trait.
Reference_< VT > Reference
Reference to a non-constant matrix value.
Definition: SVecTransposer.h:85
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:109
Headerfile for the generic max algorithm.
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: SVecTransposer.h:347
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse vector.
Definition: SVecTransposer.h:310
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Header file for the subvector trait.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:147
bool isIntact() const noexcept
Returns whether the invariants of the vector are intact.
Definition: SVecTransposer.h:320
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:61
Constraint on the data type.
Header file for the exception macros of the math module.
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransposer.h:181
Base template for the ElementsTrait class.
Definition: ElementsTrait.h:108
Constraint on the data type.
void reset()
Resets the vector elements.
Definition: SVecTransposer.h:231
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:303
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse vector.
Definition: SVecTransposer.h:280
typename SubvectorTrait< VT, CSAs... >::Type SubvectorTrait_
Auxiliary alias declaration for the SubvectorTrait type trait.The SubvectorTrait_ alias declaration p...
Definition: SubvectorTrait.h:145
ElementType_< VT > ElementType
Resulting element type.
Definition: SVecTransposer.h:82
Header file for run time assertion macros.
ConstReference at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransposer.h:128
ConstIterator cbegin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:161
Iterator end()
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransposer.h:171
Header file for the isDefault shim.
TransposeType_< VT > ResultType
Result type for expression template evaluations.
Definition: SVecTransposer.h:80
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: SVecTransposer.h:334
ConstReference_< VT > ConstReference
Reference to a constant matrix value.
Definition: SVecTransposer.h:86
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:789
VT & sv_
The sparse vector operand.
Definition: SVecTransposer.h:409
Iterator begin()
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:141
Iterator_< VT > Iterator
Iterator over non-constant elements.
Definition: SVecTransposer.h:87
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:177
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition: SVecTransposer.h:393
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse vector.
Definition: SVecTransposer.h:248
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: SVecTransposer.h:358
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransposer.h:191
ConstReference operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransposer.h:115
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
#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:63
#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
SVecTransposer(VT &sv) noexcept
Constructor for the SVecTransposer class.
Definition: SVecTransposer.h:104