Scippy

SoPlex

Sequential object-oriented simPlex

svectorbase.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file svectorbase.h
17  * @brief Sparse vectors.
18  */
19 #ifndef _SVECTORBASE_H_
20 #define _SVECTORBASE_H_
21 
22 #include <iostream>
23 #include <assert.h>
24 #include <math.h>
25 #include "soplex/stablesum.h"
26 
27 namespace soplex
28 {
29 template < class R > class VectorBase;
30 template < class R > class SSVectorBase;
31 
32 /// Sparse vector nonzero element.
33 /** SVectorBase keeps its nonzeros in an array of Nonzero%s providing members for saving the index and value.
34  */
35 template < class R >
36 class Nonzero
37 {
38 public:
39 
40  R val; ///< Value of nonzero element.
41  int idx; ///< Index of nonzero element.
42 
43  template < class S >
45  {
46  val = vec.val;
47  idx = vec.idx;
48  return *this;
49  }
50 
51  template < class S >
52  Nonzero<R>(const Nonzero<S>& vec)
53  : val(vec.val)
54  , idx(vec.idx)
55  {
56  }
57 
59  : val()
60  , idx(0)
61  {
62  }
63 };
64 
65 
66 
67 // specialized assignment operator
68 template <>
69 template < class S >
71 {
72  val = Real(vec.val);
73  idx = vec.idx;
74  return *this;
75 }
76 
77 
78 /**@brief Sparse vectors.
79  * @ingroup Algebra
80  *
81  * Class SVectorBase provides packed sparse vectors. Such are a sparse vectors, with a storage scheme that keeps all
82  * data in one contiguous block of memory. This is best suited for using them for parallel computing on a distributed
83  * memory multiprocessor.
84  *
85  * SVectorBase does not provide any memory management (this will be done by class DSVectorBase). This means, that the
86  * constructor of SVectorBase expects memory where to save the nonzeros. Further, adding nonzeros to an SVectorBase may
87  * fail if no more memory is available for saving them (see also DSVectorBase).
88  *
89  * When nonzeros are added to an SVectorBase, they are appended to the set of nonzeros, i.e., they recieve numbers
90  * size(), size()+1 ... . An SVectorBase can hold atmost max() nonzeros, where max() is given in the constructor. When
91  * removing nonzeros, the remaining nonzeros are renumbered. However, only the numbers greater than the number of the
92  * first removed nonzero are affected.
93  *
94  * The following mathematical operations are provided by class SVectorBase (SVectorBase \p a, \p b, \p c; R \p x):
95  *
96  * <TABLE>
97  * <TR><TD>Operation</TD><TD>Description </TD><TD></TD>&nbsp;</TR>
98  * <TR><TD>\c -= </TD><TD>subtraction </TD><TD>\c a \c -= \c b </TD></TR>
99  * <TR><TD>\c += </TD><TD>addition </TD><TD>\c a \c += \c b </TD></TR>
100  * <TR><TD>\c * </TD><TD>skalar product</TD>
101  * <TD>\c x = \c a \c * \c b </TD></TR>
102  * <TR><TD>\c *= </TD><TD>scaling </TD><TD>\c a \c *= \c x </TD></TR>
103  * <TR><TD>maxAbs() </TD><TD>infinity norm </TD>
104  * <TD>\c a.maxAbs() == \f$\|a\|_{\infty}\f$ </TD></TR>
105  * <TR><TD>length() </TD><TD>eucledian norm</TD>
106  * <TD>\c a.length() == \f$\sqrt{a^2}\f$ </TD></TR>
107  * <TR><TD>length2()</TD><TD>square norm </TD>
108  * <TD>\c a.length2() == \f$a^2\f$ </TD></TR>
109  * </TABLE>
110  *
111  * Operators \c += and \c -= should be used with caution, since no efficient implementation is available. One should
112  * think of assigning the left handside vector to a dense VectorBase first and perform the addition on it. The same
113  * applies to the scalar product \c *.
114  *
115  * There are two numberings of the nonzeros of an SVectorBase. First, an SVectorBase is supposed to act like a linear
116  * algebra VectorBase. An \em index refers to this view of an SVectorBase: operator[]() is provided which returns the
117  * value at the given index of the vector, i.e., 0 for all indices which are not in the set of nonzeros. The other view
118  * of SVectorBase%s is that of a set of nonzeros. The nonzeros are numbered from 0 to size()-1. The methods index(int
119  * n) and value(int n) allow to access the index and value of the \p n 'th nonzero. \p n is referred to as the \em
120  * number of a nonzero.
121  *
122  * @todo SVectorBase should get a new implementation. There maybe a lot of memory lost due to padding the Nonzero
123  * structure. A better idea seems to be class SVectorBase { int size; int used; int* idx; R* val; }; which for
124  * several reasons could be faster or slower. If SVectorBase is changed, also DSVectorBase and SVSet have to be
125  * modified.
126  */
127 template < class R >
128 class SVectorBase
129 {
130  template < class S > friend class SVectorBase;
131 
132 private:
133 
134  // ------------------------------------------------------------------------------------------------------------------
135  /**@name Data */
136  //@{
137 
139  int memsize;
140  int memused;
141 
142  //@}
143 
144 public:
145 
147 
148  // ------------------------------------------------------------------------------------------------------------------
149  /**@name Access */
150  //@{
151 
152  /// Number of used indices.
153  int size() const
154  {
155  assert(m_elem != 0 || memused == 0);
156  return memused;
157  }
158 
159  /// Maximal number of indices.
160  int max() const
161  {
162  assert(m_elem != 0 || memused == 0);
163  return memsize;
164  }
165 
166  /// Dimension of the vector defined as maximal index + 1
167  int dim() const
168  {
169  const Nonzero<R>* e = m_elem;
170  int d = -1;
171  int n = size();
172 
173  while(n--)
174  {
175  d = (d > e->idx) ? d : e->idx;
176  e++;
177  }
178 
179  return d + 1;
180  }
181 
182  /// Position of index \p i.
183  /** @return Finds the position of the first index \p i in the index set. If no such index \p i is found,
184  * -1 is returned. Otherwise, index(pos(i)) == i holds.
185  */
186  int pos(int i) const
187  {
188  if(m_elem != 0)
189  {
190  int n = size();
191 
192  for(int p = 0; p < n; ++p)
193  {
194  if(m_elem[p].idx == i)
195  {
196  assert(index(p) == i);
197  return p;
198  }
199  }
200  }
201 
202  return -1;
203  }
204 
205  /// Value to index \p i.
206  R operator[](int i) const
207  {
208  int n = pos(i);
209 
210  if(n >= 0)
211  return m_elem[n].val;
212 
213  return 0;
214  }
215 
216  /// Reference to the \p n 'th nonzero element.
218  {
219  assert(n >= 0);
220  assert(n < max());
221 
222  return m_elem[n];
223  }
224 
225  /// The \p n 'th nonzero element.
226  const Nonzero<R>& element(int n) const
227  {
228  assert(n >= 0);
229  assert(n < size());
230 
231  return m_elem[n];
232  }
233 
234  /// Reference to index of \p n 'th nonzero.
235  int& index(int n)
236  {
237  assert(n >= 0);
238  assert(n < size());
239 
240  return m_elem[n].idx;
241  }
242 
243  /// Index of \p n 'th nonzero.
244  int index(int n) const
245  {
246  assert(n >= 0);
247  assert(n < size());
248 
249  return m_elem[n].idx;
250  }
251 
252  /// Reference to value of \p n 'th nonzero.
253  R& value(int n)
254  {
255  assert(n >= 0);
256  assert(n < size());
257 
258  return m_elem[n].val;
259  }
260 
261  /// Value of \p n 'th nonzero.
262  const R& value(int n) const
263  {
264  assert(n >= 0);
265  assert(n < size());
266 
267  return m_elem[n].val;
268  }
269 
270  /// Append one nonzero \p (i,v).
271  void add(int i, const R& v)
272  {
273  assert(m_elem != 0);
274  assert(size() < max());
275 
276  if(v != 0.0)
277  {
278  int n = size();
279 
280  m_elem[n].idx = i;
281  m_elem[n].val = v;
282  set_size(n + 1);
283 
284  assert(size() <= max());
285  }
286  }
287 
288  /// Append one uninitialized nonzero.
289  void add(int i)
290  {
291  assert(m_elem != 0);
292  assert(size() < max());
293 
294  int n = size();
295 
296  m_elem[n].idx = i;
297  set_size(n + 1);
298 
299  assert(size() <= max());
300  }
301 
302  /// Append nonzeros of \p sv.
303  void add(const SVectorBase& sv)
304  {
305  add(sv.size(), sv.m_elem);
306  }
307 
308  /// Append \p n nonzeros.
309  void add(int n, const int i[], const R v[])
310  {
311  assert(n + size() <= max());
312 
313  if(n <= 0)
314  return;
315 
316  int newnnz = 0;
317 
318  Nonzero<R>* e = m_elem + size();
319 
320  while(n--)
321  {
322  if(*v != 0.0)
323  {
324  e->idx = *i;
325  e->val = *v;
326  e++;
327  ++newnnz;
328  }
329 
330  i++;
331  v++;
332  }
333 
334  set_size(size() + newnnz);
335  }
336 
337  /// Append \p n nonzeros.
338  template < class S >
339  void add(int n, const int i[], const S v[])
340  {
341  assert(n + size() <= max());
342 
343  if(n <= 0)
344  return;
345 
346  int newnnz = 0;
347 
348  Nonzero<R>* e = m_elem + size();
349 
350  while(n--)
351  {
352  if(*v != R(0.0))
353  {
354  e->idx = *i;
355  e->val = *v;
356  e++;
357  ++newnnz;
358  }
359 
360  i++;
361  v++;
362  }
363 
364  set_size(size() + newnnz);
365  }
366 
367  /// Append \p n nonzeros.
368  void add(int n, const Nonzero<R> e[])
369  {
370  assert(n + size() <= max());
371 
372  if(n <= 0)
373  return;
374 
375  int newnnz = 0;
376 
377  Nonzero<R>* ee = m_elem + size();
378 
379  while(n--)
380  {
381  if(e->val != 0.0)
382  {
383  *ee++ = *e;
384  ++newnnz;
385  }
386 
387  e++;
388  }
389 
390  set_size(size() + newnnz);
391  }
392 
393  /// Remove nonzeros \p n thru \p m.
394  void remove(int n, int m)
395  {
396  assert(n <= m);
397  assert(m < size());
398  assert(n >= 0);
399 
400  ++m;
401 
402  int cpy = m - n;
403  cpy = (size() - m >= cpy) ? cpy : size() - m;
404 
405  Nonzero<R>* e = &m_elem[size() - 1];
406  Nonzero<R>* r = &m_elem[n];
407 
408  set_size(size() - cpy);
409 
410  do
411  {
412  *r++ = *e--;
413  }
414  while(--cpy);
415  }
416 
417  /// Remove \p n 'th nonzero.
418  void remove(int n)
419  {
420  assert(n >= 0);
421  assert(n < size());
422 
423  int newsize = size() - 1;
424  set_size(newsize);
425 
426  if(n < newsize)
427  m_elem[n] = m_elem[newsize];
428  }
429 
430  /// Remove all indices.
431  void clear()
432  {
433  set_size(0);
434  }
435 
436  /// Sort nonzeros to increasing indices.
437  void sort()
438  {
439  if(m_elem != 0)
440  {
441  Nonzero<R> dummy;
442  Nonzero<R>* w;
443  Nonzero<R>* l;
444  Nonzero<R>* s = &(m_elem[0]);
445  Nonzero<R>* e = s + size();
446 
447  for(l = s, w = s + 1; w < e; l = w, ++w)
448  {
449  if(l->idx > w->idx)
450  {
451  dummy = *w;
452 
453  do
454  {
455  l[1] = *l;
456 
457  if(l-- == s)
458  break;
459  }
460  while(l->idx > dummy.idx);
461 
462  l[1] = dummy;
463  }
464  }
465  }
466  }
467 
468  //@}
469 
470  // ------------------------------------------------------------------------------------------------------------------
471  /**@name Arithmetic operations */
472  //@{
473 
474  /// Maximum absolute value, i.e., infinity norm.
475  R maxAbs() const
476  {
477  R maxi = 0;
478 
479  for(int i = size() - 1; i >= 0; --i)
480  {
481  if(spxAbs(m_elem[i].val) > maxi)
482  maxi = spxAbs(m_elem[i].val);
483  }
484 
485  assert(maxi >= 0);
486 
487  return maxi;
488  }
489 
490  /// Minimum absolute value.
491  R minAbs() const
492  {
493  R mini = infinity;
494 
495  for(int i = size() - 1; i >= 0; --i)
496  {
497  if(spxAbs(m_elem[i].val) < mini)
498  mini = spxAbs(m_elem[i].val);
499  }
500 
501  assert(mini >= 0);
502 
503  return mini;
504  }
505 
506  /// Floating point approximation of euclidian norm (without any approximation guarantee).
507  Real length() const
508  {
509  return spxSqrt((Real)length2());
510  }
511 
512  /// Squared norm.
513  R length2() const
514  {
515  R x = 0;
516  int n = size();
517  const Nonzero<R>* e = m_elem;
518 
519  while(n--)
520  {
521  x += e->val * e->val;
522  e++;
523  }
524 
525  return x;
526  }
527 
528  /// Scaling.
530  {
531  int n = size();
532  Nonzero<R>* e = m_elem;
533 
534  assert(x != 0);
535 
536  while(n--)
537  {
538  e->val *= x;
539  e++;
540  }
541 
542  return *this;
543  }
544 
545  /// Inner product.
546  R operator*(const VectorBase<R>& w) const;
547 
548  /// inner product for sparse vectors
549  template < class S >
550  R operator*(const SVectorBase<S>& w) const
551  {
552  StableSum<R> x;
553  int n = size();
554  int m = w.size();
555 
556  if(n == 0 || m == 0)
557  return x;
558 
559  int i = 0;
560  int j = 0;
561  Element* e = m_elem;
562  typename SVectorBase<S>::Element wj = w.element(j);
563 
564  while(true)
565  {
566  if(e->idx == wj.idx)
567  {
568  x += e->val * wj.val;
569  i++;
570  j++;
571 
572  if(i == n || j == m)
573  break;
574 
575  e++;
576  wj = w.element(j);
577  }
578  else if(e->idx < wj.idx)
579  {
580  i++;
581 
582  if(i == n)
583  break;
584 
585  e++;
586  }
587  else
588  {
589  j++;
590 
591  if(j == m)
592  break;
593 
594  wj = w.element(j);
595  }
596  }
597 
598  return x;
599  }
600 
601  //@}
602 
603  // ------------------------------------------------------------------------------------------------------------------
604  /**@name Constructions, destruction, and assignment */
605  //@{
606 
607  /// Default constructor.
608  /** The constructor expects one memory block where to store the nonzero elements. This must be passed to the
609  * constructor, where the \em number of Nonzero%s needs that fit into the memory must be given and a pointer to the
610  * beginning of the memory block. Once this memory has been passed, it shall not be modified until the SVectorBase
611  * is no longer used.
612  */
613  explicit SVectorBase<R>(int n = 0, Nonzero<R>* p_mem = 0)
614  {
615  setMem(n, p_mem);
616  }
617 
618  /// Assignment operator.
619  template < class S >
621 
622  /// Assignment operator.
624  {
625  if(this != &sv)
626  {
627  assert(max() >= sv.size());
628 
629  int i = sv.size();
630  int nnz = 0;
631  Nonzero<R>* e = m_elem;
632  const Nonzero<R>* s = sv.m_elem;
633 
634  while(i--)
635  {
636  assert(e != 0);
637 
638  if(s->val != 0.0)
639  {
640  *e++ = *s;
641  ++nnz;
642  }
643 
644  ++s;
645  }
646 
647  set_size(nnz);
648  }
649 
650  return *this;
651  }
652 
653  /// Assignment operator.
654  template < class S >
656  {
657  if(this != (const SVectorBase<R>*)(&sv))
658  {
659  assert(max() >= sv.size());
660 
661  int i = sv.size();
662  int nnz = 0;
663  Nonzero<R>* e = m_elem;
664  const Nonzero<S>* s = sv.m_elem;
665 
666  while(i--)
667  {
668  assert(e != 0);
669 
670  if(s->val != 0.0)
671  {
672  *e++ = *s;
673  ++nnz;
674  }
675 
676  ++s;
677  }
678 
679  set_size(nnz);
680  }
681 
682  return *this;
683  }
684 
685  /// scale and assign
687  {
688  if(this != &sv)
689  {
690  assert(max() >= sv.size());
691 
692  for(int i = 0; i < sv.size(); ++i)
693  {
694  m_elem[i].val = spxLdexp(sv.value(i), scaleExp);
695  m_elem[i].idx = sv.index(i);
696  }
697 
698  assert(isConsistent());
699  }
700 
701  return *this;
702  }
703 
704  /// scale and assign
705  SVectorBase<Real>& scaleAssign(const int* scaleExp, const SVectorBase<Real>& sv,
706  bool negateExp = false)
707  {
708  if(this != &sv)
709  {
710  assert(max() >= sv.size());
711 
712  if(negateExp)
713  {
714  for(int i = 0; i < sv.size(); ++i)
715  {
716  m_elem[i].val = spxLdexp(sv.value(i), -scaleExp[sv.index(i)]);
717  m_elem[i].idx = sv.index(i);
718  }
719  }
720  else
721  {
722  for(int i = 0; i < sv.size(); ++i)
723  {
724  m_elem[i].val = spxLdexp(sv.value(i), scaleExp[sv.index(i)]);
725  m_elem[i].idx = sv.index(i);
726  }
727  }
728 
729  assert(isConsistent());
730  }
731 
732  return *this;
733  }
734 
735 
736  /// Assignment operator.
737  template < class S >
738  SVectorBase<R>& assignArray(const S* rowValues, const int* rowIndices, int rowSize)
739  {
740  assert(max() >= rowSize);
741 
742  int i;
743 
744  for(i = 0; i < rowSize && i < max(); i++)
745  {
746  m_elem[i].val = rowValues[i];
747  m_elem[i].idx = rowIndices[i];
748  }
749 
750  set_size(i);
751 
752  return *this;
753  }
754 
755  /// Assignment operator.
756  template < class S >
758 
759  //@}
760 
761  // ------------------------------------------------------------------------------------------------------------------
762  /**@name Memory */
763  //@{
764 
765  /// get pointer to internal memory.
766  Nonzero<R>* mem() const
767  {
768  return m_elem;
769  }
770 
771  /// Set size of the vector.
772  void set_size(int s)
773  {
774  assert(m_elem != 0 || s == 0);
775  memused = s;
776  }
777 
778  /// Set the maximum number of nonzeros in the vector.
779  void set_max(int m)
780  {
781  assert(m_elem != 0 || m == 0);
782  memsize = m;
783  }
784 
785  /// Set the memory area where the nonzeros will be stored.
786  void setMem(int n, Nonzero<R>* elmem)
787  {
788  assert(n >= 0);
789  assert(n == 0 || elmem != 0);
790 
791  m_elem = elmem;
792  set_size(0);
793  set_max(n);
794  }
795 
796  //@}
797 
798  // ------------------------------------------------------------------------------------------------------------------
799  /**@name Utilities */
800  //@{
801 
802  /// Consistency check.
803  bool isConsistent() const
804  {
805 #ifdef ENABLE_CONSISTENCY_CHECKS
806 
807  if(m_elem != 0)
808  {
809  const int my_size = size();
810  const int my_max = max();
811 
812  if(my_size < 0 || my_max < 0 || my_size > my_max)
813  return MSGinconsistent("SVectorBase");
814 
815  for(int i = 1; i < my_size; ++i)
816  {
817  for(int j = 0; j < i; ++j)
818  {
819  // allow trailing zeros
820  if(m_elem[i].idx == m_elem[j].idx && m_elem[i].val != 0)
821  return MSGinconsistent("SVectorBase");
822  }
823  }
824  }
825 
826 #endif
827 
828  return true;
829  }
830 
831  //@}
832 };
833 
834 
835 
836 /// specialization for inner product for sparse vectors
837 template <>
838 template < class S >
840 {
841  StableSum<Real> x;
842  int n = size();
843  int m = w.size();
844 
845  if(n == 0 || m == 0)
846  return Real(0);
847 
848  int i = 0;
849  int j = 0;
850  SVectorBase<Real>::Element* e = m_elem;
851  typename SVectorBase<S>::Element wj = w.element(j);
852 
853  while(true)
854  {
855  if(e->idx == wj.idx)
856  {
857  x += e->val * Real(wj.val);
858  i++;
859  j++;
860 
861  if(i == n || j == m)
862  break;
863 
864  e++;
865  wj = w.element(j);
866  }
867  else if(e->idx < wj.idx)
868  {
869  i++;
870 
871  if(i == n)
872  break;
873 
874  e++;
875  }
876  else
877  {
878  j++;
879 
880  if(j == m)
881  break;
882 
883  wj = w.element(j);
884  }
885  }
886 
887  return x;
888 }
889 
890 } // namespace soplex
891 #endif // _SVECTORBASE_H_
Rational spxAbs(const Rational &r)
Absolute.
Definition: rational.cpp:4102
const Nonzero< R > & element(int n) const
The n &#39;th nonzero element.
Definition: svectorbase.h:226
Nonzero< R > * m_elem
Definition: svectorbase.h:138
Sparse vector nonzero element.
Definition: svectorbase.h:36
R operator*(const VectorBase< R > &w) const
Inner product.
Definition: basevectors.h:1039
THREADLOCAL const Real infinity
Definition: spxdefines.cpp:26
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Definition: svectorbase.h:475
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
Definition: dsvectorbase.h:28
void setMem(int n, Nonzero< R > *elmem)
Set the memory area where the nonzeros will be stored.
Definition: svectorbase.h:786
void set_max(int m)
Set the maximum number of nonzeros in the vector.
Definition: svectorbase.h:779
SVectorBase< R > & operator=(const SVectorBase< R > &sv)
Assignment operator.
Definition: svectorbase.h:623
int size() const
Number of used indices.
Definition: svectorbase.h:153
Nonzero< R > & element(int n)
Reference to the n &#39;th nonzero element.
Definition: svectorbase.h:217
R minAbs() const
Minimum absolute value.
Definition: svectorbase.h:491
void add(int n, const int i[], const R v[])
Append n nonzeros.
Definition: svectorbase.h:309
void set_size(int s)
Set size of the vector.
Definition: svectorbase.h:772
void add(int n, const Nonzero< R > e[])
Append n nonzeros.
Definition: svectorbase.h:368
R & value(int n)
Reference to value of n &#39;th nonzero.
Definition: svectorbase.h:253
SVectorBase< R > & operator=(const SVectorBase< S > &sv)
Assignment operator.
Definition: svectorbase.h:655
int idx
Index of nonzero element.
Definition: svectorbase.h:41
Nonzero< R > * mem() const
get pointer to internal memory.
Definition: svectorbase.h:766
Semi sparse vector.This class implements semi-sparse vectors. Such are DVectorBases where the indices...
Definition: dsvectorbase.h:29
Nonzero< R > Element
Definition: svectorbase.h:146
const R & value(int n) const
Value of n &#39;th nonzero.
Definition: svectorbase.h:262
SVectorBase< R > & operator*=(const R &x)
Scaling.
Definition: svectorbase.h:529
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Definition: spxdefines.h:348
double Real
Definition: spxdefines.h:218
R operator*(const SVectorBase< S > &w) const
inner product for sparse vectors
Definition: svectorbase.h:550
int & index(int n)
Reference to index of n &#39;th nonzero.
Definition: svectorbase.h:235
R operator[](int i) const
Value to index i.
Definition: svectorbase.h:206
DVectorBase< R > operator*(const VectorBase< R > &v, R x)
Scaling.
Definition: basevectors.h:1259
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition: svectorbase.h:507
Real spxSqrt(Real a)
returns square root
Definition: spxdefines.h:332
void add(int i, const R &v)
Append one nonzero (i,v).
Definition: svectorbase.h:271
int index(int n) const
Index of n &#39;th nonzero.
Definition: svectorbase.h:244
bool isConsistent() const
Consistency check.
Definition: svectorbase.h:803
Everything should be within this namespace.
int dim() const
Dimension of the vector defined as maximal index + 1.
Definition: svectorbase.h:167
int max() const
Maximal number of indices.
Definition: svectorbase.h:160
void clear()
Remove all indices.
Definition: svectorbase.h:431
SVectorBase< Real > & scaleAssign(int scaleExp, const SVectorBase< Real > &sv)
scale and assign
Definition: svectorbase.h:686
Nonzero< R > & operator=(const Nonzero< S > &vec)
Definition: svectorbase.h:44
void add(const SVectorBase &sv)
Append nonzeros of sv.
Definition: svectorbase.h:303
SVectorBase< R > & assignArray(const S *rowValues, const int *rowIndices, int rowSize)
Assignment operator.
Definition: svectorbase.h:738
void sort()
Sort nonzeros to increasing indices.
Definition: svectorbase.h:437
int pos(int i) const
Position of index i.
Definition: svectorbase.h:186
R val
Value of nonzero element.
Definition: svectorbase.h:40
void add(int i)
Append one uninitialized nonzero.
Definition: svectorbase.h:289
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
Definition: dvectorbase.h:31
#define MSGinconsistent(name)
Definition: spxdefines.h:126
SVectorBase< Real > & scaleAssign(const int *scaleExp, const SVectorBase< Real > &sv, bool negateExp=false)
scale and assign
Definition: svectorbase.h:705
void add(int n, const int i[], const S v[])
Append n nonzeros.
Definition: svectorbase.h:339
R length2() const
Squared norm.
Definition: svectorbase.h:513