Scippy

SoPlex

Sequential object-oriented simPlex

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.
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 {
148
149 int d = dim();
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.
168 {
169 // check vector setup
170#ifndef NDEBUG
171 assert(VectorBase<R>::dim() >= 0);
172 std::vector<bool> entry(VectorBase<R>::dim(), false);
173 assert(num >= 0);
174 assert(num <= VectorBase<R>::dim());
175
176 for(int i = 0; i < num; ++i)
177 {
178 assert(idx[i] >= 0);
179 assert(idx[i] < VectorBase<R>::dim());
180 assert(VectorBase<R>::val[idx[i]] != 0);
181 assert(VectorBase<R>::val[idx[i]] == VectorBase<R>::val[idx[i]]);
182 assert(!entry[idx[i]]);
183 entry[idx[i]] = true;
184 }
185
186 for(int i = 0; i < VectorBase<R>::dim(); ++i)
187 {
188 if(!entry[i])
189 assert(soplex::isPlusZero<R>(VectorBase<R>::val[i]));
190 }
191
192#endif
193
194 setupStatus = true;
195 }
196
197 ///@}
198
199 // ------------------------------------------------------------------------------------------------------------------
200 /**@name Methods for setup SSVectorBases */
201 ///@{
202
203 /// Returns index of the \p n 'th nonzero element.
204 int index(int n) const
205 {
206 assert(isSetup());
207
208 return IdxSet::index(n);
209 }
210
211 /// Returns value of the \p n 'th nonzero element.
212 R value(int n) const
213 {
214 assert(isSetup());
215 assert(n >= 0 && n < size());
216
217 return VectorBase<R>::val[idx[n]];
218 }
219
220 /// Finds the position of index \p i in the #IdxSet, or -1 if \p i doesn't exist.
221 int pos(int i) const
222 {
223 assert(isSetup());
224
225 return IdxSet::pos(i);
226 }
227
228 /// Returns the number of nonzeros.
229 int size() const
230 {
231 assert(isSetup());
232
233 return IdxSet::size();
234 }
235
236 /// Adds nonzero (\p i, \p x) to SSVectorBase.
237 /** No nonzero with index \p i must exist in the SSVectorBase. */
238 void add(int i, R x)
239 {
240 assert(VectorBase<R>::val[i] == R(0));
241 assert(pos(i) < 0);
242
243 addIdx(i);
244 VectorBase<R>::val[i] = x;
245 }
246
247 /// Sets \p i 'th element to \p x.
248 void setValue(int i, R x)
249 {
250 assert(i >= 0);
251 assert(i < VectorBase<R>::dim());
252
253 if(isSetup())
254 {
255 int n = pos(i);
256
257 if(n < 0)
258 {
259 if(spxAbs(x) > this->getEpsilon())
260 IdxSet::add(1, &i);
261 }
262 else if(x == R(0))
263 clearNum(n);
264 }
265
266 VectorBase<R>::val[i] = x;
267
268 assert(isConsistent());
269 }
270
271 /// Scale \p i 'th element by a
272 void scaleValue(int i, int scaleExp)
273 {
274 assert(i >= 0);
275 assert(i < VectorBase<R>::dim());
276
277 VectorBase<R>::val[i] = spxLdexp(VectorBase<R>::val[i], scaleExp);
278
279 assert(isConsistent());
280 }
281
282 /// Clears element \p i.
283 void clearIdx(int i)
284 {
285 if(isSetup())
286 {
287 int n = pos(i);
288
289 if(n >= 0)
290 remove(n);
291 }
292
293 VectorBase<R>::val[i] = 0;
294
295 assert(isConsistent());
296 }
297
298 /// Sets \p n 'th nonzero element to 0 (index \p n must exist).
299 void clearNum(int n)
300 {
301 assert(isSetup());
302 assert(index(n) >= 0);
303
305 remove(n);
306
307 assert(isConsistent());
308 }
309
310 ///@}
311
312 // ------------------------------------------------------------------------------------------------------------------
313 /**@name Methods independent of the Status */
314 ///@{
315
316 /// Returns \p i 'th value.
317 R operator[](int i) const
318 {
319 return VectorBase<R>::val[i];
320 }
321
322 /// Returns array indices.
323 const int* indexMem() const
324 {
325 return idx;
326 }
327
328 /// Returns array values.
329 const R* values() const
330 {
331 return VectorBase<R>::val.data();
332 }
333
334 /// Returns indices.
335 const IdxSet& indices() const
336 {
337 return *this;
338 }
339
340 /// Returns array indices.
342 {
343 unSetup();
344 return idx;
345 }
346
347 /// Returns array values.
349 {
350 unSetup();
351 return VectorBase<R>::val.data();
352 }
353
354 /// Returns indices.
356 {
357 unSetup();
358 return *this;
359 }
360
361 ///@}
362
363 // ------------------------------------------------------------------------------------------------------------------
364 /**@name Arithmetic operations */
365 ///@{
366
367 /// Addition.
368 template < class S >
370 {
372
373 if(isSetup())
374 {
375 setupStatus = false;
376 setup();
377 }
378
379 return *this;
380 }
381
382 /// Addition.
383 template < class S >
385
386 /// Addition.
387 template < class S >
389 {
390 assert(vec.isSetup());
391
392 for(int i = vec.size() - 1; i >= 0; --i)
393 VectorBase<R>::val[vec.index(i)] += vec.value(i);
394
395 if(isSetup())
396 {
397 setupStatus = false;
398 setup();
399 }
400
401 return *this;
402 }
403
404 /// Subtraction.
405 template < class S >
407 {
409
410 if(isSetup())
411 {
412 setupStatus = false;
413 setup();
414 }
415
416 return *this;
417 }
418
419 /// Subtraction.
420 template < class S >
422
423 /// Subtraction.
424 template < class S >
426 {
427 if(vec.isSetup())
428 {
429 for(int i = vec.size() - 1; i >= 0; --i)
430 VectorBase<R>::val[vec.index(i)] -= vec.value(i);
431 }
432 else
434
435 if(isSetup())
436 {
437 setupStatus = false;
438 setup();
439 }
440
441 return *this;
442 }
443
444 /// Scaling.
445 template < class S >
447 {
448 assert(isSetup());
449 assert(x != S(0));
450
451 for(int i = size() - 1; i >= 0; --i)
452 VectorBase<R>::val[index(i)] *= x;
453
454 assert(isConsistent());
455
456 return *this;
457 }
458
459 // Inner product.
460 template < class S >
462 {
463 setup();
464
465 StableSum<R> x;
466 int i = size() - 1;
467 int j = w.size() - 1;
468
469 // both *this and w non-zero vectors?
470 if(i >= 0 && j >= 0)
471 {
472 int vi = index(i);
473 int wj = w.index(j);
474
475 while(i != 0 && j != 0)
476 {
477 if(vi == wj)
478 {
479 x += VectorBase<R>::val[vi] * R(w.val[wj]);
480 vi = index(--i);
481 wj = w.index(--j);
482 }
483 else if(vi > wj)
484 vi = index(--i);
485 else
486 wj = w.index(--j);
487 }
488
489 /* check remaining indices */
490
491 while(i != 0 && vi != wj)
492 vi = index(--i);
493
494 while(j != 0 && vi != wj)
495 wj = w.index(--j);
496
497 if(vi == wj)
498 x += VectorBase<R>::val[vi] * R(w.val[wj]);
499 }
500
501 return x;
502 }
503
504 /// Addition of a scaled vector.
505 ///@todo SSVectorBase::multAdd() should be rewritten without pointer arithmetic.
506 template < class S, class T >
508
509 /// Addition of a scaled vector.
510 template < class S, class T >
512 {
514
515 if(isSetup())
516 {
517 setupStatus = false;
518 setup();
519 }
520
521 return *this;
522 }
523
524 /// Assigns pair wise vector product to SSVectorBase.
525 template < class S, class T >
527
528 /// Assigns \f$x^T \cdot A\f$ to SSVectorBase.
529 template < class S, class T >
531
532 /// Assigns SSVectorBase to \f$A \cdot x\f$ for a setup \p x.
533 template < class S, class T >
535 Timer* timeSparse, Timer* timeFull, int& nCallsSparse, int& nCallsFull);
536
537public:
538
539 /// Assigns SSVectorBase to \f$A \cdot x\f$ thereby setting up \p x.
540 template < class S, class T >
542
543 /// Maximum absolute value, i.e., infinity norm.
544 R maxAbs() const
545 {
546 if(isSetup())
547 {
548 R maxabs = 0;
549
550 for(int i = 0; i < num; ++i)
551 {
552 R x = spxAbs(VectorBase<R>::val[idx[i]]);
553
554 if(x > maxabs)
555 maxabs = x;
556 }
557
558 return maxabs;
559 }
560 else
561 return VectorBase<R>::maxAbs();
562 }
563
564 /// Squared euclidian norm.
565 R length2() const
566 {
567 R x = 0;
568
569 if(isSetup())
570 {
571 for(int i = 0; i < num; ++i)
573 }
574 else
576
577 return x;
578 }
579
580 /// Floating point approximation of euclidian norm (without any approximation guarantee).
581 R length() const
582 {
583 return spxSqrt(R(length2()));
584 }
585
586 ///@}
587
588 // ------------------------------------------------------------------------------------------------------------------
589 /**@name Miscellaneous */
590 ///@{
591
592 /// Dimension of VectorBase.
593 int dim() const
594 {
595 return VectorBase<R>::dim();
596 }
597
598 /// Resets dimension to \p newdim.
599 void reDim(int newdim)
600 {
601 for(int i = IdxSet::size() - 1; i >= 0; --i)
602 {
603 if(index(i) >= newdim)
604 remove(i);
605 }
606
607 VectorBase<R>::reDim(newdim);
609
610 assert(isConsistent());
611 }
612
613 /// Sets number of nonzeros (thereby unSetup SSVectorBase).
614 void setSize(int n)
615 {
616 assert(n >= 0);
617 assert(n <= IdxSet::max());
618
619 unSetup();
620 num = n;
621 }
622
623 /// Resets memory consumption to \p newsize.
624 void reMem(int newsize)
625 {
626 VectorBase<R>::reSize(newsize);
627 assert(isConsistent());
628
630 }
631
632 /// Clears vector.
633 void clear()
634 {
635 if(isSetup())
636 {
637 for(int i = 0; i < num; ++i)
638 VectorBase<R>::val[idx[i]] = 0;
639 }
640 else
642
644 setupStatus = true;
645
646 assert(isConsistent());
647 }
648
649 /// consistency check.
650 bool isConsistent() const
651 {
652#ifdef ENABLE_CONSISTENCY_CHECKS
653
655 return SPX_MSG_INCONSISTENT("SSVectorBase");
656
658 return SPX_MSG_INCONSISTENT("SSVectorBase");
659
660 if(isSetup())
661 {
662 for(int i = 0; i < VectorBase<R>::dim(); ++i)
663 {
664 int j = pos(i);
665
666 if(j < 0 && spxAbs(VectorBase<R>::val[i]) > 0)
667 {
668 SPX_MSG_ERROR(std::cerr << "ESSVEC01 i = " << i
669 << "\tidx = " << j
670 << "\tval = " << std::setprecision(16) << VectorBase<R>::val[i]
671 << std::endl;)
672
673 return SPX_MSG_INCONSISTENT("SSVectorBase");
674 }
675 }
676 }
677
679#else
680 return true;
681#endif
682 }
683
684 ///@}
685
686 // ------------------------------------------------------------------------------------------------------------------
687 /**@name Constructors / Destructors */
688 ///@{
689
690 /// Default constructor.
691 explicit SSVectorBase(int p_dim, std::shared_ptr<Tolerances> tol = nullptr)
692 : VectorBase<R>(p_dim)
693 , IdxSet()
694 , setupStatus(true)
695 {
696 len = (p_dim < 1) ? 1 : p_dim;
697 spx_alloc(idx, len);
699 _tolerances = tol;
700
701 assert(isConsistent());
702 }
703
704 /// Copy constructor.
705 template < class S >
707 : VectorBase<R>(vec)
708 , IdxSet()
710 {
711 len = (vec.dim() < 1) ? 1 : vec.dim();
712 spx_alloc(idx, len);
714 _tolerances = vec._tolerances;
715
716 assert(isConsistent());
717 }
718
719 /// Copy constructor.
720 /** The redundancy with the copy constructor below is necessary since otherwise the compiler doesn't realize that it
721 * could use the more general one with S = R and generates a shallow copy constructor.
722 */
724 : VectorBase<R>(vec)
725 , IdxSet()
727 {
728 len = (vec.dim() < 1) ? 1 : vec.dim();
729 spx_alloc(idx, len);
731 _tolerances = vec._tolerances;
732
733 assert(isConsistent());
734 }
735
736 /// Constructs nonsetup copy of \p vec.
737 template < class S >
739 : VectorBase<R>(vec)
740 , IdxSet()
741 , setupStatus(false)
742 {
743 len = (vec.dim() < 1) ? 1 : vec.dim();
744 spx_alloc(idx, len);
745
746 assert(isConsistent());
747 }
748
749 /// Sets up \p rhs vector, and assigns it.
750 template < class S >
752 {
753 clear();
754 setMax(rhs.max());
756 _tolerances = rhs.tolerances();
757
758 if(rhs.isSetup())
759 {
761
762 for(int i = size() - 1; i >= 0; --i)
763 {
764 int j = index(i);
765 VectorBase<R>::val[j] = rhs.val[j];
766 }
767 }
768 else
769 {
770 int d = rhs.dim();
771 num = 0;
772
773 for(int i = 0; i < d; ++i)
774 {
775 if(isNotZero(rhs.val[i], this->getEpsilon()))
776 {
777 rhs.idx[num] = i;
778 idx[num] = i;
779 VectorBase<R>::val[i] = rhs.val[i];
780 num++;
781 }
782 else
783 rhs.val[i] = +R(0);
784 }
785
786 rhs.num = num;
787 rhs.setupStatus = true;
788 }
789
790 setupStatus = true;
791
792 assert(rhs.isConsistent());
793 assert(isConsistent());
794 }
795
796 /// Assigns only the elements of \p rhs.
797 template < class S >
799
800 /// Assignment operator.
801 template < class S >
803 {
804 assert(rhs.isConsistent());
805
806 if(this != &rhs)
807 {
808 clear();
810 setMax(rhs.max());
812
813 if(rhs.isSetup())
814 {
816
817 for(int i = size() - 1; i >= 0; --i)
818 {
819 int j = index(i);
820 VectorBase<R>::val[j] = rhs.val[j];
821 }
822 }
823 else
824 {
825 int d = rhs.dim();
826 num = 0;
827
828 for(int i = 0; i < d; ++i)
829 {
830 if(spxAbs(rhs.val[i]) > this->getEpsilon())
831 {
832 VectorBase<R>::val[i] = rhs.val[i];
833 idx[num] = i;
834 num++;
835 }
836 }
837 }
838
839 setupStatus = true;
840 }
841
842 assert(isConsistent());
843
844 return *this;
845 }
846
847 /// Assignment operator.
849 {
850 assert(rhs.isConsistent());
851
852 if(this != &rhs)
853 {
854 clear();
856 setMax(rhs.max());
858
859 if(rhs.isSetup())
860 {
862
863 for(int i = size() - 1; i >= 0; --i)
864 {
865 int j = index(i);
866 VectorBase<R>::val[j] = rhs.val[j];
867 }
868 }
869 else
870 {
871 num = 0;
872
873 for(int i = 0; i < rhs.dim(); ++i)
874 {
875 if(spxAbs(rhs.val[i]) > this->getEpsilon())
876 {
877 VectorBase<R>::val[i] = rhs.val[i];
878 idx[num] = i;
879 num++;
880 }
881 }
882 }
883
884 setupStatus = true;
885 }
886
887 assert(isConsistent());
888
889 return *this;
890 }
891
892 /// Assignment operator.
893 template < class S >
895
896 /// Assignment operator.
897 template < class S >
899 {
900 unSetup();
902
903 assert(isConsistent());
904
905 return *this;
906 }
907
908 /// destructor
910 {
911 if(idx)
912 spx_free(idx);
913 }
914
915 ///@}
916
917private:
918
919 // ------------------------------------------------------------------------------------------------------------------
920 /**@name Private helpers */
921 ///@{
922
923 /// Assignment helper.
924 template < class S, class T >
926
927 /// Assignment helper.
928 template < class S, class T >
930
931 /// Assignment helper.
932 template < class S, class T >
934
935 ///@}
936};
937
938} // namespace soplex
939#endif // _SSVECTORBASE_H_
Dynamic sparse vectors.
Definition: dsvectorbase.h:53
Set of indices.
Definition: idxset.h:66
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
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
Semi sparse vector.
Definition: ssvectorbase.h:57
R * get_ptr()
Only used in slufactor.hpp.
Definition: ssvectorbase.h:108
SSVectorBase(const SSVectorBase< S > &vec)
Copy constructor.
Definition: ssvectorbase.h:706
SSVectorBase< R > & assign2productShort(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:637
SSVectorBase< R > & assign2product1(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:601
bool setupStatus
Is the SSVectorBase set up?
Definition: ssvectorbase.h:68
const R * values() const
Returns array values.
Definition: ssvectorbase.h:329
SSVectorBase< R > & multAdd(S xx, const SVectorBase< T > &vec)
Addition of a scaled vector.
Definition: basevectors.h:387
SSVectorBase(const SSVectorBase< R > &vec)
Copy constructor.
Definition: ssvectorbase.h:723
R length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Definition: ssvectorbase.h:581
SSVectorBase< R > & assign(const SVectorBase< S > &rhs)
Assigns only the elements of rhs.
Definition: basevectors.h:831
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.
Definition: basevectors.h:539
SSVectorBase(const VectorBase< S > &vec)
Constructs nonsetup copy of vec.
Definition: ssvectorbase.h:738
R length2() const
Squared euclidian norm.
Definition: ssvectorbase.h:565
void scaleValue(int i, int scaleExp)
Scale i 'th element by a.
Definition: ssvectorbase.h:272
SSVectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition: ssvectorbase.h:406
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Definition: ssvectorbase.h:544
bool isConsistent() const
consistency check.
Definition: ssvectorbase.h:650
SSVectorBase(int p_dim, std::shared_ptr< Tolerances > tol=nullptr)
Default constructor.
Definition: ssvectorbase.h:691
R * altValues()
Returns array values.
Definition: ssvectorbase.h:348
virtual void setTolerances(std::shared_ptr< Tolerances > newTolerances)
set the _tolerances member variable
Definition: ssvectorbase.h:114
void setup()
Initializes nonzero indices for elements with absolute values above epsilon and sets all other elemen...
Definition: ssvectorbase.h:143
SSVectorBase< R > & assign2product(const SSVectorBase< S > &x, const SVSetBase< T > &A)
Assigns to SSVectorBase.
Definition: basevectors.h:508
SSVectorBase< R > & operator-=(const SSVectorBase< S > &vec)
Subtraction.
Definition: ssvectorbase.h:425
void reMem(int newsize)
Resets memory consumption to newsize.
Definition: ssvectorbase.h:624
int pos(int i) const
Finds the position of index i in the IdxSet, or -1 if i doesn't exist.
Definition: ssvectorbase.h:221
R value(int n) const
Returns value of the n 'th nonzero element.
Definition: ssvectorbase.h:212
void add(int i, R x)
Adds nonzero (i, x) to SSVectorBase.
Definition: ssvectorbase.h:238
std::shared_ptr< Tolerances > _tolerances
Definition: ssvectorbase.h:84
SSVectorBase< R > & assignPWproduct4setup(const SSVectorBase< S > &x, const SSVectorBase< T > &y)
Assigns pair wise vector product to SSVectorBase.
Definition: basevectors.h:447
SSVectorBase< R > & operator=(const SSVectorBase< S > &rhs)
Assignment operator.
Definition: ssvectorbase.h:802
void clearIdx(int i)
Clears element i.
Definition: ssvectorbase.h:283
void forceSetup()
Forces setup status.
Definition: ssvectorbase.h:167
SSVectorBase< R > & operator=(const SSVectorBase< R > &rhs)
Assignment operator.
Definition: ssvectorbase.h:848
void unSetup()
Makes SSVectorBase not setup.
Definition: ssvectorbase.h:137
SSVectorBase< R > & multAdd(S x, const VectorBase< T > &vec)
Addition of a scaled vector.
Definition: ssvectorbase.h:511
void setSize(int n)
Sets number of nonzeros (thereby unSetup SSVectorBase).
Definition: ssvectorbase.h:614
R operator[](int i) const
Returns i 'th value.
Definition: ssvectorbase.h:317
SSVectorBase< R > & operator*=(S x)
Scaling.
Definition: ssvectorbase.h:446
void setValue(int i, R x)
Sets i 'th element to x.
Definition: ssvectorbase.h:248
int * altIndexMem()
Returns array indices.
Definition: ssvectorbase.h:341
~SSVectorBase()
destructor
Definition: ssvectorbase.h:909
int index(int n) const
Returns index of the n 'th nonzero element.
Definition: ssvectorbase.h:204
int dim() const
Dimension of VectorBase.
Definition: ssvectorbase.h:593
SSVectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Definition: ssvectorbase.h:369
void setup_and_assign(SSVectorBase< S > &rhs)
Sets up rhs vector, and assigns it.
Definition: ssvectorbase.h:751
const int * indexMem() const
Returns array indices.
Definition: ssvectorbase.h:323
R operator*(const SSVectorBase< S > &w)
Definition: ssvectorbase.h:461
IdxSet & altIndices()
Returns indices.
Definition: ssvectorbase.h:355
void clear()
Clears vector.
Definition: ssvectorbase.h:633
void setMax(int newmax)
Allocates enough space to accommodate newmax values.
Definition: ssvectorbase.h:71
const IdxSet & indices() const
Returns indices.
Definition: ssvectorbase.h:335
void reDim(int newdim)
Resets dimension to newdim.
Definition: ssvectorbase.h:599
SSVectorBase< R > & operator+=(const SSVectorBase< S > &vec)
Addition.
Definition: ssvectorbase.h:388
SSVectorBase< R > & assign2productFull(const SVSetBase< S > &A, const SSVectorBase< T > &x)
Assignment helper.
Definition: basevectors.h:729
SSVectorBase< R > & operator=(const VectorBase< S > &rhs)
Assignment operator.
Definition: ssvectorbase.h:898
bool isSetup() const
Returns setup status.
Definition: ssvectorbase.h:126
const std::shared_ptr< Tolerances > & tolerances() const
returns current tolerances
Definition: ssvectorbase.h:120
void clearNum(int n)
Sets n 'th nonzero element to 0 (index n must exist).
Definition: ssvectorbase.h:299
SSVectorBase< R > & assign2productAndSetup(const SVSetBase< S > &A, SSVectorBase< T > &x)
Assigns SSVectorBase to thereby setting up x.
Definition: basevectors.h:773
int size() const
Returns the number of nonzeros.
Definition: ssvectorbase.h:229
Sparse vector set.
Definition: svsetbase.h:73
Sparse vectors.
Definition: svectorbase.h:140
Wrapper for the system time query methods.
Definition: timer.h:86
Dense vector.
Definition: vectorbase.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
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
Definition: vectorbase.h:338
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< R > & vec()
Return underlying std::vector.
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.
void spx_realloc(T &p, size_t n)
Change amount of allocated memory.
Definition: spxalloc.h:89
R spxAbs(R a)
Definition: spxdefines.h:409
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:118
Real spxSqrt(Real a)
returns square root
Definition: spxdefines.h:442
void spx_alloc(T &p, size_t n=1)
Allocate memory.
Definition: spxalloc.h:58
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.