20 #ifndef _VECTORBASE_H_ 21 #define _VECTORBASE_H_ 36 template <
class R >
class SVectorBase;
37 template <
class R >
class SSVectorBase;
118 val.
assign(p_val, p_val + dimen);
129 template <
typename S>
154 val.reserve(vec.dim());
156 for(
auto& v : vec.val)
170 val.reserve(vec.dim());
181 val = std::move(
vec.val);
190 assert(
dim() == vec.dim());
194 for(decltype(dimen) i = 0 ; i < dimen; i++)
195 val[i] =
spxLdexp(vec[i], scaleExp);
207 assert(
dim() == vec.dim());
213 for(decltype(dimen) i = 0; i < dimen; i++)
214 val[i] =
spxLdexp(vec[i], -scaleExp[i]);
220 for(decltype(dimen) i = 0; i < dimen; i++)
221 val[i] =
spxLdexp(vec[i], scaleExp[i]);
264 return int(val.size());
270 assert(n >= 0 && n <
dim());
277 assert(n >= 0 && n <
dim());
284 return (vec1.val == vec2.val);
288 const std::vector<R>&
vec()
310 assert(
dim() == vec.dim());
314 for(decltype(dimen) i = 0; i < dimen; i++)
332 assert(
dim() == vec.dim());
336 for(decltype(dimen) i = 0; i < dimen; i++)
357 for(decltype(dimen) i = 0; i < dimen; i++)
371 for(decltype(dimen) i = 0; i < dimen; i++)
384 for(decltype(dimen) i = 0; i < dimen; i++)
385 x += val[i] * vec.val[i];
402 auto absCmpr = [](R a, R b)
407 auto maxReference = std::max_element(val.begin(), val.end(), absCmpr);
409 R maxi =
spxAbs(*maxReference);
422 auto absCmpr = [](R a, R b)
427 auto minReference = std::min_element(val.begin(), val.end(), absCmpr);
429 R mini =
spxAbs(*minReference);
445 return (*
this) * (*this);
449 template <
class S,
class T >
452 assert(vec.dim() ==
dim());
456 for(decltype(dimen) i = 0; i < dimen; i++)
457 val[i] += x * vec.val[i];
463 template <
class S,
class T >
467 template <
class S,
class T >
471 template <
class S,
class T >
501 typename std::vector<R>::const_iterator
begin()
const 506 typename std::vector<R>::iterator
begin()
512 typename std::vector<R>::const_iterator
end()
const 517 typename std::vector<R>::iterator
end()
529 return int(val.capacity());
533 void reDim(
int newdim,
const bool setZero =
true)
535 if(setZero && newdim >
dim())
559 val.reserve(newsize);
565 assert(vec.dim() ==
dim());
571 for(decltype(dimen) i = 0; i < dimen; i++)
573 res.val.push_back(val[i] - vec[i]);
582 assert(v.dim() ==
dim());
588 for(decltype(dimen) i = 0; i < dimen; i++)
590 res.val.push_back(val[i] + v[i]);
601 res.val.reserve(vec.dim());
603 for(
auto& v : vec.val)
605 res.val.push_back(-(v));
626 assert(vec.
dim() ==
dim());
628 if(
dim() <= 0 || vec.
dim() <= 0)
636 for(decltype(dimen) i = 1; i < dimen; i++)
637 x += val[i] * vec.
val[i];
643 #endif // _VECTORBASE_H_ number< gmp_rational, et_off > Rational
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()
VectorBase< R > & operator+=(const VectorBase< S > &vec)
Addition.
Semi sparse vector.This class implements semi-sparse vectors. Such are VectorBases where the indices ...
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.
boost::multiprecision::number< T > spxLdexp(boost::multiprecision::number< T, eto > x, int exp)
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.