22 #ifndef _BLAZE_MATH_SPARSEVECTOR_H_
23 #define _BLAZE_MATH_SPARSEVECTOR_H_
69 template<
typename T1,
bool TF1,
typename T2,
bool TF2 >
70 inline bool operator==(
const SparseVector<T1,TF1>& lhs,
const SparseVector<T2,TF2>& rhs );
72 template<
typename T1,
bool TF1,
typename T2,
bool TF2 >
73 inline bool operator!=(
const SparseVector<T1,TF1>& lhs,
const SparseVector<T2,TF2>& rhs );
92 typedef typename T1::CompositeType CT1;
93 typedef typename T2::CompositeType CT2;
98 if( (~lhs).size() != (~rhs).size() )
return false;
106 const LhsConstIterator lend( a.end() );
107 const RhsConstIterator rend( b.end() );
109 LhsConstIterator lelem( a.begin() );
110 RhsConstIterator relem( b.begin() );
112 while( lelem < lend && relem < rend )
114 if(
isDefault( lelem->value() ) ) { ++lelem;
continue; }
115 if(
isDefault( relem->value() ) ) { ++relem;
continue; }
117 if( lelem->index() != relem->index() || !
equal( lelem->value(), relem->value() ) ) {
126 while( lelem < lend ) {
132 while( relem < rend ) {
151 template<
typename T1
157 return !( lhs == rhs );
173 template<
typename VT,
bool TF >
174 inline typename CMathTrait<typename VT::ElementType>::Type
length(
const SparseVector<VT,TF>& dv );
176 template<
typename VT,
bool TF >
177 inline const typename VT::ElementType
sqrLength(
const SparseVector<VT,TF>& dv );
179 template<
typename VT,
bool TF >
180 inline const typename VT::ElementType
min(
const SparseVector<VT,TF>& sv );
182 template<
typename VT,
bool TF >
183 inline const typename VT::ElementType
max(
const SparseVector<VT,TF>& sv );
220 template<
typename VT
224 typedef typename VT::ElementType ElementType;
225 typedef typename VT::ConstIterator ConstIterator;
231 for( ConstIterator element=(~sv).begin(); element!=(~sv).end(); ++element )
232 sum +=
sq( element->value() );
233 return std::sqrt( sum );
250 template<
typename VT
254 typedef typename VT::ElementType ElementType;
255 typedef typename VT::ConstIterator ConstIterator;
259 ElementType
sum( 0 );
260 for( ConstIterator element=(~sv).begin(); element!=(~sv).end(); ++element )
261 sum +=
sq( element->value() );
287 template<
typename VT
293 typedef typename VT::ElementType ET;
294 typedef typename VT::CompositeType SV;
299 const ConstIterator end( a.end() );
300 ConstIterator element( a.begin() );
302 if( element == end ) {
305 else if( a.nonZeros() == a.size() ) {
306 ET minimum( element->value() );
308 for( ; element!=end; ++element )
309 minimum =
min( minimum, element->value() );
314 for( ; element!=end; ++element )
315 minimum =
min( minimum, element->value() );
342 template<
typename VT
348 typedef typename VT::ElementType ET;
349 typedef typename VT::CompositeType SV;
354 const ConstIterator end( a.end() );
355 ConstIterator element( a.begin() );
357 if( element == end ) {
360 else if( a.nonZeros() == a.size() ) {
361 ET maximum( element->value() );
363 for( ; element!=end; ++element )
364 maximum =
max( maximum, element->value() );
369 for( ; element!=end; ++element )
370 maximum =
max( maximum, element->value() );