28 #ifndef _SVECTORBASE_H_ 29 #define _SVECTORBASE_H_ 39 template <
class R >
class VectorBase;
40 template <
class R >
class SSVectorBase;
166 assert(m_elem != 0 || memused == 0);
173 assert(m_elem != 0 || memused == 0);
186 d = (d > e->
idx) ? d : e->
idx;
203 for(
int p = 0; p < n; ++p)
205 if(m_elem[p].
idx == i)
207 assert(index(p) == i);
222 return m_elem[n].
val;
251 return m_elem[n].
idx;
260 return m_elem[n].
idx;
269 return m_elem[n].
val;
278 return m_elem[n].
val;
282 void add(
int i,
const R& v)
285 assert(size() < max());
295 assert(size() <= max());
303 assert(size() < max());
310 assert(size() <= max());
320 void add(
int n,
const int i[],
const R v[])
322 assert(n + size() <= max());
335 assert(e !=
nullptr);
346 set_size(size() + newnnz);
351 void add(
int n,
const int i[],
const S v[])
353 assert(n + size() <= max());
376 set_size(size() + newnnz);
382 assert(n + size() <= max());
402 set_size(size() + newnnz);
406 void remove(
int n,
int m)
415 cpy = (size() - m >= cpy) ? cpy : size() - m;
420 set_size(size() - cpy);
435 int newsize = size() - 1;
439 m_elem[n] = m_elem[newsize];
459 for(l = s, w = s + 1; w < e; l = w, ++w)
472 while(l->
idx > dummy.
idx);
491 for(
int i = size() - 1; i >= 0; --i)
494 maxi =
spxAbs(m_elem[i].val);
507 for(
int i = size() - 1; i >= 0; --i)
510 mini =
spxAbs(m_elem[i].val);
521 return std::sqrt(R(length2()));
641 assert(max() >= sv.
size());
686 assert(max() >= sv.
size());
717 assert(max() >= sv.
size());
719 for(
int i = 0; i < sv.
size(); ++i)
725 assert(isConsistent());
733 bool negateExp =
false)
737 assert(max() >= sv.
size());
741 for(
int i = 0; i < sv.
size(); ++i)
749 for(
int i = 0; i < sv.
size(); ++i)
756 assert(isConsistent());
767 assert(max() >= rowSize);
771 for(i = 0; i < rowSize && i < max(); i++)
773 m_elem[i].
val = rowValues[i];
774 m_elem[i].
idx = rowIndices[i];
801 assert(m_elem != 0 || s == 0);
808 assert(m_elem != 0 || m == 0);
816 assert(n == 0 || elmem != 0);
832 #ifdef ENABLE_CONSISTENCY_CHECKS 836 const int my_size = size();
837 const int my_max = max();
839 if(my_size < 0 || my_max < 0 || my_size > my_max)
842 for(
int i = 1; i < my_size; ++i)
844 for(
int j = 0; j < i; ++j)
847 if(m_elem[i].
idx == m_elem[j].
idx && m_elem[i].
val != 0)
918 #endif // _SVECTORBASE_H_ const Nonzero< R > & element(int n) const
The n 'th nonzero element.
Sparse vector nonzero element.
R operator*(const VectorBase< R > &w) const
Inner product.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Dense vector.Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std...
void setMem(int n, Nonzero< R > *elmem)
Set the memory area where the nonzeros will be stored.
void set_max(int m)
Set the maximum number of nonzeros in the vector.
SVectorBase< R > & operator=(const SVectorBase< R > &sv)
Assignment operator.
int size() const
Number of used indices.
Nonzero< R > & element(int n)
Reference to the n 'th nonzero element.
R minAbs() const
Minimum absolute value.
void add(int n, const int i[], const R v[])
Append n nonzeros.
void set_size(int s)
Set size of the vector.
#define SPX_MSG_INCONSISTENT(name)
Nonzero(const Nonzero< S > &vec)
void add(int n, const Nonzero< R > e[])
Append n nonzeros.
R & value(int n)
Reference to value of n 'th nonzero.
SVectorBase< R > & operator=(const SVectorBase< S > &sv)
Assignment operator.
R length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
int idx
Index of nonzero element.
Nonzero< R > * mem() const
get pointer to internal memory.
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
const R & value(int n) const
Value of n 'th nonzero.
SVectorBase< R > & operator*=(const R &x)
Scaling.
DSVectorBase< R > operator*(const SVectorBase< R > &v, R x)
Scaling.
R operator*(const SVectorBase< S > &w) const
inner product for sparse vectors
int & index(int n)
Reference to index of n 'th nonzero.
R operator[](int i) const
Value to index i.
SVectorBase< R > & operator=(const SVectorBase< R > &&sv)
move assignement operator.
SVectorBase(int n=0, Nonzero< R > *p_mem=0)
Default constructor.
SOPLEX_THREADLOCAL const Real infinity
boost::multiprecision::number< T > spxLdexp(boost::multiprecision::number< T, eto > x, int exp)
void add(int i, const R &v)
Append one nonzero (i,v).
int index(int n) const
Index of n 'th nonzero.
bool isConsistent() const
Consistency check.
Everything should be within this namespace.
int dim() const
Dimension of the vector defined as maximal index + 1.
int max() const
Maximal number of indices.
void clear()
Remove all indices.
SVectorBase< Real > & scaleAssign(int scaleExp, const SVectorBase< Real > &sv)
scale and assign
Nonzero< R > & operator=(const Nonzero< S > &vec)
void add(const SVectorBase &sv)
Append nonzeros of sv.
SVectorBase< R > & assignArray(const S *rowValues, const int *rowIndices, int rowSize)
Assignment operator.
void sort()
Sort nonzeros to increasing indices.
int pos(int i) const
Position of index i.
R val
Value of nonzero element.
void add(int i)
Append one uninitialized nonzero.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
SVectorBase< Real > & scaleAssign(const int *scaleExp, const SVectorBase< Real > &sv, bool negateExp=false)
scale and assign
void add(int n, const int i[], const S v[])
Append n nonzeros.
R length2() const
Squared norm.