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