CppNoddy  0.92
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CppNoddy::SparseVector< _Type > Class Template Reference

An SparseVector class – a sparse vector object. More...

#include <SparseVector.h>

Public Member Functions

 SparseVector (const std::size_t &max)
 Constructor for a non-filled vector, to be filled by the user. More...
 
 SparseVector (const SparseVector &source)
 Copy constructor. More...
 
SparseVectoroperator= (const SparseVector &source)
 Assignment operator. More...
 
iter begin ()
 Not a full iterator implementation – just a pass through to the storage container. More...
 
citer begin () const
 Not a full iterator implementation – just a pass through to the storage container. More...
 
iter end ()
 Not a full iterator implementation – just a pass through to the storage container. More...
 
citer end () const
 Not a full iterator implementation – just a pass through to the storage container. More...
 
void resize (const std::size_t &length)
 Resize the maximum length of the sparse vector. More...
 
void clear ()
 Remove all elements from the sparse vector. More...
 
void erase (const iter &pos)
 Erase an element from the vector. More...
 
void erase (const std::size_t &index)
 Erase an element from th vector. More...
 
void swap (const std::size_t &i, const std::size_t &j)
 Swap elements i and j. More...
 
void swap (SparseVector< _Type > &X)
 Swap ALL elements with those of another SparseVector. More...
 
std::size_t size () const
 Find the (max) size of the vector. More...
 
std::size_t nelts () const
 Find the number of non-zero elements in the vector. More...
 
_Type & set (const std::size_t &i)
 Set an element of the vector. More...
 
const _Type & get (const std::size_t &i) const
 Get an element of the vector. More...
 
const _Type & operator[] (const std::size_t &i) const
 Equivalent to the 'get' method. More...
 
_Type & operator[] (const std::size_t &i)
 Equivalent to the 'set' method. More...
 
SparseVector< _Type > operator+ (const SparseVector< _Type > &X) const
 Operator overloading for sparse vector addition. More...
 
SparseVector< _Type > operator+ () const
 Overloading for +. More...
 
SparseVector< _Type > operator- (const SparseVector< _Type > &X) const
 Operator overloading for sparse vector subtraction. More...
 
SparseVector< _Type > operator- () const
 Overloading for -. More...
 
SparseVector< _Type > operator* (const _Type &m) const
 Overloading multiplication for a scalar. More...
 
SparseVector< _Type > & operator*= (const _Type &m)
 Overloading *= for scalar multiplication. More...
 
SparseVector< _Type > & operator-= (const SparseVector< _Type > &X)
 Overloading -= for sparse vectors. More...
 
SparseVector< _Type > & operator+= (const SparseVector< _Type > &X)
 Overloading += for sparse vectors. More...
 
citer find (std::size_t i) const
 Look for an element index. More...
 
const _Type dot (const SparseVector< _Type > &x) const
 A dot product. More...
 
double one_norm () const
 l1-norm. More...
 
double two_norm () const
 l2-norm. More...
 
double inf_norm () const
 Infinity norm. More...
 
void scale (const _Type &scale)
 Scale each element of the vector. More...
 
void add (const SparseVector< _Type > &X)
 Add a vector, element wise. More...
 
void sub (const SparseVector< _Type > &X)
 Subtract a vector, element wise. More...
 
std::size_t nearest_index (const _Type &value) const
 Find the index of the element NEAREST in value to that specified. More...
 
std::size_t maxabs_index () const
 Find the index of the maximum element in the vector. More...
 
std::size_t minabs_index () const
 Find the index of the maximum element in the vector. More...
 
void dump () const
 Output the sparse vector's contents. More...
 

Detailed Description

template<typename _Type>
class CppNoddy::SparseVector< _Type >

An SparseVector class – a sparse vector object.

This is templated but intended ONLY for double or std::complex<double>.

Definition at line 20 of file SparseVector.h.

Constructor & Destructor Documentation

◆ SparseVector() [1/2]

template<typename _Type >
CppNoddy::SparseVector< _Type >::SparseVector ( const std::size_t &  max)
explicit

Constructor for a non-filled vector, to be filled by the user.

Parameters
maxA maximum size for the sparse vector, used in geometry checking.

Definition at line 18 of file SparseVector.cpp.

