19 #ifndef _SVECTORBASE_H_ 20 #define _SVECTORBASE_H_ 28 template <
class R >
class VectorBase;
29 template <
class R >
class SSVectorBase;
154 assert(m_elem != 0 || memused == 0);
161 assert(m_elem != 0 || memused == 0);
174 d = (d > e->
idx) ? d : e->
idx;
191 for(
int p = 0; p < n; ++p )
193 if( m_elem[p].
idx == i )
195 assert(index(p) == i);
210 return m_elem[n].
val;
239 return m_elem[n].
idx;
248 return m_elem[n].
idx;
257 return m_elem[n].
val;
266 return m_elem[n].
val;
270 void add(
int i,
const R& v)
273 assert(size() < max());
283 assert(size() <= max());
291 assert(size() < max());
298 assert(size() <= max());
308 void add(
int n,
const int i[],
const R v[])
310 assert(n + size() <= max());
331 set_size(size() + newnnz);
336 void add(
int n,
const int i[],
const S v[])
338 assert(n + size() <= max());
359 set_size(size() + newnnz);
365 assert(n + size() <= max());
383 set_size(size() + newnnz);
387 void remove(
int n,
int m)
396 cpy = (size() - m >= cpy) ? cpy : size() - m;
401 set_size(size() - cpy);
415 int newsize = size() - 1;
418 m_elem[n] = m_elem[newsize];
438 for( l = s, w = s + 1; w < e; l = w, ++w )
450 while( l->
idx > dummy.
idx );
469 for(
int i = size() - 1; i >= 0; --i )
472 maxi =
spxAbs(m_elem[i].val);
485 for(
int i = size() - 1; i >= 0; --i )
488 mini =
spxAbs(m_elem[i].val);
545 if( n == 0 || m == 0 )
559 if( i == n || j == m )
564 else if( e->
idx < wj.
idx )
609 assert(max() >= sv.
size());
639 assert(max() >= sv.
size());
668 assert(max() >= sv.
size());
670 for(
int i = 0; i < sv.
size(); ++i )
676 assert(isConsistent());
687 assert(max() >= sv.
size());
691 for(
int i = 0; i < sv.
size(); ++i )
699 for(
int i = 0; i < sv.
size(); ++i )
706 assert(isConsistent());
717 assert(max() >= rowSize);
720 for( i = 0; i < rowSize && i < max(); i++ )
722 m_elem[i].
val = rowValues[i];
723 m_elem[i].
idx = rowIndices[i];
750 assert(m_elem != 0 || s == 0);
757 assert(m_elem != 0 || m == 0);
765 assert(n == 0 || elmem != 0);
781 #ifdef ENABLE_CONSISTENCY_CHECKS 784 const int my_size = size();
785 const int my_max = max();
787 if( my_size < 0 || my_max < 0 || my_size > my_max )
790 for(
int i = 1; i < my_size; ++i )
792 for(
int j = 0; j < i; ++j )
795 if( m_elem[i].
idx == m_elem[j].
idx && m_elem[i].
val != 0 )
818 if( n == 0 || m == 0 )
827 if( e->idx == wj.
idx )
832 if( i == n || j == m )
837 else if( e->idx < wj.
idx )
857 #endif // _SVECTORBASE_H_ Rational spxAbs(const Rational &r)
Absolute.
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.
THREADLOCAL const Real infinity
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
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.
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.
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 DVectorBases where the indices...
const R & value(int n) const
Value of n 'th nonzero.
SVectorBase< R > & operator*=(const R &x)
Scaling.
Real spxLdexp(Real x, int exp)
returns x * 2^exp
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.
DVectorBase< R > operator*(const VectorBase< R > &v, R x)
Scaling.
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Real spxSqrt(Real a)
returns square root
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...
#define MSGinconsistent(name)
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.