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