18 : ZERO(0.0), MAX_SIZE(max)
19 {}

◆ SparseVector() [2/2]

template<typename _Type >
CppNoddy::SparseVector< _Type >::SparseVector ( const SparseVector< _Type > &  source)

Copy constructor.

Parameters
sourceThe source object to be copied

Definition at line 22 of file SparseVector.cpp.

22 {
23 *this = source;
24 }
double source(const double &x, const double &y, const double &t)
Definition: IBVPLinear.cpp:26

Member Function Documentation

◆ add()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::add ( const SparseVector< _Type > &  X)

Add a vector, element wise.

Parameters
XThe vector to be added to this object.

Definition at line 249 of file SparseVector.cpp.

250 {
251 *this += X;
252 }

◆ begin() [1/2]

template<typename _Type >
std::map< std::size_t, _Type >::iterator CppNoddy::SparseVector< _Type >::begin
inline

Not a full iterator implementation – just a pass through to the storage container.

Return an iterator pointing to the beginning of the encpsulated STL map storage

Definition at line 240 of file SparseVector.h.

240 {
241 return MAP_VEC.begin();
242 }

◆ begin() [2/2]

template<typename _Type >
std::map< std::size_t, _Type >::const_iterator CppNoddy::SparseVector< _Type >::begin
inline

Not a full iterator implementation – just a pass through to the storage container.

Return a constant iterator pointing to the beginning of the encapsulated STL map storage

Definition at line 245 of file SparseVector.h.

245 {
246 return MAP_VEC.begin();
247 }

◆ clear()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::clear

Remove all elements from the sparse vector.

Definition at line 181 of file SparseVector.cpp.

181 {
182 MAP_VEC.clear();
183 }

◆ dot()

template<typename _Type >
const _Type CppNoddy::SparseVector< _Type >::dot ( const SparseVector< _Type > &  x) const

A dot product.

Parameters
xThe vector to be "dotted" with.
Todo:
Using a 'get' (aka find) here is slooow
  • obviously this can be improved.

Definition at line 186 of file SparseVector.cpp.

186 {
187#ifdef PARANOID
188 if(X.size() != size()) {
189 std::string problem;
190 problem = " The SparseVector.dot method is trying to use \n";
191 problem += " two vectors of unequal length \n";
192 throw ExceptionGeom(problem, size(), X.size());
193 }
194#endif
195 SparseVector<_Type> temp(X);
196 _Type sum(0.0);
197 for(iter pos = temp.MAP_VEC.begin(); pos != temp.MAP_VEC.end(); ++pos) {
198 std::size_t index = pos -> first;
199 /// \todo Using a 'get' (aka find) here is slooow
200 /// - obviously this can be improved.
201 // the get method returns 0.0 if not stored
202 temp[ index ] *= get(index);
203 }
204 return sum;
205 }
std::size_t size() const
Find the (max) size of the vector.
Definition: SparseVector.h:318
const _Type & get(const std::size_t &i) const
Get an element of the vector.
Definition: SparseVector.h:299

References CppNoddy::SparseVector< _Type >::size().

◆ dump()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::dump

Output the sparse vector's contents.

Definition at line 317 of file SparseVector.cpp.

317 {
318 std::cout.precision(6);
319 if(MAP_VEC.begin() == MAP_VEC.end()) {
320 std::cout << "[ Empty vector ]\n";
321 } else {
322 for(citer pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
323 std::cout << "[ " << pos -> first << " ]" << " = " << pos -> second << " ";
324 }
325 std::cout << "\n";
326 }
327 }

◆ end() [1/2]

template<typename _Type >
std::map< std::size_t, _Type >::iterator CppNoddy::SparseVector< _Type >::end
inline

Not a full iterator implementation – just a pass through to the storage container.

Return an iterator pointing to the end of the encapsulated STL map storage

Definition at line 250 of file SparseVector.h.

250 {
251 return MAP_VEC.end();
252 }

◆ end() [2/2]

template<typename _Type >
std::map< std::size_t, _Type >::const_iterator CppNoddy::SparseVector< _Type >::end
inline

Not a full iterator implementation – just a pass through to the storage container.

Return a constant iterator pointing to the end of the encapsulated STL map storage

