aimstil  5.0.5
sparse_vector_operators.h
Go to the documentation of this file.
1 #ifndef TIL_SPARSE_VECTOR_OPERATORS_H_
2 #define TIL_SPARSE_VECTOR_OPERATORS_H_
3 
6 
7 // includes from BOOST
8 #include <boost/call_traits.hpp>
9 
10 namespace til
11 {
12 
13 // NB: to be undef'd at the end of this file
14 #define TIL_DEFINE_SPARSE_OP(op) \
15  template < typename T > \
16  sparse_vector<T> \
17  operator op (const sparse_vector<T> & a, typename boost::call_traits<T>::param_type value) \
18  { \
19  sparse_vector<T> res(a.size()); \
20  typename sparse_vector<T>::Map::const_iterator i = a.getMap().begin(); \
21  typename sparse_vector<T>::Map::const_iterator end = a.getMap().end(); \
22  for (; i != end; ++i) \
23  { \
24  res[i->first] = i->second op value; \
25  } \
26  return res; \
27  } \
28  \
29  template < typename T > \
30  sparse_vector<T> \
31  operator op (typename boost::call_traits<T>::param_type value, const sparse_vector<T> & a) \
32  { \
33  sparse_vector<T> res(a.size()); \
34  typename sparse_vector<T>::Map::const_iterator i = a.getMap().begin(); \
35  typename sparse_vector<T>::Map::const_iterator end = a.getMap().end(); \
36  for (; i != end; ++i) \
37  { \
38  res[i->first] = value op i->second; \
39  } \
40  return res; \
41  } \
42 
46 
47 #undef TIL_DEFINE_SPARSE_OP
48 
49 } // namespace til
50 
51 
52 #endif /*SPARSE_VECTOR_OPERATORS_H_*/
TIL_DEFINE_SPARSE_OP(+)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10