20 #ifndef _VECTORBASE_H_ 21 #define _VECTORBASE_H_ 35 template <
class R >
class SVectorBase;
36 template <
class R >
class SSVectorBase;
117 val.
assign(p_val, p_val + dimen);
128 template <
typename S>
153 val.reserve(vec.dim());
155 for(
auto& v : vec.val)
169 val.reserve(vec.dim());
180 val = std::move(
vec.val);
189 assert(
dim() == vec.dim());
193 for(decltype(dimen) i = 0 ; i < dimen; i++)
194 val[i] =
spxLdexp(vec[i], scaleExp);
206 assert(
dim() == vec.dim());
212 for(decltype(dimen) i = 0; i < dimen; i++)
213 val[i] =
spxLdexp(vec[i], -scaleExp[i]);
219 for(decltype(dimen) i = 0; i < dimen; i++)
220 val[i] =
spxLdexp(vec[i], scaleExp[i]);
263 return int(val.size());
269 assert(n >= 0 && n <
dim());
276 assert(n >= 0 && n <
dim());
283 return (vec1.val == vec2.val);
287 const std::vector<R>&
vec()
309 assert(
dim() == vec.dim());
313 for(decltype(dimen) i = 0; i < dimen; i++)
331 assert(
dim() == vec.dim());
335 for(decltype(dimen) i = 0; i < dimen; i++)
356 for(decltype(dimen) i = 0; i < dimen; i++)
370 for(decltype(dimen) i = 0; i < dimen; i++)
383 for(decltype(dimen) i = 0; i < dimen; i++)
384 x += val[i] * vec.val[i];
401 auto absCmpr = [](R a, R b)
406 auto maxReference = std::max_element(val.begin(), val.end(), absCmpr);
408 R maxi =
spxAbs(*maxReference);
421 auto absCmpr = [](R a, R b)
426 auto minReference = std::min_element(val.begin(), val.end(), absCmpr);
428 R mini =
spxAbs(*minReference);
444 return (*
this) * (*this);
448 template <
class S,
class T >
451 assert(vec.dim() ==
dim());
455 for(decltype(dimen) i = 0; i < dimen; i++)
456 val[i] += x * vec.val[i];
462 template <
class S,
class T >
466 template <
class S,
class T >
470 template <
class S,
class T >
500 typename std::vector<R>::const_iterator
begin()
const 505 typename std::vector<R>::iterator
begin()
511 typename std::vector<R>::const_iterator
end()
const 516 typename std::vector<R>::iterator
end()
528 return int(val.capacity());
532 void reDim(
int newdim,
const bool setZero =
true)
534 if(setZero && newdim >
dim())
558 val.reserve(newsize);
564 assert(vec.dim() ==
dim());
570 for(decltype(dimen) i = 0; i < dimen; i++)
572 res.val.push_back(val[i] - vec[i]);
581 assert(v.dim() ==
dim());
587 for(decltype(dimen) i = 0; i < dimen; i++)
589 res.val.push_back(val[i] + v[i]);
600 res.val.reserve(vec.dim());
602 for(
auto& v : vec.val)
604 res.val.push_back(-(v));
625 assert(vec.
dim() ==
dim());
627 if(
dim() <= 0 || vec.
dim() <= 0)
635 for(decltype(dimen) i = 1; i < dimen; i++)
642 #endif // _VECTORBASE_H_ Rational spxAbs(const Rational &r)
Absolute.
Rational & addProduct(const Rational &r, const Rational &s)
add product of two rationals
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. Internally, VectorBase wraps std...
const VectorBase< R > operator+(const VectorBase< R > &v) const
const VectorBase< R > operator-(const VectorBase< R > &vec) const
VectorBase< R > & scaleAssign(int scaleExp, const VectorBase< R > &vec)
scale and assign
R length() const
Floating point approximation of euclidian norm (without any approximation guarantee).
std::vector< R >::iterator end()
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.
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
Rational spxLdexp(Rational x, int exp)
const R * get_const_ptr() const
Conversion to C-style pointer.
R * get_ptr()
Conversion to C-style pointer.
Real spxSqrt(Real a)
returns square root
VectorBase< R > & operator*=(const S &x)
Scaling.
VectorBase< R > & operator=(const VectorBase< R > &&vec)
Move assignment operator.
void reSize(int newsize)
Resets VectorBase's memory size to newsize.
friend bool operator==(const VectorBase< R > &vec1, const VectorBase< R > &vec2)
Equality operator.
bool isConsistent() const
Consistency check.
Debugging, floating point type and parameter definitions.
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.
friend VectorBase< R > operator-(const VectorBase< R > &vec)
Everything should be within this namespace.
VectorBase< R > & operator-=(const VectorBase< S > &vec)
Subtraction.
std::vector< R >::iterator begin()
std::vector< R >::const_iterator begin() const
void reDim(int newdim, const bool setZero=true)
Resets VectorBase's dimension to newdim.
VectorBase< R > & scaleAssign(const int *scaleExp, const VectorBase< R > &vec, bool negateExp=false)
scale and assign
R operator*(const VectorBase< R > &vec) const
Inner product.
void clear()
Set vector to contain all-zeros (keeping the same length)
const R & operator[](int n) const
Return n 'th value.
std::vector< R > val
Values of vector.
VectorBase< R > & operator/=(const S &x)
Division.
Sparse vectors.Class SVectorBase provides packed sparse vectors. Such are a sparse vectors...
std::vector< R >::const_iterator end() const
VectorBase< R > & assign(const SVectorBase< S > &vec)
Assign values of vec.
R maxAbs() const
Maximum absolute value, i.e., infinity norm.
const std::vector< R > & vec()
Return underlying std::vector.
VectorBase< R > & multSub(const S &x, const SVectorBase< T > &vec)
Subtraction of scaled vector.
VectorBase< R > & operator=(const VectorBase< R > &vec)
Assignment operator.