Definition at line 255 of file SparseVector.h.

255 {
256 return MAP_VEC.end();
257 }

◆ erase() [1/2]

template<typename _Type >
void CppNoddy::SparseVector< _Type >::erase ( const iter &  pos)
inline

Erase an element from the vector.

Parameters
posAn std::map< std::size_t, _Type >::iterator to the map element

Definition at line 333 of file SparseVector.h.

333 {
334 MAP_VEC.erase(pos);
335 }

◆ erase() [2/2]

template<typename _Type >
void CppNoddy::SparseVector< _Type >::erase ( const std::size_t &  index)
inline

Erase an element from th vector.

Parameters
indexThe index of the element to be erased

Definition at line 328 of file SparseVector.h.

328 {
329 MAP_VEC.erase(index);
330 }

◆ find()

template<typename _Type >
citer CppNoddy::SparseVector< _Type >::find ( std::size_t  i) const
inline

Look for an element index.

Parameters
iThe index of the element to search for

Definition at line 151 of file SparseVector.h.

151 {
152 citer pos;
153 pos = MAP_VEC.find(i);
154 return pos;
155 }

◆ get()

template<typename _Type >
const _Type & CppNoddy::SparseVector< _Type >::get ( const std::size_t &  i) const
inline

Get an element of the vector.

Parameters
iThe index to be accessed
Returns
The contents of the element, including a zero if the element has not been set

Definition at line 299 of file SparseVector.h.

299 {
300#ifdef PARANOID
301 if(i >= size()) {
302 std::string problem;
303 problem = " The SparseVector.get method is trying to access \n";
304 problem += " outside the container. \n";
305 throw ExceptionRange(problem, size(), i);
306 }
307#endif
308 citer pos;
309 pos = MAP_VEC.find(i);
310 if(pos != MAP_VEC.end()) {
311 return pos -> second;
312 } else {
313 return ZERO;
314 }
315 }

◆ inf_norm()

template<typename _Type >
double CppNoddy::SparseVector< _Type >::inf_norm

Infinity norm.

Returns
The maximum (abs) element in the vector.

Definition at line 230 of file SparseVector.cpp.

230 {
231 double max(0.0);
232 // Return the maximum (abs) element in the vector
233 for(citer pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
234 if(std::abs(pos -> second) > max) {
235 max = std::abs(pos -> second);
236 }
237 }
238 return max;
239 }

◆ maxabs_index()

template<typename _Type >
std::size_t CppNoddy::SparseVector< _Type >::maxabs_index

Find the index of the maximum element in the vector.

Returns
The index of the maximum element.

Definition at line 275 of file SparseVector.cpp.

275 {
276 citer location(MAP_VEC.begin());
277 double max(std::abs(location -> second));
278 citer start(++location);
279 for(citer pos = start; pos != MAP_VEC.end(); ++pos) {
280 if(std::abs(pos -> second) > max) {
281 max = std::abs(pos -> second);
282 location = pos;
283 }
284 }
285 return location -> first;
286 }

◆ minabs_index()

template<typename _Type >
std::size_t CppNoddy::SparseVector< _Type >::minabs_index

Find the index of the maximum element in the vector.

Returns
The index of the maximum element.

Definition at line 289 of file SparseVector.cpp.

289 {
290 citer location(MAP_VEC.begin());
291 double min(std::abs(location -> second));
292 citer start(++location);
293 for(citer pos = start; pos != MAP_VEC.end(); ++pos) {
294 if(std::abs(pos -> second) < min) {
295 min = std::abs(pos -> second);
296 location = pos;
297 }
298 }
299 return location -> first;
300 }

◆ nearest_index()

template<typename _Type >
std::size_t CppNoddy::SparseVector< _Type >::nearest_index ( const _Type &  value) const

Find the index of the element NEAREST in value to that specified.

Parameters
valueThe value to search for.
Returns
The index of the element with value that minimises the difference.

Definition at line 260 of file SparseVector.cpp.

260 {
261 citer location(MAP_VEC.begin());
262 _Type min_diff(location -> second - value);
263 citer start(++location);
264 for(citer pos = start; pos != MAP_VEC.end(); ++pos) {
265 _Type diff(pos -> second - value);
266 if(std::abs(diff) < std::abs(min_diff)) {
267 min_diff = diff;
268 location = pos;
269 }
270 }
271 return location -> first;
272 }

