35#ifndef _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
36#define _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
215template<
typename Type
219 :
public SparseVector< CompressedVector<Type,TF,Tag>, TF >
239 Element(
const Element& rhs ) =
default;
240 Element( Element&& rhs ) =
default;
244 inline Element&
operator=(
const Element& rhs )
246 this->value_ = rhs.value_;
250 inline Element&
operator=( Element&& rhs )
252 this->value_ = std::move( rhs.value_ );
256 template<
typename Other >
257 inline auto operator=(
const Other& rhs )
260 this->value_ = rhs.value();
264 template<
typename Other >
269 this->value_ = std::move( rhs.value() );
273 template<
typename Other >
281 template<
typename Other >
286 this->value_ = std::move( v );
321 template<
typename NewType >
330 template<
size_t NewN >
391 template< typename VT > inline
CompressedVector& operator= ( const SparseVector<VT,TF>& rhs ) &;
395 template< typename VT > inline
CompressedVector& operator*=( const SparseVector<VT,TF>& rhs ) &;
404 inline
size_t size() const noexcept;
409 inline
void resize(
size_t n,
bool preserve=true );
421 inline
void append(
size_t index, const
Type& value,
bool check=false );
433 inline
void erase( Pred predicate );
435 template< typename Pred >
455 template< typename Other > inline
CompressedVector& scale( const Other& scalar );
462 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
463 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
468 template< typename VT > inline
void assign ( const SparseVector<VT,TF>& rhs );
470 template< typename VT > inline
void addAssign ( const SparseVector<VT,TF>& rhs );
472 template< typename VT > inline
void subAssign ( const SparseVector<VT,TF>& rhs );
528template< typename
Type
545template<
typename Type
562template<
typename Type
580template<
typename Type
607template<
typename Type
615 for(
const Type& element : list ) {
632template<
typename Type
649template<
typename Type
671template<
typename Type
674template<
typename VT >
692template<
typename Type
695template<
typename VT >
719template<
typename Type
748template<
typename Type
767template<
typename Type
777 if( pos ==
end_ || pos->index_ != index )
797template<
typename Type
803 if( index >=
size_ ) {
806 return (*
this)[index];
821template<
typename Type
827 if( index >=
size_ ) {
830 return (*
this)[index];
840template<
typename Type
856template<
typename Type
872template<
typename Type
888template<
typename Type
904template<
typename Type
920template<
typename Type
955template<
typename Type
963 resize( list.size(),
false );
968 for(
const Type& element : list ) {
988template<
typename Type
996 if( &rhs ==
this )
return *
this;
998 const size_t nonzeros( rhs.nonZeros() );
1025template<
typename Type
1039 rhs.capacity_ = 0UL;
1040 rhs.begin_ =
nullptr;
1057template<
typename Type
1060template<
typename VT >
1064 using blaze::assign;
1068 if( (*rhs).canAlias(
this ) ) {
1073 size_ = (*rhs).size();
1092template<
typename Type
1095template<
typename VT >
1099 using blaze::assign;
1103 if( (*rhs).canAlias(
this ) || (*rhs).nonZeros() >
capacity_ ) {
1108 size_ = (*rhs).size();
1131template<
typename Type
1134template<
typename VT >
1138 using blaze::addAssign;
1142 if( (*rhs).size() !=
size_ ) {
1165template<
typename Type
1168template<
typename VT >
1172 using blaze::subAssign;
1176 if( (*rhs).size() !=
size_ ) {
1200template<
typename Type
1203template<
typename VT >
1207 using blaze::multAssign;
1211 if( (*rhs).size() !=
size_ ) {
1215 if( (*rhs).canAlias(
this ) ) {
1240template<
typename Type
1243template<
typename VT >
1245 CompressedVector<Type,TF,Tag>::operator*=(
const SparseVector<VT,TF>& rhs ) &
1249 if( (*rhs).size() !=
size_ ) {
1276template<
typename Type
1279template<
typename VT >
1283 using blaze::divAssign;
1287 if( (*rhs).size() !=
size_ ) {
1291 if( (*rhs).canAlias(
this ) ) {
1316template<
typename Type
1319template<
typename VT >
1323 using blaze::assign;
1336 if(
size_ != 3UL || (*rhs).size() != 3UL ) {
1341 const CrossType tmp( *
this % (*rhs) );
1367template<
typename Type
1382template<
typename Type
1400template<
typename Type
1415template<
typename Type
1432template<
typename Type
1457template<
typename Type
1483template<
typename Type
1491 const size_t newCapacity( n );
1515template<
typename Type
1533template<
typename Type
1556template<
typename Type
1565 nonzeros =
max( nonzeros, 7UL );
1583template<
typename Type
1589 return static_cast<Iterator>( it );
1602template<
typename Type
1632template<
typename Type
1642 if( pos !=
end_ && pos->index_ == index ) {
1643 pos->value() = value;
1646 else return insert( pos, index, value );
1663template<
typename Type
1673 if( pos !=
end_ && pos->index_ == index ) {
1677 return insert( pos, index, value );
1691template<
typename Type
1701 pos->value_ = value;
1702 pos->index_ = index;
1712 tmp->value_ = value;
1713 tmp->index_ = index;
1750template<
typename Type
1759 end_->value_ = value;
1762 end_->index_ = index;
1785template<
typename Type
1807template<
typename Type
1831template<
typename Type
1869template<
typename Type
1872template<
typename Pred
1877 [predicate=predicate](
const ElementBase& element ) {
1878 return predicate( element.
value() );
1907template<
typename Type
1910template<
typename Pred >
1917 const auto pos = std::remove_if(
castUp( first ),
castUp( last ),
1918 [predicate=predicate](
const ElementBase& element ) {
1919 return predicate( element.
value() );
1948template<
typename Type
1954 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( index ) );
1972template<
typename Type
1979 if( pos !=
end_ && pos->index_ == index )
1998template<
typename Type
2004 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( index ) );
2021template<
typename Type
2027 return std::lower_bound(
begin_,
end_, index,
2028 [](
const Element& element,
size_t i )
2030 return element.index() < i;
2048template<
typename Type
2054 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( index ) );
2071template<
typename Type
2077 return std::upper_bound(
begin_,
end_, index,
2078 [](
size_t i,
const Element& element )
2080 return i < element.index();
2111template<
typename Type
2114template<
typename Other >
2117 for(
auto element=
begin_; element!=
end_; ++element )
2118 element->value_ *= scalar;
2142template<
typename Type
2145template<
typename Other >
2148 return static_cast<const void*
>( this ) ==
static_cast<const void*
>( alias );
2163template<
typename Type
2166template<
typename Other >
2169 return static_cast<const void*
>( this ) ==
static_cast<const void*
>( alias );
2184template<
typename Type
2205template<
typename Type
2208template<
typename VT >
2214 size_t nonzeros( 0UL );
2216 for(
size_t i=0UL; i<
size_; ++i )
2221 end_->value_ = (*rhs)[i];
2244template<
typename Type
2247template<
typename VT >
2259 for(
auto element=(*rhs).begin(); element!=(*rhs).end(); ++element )
2260 append( element->index(), element->value() );
2276template<
typename Type
2279template<
typename VT >
2290 const AddType tmp(
serial( *
this + (*rhs) ) );
2308template<
typename Type
2311template<
typename VT >
2333template<
typename Type
2336template<
typename VT >
2347 const SubType tmp(
serial( *
this - (*rhs) ) );
2365template<
typename Type
2368template<
typename VT >
2390template<
typename Type
2393template<
typename VT >
2400 for(
auto element=
begin_; element!=
end_; ++element ) {
2401 element->value_ *= (*rhs)[element->index_];
2418template<
typename Type
2421template<
typename VT >
2428 for(
auto element=
begin_; element!=
end_; ++element ) {
2429 element->value_ /= (*rhs)[element->index_];
2446template< RelaxationFlag RF,
typename Type,
bool TF,
typename Tag >
2449template<
typename Type,
bool TF,
typename Tag >
2452template<
typename Type,
bool TF,
typename Tag >
2488 return ( v.
size() == 0UL );
2511template<
typename Type
2516 return ( v.nonZeros() <= v.capacity() );
2529template<
typename Type
2549template<
typename T1,
typename T2 >
2550struct AddTraitEval2< T1, T2
2553 using Type = CompressedVector< AddTrait_t< ElementType_t<T1>, ElementType_t<T2> >
2571template<
typename T1,
typename T2 >
2572struct SubTraitEval2< T1, T2
2593template<
typename T1,
typename T2 >
2594struct MultTraitEval2< T1, T2
2602template<
typename T1,
typename T2 >
2603struct MultTraitEval2< T1, T2
2611template<
typename T1,
typename T2 >
2612struct MultTraitEval2< T1, T2
2622template<
typename T1,
typename T2 >
2623struct MultTraitEval2< T1, T2
2636template<
typename T1,
typename T2 >
2637struct MultTraitEval2< T1, T2
2663template<
typename T1
2665struct KronTraitEval2< T1, T2
2688template<
typename T1,
typename T2 >
2689struct DivTraitEval2< T1, T2
2697template<
typename T1,
typename T2 >
2698struct DivTraitEval2< T1, T2
2719template<
typename T,
typename OP >
2720struct UnaryMapTraitEval2< T, OP
2723 using ElementType =
decltype( std::declval<OP>()( std::declval< ElementType_t<T> >() ) );
2725 using Type = CompressedVector< EvaluateTrait_t<ElementType>
2726 , TransposeFlag_v<T>
2727 , MapTrait_t< TagType_t<T>, OP > >;
2743template<
typename T,
size_t R0 >
2744struct RepeatTraitEval2< T, R0,
inf,
inf
2747 using Type = CompressedVector< ElementType_t<T>
2748 , TransposeFlag_v<T>
2765template<
typename T1,
bool TF,
typename Tag,
typename T2 >
2768 using Type = CompressedVector< typename HighType<T1,T2>::Type, TF, Tag >;
2784template<
typename T1,
bool TF,
typename Tag,
typename T2 >
2787 using Type = CompressedVector< typename LowType<T1,T2>::Type, TF, Tag >;
2803template<
typename VT,
size_t I,
size_t N >
2804struct SubvectorTraitEval2< VT, I, N
2807 using Type = CompressedVector< RemoveConst_t< ElementType_t<VT> >
2808 , TransposeFlag_v<VT>
2825template<
typename VT,
size_t N >
2826struct ElementsTraitEval2< VT, N
2829 using Type = CompressedVector< RemoveConst_t< ElementType_t<VT> >
2830 , TransposeFlag_v<VT>
2847template<
typename MT,
size_t I >
2848struct RowTraitEval2< MT, I
2851 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
2869template<
typename MT,
size_t I >
2870struct ColumnTraitEval2< MT, I
2873 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
2891template<
typename MT, ptrdiff_t I >
2892struct BandTraitEval2< MT, I
2895 using Type = CompressedVector< RemoveConst_t< ElementType_t<MT> >
Header file for the addition trait.
Header file for auxiliary alias declarations.
typename ResultType_t< T >::TagType TagType_t
Alias declaration for nested TagType type definitions.
Definition Aliases.h:530
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition Aliases.h:110
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 band trait.
Header file for the column trait.
Constraint on the data type.
Header file for the cross product trait.
Header file for the division trait.
Header file for the elements trait.
Header file for the EnableIf class template.
Header file for the EvaluateTrait class template.
Header file for the HighType type trait.
Header file for the IntegralConstant class template.
Header file for the IsColumnVector type trait.
Header file for the isDefault shim.
Header file for the IsDenseVector type trait.
Header file for the IsFloatingPoint type trait.
Header file for the IsIntegral type trait.
Header file for the IsRowVector type trait.
Header file for the IsSMPAssignable type trait.
Header file for the IsScalar type trait.
Header file for the IsSparseMatrix type trait.
Header file for the IsSparseVector type trait.
Header file for the IsVector type trait.
Header file for the Kron product trait.
Header file for the LowType type trait.
Header file for the map trait.
Header file for memory allocation and deallocation functionality.
Header file for the multiplication trait.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Header file for the RemoveConst type trait.
Header file for the repeat trait.
Header file for the row trait.
Constraint on the size of two data types.
Header file for the subtraction trait.
Header file for the subvector trait.
Header file for the generic transfer algorithm.
Header file for the ValueIndexPair class.
Header file for the VectorAccessProxy class.
Constraint on the data type.
Efficient implementation of an arbitrary sized sparse vector.
Definition CompressedVector.h:220
bool canAlias(const Other *alias) const noexcept
SparseVector< This, TF > BaseType
Base type of this CompressedVector instance.
Definition CompressedVector.h:301
Iterator insert(size_t index, const Type &value)
size_t capacity() const noexcept
ConstIterator cbegin() const noexcept
const CompressedVector & CompositeType
Definition CompressedVector.h:310
Iterator begin_
Definition CompressedVector.h:500
void swap(CompressedVector &sv) noexcept
size_t size() const noexcept
Iterator begin() noexcept
Iterator end_
Definition CompressedVector.h:501
Tag TagType
Definition CompressedVector.h:308
void subAssign(const DenseVector< VT, TF > &rhs)
void assign(const DenseVector< VT, TF > &rhs)
ConstIterator cend() const noexcept
This ResultType
Result type for expression template evaluations.
Definition CompressedVector.h:302
Type ElementType
Definition CompressedVector.h:307
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the compressed vector elements.
Definition CompressedVector.h:752
ElementBase * IteratorBase
Iterator over non-constant base elements.
Definition CompressedVector.h:224
bool isAliased(const Other *alias) const noexcept
size_t extendCapacity() const noexcept
static const Type zero_
Definition CompressedVector.h:503
void divAssign(const DenseVector< VT, TF > &rhs)
void multAssign(const DenseVector< VT, TF > &rhs)
void resize(size_t n, bool preserve=true)
Iterator castDown(IteratorBase it) const noexcept
Reference at(size_t index)
bool canSMPAssign() const noexcept
void addAssign(const DenseVector< VT, TF > &rhs)
void append(size_t index, const Type &value, bool check=false)
IteratorBase castUp(Iterator it) const noexcept
CompressedVector() noexcept
The default constructor for CompressedVector.
Definition CompressedVector.h:548
const Type & ReturnType
Definition CompressedVector.h:309
Iterator upperBound(size_t index)
Element * Iterator
Definition CompressedVector.h:314
Iterator find(size_t index)
static constexpr bool smpAssignable
Definition CompressedVector.h:341
~CompressedVector()
The destructor for CompressedVector.
Definition CompressedVector.h:722
VectorAccessProxy< This > Reference
Definition CompressedVector.h:312
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition CompressedVector.h:223
size_t size_
Definition CompressedVector.h:498
Iterator lowerBound(size_t index)
CompressedVector & operator=(initializer_list< Type > list) &
List assignment to all vector elements.
Definition CompressedVector.h:959
CompressedVector< Type,!TF, Tag > TransposeType
Transpose type for expression template evaluations.
Definition CompressedVector.h:305
size_t capacity_
Definition CompressedVector.h:499
CompressedVector< Type, TF, Tag > This
Type of this CompressedVector instance.
Definition CompressedVector.h:300
const Element * ConstIterator
Definition CompressedVector.h:315
const Type & ConstReference
Definition CompressedVector.h:313
Iterator set(size_t index, const Type &value)
Base class for N-dimensional dense vectors.
Definition DenseVector.h:77
Index-value-pair for sparse vectors and matrices.
Definition ValueIndexPair.h:75
constexpr Reference value() noexcept
Access to the current value of the value-index-pair.
Definition ValueIndexPair.h:370
Access proxy for sparse, N-dimensional vectors.
Definition VectorAccessProxy.h:101
Base class for N-dimensional vectors.
Definition Vector.h:82
Initializer list type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Header file for the DenseVector base class.
Header file for the SparseVector base class.
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition Transfer.h:71
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.
Definition SameSize.h:60
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition Reference.h:60
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition Const.h:79
#define BLAZE_CONSTRAINT_MUST_BE_SAME_TAG(A, B)
Data type constraint.
Definition SameTag.h:68
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition Reference.h:79
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) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition DMatSerialExpr.h:812
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition DiagonalMatrix.h:207
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition DiagonalMatrix.h:225
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.
Definition TransposeFlag.h:63
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition DenseVector.h:61
typename CrossTrait< T1, T2 >::Type CrossTrait_t
Auxiliary alias declaration for the CrossTrait class template.
Definition CrossTrait.h:138
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.
Definition SubTrait.h:163
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.
Definition AddTrait.h:163
typename DivTrait< T1, T2 >::Type DivTrait_t
Auxiliary alias declaration for the DivTrait class template.
Definition DivTrait.h:164
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition MultTrait.h:165
constexpr bool IsScalar_v
Auxiliary variable template for the IsScalar type trait.
Definition IsScalar.h:104
constexpr bool IsVector_v
Auxiliary variable template for the IsVector type trait.
Definition IsVector.h:125
constexpr bool IsZero_v
Auxiliary variable template for the IsZero type trait.
Definition IsZero.h:166
constexpr bool IsColumnVector_v
Auxiliary variable template for the IsColumnVector type trait.
Definition IsColumnVector.h:126
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.
Definition IsSparseMatrix.h:124
constexpr bool IsSMPAssignable_v
Auxiliary variable template for the IsSMPAssignable type trait.
Definition IsSMPAssignable.h:132
constexpr bool IsRowVector_v
Auxiliary variable template for the IsRowVector type trait.
Definition IsRowVector.h:126
constexpr bool IsSparseVector_v
Auxiliary variable template for the IsSparseVector type trait.
Definition IsSparseVector.h:124
constexpr bool TransposeFlag_v
Auxiliary variable template for the TransposeFlag type trait.
Definition TransposeFlag.h:93
constexpr bool IsDenseVector_v
Auxiliary variable template for the IsDenseVector type trait.
Definition IsDenseVector.h:124
RelaxationFlag
Relaxation flag for strict or relaxed semantics.
Definition RelaxationFlag.h:66
constexpr Infinity inf
Global Infinity instance.
Definition Infinity.h:1080
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition Matrix.h:730
#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
constexpr bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.
Definition TransposeFlag.h:75
constexpr bool IsRValueReference_v
Auxiliary variable template for the IsRValueReference type trait.
Definition IsRValueReference.h:97
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.
Definition IsIntegral.h:95
void deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition Memory.h:230
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:138
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition Exception.h:235
T * allocate(size_t size)
Aligned array allocation for built-in data types.
Definition Memory.h:158
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition EnableIf.h:175
Header file for the exception macros of the math module.
Header file for all forward declarations of the math module.
Header file for the extended initializer_list functionality.
Constraint on the data type.
Header file for all forward declarations for sparse vectors and matrices.
Header file for the TransposeFlag type trait.
Header file for the serial shim.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition CompressedVector.h:322
CompressedVector< NewType, TF, Tag > Other
The type of the other CompressedVector.
Definition CompressedVector.h:323
Resize mechanism to obtain a CompressedVector with a different fixed number of elements.
Definition CompressedVector.h:331
CompressedVector< Type, TF, Tag > Other
The type of the other CompressedVector.
Definition CompressedVector.h:332
Base template for the HighType type trait.
Definition HighType.h:322
Base template for the LowType type trait.
Definition LowType.h:322
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the IsZero type trait.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.