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