Blaze 3.9
Loading...
Searching...
No Matches
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>
55#include <blaze/util/Assert.h>
56#include <blaze/util/Types.h>
57
58
59namespace blaze {
60
61//=================================================================================================
62//
63// CLASS SVECTRANSPOSER
64//
65//=================================================================================================
66
67//*************************************************************************************************
73template< typename VT // Type of the sparse vector
74 , bool TF > // Transpose flag
76 : public SparseVector< SVecTransposer<VT,TF>, TF >
77{
78 public:
79 //**Type definitions****************************************************************************
81 using BaseType = SparseVector<This,TF>;
86 using CompositeType = const This&;
91 //**********************************************************************************************
92
93 //**Compilation flags***************************************************************************
95
98 static constexpr bool smpAssignable = VT::smpAssignable;
99 //**********************************************************************************************
100
101 //**Constructor*********************************************************************************
106 explicit inline SVecTransposer( VT& sv ) noexcept
107 : sv_( sv ) // The sparse vector operand
108 {}
109 //**********************************************************************************************
110
111 //**Subscript operator**************************************************************************
117 inline ConstReference operator[]( size_t index ) const {
118 BLAZE_USER_ASSERT( index < sv_.size(), "Invalid vector access index" );
119 return const_cast<const VT&>( sv_ )[index];
120 }
121 //**********************************************************************************************
122
123 //**At function*********************************************************************************
130 inline ConstReference at( size_t index ) const {
131 if( index >= sv_.size() ) {
132 BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
133 }
134 return (*this)[index];
135 }
136 //**********************************************************************************************
137
138 //**Begin function******************************************************************************
143 inline Iterator begin() {
144 return sv_.begin();
145 }
146 //**********************************************************************************************
147
148 //**Begin function******************************************************************************
153 inline ConstIterator begin() const {
154 return sv_.cbegin();
155 }
156 //**********************************************************************************************
157
158 //**Cbegin function*****************************************************************************
163 inline ConstIterator cbegin() const {
164 return sv_.cbegin();
165 }
166 //**********************************************************************************************
167
168 //**End function********************************************************************************
173 inline Iterator end() {
174 return sv_.end();
175 }
176 //**********************************************************************************************
177
178 //**End function********************************************************************************
183 inline ConstIterator end() const {
184 return sv_.cend();
185 }
186 //**********************************************************************************************
187
188 //**Cend function*******************************************************************************
193 inline ConstIterator cend() const {
194 return sv_.cend();
195 }
196 //**********************************************************************************************
197
198 //**Size function*******************************************************************************
203 inline size_t size() const noexcept {
204 return sv_.size();
205 }
206 //**********************************************************************************************
207
208 //**Capacity function***************************************************************************
213 inline size_t capacity() const noexcept {
214 return sv_.capacity();
215 }
216 //**********************************************************************************************
217
218 //**NonZeros function***************************************************************************
223 inline size_t nonZeros() const {
224 return sv_.nonZeros();
225 }
226 //**********************************************************************************************
227
228 //**Reset function******************************************************************************
233 inline void reset() {
234 return sv_.reset();
235 }
236 //**********************************************************************************************
237
238 //**Insert function*****************************************************************************
250 inline Iterator insert( size_t index, const ElementType& value ) {
251 return sv_.insert( index, value );
252 }
253 //**********************************************************************************************
254
255 //**Find function*******************************************************************************
268 inline Iterator find( size_t index ) {
269 return sv_.find( index );
270 }
271 //**********************************************************************************************
272
273 //**Reserve function****************************************************************************
282 inline void reserve( size_t nonzeros ) {
283 sv_.reserve( nonzeros );
284 }
285 //**********************************************************************************************
286
287 //**Append function*****************************************************************************
312 inline void append( size_t index, const ElementType& value, bool check=false ) {
313 sv_.append( index, value, check );
314 }
315 //**********************************************************************************************
316
317 //**IsIntact function***************************************************************************
322 inline bool isIntact() const noexcept
323 {
324 using blaze::isIntact;
325 return isIntact( sv_ );
326 }
327 //**********************************************************************************************
328
329 //**CanAlias function***************************************************************************
335 template< typename Other > // Data type of the foreign expression
336 inline bool canAlias( const Other* alias ) const noexcept
337 {
338 return sv_.canAlias( alias );
339 }
340 //**********************************************************************************************
341
342 //**IsAliased function**************************************************************************
348 template< typename Other > // Data type of the foreign expression
349 inline bool isAliased( const Other* alias ) const noexcept
350 {
351 return sv_.isAliased( alias );
352 }
353 //**********************************************************************************************
354
355 //**CanSMPAssign function***********************************************************************
360 inline bool canSMPAssign() const noexcept
361 {
362 return sv_.canSMPAssign();
363 }
364 //**********************************************************************************************
365
366 //**Transpose assignment of vectors*************************************************************
377 template< typename VT2 > // Type of the right-hand side vector
378 inline void assign( const Vector<VT2,TF>& rhs )
379 {
381
382 sv_.assign( trans( *rhs ) );
383 }
384 //**********************************************************************************************
385
386 private:
387 //**********************************************************************************************
395 inline size_t extendCapacity() const noexcept
396 {
397 using blaze::max;
398 using blaze::min;
399
400 size_t nonzeros( 2UL*sv_.capacity()+1UL );
401 nonzeros = max( nonzeros, 7UL );
402 nonzeros = min( nonzeros, sv_.size() );
403
404 BLAZE_INTERNAL_ASSERT( nonzeros > sv_.capacity(), "Invalid capacity value" );
405
406 return nonzeros;
407 }
408 //**********************************************************************************************
409
410 //**Member variables****************************************************************************
411 VT& sv_;
412 //**********************************************************************************************
413
414 //**Compile time checks*************************************************************************
420 //**********************************************************************************************
421};
422//*************************************************************************************************
423
424
425
426
427//=================================================================================================
428//
429// GLOBAL OPERATORS
430//
431//=================================================================================================
432
433//*************************************************************************************************
441template< typename VT // Type of the sparse vector
442 , bool TF > // Transpose flag
443inline bool isIntact( const SVecTransposer<VT,TF>& v ) noexcept
444{
445 return v.isIntact();
446}
448//*************************************************************************************************
449
450
451
452
453//=================================================================================================
454//
455// SIZE SPECIALIZATIONS
456//
457//=================================================================================================
458
459//*************************************************************************************************
461template< typename VT, bool TF >
462struct Size< SVecTransposer<VT,TF>, 0UL >
463 : public Size<VT,0UL>
464{};
466//*************************************************************************************************
467
468
469
470
471//=================================================================================================
472//
473// MAXSIZE SPECIALIZATIONS
474//
475//=================================================================================================
476
477//*************************************************************************************************
479template< typename VT, bool TF >
480struct MaxSize< SVecTransposer<VT,TF>, 0UL >
481 : public MaxSize<VT,0UL>
482{};
484//*************************************************************************************************
485
486} // namespace blaze
487
488#endif
Header file for auxiliary alias declarations.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition Aliases.h:470
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.
Definition Aliases.h:170
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition Aliases.h:130
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition Aliases.h:390
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition Aliases.h:210
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition Aliases.h:550
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition Aliases.h:190
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition Aliases.h:450
Header file for run time assertion macros.
Header file for the isDefault shim.
Deactivation of problematic macros.
Header file for the MaxSize type trait.
Expression object for the transposition of a sparse vector.
Definition SVecTransposer.h:77
ElementType_t< VT > ElementType
Resulting element type.
Definition SVecTransposer.h:84
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse vector.
Definition SVecTransposer.h:250
ConstReference at(size_t index) const
Checked access to the vector elements.
Definition SVecTransposer.h:130
Iterator begin()
Returns an iterator to the first non-zero element of the sparse vector.
Definition SVecTransposer.h:143
ResultType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition SVecTransposer.h:83
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition SVecTransposer.h:336
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition SVecTransposer.h:98
ConstIterator cbegin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition SVecTransposer.h:163
size_t capacity() const noexcept
Returns the maximum capacity of the vector.
Definition SVecTransposer.h:213
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition SVecTransposer.h:183
const This & CompositeType
Data type for composite expression templates.
Definition SVecTransposer.h:86
ConstReference_t< VT > ConstReference
Reference to a constant matrix value.
Definition SVecTransposer.h:88
SVecTransposer< VT, TF > This
Type of this SVecTransposer instance.
Definition SVecTransposer.h:80
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition SVecTransposer.h:193
void reset()
Resets the vector elements.
Definition SVecTransposer.h:233
ConstReference operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition SVecTransposer.h:117
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition SVecTransposer.h:223
ConstIterator_t< VT > ConstIterator
Iterator over constant elements.
Definition SVecTransposer.h:90
Iterator_t< VT > Iterator
Iterator over non-constant elements.
Definition SVecTransposer.h:89
Iterator find(size_t index)
Inserting an element into the sparse vector.
Definition SVecTransposer.h:268
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition SVecTransposer.h:85
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse vector.
Definition SVecTransposer.h:282
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition SVecTransposer.h:153
TransposeType_t< VT > ResultType
Result type for expression template evaluations.
Definition SVecTransposer.h:82
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition SVecTransposer.h:360
VT & sv_
The sparse vector operand.
Definition SVecTransposer.h:411
Reference_t< VT > Reference
Reference to a non-constant matrix value.
Definition SVecTransposer.h:87
SVecTransposer(VT &sv) noexcept
Constructor for the SVecTransposer class.
Definition SVecTransposer.h:106
void assign(const Vector< VT2, TF > &rhs)
Implementation of the transpose assignment of a vector.
Definition SVecTransposer.h:378
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition SVecTransposer.h:203
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse vector.
Definition SVecTransposer.h:312
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition SVecTransposer.h:349
Iterator end()
Returns an iterator just past the last non-zero element of the sparse vector.
Definition SVecTransposer.h:173
SparseVector< This, TF > BaseType
Base type of this SVecTransposer instance.
Definition SVecTransposer.h:81
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition SVecTransposer.h:395
bool isIntact() const noexcept
Returns whether the invariants of the vector are intact.
Definition SVecTransposer.h:322
Base class for N-dimensional vectors.
Definition Vector.h:82
Constraint on the data type.
Constraint on the data type.
Header file for the SparseVector base class.
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:1339
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:1375
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition DMatTransExpr.h:766
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition DiagonalMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition SparseVector.h:61
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition Assert.h:117
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition Exception.h:331
Header file for the exception macros of the math module.
Constraint on the data type.
Header file for the Size type trait.
Compile time evaluation of the maximum size of vectors and matrices.
Definition MaxSize.h:118
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.