◆ nelts()

template<typename _Type >
std::size_t CppNoddy::SparseVector< _Type >::nelts
inline

Find the number of non-zero elements in the vector.

Definition at line 323 of file SparseVector.h.

323 {
324 return MAP_VEC.size();
325 }

◆ one_norm()

template<typename _Type >
double CppNoddy::SparseVector< _Type >::one_norm

l1-norm.

Returns
The square-root of the sum of the squares divided by number of elts.

Definition at line 208 of file SparseVector.cpp.

208 {
209 // Accumulate the ABS values of the container entries
210 // using a fuction object.
211 double sum(0.0);
212 for(citer pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
213 sum += std::abs(pos -> second);
214 }
215 return sum;
216 }

Referenced by main().

◆ operator*()

template<typename _Type >
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator* ( const _Type &  m) const

Overloading multiplication for a scalar.

Parameters
mThe scalar to multiply by
Returns
The scalar multiplication of the vector

Definition at line 168 of file SparseVector.cpp.

168 {
169 SparseVector<_Type> temp(*this);
170 temp *= m;
171 return temp;
172 }

References m.

◆ operator*=()

template<typename _Type >
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator*= ( const _Type &  m)

Overloading *= for scalar multiplication.

Parameters
mThe scalar to multiply by

Definition at line 37 of file SparseVector.cpp.

37 {
38 for(iter pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
39 pos -> second *= m;
40 }
41 return *this;
42 }

References m.

◆ operator+() [1/2]

template<typename _Type >
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator+
inline

Overloading for +.

Returns
+this

Definition at line 351 of file SparseVector.h.

351 {
352 return * this;
353 }

◆ operator+() [2/2]

template<typename _Type >
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator+ ( const SparseVector< _Type > &  X) const

Operator overloading for sparse vector addition.

Parameters
XA sparse vector to be added
Returns
The sum of this and the passed vector X

Definition at line 131 of file SparseVector.cpp.

131 {
132#ifdef PARANOID
133 if(X.size() != size()) {
134 std::string problem;
135 problem = " The SparseVector.operator+ method is trying to use \n";
136 problem += " two vectors of unequal length \n";
137 throw ExceptionGeom(problem, size(), X.size());
138 }
139#endif
140 SparseVector<_Type> temp(*this);
141 temp += X;
142 return temp;
143 }

References CppNoddy::SparseVector< _Type >::size().

◆ operator+=()

template<typename _Type >
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator+= ( const SparseVector< _Type > &  X)

Overloading += for sparse vectors.

Parameters
XThe sparse vector to be added
Returns
Adds X to the 'this' vector

Definition at line 88 of file SparseVector.cpp.

88 {
89#ifdef PARANOID
90 if(X.size() != size()) {
91 std::string problem;
92 problem = " The SparseVector.operator+= method is trying to use \n";
93 problem += " two vectors of unequal length \n";
94 throw ExceptionGeom(problem, size(), X.size());
95 }
96#endif
97 citer pos_ro = X.MAP_VEC.begin();
98 iter pos_rw = MAP_VEC.begin();
99 do {
100 std::size_t index_rw = pos_rw -> first;
101 std::size_t index_ro = pos_ro -> first;
102 if(index_rw == index_ro) {
103 // element in both vectors
104 pos_rw -> second += pos_ro -> second;
105 ++pos_rw;
106 ++pos_ro;
107 }
108 if(index_rw > index_ro) {
109 // element is in X but not 'this'
110 set
111 (index_ro) = pos_ro -> second;
112 ++pos_ro;
113 }
114 if(index_rw < index_ro) {
115 // element is in 'this' but not X
116 ++pos_rw;
117 }
118 } while(pos_ro != X.MAP_VEC.end() && pos_rw != MAP_VEC.end());
119 if(pos_ro != X.MAP_VEC.end()) {
120 // need to finish the X data
121 do {
122 set
123 (pos_ro -> first) = pos_ro -> second;
124 ++pos_ro;
125 } while(pos_ro != X.MAP_VEC.end());
126 }
127 return *this;
128 }
_Type & set(const std::size_t &i)
Set an element of the vector.
Definition: SparseVector.h:286

