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