28#ifndef _SSVECTORBASE_H_
29#define _SSVECTORBASE_H_
73 assert(
idx !=
nullptr);
114 virtual void setTolerances(std::shared_ptr<Tolerances> newTolerances)
116 this->_tolerances = newTolerances;
120 const std::shared_ptr<Tolerances>& tolerances()
const
122 return this->_tolerances;
133 return this->
_tolerances ==
nullptr ? R(0) : R(this->tolerances()->epsilon());
152 for(
int i = 0; i < d; ++i)
173 std::vector<bool> entry(d,
false);
177 for(
int i = 0; i <
num; ++i)
183 assert(!entry[
idx[i]]);
184 entry[
idx[i]] =
true;
187 for(
int i = 0; i < d; ++i)
216 assert(n >= 0 && n <
size());
260 if(
spxAbs(x) > this->getEpsilon())
303 assert(
index(n) >= 0);
391 assert(
vec.isSetup());
393 for(
int i =
vec.size() - 1; i >= 0; --i)
430 for(
int i =
vec.size() - 1; i >= 0; --i)
452 for(
int i =
size() - 1; i >= 0; --i)
468 int j = w.
size() - 1;
476 while(i != 0 && j != 0)
492 while(i != 0 && vi != wj)
495 while(j != 0 && vi != wj)
507 template <
class S,
class T >
511 template <
class S,
class T >
526 template <
class S,
class T >
530 template <
class S,
class T >
534 template <
class S,
class T >
536 Timer* timeSparse,
Timer* timeFull,
int& nCallsSparse,
int& nCallsFull);
541 template <
class S,
class T >
551 for(
int i = 0; i <
num; ++i)
572 for(
int i = 0; i <
num; ++i)
604 if(
index(i) >= newdim)
638 for(
int i = 0; i <
num; ++i)
653#ifdef ENABLE_CONSISTENCY_CHECKS
664 for(
int i = 0; i < d; ++i)
666 const int j =
pos(i);
693 explicit SSVectorBase(
int p_dim, std::shared_ptr<Tolerances> tol =
nullptr)
698 len = (p_dim < 1) ? 1 : p_dim;
764 for(
int i =
size() - 1; i >= 0; --i)
766 const int j =
index(i);
773 const int d = rhs.
dim();
777 for(
int i = 0; i < d; ++i)
779 if(isNotZero(rhs.
val[i], this->getEpsilon()))
821 for(
int i =
size() - 1; i >= 0; --i)
823 const int j =
index(i);
830 const int d = rhs.
dim();
834 for(
int i = 0; i < d; ++i)
836 if(
spxAbs(rhs.
val[i]) > this->getEpsilon())
869 for(
int i =
size() - 1; i >= 0; --i)
871 const int j =
index(i);
878 const int d = rhs.
dim();
882 for(
int i = 0; i < d; ++i)
884 if(
spxAbs(rhs.
val[i]) > this->getEpsilon())
933 template <
class S,
class T >
937 template <
class S,
class T >
941 template <
class S,
class T >
bool isConsistent() const
consistency check.
int pos(int i) const
returns the position of index i.
void addIdx(int i)
appends index i.
void remove(int n, int m)
removes indices at position numbers n through m.
int max() const
returns the maximal number of indices which can be stored in IdxSet.
int num
number of used indices
IdxSet(int n, int imem[], int l=0)
constructor.
int index(int n) const
access n 'th index.
int dim() const
returns the maximal index.
int * idx
array of indices
void clear()
removes all indices.
void add(int n)
appends n uninitialized indices.
int size() const
returns the number of used indices.
IdxSet & operator=(const IdxSet &set)
assignment operator.
int len
length of array idx
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.
friend class DSVectorBase
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.
Wrapper for the system time query methods.
R * get_ptr()
Conversion to C-style pointer.
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
R length2() const
Squared norm.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
bool isConsistent() const
Consistency check.
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
int dim() const
Dimension of vector.
std::vector< R > val
Values of vector.
void reSize(int newsize)
Resets VectorBase's memory size to newsize.
const std::vector< Real > & vec()
void clear()
Set vector to contain all-zeros (keeping the same length).
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
Everything should be within this namespace.
void spx_alloc(T &p, size_t n=1)
Allocate memory.
bool isPlusZero(R x)
detects whether value is positive zero
Real spxSqrt(Real a)
returns square root
void spx_free(T &p)
Release memory.
void spx_realloc(T &p, size_t n)
Change amount of allocated memory.
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.
#define SPX_MSG_INCONSISTENT(name)