SoPlex
Loading...
Searching...
No Matches
ssvectorbase.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 ssvectorbase.h
26 * @brief Semi sparse vector.
27 */
28#ifndef _SSVECTORBASE_H_
29#define _SSVECTORBASE_H_
30
31#include <assert.h>
32
33#include "soplex/spxdefines.h"
34#include "soplex/vectorbase.h"
35#include "soplex/idxset.h"
36#include "soplex/spxalloc.h"
37#include "soplex/timer.h"
38#include "soplex/stablesum.h"
39
40namespace soplex
41{
42template < class R > class SVectorBase;
43template < class R > class SVSetBase;
44
45/**@brief Semi sparse vector.
46 * @ingroup Algebra
47 *
48 * This class implements semi-sparse vectors. Such are #VectorBase%s where the indices of its nonzero elements can be
49 * stored in an extra IdxSet. Only elements with absolute value > #getEpsilon() are considered to be nonzero. Since really
50 * storing the nonzeros is not always convenient, an SSVectorBase provides two different stati: setup and not setup.
51 * An SSVectorBase being setup means that the nonzero indices are available, otherwise an SSVectorBase is just an
52 * ordinary VectorBase with an empty IdxSet. Note that due to arithmetic operation, zeros can slip in, i.e., it is
53 * only guaranteed that at least every non-zero is in the IdxSet.
54 */
55template < class R >
56class SSVectorBase : public VectorBase<R>, protected IdxSet
57{
58private:
59
60 friend class VectorBase<R>;
61 template < class S > friend class DSVectorBase;
62
63 // ------------------------------------------------------------------------------------------------------------------
64 /**@name Data */
65 ///@{
66
67 /// Is the SSVectorBase set up?
69
70 /// Allocates enough space to accommodate \p newmax values.
71 void setMax(int newmax)
72 {
73 assert(idx != nullptr);
74 assert(newmax != 0);
75 assert(newmax >= IdxSet::size());
76
77 len = newmax;
79 }
80
81 ///@}
82
83protected:
84 std::shared_ptr<Tolerances> _tolerances;
85
86public:
87
88 // ------------------------------------------------------------------------------------------------------------------
89 /**@name Status of an SSVectorBase
90 *
91 * An SSVectorBase can be set up or not. In case it is set up, its IdxSet correctly contains all indices of nonzero
92 * elements of the SSVectorBase. Otherwise, it does not contain any useful data. Whether or not an SSVectorBase is
93 * setup can be determined with the method \ref soplex::SSVectorBase::isSetup() "isSetup()".
94 *
95 * There are three methods for directly affecting the setup status of an SSVectorBase:
96 *
97 * - unSetup(): This method sets the status to ``not setup''.
98 *
99 * - setup(): This method initializes the IdxSet to the SSVectorBase's nonzero indices and sets the status to
100 * ``setup''.
101 *
102 * - forceSetup(): This method sets the status to ``setup'' without verifying that the IdxSet correctly contains all
103 * nonzero indices. It may be used when the nonzero indices have been computed externally.
104 */
105 ///@{
106
107 /// Only used in slufactor.hpp.
108 R* get_ptr()
109 {
110 return VectorBase<R>::get_ptr();
111 }
112
113 /// set the _tolerances member variable
114 virtual void setTolerances(std::shared_ptr<Tolerances> newTolerances)
115 {
116 this->_tolerances = newTolerances;
117 }
118
119 /// returns current tolerances
120 const std::shared_ptr<Tolerances>& tolerances() const
121 {
122 return this->_tolerances;
123 }
124
125 /// Returns setup status.
126 bool isSetup() const
127 {
128 return setupStatus;
129 }
130
131 R getEpsilon() const
132 {
133 return this->_tolerances == nullptr ? R(0) : R(this->tolerances()->epsilon());
134 }
135
136 /// Makes SSVectorBase not setup.
137 void unSetup()
138 {
139 setupStatus = false;
140 }
141
142 /// Initializes nonzero indices for elements with absolute values above epsilon and sets all other elements to 0.
143 void setup()
144 {
145 if(!isSetup())
146 {
147 const int d = dim();
148
150 num = 0;
151
152 for(int i = 0; i < d; ++i)
153 {
154 if(isNotZero(VectorBase<R>::val[i], this->getEpsilon()))
155 idx[num++] = i;
156 else
157 VectorBase<R>::val[i] = +R(0);
158 }
159
160 setupStatus = true;
161
162 assert(isConsistent());
163 }
164 }
165
166 /// Forces setup status.
167 void forceSetup()
168 {
169 // check vector setup
170#ifndef NDEBUG
171 const int d = VectorBase<R>::dim();
172 assert(d >= 0);
173 std::vector<bool> entry(d, false);
174 assert(num >= 0);
175 assert(num <= d);
176
177 for(int i = 0; i < num; ++i)
178 {
179 assert(idx[i] >= 0);
180 assert(idx[i] < d);
181 assert(VectorBase<R>::val[idx[i]] != 0);
182 assert(VectorBase<R>::val[idx[i]] == VectorBase<R>::val[idx[i]]);
183 assert(!entry[idx[i]]);
184 entry[idx[i]] = true;
185 }
186
187 for(int i = 0; i < d; ++i)
188 {
189 if(!entry[i])
191 }
192
193#endif
194
195 setupStatus = true;
196 }
197
198 ///@}
199
200 // ------------------------------------------------------------------------------------------------------------------
201 /**@name Methods for setup SSVectorBases */
202 ///@{
203
204 /// Returns index of the \p n 'th nonzero element.
205 int index(int n) const
206 {
207 assert(isSetup());
208
209 return IdxSet::index(n);
210 }
211
212 /// Returns value of the \p n 'th nonzero element.
213 R value(int n) const
214 {
215 assert(isSetup());
216 assert(n >= 0 && n < size());
217
218 return VectorBase<R>::val[idx[n]];
219 }
220
221 /// Finds the position of index \p i in the #IdxSet, or -1 if \p i doesn't exist.
222 int pos(int i) const
223 {
224 assert(isSetup());
225
226 return IdxSet::pos(i);
227 }
228
229 /// Returns the number of nonzeros.
230 int size() const
231 {
232 assert(isSetup());
233
234 return IdxSet::size();
235 }
236
237 /// Adds nonzero (\p i, \p x) to SSVectorBase.
238 /** No nonzero with index \p i must exist in the SSVectorBase. */
239 void add(int i, R x)
240 {
241 assert(VectorBase<R>::val[i] == R(0));
242 assert(pos(i) < 0);
243
244 addIdx(i);
245 VectorBase<R>::val[i] = x;
246 }
247
248 /// Sets \p i 'th element to \p x.
249 void setValue(int i, R x)
250 {
251 assert(i >= 0);
252 assert(i < VectorBase<R>::dim());
253
254 if(isSetup())
255 {
256 int n = pos(i);
257
258 if(n < 0)
259 {
260 if(spxAbs(x) > this->getEpsilon())
261 IdxSet::add(1, &i);
262 }
263 else if(x == R(0))
264 clearNum(n);
265 }
266
267 VectorBase<R>::val[i] = x;
268
269 assert(isConsistent());
270 }
271
272 /// Scale \p i 'th element by a
273 void scaleValue(int i, int scaleExp)
274 {
275 assert(i >= 0);
276 assert(i < VectorBase<R>::dim());
277
278 VectorBase<R>::val[i] = spxLdexp(VectorBase<R>::val[i], scaleExp);
279
280 assert(isConsistent());
281 }
282
283 /// Clears element \p i.
284 void clearIdx(int i)
285 {
286 if(isSetup())
287 {
288 int n = pos(i);
289
290 if(n >= 0)
291 remove(n);
292 }
293
294 VectorBase<R>::val[i] = 0;
295
296 assert(isConsistent());
297 }
298
299 /// Sets \p n 'th nonzero element to 0 (index \p n must exist).
300 void clearNum(int n)
301 {
302 assert(isSetup());
303 assert(index(n) >= 0);
304
306 remove(n);
307
308 assert(isConsistent());
309 }
310
311 ///@}
312
313 // ------------------------------------------------------------------------------------------------------------------
314 /**@name Methods independent of the Status */
315 ///@{
316
317 /// Returns \p i 'th value.
318 R operator[](int i) const
319 {
320 return VectorBase<R>::val[i];
321 }
322
323 /// Returns array indices.
324 const int* indexMem() const
325 {
326 return idx;
327 }
328
329 /// Returns array values.
330 const R* values() const
331 {
332 return VectorBase<R>::val.data();
333 }
334
335 /// Returns indices.
336 const IdxSet& indices() const
337 {
338 return *this;
339 }
340
341 /// Returns array indices.
343 {
344 unSetup();
345 return idx;
346 }
347
348 /// Returns array values.
350 {
351 unSetup();
352 return VectorBase<R>::val.data();
353 }
354
355 /// Returns indices.
357 {
358 unSetup();
359 return *this;
360 }
361
362 ///@}
363
364 // ------------------------------------------------------------------------------------------------------------------
365 /**@name Arithmetic operations */
366 ///@{
367
368 /// Addition.
369 template < class S >
371 {
373
374 if(isSetup())
375 {
376 setupStatus = false;
377 setup();
378 }
379
380 return *this;
381 }
382
383 /// Addition.
384 template < class S >
386
387 /// Addition.
388 template < class S >
390 {
391 assert(vec.isSetup());
392
393 for(int i = vec.size() - 1; i >= 0; --i)
394 VectorBase<R>::val[vec.index(i)] += vec.value(i);
395
396 if(isSetup())
397 {
398 setupStatus = false;
399 setup();
400 }
401
402 return *this;
403 }
404
405 /// Subtraction.
406 template < class S >
408 {
410
411 if(isSetup())
412 {
413 setupStatus = false;
414 setup();
415 }
416
417 return *this;
418 }
419
420 /// Subtraction.
421 template < class S >
423
424 /// Subtraction.
425 template < class S >
427 {
428 if(vec.isSetup())
429 {
430 for(int i = vec.size() - 1; i >= 0; --i)
431 VectorBase<R>::val[vec.index(i)] -= vec.value(i);
432 }
433 else
435
436 if(isSetup())
437 {
438 setupStatus = false;
439 setup();
440 }
441
442 return *this;
443 }
444
445 /// Scaling.
446 template < class S >
448 {
449 assert(isSetup());
450 assert(x != S(0));
451
452 for(int i = size() - 1; i >= 0; --i)
453 VectorBase<R>::val[index(i)] *= x;
454
455 assert(isConsistent());
456
457 return *this;
458 }
459
460 // Inner product.
461 template < class S >
463 {
464 setup();
465
466 StableSum<R> x;
467 int i = size() - 1;
468 int j = w.size() - 1;
469
470 // both *this and w non-zero vectors?
471 if(i >= 0 && j >= 0)
472 {
473 int vi = index(i);
474 int wj = w.index(j);
475
476 while(i != 0 && j != 0)
477 {
478 if(vi == wj)
479 {
480 x += VectorBase<R>::val[vi] * R(w.val[wj]);
481 vi = index(--i);
482 wj = w.index(--j);
483 }
484 else if(vi > wj)
485 vi = index(--i);
486 else
487 wj = w.index(--j);
488 }
489
490 /* check remaining indices */
491
492 while(i != 0 && vi != wj)
493 vi = index(--i);
494
495 while(j != 0 && vi != wj)
496 wj = w.index(--j);
497
498 if(vi == wj)
499 x += VectorBase<R>::val[vi] * R(w.val[wj]);
500 }
501
502 return x;
503 }
504
505 /// Addition of a scaled vector.
506 ///@todo SSVectorBase::multAdd() should be rewritten without pointer arithmetic.
507 template < class S, class T >
509
510 /// Addition of a scaled vector.
511 template < class S, class T >
513 {
515
516 if(isSetup())
517 {
518 setupStatus = false;
519 setup();
520 }
521
522 return *this;
523 }
524
525 /// Assigns pair wise vector product to SSVectorBase.
526 template < class S, class T >
528
529 /// Assigns \f$x^T \cdot A\f$ to SSVectorBase.
530 template < class S, class T >
532
533 /// Assigns SSVectorBase to \f$A \cdot x\f$ for a setup \p x.
534 template < class S, class T >
536 Timer* timeSparse, Timer* timeFull, int& nCallsSparse, int& nCallsFull);
537
538public:
539
540 /// Assigns SSVectorBase to \f$A \cdot x\f$ thereby setting up \p x.
541 template < class S, class T >
543
544 /// Maximum absolute value, i.e., infinity norm.
545 R maxAbs() const
546 {
547 if(isSetup())
548 {
549 R maxabs = 0;
550
551 for(int i = 0; i < num; ++i)
552 {
553 R x = spxAbs(VectorBase<R>::val[idx[i]]);
554
555 if(x > maxabs)
556 maxabs = x;
557 }
558
559 return maxabs;
560 }
561 else
562 return VectorBase<R>::maxAbs();
563 }
564
565 /// Squared euclidian norm.
566 R length2() const
567 {
568 R x = 0;
569
570 if(isSetup())
571 {
572 for(int i = 0; i < num; ++i)
574 }
575 else
577
578 return x;
579 }
580
581 /// Floating point approximation of euclidian norm (without any approximation guarantee).
582 R length() const
583 {
584 return spxSqrt(R(length2()));
585 }
586
587 ///@}
588
589 // ------------------------------------------------------------------------------------------------------------------
590 /**@name Miscellaneous */
591 ///@{
592
593 /// Dimension of VectorBase.
594 int dim() const
595 {
596 return VectorBase<R>::dim();
597 }
598
599 /// Resets dimension to \p newdim.
600 void reDim(int newdim)
601 {
602 for(int i = IdxSet::size() - 1; i >= 0; --i)
603 {
604 if(index(i) >= newdim)
605 remove(i);
606 }
607
608 VectorBase<R>::reDim(newdim);
610
611 assert(isConsistent());
612 }
613
614 /// Sets number of nonzeros (thereby unSetup SSVectorBase).
615 void setSize(int n)
616 {
617 assert(n >= 0);
618 assert(n <= IdxSet::max());
619
620 unSetup();
621 num = n;
622 }
623
624 /// Resets memory consumption to \p newsize.
625 void reMem(int newsize)
626 {
627 VectorBase<R>::reSize(newsize);
628 assert(isConsistent());
629
631 }
632
633 /// Clears vector.
634 void clear()
635 {
636 if(isSetup())
637 {
638 for(int i = 0; i < num; ++i)
639 VectorBase<R>::val[idx[i]] = 0;
640 }
641 else
643
645 setupStatus = true;
646
647 assert(isConsistent());
648 }
649
650 /// consistency check.
651 bool isConsistent() const
652 {
653#ifdef ENABLE_CONSISTENCY_CHECKS
654 const int d = VectorBase<R>::dim();
655
656 if(d > IdxSet::max())
657 return SPX_MSG_INCONSISTENT("SSVectorBase");
658
659 if(d < IdxSet::dim())
660 return SPX_MSG_INCONSISTENT("SSVectorBase");
661
662 if(isSetup())
663 {
664 for(int i = 0; i < d; ++i)
665 {
666 const int j = pos(i);
667
668 if(j < 0 && spxAbs(VectorBase<R>::val[i]) > 0)
669 {
670 SPX_MSG_ERROR(std::cerr << "ESSVEC01 i = " << i
671 << "\tidx = " << j
672 << "\tval = " << std::setprecision(16) << VectorBase<R>::val[i]
673 << std::endl;)
674
675 return SPX_MSG_INCONSISTENT("SSVectorBase");
676 }
677 }
678 }
679
681#else
682 return true;
683#endif
684 }
685
686 ///@}
687
688 // ------------------------------------------------------------------------------------------------------------------
689 /**@name Constructors / Destructors */
690 ///@{
691
692 /// Default constructor.
693 explicit SSVectorBase(int p_dim, std::shared_ptr<Tolerances> tol = nullptr)
694 : VectorBase<R>(p_dim)
695 , IdxSet()
696 , setupStatus(true)
697 {
698 len = (p_dim < 1) ? 1 : p_dim;
699 spx_alloc(idx, len);
701 _tolerances = tol;
702
703 assert(isConsistent());
704 }
705
706 /// Copy constructor.
707 template < class S >
709 : VectorBase<R>(vec)
710 , IdxSet()
712 {
713 len = (vec.dim() < 1) ? 1 : vec.dim();
714 spx_alloc(idx, len);
716 _tolerances = vec._tolerances;
717
718 assert(isConsistent());
719 }
720
721 /// Copy constructor.
722 /** The redundancy with the copy constructor below is necessary since otherwise the compiler doesn't realize that it
723 * could use the more general one with S = R and generates a shallow copy constructor.
724 */
726 : VectorBase<R>(vec)
727 , IdxSet()
729 {
730 len = (vec.dim() < 1) ? 1 : vec.dim();
731 spx_alloc(idx, len);
733 _tolerances = vec._tolerances;
734
735 assert(isConsistent());
736 }
737
738 /// Constructs nonsetup copy of \p vec.
739 template < class S >
741 : VectorBase<R>(vec)
742 , IdxSet()
743 , setupStatus(false)
744 {
745 len = (vec.dim() < 1) ? 1 : vec.dim();
746 spx_alloc(idx, len);
747
748 assert(isConsistent());
749 }
750
751 /// Sets up \p rhs vector, and assigns it.
752 template < class S >
754 {
755 clear();
756 setMax(rhs.max());
758 _tolerances = rhs.tolerances();
759
760 if(rhs.isSetup())
761 {
763
764 for(int i = size() - 1; i >= 0; --i)
765 {
766 const int j = index(i);
767
768 VectorBase<R>::val[j] = rhs.val[j];
769 }
770 }
771 else
772 {
773 const int d = rhs.dim();
774
775 num = 0;
776
777 for(int i = 0; i < d; ++i)
778 {
779 if(isNotZero(rhs.val[i], this->getEpsilon()))
780 {
781 rhs.idx[num] = i;
782 idx[num] = i;
783 VectorBase<R>::val[i] = rhs.val[i];
784 ++num;
785 }
786 else
787 rhs.val[i] = +R(0);
788 }
789
790 rhs.num = num;
791 rhs.setupStatus = true;
792 }
793
794 setupStatus = true;
795
796 assert(rhs.isConsistent());
797 assert(isConsistent());
798 }
799
800 /// Assigns only the elements of \p rhs.
801 template < class S >
803
804 /// Assignment operator.
805 template < class S >
807 {
808 assert(rhs.isConsistent());
809
810 if(this != &rhs)
811 {
812 clear();
814 setMax(rhs.max());
816
817 if(rhs.isSetup())
818 {
820
821 for(int i = size() - 1; i >= 0; --i)
822 {
823 const int j = index(i);
824
825 VectorBase<R>::val[j] = rhs.val[j];
826 }
827 }
828 else
829 {
830 const int d = rhs.dim();
831
832 num = 0;
833
834 for(int i = 0; i < d; ++i)
835 {
836 if(spxAbs(rhs.val[i]) > this->getEpsilon())
837 {
838 VectorBase<R>::val[i] = rhs.val[i];
839 idx[num] = i;
840 ++num;
841 }
842 }
843 }
844
845 setupStatus = true;
846 }
847
848 assert(isConsistent());
849
850 return *this;
851 }
852
853 /// Assignment operator.
855 {
856 assert(rhs.isConsistent());
857
858 if(this != &rhs)
859 {
860 clear();
862 setMax(rhs.max());
864
865 if(rhs.isSetup())
866 {
868
869 for(int i = size() - 1; i >= 0; --i)
870 {
871 const int j = index(i);
872
873 VectorBase<R>::val[j] = rhs.val[j];
874 }
875 }
876 else
877 {
878 const int d = rhs.dim();
879
880 num = 0;
881
882 for(int i = 0; i < d; ++i)
883 {
884 if(spxAbs(rhs.val[i]) > this->getEpsilon())
885 {
886 VectorBase<R>::val[i] = rhs.val[i];
887 idx[num] = i;
888 ++num;
889 }
890 }
891 }
892
893 setupStatus = true;
894 }
895
896 assert(isConsistent());
897
898 return *this;
899 }
900
901 /// Assignment operator.
902 template < class S >
904
905 /// Assignment operator.
906 template < class S >
908 {
909 unSetup();
911
912 assert(isConsistent());
913
914 return *this;
915 }
916
917 /// destructor
919 {
920 if(idx)
921 spx_free(idx);
922 }
923
924 ///@}
925
926private:
927
928 // ------------------------------------------------------------------------------------------------------------------
929 /**@name Private helpers */
930 ///@{
931
932 /// Assignment helper.
933 template < class S, class T >
935
936 /// Assignment helper.
937 template < class S, class T >
939
940 /// Assignment helper.
941 template < class S, class T >
943
944 ///@}
945};
946
947} // namespace soplex
948#endif // _SSVECTORBASE_H_
bool isConsistent() const
consistency check.
Definition idxset.cpp:126
int pos(int i) const
returns the position of index i.
Definition idxset.cpp:41
void addIdx(int i)
appends index i.
Definition idxset.h:174
void remove(int n, int m)
removes indices at position numbers n through m.
Definition idxset.cpp:60
int max() const
returns the maximal number of indices which can be stored in IdxSet.
Definition idxset.h:138
int num
number of used indices
Definition idxset.h:72
IdxSet(int n, int imem[], int l=0)
constructor.
Definition idxset.h:89
int index(int n) const
access n 'th index.
Definition idxset.h:127
int dim() const
returns the maximal index.
Definition idxset.cpp:30
int * idx
array of indices
Definition idxset.h:74
void clear()
removes all indices.
Definition idxset.h:193
void add(int n)
appends n uninitialized indices.
Definition idxset.h:158
int size() const
returns the number of used indices.
Definition idxset.h:133
IdxSet & operator=(const IdxSet &set)
assignment operator.
Definition idxset.cpp:80
int len
length of array idx
Definition idxset.h:73
SSVectorBase(const SSVectorBase< S > &vec)
Copy constructor.
SSVectorBase< R > & assign2productShort(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
SSVectorBase< R > & assign2product1(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
const R * values() const
Returns array values.
SSVectorBase< R > & multAdd(S xx, const SVectorBase< T > &vec)
Addition of a scaled vector.
SSVectorBase(const SSVectorBase< R > &vec)
Copy constructor.
R length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
SSVectorBase< R > & assign2product4setup(const SVSetBase< S > &A, const SSVectorBase< T > &x, Timer *timeSparse, Timer *timeFull, int &nCallsSparse, int &nCallsFull)
Assigns SSVectorBase to for a setup x.
SSVectorBase(const VectorBase< S > &vec)
Constructs nonsetup copy of vec.
R length2() const
Squared euclidian norm.
void scaleValue(int i, int scaleExp)
Scale i 'th element by a.
SSVectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
bool isConsistent() const
consistency check.
SSVectorBase(int p_dim, std::shared_ptr< Tolerances > tol=nullptr)
Default constructor.
R * altValues()
Returns array values.
SSVectorBase< R > & operator=(const SVectorBase< S > &rhs)
Assignment operator.
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
SSVectorBase< R > & operator-=(const SSVectorBase< S > &vec)
Subtraction.
void reMem(int newsize)
Resets memory consumption to newsize.
int pos(int i) const
Finds the position of index i in the IdxSet, or -1 if i doesn't exist.
R value(int n) const
Returns value of the n 'th nonzero element.
void add(int i, R x)
Adds nonzero (i, x) to SSVectorBase.
std::shared_ptr< Tolerances > _tolerances
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
SSVectorBase< R > & operator=(const SSVectorBase< S > &rhs)
Assignment operator.
void clearIdx(int i)
Clears element i.
SSVectorBase< R > & operator=(const SSVectorBase< R > &rhs)
Assignment operator.
SSVectorBase< R > & multAdd(S x, const VectorBase< T > &vec)
Addition of a scaled vector.
void setSize(int n)
Sets number of nonzeros (thereby unSetup SSVectorBase).
R operator[](int i) const
Returns i 'th value.
SSVectorBase< R > & operator*=(S x)
Scaling.
void setValue(int i, R x)
Sets i 'th element to x.
int * altIndexMem()
Returns array indices.
~SSVectorBase()
destructor
int index(int n) const
Returns index of the n 'th nonzero element.
int dim() const
Dimension of VectorBase.
SSVectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
const int * indexMem() const
Returns array indices.
R operator*(const SSVectorBase< S > &w)
IdxSet & altIndices()
Returns indices.
void clear()
Clears vector.
SSVectorBase< R > & operator-=(const SVectorBase< S > &vec)
Subtraction.
void setMax(int newmax)
Allocates enough space to accommodate newmax values.
const IdxSet & indices() const
Returns indices.
void reDim(int newdim)
Resets dimension to newdim.
SSVectorBase< R > & operator+=(const SSVectorBase< S > &vec)
Addition.
SSVectorBase< R > & operator+=(const SVectorBase< S > &vec)
Addition.
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
SSVectorBase< R > & operator=(const VectorBase< S > &rhs)
Assignment operator.
void clearNum(int n)
Sets n 'th nonzero element to 0 (index n must exist).
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
int size() const
Returns the number of nonzeros.
Sparse vector set.
Definition svsetbase.h:73
Sparse vectors.
Wrapper for the system time query methods.
Definition timer.h:86
R * get_ptr()
Conversion to C-style pointer.
Definition vectorbase.h:494
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Definition vectorbase.h:316
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
Definition vectorbase.h:157
R length2() const
Squared norm.
Definition vectorbase.h:451
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Definition vectorbase.h:405
bool isConsistent() const
Consistency check.
Definition vectorbase.h:622
friend class VectorBase
Definition vectorbase.h:91
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition vectorbase.h:338
int memSize() const
Definition vectorbase.h:535
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
Definition vectorbase.h:541
int dim() const
Dimension of vector.
Definition vectorbase.h:270
std::vector< R > val
Values of vector.
Definition vectorbase.h:101
void reSize(int newsize)
Resets VectorBase's memory size to newsize.
Definition vectorbase.h:560
const std::vector< Real > & vec()
Definition vectorbase.h:296
void clear()
Set vector to contain all-zeros (keeping the same length).
Definition vectorbase.h:308
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Definition vectorbase.h:458
Set of indices.
Everything should be within this namespace.
R spxAbs(R a)
Definition spxdefines.h:409
void spx_alloc(T &p, size_t n=1)
Allocate memory.
Definition spxalloc.h:58
bool isPlusZero(R x)
detects whether value is positive zero
Definition spxdefines.h:312
Real spxSqrt(Real a)
returns square root
Definition spxdefines.h:442
void spx_free(T &p)
Release memory.
Definition spxalloc.h:118
void spx_realloc(T &p, size_t n)
Change amount of allocated memory.
Definition spxalloc.h:89
Memory allocation routines.
Debugging, floating point type and parameter definitions.
#define SPX_MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::VERB_ERROR.
Definition spxdefines.h:163
#define SPX_MSG_INCONSISTENT(name)
Definition spxdefines.h:175
Timer class.
Dense vector.