35 #ifndef _BLAZE_MATH_VIEWS_SPARSESUBVECTOR_H_
36 #define _BLAZE_MATH_VIEWS_SPARSESUBVECTOR_H_
319 template<
typename VT
320 ,
bool TF = IsRowVector<VT>::value >
321 class SparseSubvector :
public SparseVector< SparseSubvector<VT,TF>, TF >
361 ,
typename IteratorType >
469 return pos_->value();
495 ,
typename IteratorType >
540 template<
typename VectorType2,
typename IteratorType2 >
596 template<
typename VectorType2,
typename IteratorType2 >
608 template<
typename VectorType2,
typename IteratorType2 >
610 return !( *
this == rhs );
633 template<
typename VectorType2,
typename IteratorType2 >
friend class SubvectorIterator;
684 template<
typename Other >
686 operator*=( Other rhs );
688 template<
typename Other >
690 operator/=( Other rhs );
697 inline size_t size()
const;
702 inline void erase (
size_t index );
705 inline void reserve(
size_t n );
706 template<
typename Other >
inline SparseSubvector& scale ( Other scalar );
732 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
733 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
755 template<
typename VT2,
bool TF2 >
792 template<
typename VT
799 if( index + n > vector.size() )
800 throw std::invalid_argument(
"Invalid subvector specification" );
819 template<
typename VT
825 return vector_[offset_+index];
836 template<
typename VT
842 return const_cast<const VT&
>( vector_ )[offset_+index];
854 template<
typename VT
859 return Iterator( vector_.begin(), offset_ );
861 return Iterator( vector_.lowerBound( offset_ ), offset_ );
873 template<
typename VT
880 return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
892 template<
typename VT
899 return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
911 template<
typename VT
915 if( offset_ + size_ == vector_.size() )
916 return Iterator( vector_.end(), offset_ );
918 return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
930 template<
typename VT
934 if( offset_ + size_ == vector_.size() )
937 return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
949 template<
typename VT
953 if( offset_ + size_ == vector_.size() )
956 return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
979 template<
typename VT
988 if(
this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
991 if( size() != rhs.size() )
992 throw std::invalid_argument(
"Vector sizes do not match" );
994 if( rhs.canAlias( &vector_ ) ) {
1019 template<
typename VT
1021 template<
typename VT2 >
1030 if( size() != (~rhs).size() )
1031 throw std::invalid_argument(
"Vector sizes do not match" );
1058 template<
typename VT
1060 template<
typename VT2 >
1069 if( size() != (~rhs).size() )
1070 throw std::invalid_argument(
"Vector sizes do not match" );
1097 template<
typename VT
1099 template<
typename VT2 >
1104 if( size() != (~rhs).size() )
1105 throw std::invalid_argument(
"Vector sizes do not match" );
1124 template<
typename VT
1126 template<
typename VT2 >
1131 if( size() != (~rhs).size() )
1132 throw std::invalid_argument(
"Vector sizes do not match" );
1152 template<
typename VT
1154 template<
typename VT2 >
1157 if( size() != (~rhs).size() )
1158 throw std::invalid_argument(
"Vector sizes do not match" );
1166 const MultType tmp( *
this * (~rhs) );
1186 template<
typename VT
1188 template<
typename Other >
1193 for(
Iterator element=begin(); element!=last; ++element )
1194 element->value() *= rhs;
1212 template<
typename VT
1214 template<
typename Other >
1228 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1229 for(
Iterator element=begin(); element!=last; ++element )
1230 element->value() *= tmp;
1233 for(
Iterator element=begin(); element!=last; ++element )
1234 element->value() /= rhs;
1255 template<
typename VT
1269 template<
typename VT
1273 return nonZeros() + vector_.capacity() - vector_.nonZeros();
1285 template<
typename VT
1289 return end() - begin();
1299 template<
typename VT
1303 vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1320 template<
typename VT
1325 return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1338 template<
typename VT
1342 vector_.erase( offset_ + index );
1355 template<
typename VT
1359 return Iterator( vector_.erase( pos.pos_ ), offset_ );
1373 template<
typename VT
1377 return Iterator( vector_.erase( first.pos_, last.pos_ ), offset_ );
1391 template<
typename VT
1395 const size_t current( capacity() );
1398 vector_.reserve( vector_.capacity() + n - current );
1410 template<
typename VT
1412 template<
typename Other >
1415 for(
Iterator element=begin(); element!=end(); ++element )
1416 element->value() *= scalar;
1443 template<
typename VT
1447 const typename VT::Iterator pos( vector_.find( offset_ + index ) );
1449 if( pos != vector_.end() )
1470 template<
typename VT
1476 if( pos != vector_.end() )
1496 template<
typename VT
1500 return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1517 template<
typename VT
1521 return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1538 template<
typename VT
1542 return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1559 template<
typename VT
1563 return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1600 template<
typename VT
1604 if( offset_ + size_ == vector_.size() )
1605 vector_.append( offset_ + index, value, check );
1606 else if( !check || !
isDefault( value ) )
1607 vector_.insert( offset_ + index, value );
1630 template<
typename VT
1632 template<
typename Other >
1635 return static_cast<const void*
>( &vector_ ) == static_cast<const void*>( alias );
1650 template<
typename VT
1652 template<
typename Other >
1655 return static_cast<const void*
>( &vector_ ) == static_cast<const void*>( alias );
1671 template<
typename VT
1673 template<
typename VT2 >
1679 reserve( (~rhs).size() );
1681 for(
size_t i=0UL; i<size(); ++i ) {
1682 append( i, (~rhs)[i],
true );
1699 template<
typename VT
1701 template<
typename VT2 >
1707 reserve( (~rhs).nonZeros() );
1709 for(
typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1710 append( element->index(), element->value(), true );
1727 template<
typename VT
1729 template<
typename VT2 >
1740 const AddType tmp( *
this + (~rhs) );
1758 template<
typename VT
1760 template<
typename VT2 >
1771 const AddType tmp( *
this + (~rhs) );
1789 template<
typename VT
1791 template<
typename VT2 >
1802 const SubType tmp( *
this - (~rhs) );
1820 template<
typename VT
1822 template<
typename VT2 >
1833 const SubType tmp( *
this - (~rhs) );
1855 template<
typename VT,
bool TF >
1858 template<
typename VT,
bool TF >
1861 template<
typename VT,
bool TF >
1874 template<
typename VT
1892 template<
typename VT
1919 template<
typename VT
1925 const ConstIterator end( sv.end() );
1926 for( ConstIterator element=sv.begin(); element!=end; ++element )
1927 if( !
isDefault( element->value() ) )
return false;
1969 template<
typename VT
1971 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >, SparseSubvector<VT> >::Type
2009 template<
typename VT
2011 inline typename DisableIf< Or< IsComputation<VT>, IsTransExpr<VT> >, SparseSubvector<const VT> >::Type
2042 template<
typename VT
2044 inline SparseSubvector<VT,TF>
2045 subvector(
const SparseSubvector<VT,TF>& sv,
size_t index,
size_t size )
2049 return SparseSubvector<VT,TF>( sv.vector_, sv.offset_ + index, size );
2065 template<
typename VT,
bool TF >
2066 struct SubvectorTrait< SparseSubvector<VT,TF> >
2084 template<
typename VT,
bool TF >
2085 struct SubvectorExprTrait< SparseSubvector<VT,TF> >
2087 typedef SparseSubvector<VT,TF> Type;
2095 template<
typename VT,
bool TF >
2096 struct SubvectorExprTrait< const SparseSubvector<VT,TF> >
2098 typedef SparseSubvector<VT,TF> Type;
2106 template<
typename VT,
bool TF >
2107 struct SubvectorExprTrait< volatile SparseSubvector<VT,TF> >
2109 typedef SparseSubvector<VT,TF> Type;
2117 template<
typename VT,
bool TF >
2118 struct SubvectorExprTrait< const volatile SparseSubvector<VT,TF> >
2120 typedef SparseSubvector<VT,TF> Type;
Constraint on the data type.
Pointer difference type of the Blaze library.
ReferenceType value() const
Access to the current value of the sparse subvector element.
Definition: SparseSubvector.h:468
View on a specific subvector of a sparse vector.The SparseSubvector template represents a view on a s...
Definition: Forward.h:54
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#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
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
PointerType pointer
Pointer return type.
Definition: SparseSubvector.h:509
Header file for the subtraction trait.
SelectType< useConst, ConstReference, typename VT::Reference >::Type Reference
Reference to a non-constant subvector value.
Definition: SparseSubvector.h:354
Header file for the SparseVector base class.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubvector.h:504
Header file for the View base class.
SelectType< returnConst, const ElementType &, ElementType & >::Type ReferenceType
Return type of the value member function.
Definition: SparseSubvector.h:378
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4555
PointerType operator->() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:585
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubvector.h:344
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
#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
SubvectorIterator(IteratorType pos, size_t offset)
Constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:529
size_t capacity() const
Returns the maximum capacity of the sparse subvector.
Definition: SparseSubvector.h:1271
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubvector.h:1540
Iterator begin()
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:856
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubvector.h:500
Header file for the IsRowVector type trait.
bool operator!=(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Inequality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:609
void assign(const DenseVector< VT2, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseSubvector.h:1674
Header file for the IsTransExpr type trait class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i...
Definition: TransExpr.h:118
Operand vector_
The sparse vector containing the subvector.
Definition: SparseSubvector.h:747
Header file for the RequiresEvaluation type trait.
void reserve(size_t n)
Setting the minimum capacity of the sparse subvector.
Definition: SparseSubvector.h:1393
const size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:748
SubvectorElement & operator=(const T &v)
Assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:399
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4528
SubvectorIterator & operator++()
Pre-increment operator.
Definition: SparseSubvector.h:552
SubvectorIterator< const VT, typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubvector.h:642
size_t nonZeros() const
Returns the number of non-zero elements in the subvector.
Definition: SparseSubvector.h:1287
IteratorType pos_
Iterator to the current position within the sparse subvector.
Definition: SparseSubvector.h:485
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:951
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:122
SubvectorElement & operator+=(const T &v)
Addition assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:411
SubvectorElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:435
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubvector.h:345
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseSubvector.h:1498
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:913
ReferenceType operator*() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:575
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
ValueType ReferenceType
Reference return type.
Definition: SparseSubvector.h:503
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
SubvectorIterator()
Default constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:517
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
Header file for the Or class template.
size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:628
SparseSubvector(VT &vector, size_t index, size_t n)
The constructor for SparseSubvector.
Definition: SparseSubvector.h:794
Header file for the subvector trait.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Access proxy for a specific element of the sparse subvector.
Definition: SparseSubvector.h:362
void erase(size_t index)
Erasing an element from the sparse subvector.
Definition: SparseSubvector.h:1340
Iterator find(size_t index)
Searches for a specific subvector element.
Definition: SparseSubvector.h:1445
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#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:79
Constraint on the data type.
Header file for the SparseElement base class.
Constraint on the data type.
Constraint on the data type.
const SubvectorElement * operator->() const
Direct access to the sparse subvector element at the current iterator position.
Definition: SparseSubvector.h:458
bool isAliased(const Other *alias) const
Returns whether the sparse subvector is aliased with the given address alias.
Definition: SparseSubvector.h:1653
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
Constraint on the data type.
Header file for the SelectType class template.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2377
Header file for the EnableIf class template.
const SparseSubvector & CompositeType
Data type for composite expression templates.
Definition: SparseSubvector.h:348
DifferenceType operator-(const SubvectorIterator &rhs) const
Calculating the number of elements between two subvector iterators.
Definition: SparseSubvector.h:620
Header file for the IsNumeric type trait.
Reference operator[](size_t index)
Subscript operator for the direct access to the subvector elements.
Definition: SparseSubvector.h:822
SelectType< IsExpression< VT >::value, VT, VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: SparseSubvector.h:327
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Header file for the IsConst type trait.
void reset()
Reset to the default initial values.
Definition: SparseSubvector.h:1301
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
Base template for the MultTrait class.
Definition: MultTrait.h:141
Header file for the addition trait.
Header file for the division trait.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
size_t index() const
Access to the current index of the sparse element.
Definition: SparseSubvector.h:478
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse subvector.
Definition: SparseSubvector.h:1323
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
size_t offset_
Offset within the according sparse vector.
Definition: SparseSubvector.h:486
SubvectorElement(IteratorType pos, size_t offset)
Constructor for the SubvectorElement class.
Definition: SparseSubvector.h:387
void addAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseSubvector.h:1730
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
SparseSubvector< VT, TF > This
Type of this SparseSubvector instance.
Definition: SparseSubvector.h:343
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2378
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubvector.h:511
Header file for the isDefault shim.
size_t size() const
Returns the size/dimension of the sparse subvector.
Definition: SparseSubvector.h:1257
SelectType< useConst, ConstIterator, SubvectorIterator< VT, typename VT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: SparseSubvector.h:645
SubvectorElement & operator/=(const T &v)
Division assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:447
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:118
ReferenceType reference
Reference return type.
Definition: SparseSubvector.h:510
VT VectorType
Type of the vector.
Definition: Vector.h:72
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse subvector.
Definition: SparseSubvector.h:1602
Base template for the DivTrait class.
Definition: DivTrait.h:141
ValueType value_type
Type of the underlying elements.
Definition: SparseSubvector.h:508
SubvectorIterator(const SubvectorIterator< VectorType2, IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: SparseSubvector.h:541
bool canAlias(const Other *alias) const
Returns whether the sparse subvector can alias with the given address alias.
Definition: SparseSubvector.h:1633
#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::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubvector.h:347
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:147
SubvectorElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:423
Header file for the IsComputation type trait class.
SparseSubvector & operator=(const SparseSubvector &rhs)
Copy assignment operator for SparseSubvector.
Definition: SparseSubvector.h:981
Iterator over the elements of the sparse subvector.
Definition: SparseSubvector.h:496
void subAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseSubvector.h:1792
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubvector.h:627
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: SparseSubvector.h:563
Base template for the SubTrait class.
Definition: SubTrait.h:141
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:894
VT::ElementType ElementType
Type of the subvector elements.
Definition: SparseSubvector.h:346
bool operator==(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:597
SubvectorElement< VectorType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubvector.h:501
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubvector.h:507
#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
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: SparseSubvector.h:351
#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
DisableIf< Or< IsComputation< VT >, IsTransExpr< VT > >, DenseSubvector< VT > >::Type subvector(DenseVector< VT, TF > &dv, size_t index, size_t size)
Creating a view on a specific subvector of the given dense vector.
Definition: DenseSubvector.h:2616
Header file for the IsExpression type trait class.
const size_t size_
The size of the subvector.
Definition: SparseSubvector.h:749
Header file for the FunctionTrace class.
ValueType PointerType
Pointer return type.
Definition: SparseSubvector.h:502