References CppNoddy::SparseVector< _Type >::size().

◆ operator-() [1/2]

template<typename _Type >
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator-

Overloading for -.

Returns
The negative of the vector

Definition at line 161 of file SparseVector.cpp.

161 {
162 SparseVector<_Type> temp(*this);
163 temp *= -1.0;
164 return temp;
165 }

◆ operator-() [2/2]

template<typename _Type >
SparseVector< _Type > CppNoddy::SparseVector< _Type >::operator- ( const SparseVector< _Type > &  X) const

Operator overloading for sparse vector subtraction.

Parameters
XA sparse vector to be subtracted
Returns
The subtraction of this and the passed vector X

Definition at line 146 of file SparseVector.cpp.

146 {
147#ifdef PARANOID
148 if(X.size() != size()) {
149 std::string problem;
150 problem = " The SparseVector.operator- method is trying to use \n";
151 problem += " two vectors of unequal length \n";
152 throw ExceptionGeom(problem, size(), X.size());
153 }
154#endif
155 SparseVector<_Type> temp(*this);
156 temp -= X;
157 return temp;
158 }

References CppNoddy::SparseVector< _Type >::size().

◆ operator-=()

template<typename _Type >
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator-= ( const SparseVector< _Type > &  X)

Overloading -= for sparse vectors.

Parameters
XThe sparse vector to be subtracted
Returns
Subtracts X from the 'this' vector

Definition at line 45 of file SparseVector.cpp.

45 {
46#ifdef PARANOID
47 if(X.size() != size()) {
48 std::string problem;
49 problem = " The SparseVector.operator-= method is trying to use \n";
50 problem += " two vectors of unequal length \n";
51 throw ExceptionGeom(problem, size(), X.size());
52 }
53#endif
54 citer pos_ro = X.MAP_VEC.begin();
55 iter pos_rw = MAP_VEC.begin();
56 do {
57 std::size_t index_rw = pos_rw -> first;
58 std::size_t index_ro = pos_ro -> first;
59 if(index_rw == index_ro) {
60 // element in both vectors
61 pos_rw -> second -= pos_ro -> second;
62 ++pos_rw;
63 ++pos_ro;
64 }
65 if(index_rw > index_ro) {
66 // element is in X but not 'this'
67 set
68 (index_ro) = -(pos_ro -> second);
69 ++pos_ro;
70 }
71 if(index_rw < index_ro) {
72 // element is in 'this' but not X
73 ++pos_rw;
74 }
75 } while(pos_ro != X.MAP_VEC.end() && pos_rw != MAP_VEC.end());
76 if(pos_ro != X.MAP_VEC.end()) {
77 // need to finish the X data
78 do {
79 set
80 (pos_ro -> first) = -(pos_ro -> second);
81 ++pos_ro;
82 } while(pos_ro != X.MAP_VEC.end());
83 }
84 return *this;
85 }

References CppNoddy::SparseVector< _Type >::size().

◆ operator=()

template<typename _Type >
SparseVector< _Type > & CppNoddy::SparseVector< _Type >::operator= ( const SparseVector< _Type > &  source)

Assignment operator.

Parameters
sourceThe source object for the assignment
Returns
The newly assigned object

Definition at line 27 of file SparseVector.cpp.

27 {
28 if(this == &source)
29 return * this;
30 MAP_VEC = source.MAP_VEC;
31 ZERO = source.ZERO;
32 MAX_SIZE = source.MAX_SIZE;
33 return *this;
34 }

◆ operator[]() [1/2]

template<typename _Type >
_Type & CppNoddy::SparseVector< _Type >::operator[] ( const std::size_t &  i)
inline

Equivalent to the 'set' method.

Definition at line 260 of file SparseVector.h.

260 {
261#ifdef PARANOID
262 if(i >= size()) {
263 std::string problem;
264 problem = " The SparseVector.operator[] method is trying to access \n";
265 problem += " outside the container. \n";
266 throw ExceptionRange(problem, size(), i);
267 }
268#endif
269 return MAP_VEC[ i ];
270 }

◆ operator[]() [2/2]

template<typename _Type >
const _Type & CppNoddy::SparseVector< _Type >::operator[] ( const std::size_t &  i) const
inline

