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****************************************************************************
85  using CompositeType = const This&;
90  //**********************************************************************************************
91 
92  //**Compilation flags***************************************************************************
94 
97  static constexpr bool smpAssignable = VT::smpAssignable;
98  //**********************************************************************************************
99 
100  //**Constructor*********************************************************************************
105  explicit inline SVecTransposer( VT& sv ) noexcept
106  : sv_( sv ) // The sparse vector operand
107  {}
108  //**********************************************************************************************
109 
110  //**Subscript operator**************************************************************************
116  inline ConstReference operator[]( size_t index ) const {
117  BLAZE_USER_ASSERT( index < sv_.size(), "Invalid vector access index" );
118  return const_cast<const VT&>( sv_ )[index];
119  }
120  //**********************************************************************************************
121 
122  //**At function*********************************************************************************
129  inline ConstReference at( size_t index ) const {
130  if( index >= sv_.size() ) {
131  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
132  }
133  return (*this)[index];
134  }
135  //**********************************************************************************************
136 
137  //**Begin function******************************************************************************
142  inline Iterator begin() {
143  return sv_.begin();
144  }
145  //**********************************************************************************************
146 
147  //**Begin function******************************************************************************
152  inline ConstIterator begin() const {
153  return sv_.cbegin();
154  }
155  //**********************************************************************************************
156 
157  //**Cbegin function*****************************************************************************
162  inline ConstIterator cbegin() const {
163  return sv_.cbegin();
164  }
165  //**********************************************************************************************
166 
167  //**End function********************************************************************************
172  inline Iterator end() {
173  return sv_.end();
174  }
175  //**********************************************************************************************
176 
177  //**End function********************************************************************************
182  inline ConstIterator end() const {
183  return sv_.cend();
184  }
185  //**********************************************************************************************
186 
187  //**Cend function*******************************************************************************
192  inline ConstIterator cend() const {
193  return sv_.cend();
194  }
195  //**********************************************************************************************
196 
197  //**Size function*******************************************************************************
202  inline size_t size() const noexcept {
203  return sv_.size();
204  }
205  //**********************************************************************************************
206 
207  //**Capacity function***************************************************************************
212  inline size_t capacity() const noexcept {
213  return sv_.capacity();
214  }
215  //**********************************************************************************************
216 
217  //**NonZeros function***************************************************************************
222  inline size_t nonZeros() const {
223  return sv_.nonZeros();
224  }
225  //**********************************************************************************************
226 
227  //**Reset function******************************************************************************
232  inline void reset() {
233  return sv_.reset();
234  }
235  //**********************************************************************************************
236 
237  //**Insert function*****************************************************************************
249  inline Iterator insert( size_t index, const ElementType& value ) {
250  return sv_.insert( index, value );
251  }
252  //**********************************************************************************************
253 
254  //**Find function*******************************************************************************
267  inline Iterator find( size_t index ) {
268  return sv_.find( index );
269  }
270  //**********************************************************************************************
271 
272  //**Reserve function****************************************************************************
281  inline void reserve( size_t nonzeros ) {
282  sv_.reserve( nonzeros );
283  }
284  //**********************************************************************************************
285 
286  //**Append function*****************************************************************************
311  inline void append( size_t index, const ElementType& value, bool check=false ) {
312  sv_.append( index, value, check );
313  }
314  //**********************************************************************************************
315 
316  //**IsIntact function***************************************************************************
321  inline bool isIntact() const noexcept
322  {
323  using blaze::isIntact;
324  return isIntact( sv_ );
325  }
326  //**********************************************************************************************
327 
328  //**CanAlias function***************************************************************************
334  template< typename Other > // Data type of the foreign expression
335  inline bool canAlias( const Other* alias ) const noexcept
336  {
337  return sv_.canAlias( alias );
338  }
339  //**********************************************************************************************
340 
341  //**IsAliased function**************************************************************************
347  template< typename Other > // Data type of the foreign expression
348  inline bool isAliased( const Other* alias ) const noexcept
349  {
350  return sv_.isAliased( alias );
351  }
352  //**********************************************************************************************
353 
354  //**CanSMPAssign function***********************************************************************
359  inline bool canSMPAssign() const noexcept
360  {
361  return sv_.canSMPAssign();
362  }
363  //**********************************************************************************************
364 
365  //**Transpose assignment of vectors*************************************************************
376  template< typename VT2 > // Type of the right-hand side vector
377  inline void assign( const Vector<VT2,TF>& rhs )
378  {
380 
381  sv_.assign( trans( ~rhs ) );
382  }
383  //**********************************************************************************************
384 
385  private:
386  //**********************************************************************************************
394  inline size_t extendCapacity() const noexcept
395  {
396  using blaze::max;
397  using blaze::min;
398 
399  size_t nonzeros( 2UL*sv_.capacity()+1UL );
400  nonzeros = max( nonzeros, 7UL );
401  nonzeros = min( nonzeros, sv_.size() );
402 
403  BLAZE_INTERNAL_ASSERT( nonzeros > sv_.capacity(), "Invalid capacity value" );
404 
405  return nonzeros;
406  }
407  //**********************************************************************************************
408 
409  //**Member variables****************************************************************************
410  VT& sv_;
411  //**********************************************************************************************
412 
413  //**Compile time checks*************************************************************************
419  //**********************************************************************************************
420 };
421 //*************************************************************************************************
422 
423 
424 
425 
426 //=================================================================================================
427 //
428 // GLOBAL OPERATORS
429 //
430 //=================================================================================================
431 
432 //*************************************************************************************************
440 template< typename VT // Type of the sparse vector
441  , bool TF > // Transpose flag
442 inline void reset( SVecTransposer<VT,TF>& v )
443 {
444  v.reset();
445 }
447 //*************************************************************************************************
448 
449 
450 //*************************************************************************************************
458 template< typename VT // Type of the sparse vector
459  , bool TF > // Transpose flag
460 inline bool isIntact( const SVecTransposer<VT,TF>& v ) noexcept
461 {
462  return v.isIntact();
463 }
465 //*************************************************************************************************
466 
467 
468 
469 
470 //=================================================================================================
471 //
472 // SIZE SPECIALIZATIONS
473 //
474 //=================================================================================================
475 
476 //*************************************************************************************************
478 template< typename VT, bool TF >
479 struct Size< SVecTransposer<VT,TF>, 0UL >
480  : public Size<VT,0UL>
481 {};
483 //*************************************************************************************************
484 
485 
486 
487 
488 //=================================================================================================
489 //
490 // MAXSIZE SPECIALIZATIONS
491 //
492 //=================================================================================================
493 
494 //*************************************************************************************************
496 template< typename VT, bool TF >
497 struct MaxSize< SVecTransposer<VT,TF>, 0UL >
498  : public MaxSize<VT,0UL>
499 {};
501 //*************************************************************************************************
502 
503 } // namespace blaze
504 
505 #endif
Constraint on the data type.
Iterator find(size_t index)
Inserting an element into the sparse vector.
Definition: SVecTransposer.h:267
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:222
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:152
#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.
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecTransposer.h:202
#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:212
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
void assign(const Vector< VT2, TF > &rhs)
Implementation of the transpose assignment of a vector.
Definition: SVecTransposer.h:377
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the MaxSize type trait.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecTransposer.h:84
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:348
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse vector.
Definition: SVecTransposer.h:311
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: SVecTransposer.h:97
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
#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
Iterator_t< VT > Iterator
Iterator over non-constant elements.
Definition: SVecTransposer.h:88
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:156
bool isIntact() const noexcept
Returns whether the invariants of the vector are intact.
Definition: SVecTransposer.h:321
#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:182
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1179
Constraint on the data type.
void reset()
Resets the vector elements.
Definition: SVecTransposer.h:232
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse vector.
Definition: SVecTransposer.h:281
ConstReference_t< VT > ConstReference
Reference to a constant matrix value.
Definition: SVecTransposer.h:87
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.The Iterator_t alias declaration provides a co...
Definition: Aliases.h:190
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
ConstReference at(size_t index) const
Checked access to the vector elements.
Definition: SVecTransposer.h:129
ConstIterator cbegin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:162
Reference_t< VT > Reference
Reference to a non-constant matrix value.
Definition: SVecTransposer.h:86
Iterator end()
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransposer.h:172
ElementType_t< VT > ElementType
Resulting element type.
Definition: SVecTransposer.h:83
Header file for the isDefault shim.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.The ConstReference_t alias declaration p...
Definition: Aliases.h:150
ConstIterator_t< VT > ConstIterator
Iterator over constant elements.
Definition: SVecTransposer.h:89
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
ResultType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransposer.h:82
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: SVecTransposer.h:335
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
VT & sv_
The sparse vector operand.
Definition: SVecTransposer.h:410
Iterator begin()
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransposer.h:142
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:186
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:263
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition: SVecTransposer.h:394
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse vector.
Definition: SVecTransposer.h:249
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: SVecTransposer.h:359
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransposer.h:192
ConstReference operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransposer.h:116
TransposeType_t< VT > ResultType
Result type for expression template evaluations.
Definition: SVecTransposer.h:81
Header file for the Size type trait.
#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:105