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