28#ifndef _SVECTORBASE_H_
29#define _SVECTORBASE_H_
185 d = (d > e->
idx) ? d : e->
idx;
200 const int n =
size();
202 for(
int p = 0; p < n; ++p)
206 assert(
index(p) == i);
281 void add(
int i,
const R& v)
283 assert(
m_elem !=
nullptr);
288 const int n =
size();
301 assert(
m_elem !=
nullptr);
302 const int n =
size();
318 void add(
int n,
const int i[],
const R v[])
333 assert(e !=
nullptr);
349 void add(
int n,
const int i[],
const S v[])
413 cpy = (
size() - m >= cpy) ? cpy :
size() - m;
433 const int newsize =
size() - 1;
457 for(l = s, w = s + 1; w < e; l = w, ++w)
470 while(l->
idx > dummy.
idx);
489 for(
int i =
size() - 1; i >= 0; --i)
505 for(
int i =
size() - 1; i >= 0; --i)
519 return std::sqrt(R(
length2()));
562 const int n =
size();
563 const int m = w.
size();
647 assert(e !=
nullptr);
669 this->m_elem = sv.m_elem;
670 this->memsize = sv.memsize;
671 this->memused = sv.memused;
691 assert(e !=
nullptr);
713 const int n = sv.
size();
716 for(
int i = 0; i < n; ++i)
731 bool negateExp =
false)
735 const int n = sv.
size();
740 for(
int i = 0; i < n; ++i)
748 for(
int i = 0; i < n; ++i)
768 assert(m >= rowSize);
771 for(i = 0; i < rowSize && i < m; ++i)
773 m_elem[i].val = rowValues[i];
774 m_elem[i].idx = rowIndices[i];
801 assert(
m_elem !=
nullptr || s == 0);
808 assert(
m_elem !=
nullptr || m == 0);
816 assert(n == 0 || elmem !=
nullptr);
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)
861 if(!std::is_floating_point<R>::value)
866 const int n =
size();
868 for(
int i = 0; i < n; ++i)
882 if(!std::is_floating_point<R>::value)
887 const int n =
size();
889 for(
int i = 0; i < n; ++i)
910 const int n =
size();
911 const int m = w.
size();
Sparse vector nonzero element.
Nonzero< R > & operator=(const Nonzero< S > &vec)
Nonzero(const Nonzero< S > &vec)
int idx
Index of nonzero element.
R val
Value of nonzero element.
const Nonzero< R > & element(int n) const
The n 'th nonzero element.
bool hasNaNs() const
Checks whether the array contains any nan entries.
R minAbs() const
Minimum absolute value.
void add(const SVectorBase &sv)
Append nonzeros of sv.
SVectorBase(int n=0, Nonzero< R > *p_mem=nullptr)
Default constructor.
SVectorBase< R > & operator=(const SVectorBase< S > &sv)
Assignment operator.
Nonzero< R > & element(int n)
Reference to the n 'th nonzero element.
SVectorBase(const SVectorBase< R > &sv)=default
R length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
R operator*(const SVectorBase< S > &w) const
inner product for sparse vectors
SVectorBase< R > & operator=(const SVectorBase< R > &sv)
Assignment operator.
R length2() const
Squared norm.
void add(int i)
Append one uninitialized nonzero.
R operator*(const VectorBase< R > &w) const
Inner product.
void remove(int n)
Remove n 'th nonzero.
void add(int n, const int i[], const R v[])
Append n nonzeros.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
bool isConsistent() const
Consistency check.
void setMem(int n, Nonzero< R > *elmem)
Set the memory area where the nonzeros will be stored.
void add(int n, const Nonzero< R > e[])
Append n nonzeros.
void sort()
Sort nonzeros to increasing indices.
SVectorBase< Real > & scaleAssign(const int *scaleExp, const SVectorBase< Real > &sv, bool negateExp=false)
scale and assign
int pos(int i) const
Position of index i.
int & index(int n)
Reference to index of n 'th nonzero.
void remove(int n, int m)
Remove nonzeros n thru m.
SVectorBase< R > & operator=(const SVectorBase< R > &&sv)
move assignement operator.
void add(int i, const R &v)
Append one nonzero (i,v).
int max() const
Maximal number of indices.
bool hasInfs() const
Checks whether the array contains any NaN entries.
const R & value(int n) const
Value of n 'th nonzero.
R & value(int n)
Reference to value of n 'th nonzero.
void set_size(int s)
Set size of the vector.
SVectorBase< R > & operator*=(const R &x)
Scaling.
R operator[](int i) const
Value to index i.
SVectorBase< R > & assignArray(const S *rowValues, const int *rowIndices, int rowSize)
Assignment operator.
SVectorBase< Real > & scaleAssign(int scaleExp, const SVectorBase< Real > &sv)
scale and assign
int index(int n) const
Index of n 'th nonzero.
int dim() const
Dimension of the vector defined as maximal index + 1.
Nonzero< R > * mem() const
get pointer to internal memory.
SVectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
void add(int n, const int i[], const S v[])
Append n nonzeros.
void clear()
Remove all indices.
void set_max(int m)
Set the maximum number of nonzeros in the vector.
SVectorBase< R > & operator=(const SSVectorBase< S > &sv)
Assignment operator.
int size() const
Number of used indices.
Everything should be within this namespace.
static const Real infinity
#define SPX_MSG_INCONSISTENT(name)