20 #ifndef _VECTORBASE_H_ 21 #define _VECTORBASE_H_ 31 template <
class R >
class SVectorBase;
32 template <
class R >
class SSVectorBase;
116 assert(
dim() == vec.dim());
118 for(
int i = 0; i <
dimen; i++)
132 assert(
dim() == vec.dim());
134 for(
int i = 0; i <
dimen; i++)
148 assert(
dim() == vec.
dim());
150 for(
int i = 0; i <
dimen; i++)
151 val[i] =
spxLdexp(vec[i], scaleExp);
161 bool negateExp =
false)
165 assert(
dim() == vec.
dim());
169 for(
int i = 0; i <
dimen; i++)
170 val[i] =
spxLdexp(vec[i], -scaleExp[i]);
174 for(
int i = 0; i <
dimen; i++)
175 val[i] =
spxLdexp(vec[i], scaleExp[i]);
225 assert(n >= 0 && n < dimen);
232 assert(n >= 0 && n < dimen);
241 else if(vec1.dim() != vec2.dim())
245 for(
int i = 0; i < vec1.dim(); i++)
247 if(vec1[i] != vec2[i])
266 for(
int i = 0; i <
dimen; i++)
275 assert(
dim() == vec.dim());
276 assert(
dim() == dimen);
278 for(
int i = 0; i <
dimen; i++)
296 assert(
dim() == vec.dim());
297 assert(
dim() == dimen);
299 for(
int i = 0; i <
dimen; i++)
317 assert(
dim() == dimen);
319 for(
int i = 0; i <
dimen; i++)
331 for(
int i = 0; i <
dim(); i++)
340 assert(vec.dim() ==
dimen);
344 for(
int i = 0; i <
dimen; i++)
345 x += val[i] * vec.val[i];
360 assert(
dim() == dimen);
364 for(
int i = 0; i <
dimen; i++)
381 assert(
dim() == dimen);
385 for(
int i = 1; i <
dimen; i++)
407 return (*
this) * (*this);
411 template <
class S,
class T >
414 assert(vec.dim() ==
dimen);
416 for(
int i = 0; i <
dimen; i++)
417 val[i] += x * vec.val[i];
423 template <
class S,
class T >
427 template <
class S,
class T >
431 template <
class S,
class T >
463 #ifdef ENABLE_CONSISTENCY_CHECKS 465 if(
dim() > 0 && val == 0)
486 assert(
dim() == vec.
dim());
506 assert(
dim() == vec.
dim());
508 for(
int i = 0; i <
dimen; i++)
543 for(
int i = 1; i <
dimen && i < vec.
dim(); i++)
550 #endif // _VECTORBASE_H_ Rational spxAbs(const Rational &r)
Absolute.
Rational & addProduct(const Rational &r, const Rational &s)
add product of two rationals
VectorBase< Real > & scaleAssign(int scaleExp, const VectorBase< Real > &vec)
scale and assign
R minAbs() const
Minimum absolute value.
VectorBase< R > & operator=(const VectorBase< S > &vec)
Assignment operator.
R length2() const
Squared norm.
Dense vector.Class VectorBase provides dense linear algebra vectors. It does not provide memory manag...
Real length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
Wrapper for GMP type mpq_class.We wrap mpq_class so that we can replace it by a double type if GMP is...
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
VectorBase< Real > & scaleAssign(const int *scaleExp, const VectorBase< Real > &vec, bool negateExp=false)
scale and assign
Semi sparse vector.This class implements semi-sparse vectors. Such are DVectorBases where the indices...
const R * get_const_ptr() const
Conversion to C-style pointer.
R * get_ptr()
Conversion to C-style pointer.
Real spxLdexp(Real x, int exp)
returns x * 2^exp
Real spxSqrt(Real a)
returns square root
VectorBase< R > & operator*=(const S &x)
Scaling.
friend bool operator==(const VectorBase< R > &vec1, const VectorBase< R > &vec2)
Equality operator.
bool isConsistent() const
Consistency check.
R & operator[](int n)
Return n 'th value by reference.
VectorBase< R > & multAdd(const S &x, const VectorBase< T > &vec)
Addition of scaled vector.
int dim() const
Dimension of vector.
Everything should be within this namespace.
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
R operator*(const VectorBase< R > &vec) const
Inner product.
void clear()
Set vector to 0.
const R & operator[](int n) const
Return n 'th value.
int dimen
Dimension of vector.
VectorBase< R > & operator/=(const S &x)
Division.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
#define MSGinconsistent(name)
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
VectorBase< R > & multSub(const S &x, const SVectorBase< T > &vec)
Subtraction of scaled vector.
VectorBase< R > & operator=(const VectorBase< R > &vec)
Assignment operator.