1 #ifndef SPARSEVECTOR_H_ 2 #define SPARSEVECTOR_H_ 10 #include "boost/type_traits.hpp" 23 template <
typename T >
62 template <
typename T,
typename TAccumulation >
70 template <
typename X >
71 void operator()(TAccumulation & storage, T value, X)
const { Self::store(storage, value); }
72 template <
typename X >
73 void operator()(TAccumulation & storage, T value, X, X)
const { Self::store(storage, value); }
74 template <
typename X >
75 void operator()(TAccumulation & storage, T value, X, X, X)
const { Self::store(storage, value); }
78 static void store(TAccumulation & storage, T value)
80 storage += TAccumulation(value);
85 template <
typename T >
109 template <
typename TFunctor >
115 template <
typename TFunctor,
typename TOutput =
typename TFunctor::result_type >
125 struct Default_Tag {};
127 template <
typename _T >
128 struct Tag {
typedef Default_Tag type; };
129 template <
typename _TKey,
typename _TValue >
130 struct Tag<std::pair<_TKey, _TValue> > {
typedef Pair_Tag type; };
132 template <
typename _T >
typename Tag<typename naked_type<_T>::type>::type tagOf(_T) {
return typename Tag<typename naked_type<_T>::type>::type (); }
156 template <
typename T1,
typename T2 >
159 return this->wrap(x1, tagOf(x1), x2, tagOf(x2));
193 template <
typename T1,
typename T2 >
194 TOutput wrap(T1 x1, Default_Tag, T2 x2, Default_Tag)
196 return m_functor(x1, x2);
199 template <
typename T1,
typename T2 >
200 TOutput wrap(T1 x1, Default_Tag, T2 & pair2, Pair_Tag)
202 return m_functor(x1, pair2.second);
205 template <
typename T1,
typename T2 >
206 TOutput wrap(T1 & pair1, Pair_Tag, T2 x2, Default_Tag)
208 return m_functor(pair1.second, x2);
211 template <
typename T1,
typename T2 >
212 TOutput wrap(T1 & pair1, Pair_Tag, T2 & pair2, Pair_Tag)
214 return m_functor(pair1.second, pair2.second);
229 template < typename TFunctor, typename TOutput = typename naked_type<TFunctor>::type::return_type >
243 template <
typename T1 >
245 {
return m_functor(x1); }
247 template <
typename T1,
typename T2 >
249 {
return m_functor(x1, x2); }
251 template <
typename T1,
typename T2,
typename T3 >
253 {
return m_functor(x1, x2, x3); }
261 template <
typename TFunctor >
265 template <
typename TFunctor >
275 template <
typename TFunctor,
typename TStorage,
typename TStoragePolicy >
284 StoreFunctor(
const TStorage & init) : m_functor(), m_data(init), m_storagePolicy() {}
287 const TStorage &
get()
const {
return m_data; }
305 template <
typename T1 >
307 { this->store<T1&>(x1); }
309 template <
typename T1 >
311 { this->store<const T1&>(x1); }
313 template <
typename T1,
typename T2 >
315 { this->store<T1&,T2&>(x1,x2); }
317 template <
typename T1,
typename T2 >
319 { this->store<T1&,const T2&>(x1,x2); }
321 template <
typename T1,
typename T2 >
323 { this->store<const T1&,T2&>(x1,x2); }
325 template <
typename T1,
typename T2 >
327 { this->store<const T1&,const T2&>(x1,x2); }
329 template <
typename T1,
typename T2,
typename T3 >
332 m_storagePolicy(m_data, m_functor(x1, x2, x3), x1, x2, x3);
337 template <
typename T1 >
340 m_storagePolicy(m_data, m_functor(x1), x1);
343 template <
typename T1,
typename T2 >
344 void store(T1 x1, T2 x2)
346 m_storagePolicy(m_data, m_functor(x1, x2), x1, x2);
353 TStoragePolicy m_storagePolicy;
361 template <
typename T >
371 template <
typename T >
381 template <
typename T >
391 template <
typename T >
402 template <
typename TPrecision,
typename T >
418 template <
typename T >
419 std::ostream& operator<<(std::ostream& os, const SparseVector<T> v)
424 os <<
"( " << i->first <<
" : " << i->second <<
" ) ";
TOutput operator()(T1 x1, T2 x2, T3 x3)
SparseVector< T > operator+(const SparseVector< T > &sv1, const SparseVector< T > &sv2)
Pointwise addition.
sparse_iterator sparse_begin()
void operator()(SparseVector< T > &sv, T value, const std::pair< std::size_t, T > &pair, std::pair< std::size_t, T >) const
Matrix3< T > operator-(Matrix3< T > const &mat)
void operator()(TAccumulation &storage, T value, X, X) const
void operator()(SparseVector< T > &sv, T value, const std::pair< std::size_t, T > &pair) const
TPrec dot(const numeric_array< T1, D > &a1, const numeric_array< T2, D > &a2, prec< TPrec >)
Return the dot product of two vectors.
Belongs to package Box Do not include directly, include til/Box.h instead.
boost::enable_if< boost::is_stateless< TFunctor >, LoopWraper< TFunctor > >::type loopWraper(TFunctor f)
SparseVector()
Create a null vector of size 0.
void operator()(T1 &x1, T2 &x2, T3 &x3)
boost::enable_if< boost::is_empty< TFunctor > >::type loop_mapPairs(TMap1 &map1, TMap2 &map2, TFunctor f)
sparse_iterator sparse_end()
Label class for StoreFunctor storage policy classes.
void operator()(SparseVector< T > &sv, T value, const std::pair< std::size_t, T > &pair, T) const
A mathematical vector, using sparse storage policy.
StoreFunctor storage policy for SparseVectors.
A class that mimic the behavior of std::vector but with a storage policy focused on sparse data...
void operator()(SparseVector< T > &sv, T value, T, const std::pair< std::size_t, T > &pair) const
INLINE numeric_array< typename combine< T1, T2 >::type, 3 > operator*(const Affine< T1 > &a, const numeric_array< T2, 3 > &v)
Multiplication between a 3D affine transform and a 3D vector.
void operator()(const T1 &x1, const T2 &x2)
Map & getMap()
Returns the internal data.
Default storage policy for StoreFunctor.
TOutput operator()(T1 x1, T2 x2)
Accumulate< T, TAccumulation > Self
SparseVector(std::size_t d)
Create a null vector of length d.
SparseVector< T > operator/(const SparseVector< T > &sv1, const SparseVector< T > &sv2)
Pointwise division.
const TStorage & get() const
void operator()(TAccumulation &storage, T value, X) const
A functor wrapper to transform a functor with output in an inplace functor.
std::size_t size() const
Alike STL container's "size".
TOutput operator()(T1 x1)
TOutput operator()(T1 x1, T2 x2)
void operator()(T1 &x1, T2 &x2)
boost::enable_if< boost::is_empty< TFunctor > >::type loop_mapEach(TMap1 &map1, TMap2 &map2, TFunctor f)
StoreFunctor(const TStorage &init)
Wrap functors so that it can accept pairs as input – it then apply the functor on the second argumen...
void operator()(TAccumulation &storage, T value, X, X, X) const
void operator()(const T1 &x1, T2 &x2)
void operator()(const T1 &x1)
void operator()(T1 &x1, const T2 &x2)