Equivalent to the 'get' method.

Definition at line 273 of file SparseVector.h.

273 {
274#ifdef PARANOID
275 if(i >= size()) {
276 std::string problem;
277 problem = " The SparseVector.operator[] method is trying to access \n";
278 problem += " outside the container. \n";
279 throw ExceptionRange(problem, size(), i);
280 }
281#endif
282 return get(i);
283 }

◆ resize()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::resize ( const std::size_t &  length)

Resize the maximum length of the sparse vector.

The maximum length is used in geometry checking.

Parameters
lengthThe new maximum length of the vector

Definition at line 176 of file SparseVector.cpp.

176 {
177 MAX_SIZE = length;
178 }

◆ scale()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::scale ( const _Type &  scale)

Scale each element of the vector.

Parameters
scaleThe value to scale each element by.

Definition at line 242 of file SparseVector.cpp.

242 {
243 for(iter pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
244 pos -> second *= scale;
245 }
246 }
void scale(const _Type &scale)
Scale each element of the vector.

◆ set()

template<typename _Type >
_Type & CppNoddy::SparseVector< _Type >::set ( const std::size_t &  i)
inline

Set an element of the vector.

Parameters
iThe index to be accessed
Returns
A reference to the element

Definition at line 286 of file SparseVector.h.

286 {
287#ifdef PARANOID
288 if(i >= size()) {
289 std::string problem;
290 problem = " The SparseVector.set method is trying to access \n";
291 problem += " outside the container. \n";
292 throw ExceptionRange(problem, size(), i);
293 }
294#endif
295 return MAP_VEC[ i ];
296 }

◆ size()

template<typename _Type >
std::size_t CppNoddy::SparseVector< _Type >::size
inline

◆ sub()

template<typename _Type >
void CppNoddy::SparseVector< _Type >::sub ( const SparseVector< _Type > &  X)

Subtract a vector, element wise.

Parameters
XThe vector to be subtracted from this object.

Definition at line 255 of file SparseVector.cpp.

255 {
256 *this -= X;
257 }

◆ swap() [1/2]

template<typename _Type >
void CppNoddy::SparseVector< _Type >::swap ( const std::size_t &  i,
const std::size_t &  j 
)

Swap elements i and j.

Parameters
iThe index of the element to swap.
jThe index of the other element to swap.

Definition at line 303 of file SparseVector.cpp.

304 {
305#ifdef PARANOID
306 if(i >= size() || j >= size()) {
307 std::string problem;
308 problem = " The SparseVector.swap method is trying to access \n";
309 problem += " outside the container. \n";
310 throw ExceptionRange(problem, size(), std::max(i, j));
311 }
312#endif
313 std::swap<_Type>(MAP_VEC[ i ], MAP_VEC[ j ]);
314 }

◆ swap() [2/2]

template<typename _Type >
void CppNoddy::SparseVector< _Type >::swap ( SparseVector< _Type > &  X)
inline

Swap ALL elements with those of another SparseVector.

Parameters
XThe sparse vector to exchange with

Definition at line 338 of file SparseVector.h.

338 {
339#ifdef PARANOID
340 if(X.size() != size()) {
341 std::string problem;
342 problem = " The SparseVector.swap method is trying to use \n";
343 problem += " two vectors of unequal length \n";
344 throw ExceptionGeom(problem, size(), X.size());
345 }
346#endif
347 MAP_VEC.swap(X.MAP_VEC);
348 }

References CppNoddy::SparseVector< _Type >::size().

◆ two_norm()

template<typename _Type >
double CppNoddy::SparseVector< _Type >::two_norm

l2-norm.

No attention paid to possible overflow for large vectors.

Returns
The square-root of the sum of the squares divided by number of elts.

Definition at line 219 of file SparseVector.cpp.

219 {
220 // Accumulate the ABS values of the container entries SQUARED
221 // using a fuction object.
222 double sum(0.0);
223 for(citer pos = MAP_VEC.begin(); pos != MAP_VEC.end(); ++pos) {
224 sum += std::pow(std::abs(pos -> second), 2);
225 }
226 return sum;
227 }

The documentation for this class was generated from the following files:

© 2012

R.E. Hewitt