Scippy

SoPlex

Sequential object-oriented simPlex

VectorBase< R > Class Template Reference

Dense vector. More...

#include <vectorbase.h>

Public Member Functions

bool isConsistent () const
 Consistency check. More...
 
Rational operator* (const VectorBase< Rational > &vec) const
 Inner product. More...
 
Construction and assignment
 VectorBase ()
 Constructor. More...
 
 VectorBase (int dimen, R *p_val)
 
 VectorBase (int p_dimen)
 
template<typename S >
 VectorBase (const VectorBase< S > &vec)
 
 VectorBase (const VectorBase< R > &&vec) noexcept
 
 VectorBase (const VectorBase< R > &vec)
 
template<class S >
VectorBase< R > & operator= (const VectorBase< S > &vec)
 Assignment operator. More...
 
VectorBase< R > & operator= (const VectorBase< R > &vec)
 Assignment operator. More...
 
VectorBase< R > & operator= (const VectorBase< R > &&vec)
 Move assignment operator. More...
 
VectorBase< R > & scaleAssign (int scaleExp, const VectorBase< R > &vec)
 scale and assign More...
 
VectorBase< R > & scaleAssign (const int *scaleExp, const VectorBase< R > &vec, bool negateExp=false)
 scale and assign More...
 
template<class S >
VectorBase< R > & operator= (const SVectorBase< S > &vec)
 Assignment operator. More...
 
template<class S >
VectorBase< R > & operator= (const SSVectorBase< S > &vec)
 Assignment operator. More...
 
template<class S >
VectorBase< R > & assign (const SVectorBase< S > &vec)
 Assign values of vec. More...
 
template<class S >
VectorBase< R > & assign (const SSVectorBase< S > &vec)
 Assign values of vec. More...
 
Arithmetic operations
void clear ()
 Set vector to contain all-zeros (keeping the same length) More...
 
template<class S >
VectorBase< R > & operator+= (const VectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator+= (const SVectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator+= (const SSVectorBase< S > &vec)
 Addition. More...
 
template<class S >
VectorBase< R > & operator-= (const VectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator-= (const SVectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator-= (const SSVectorBase< S > &vec)
 Subtraction. More...
 
template<class S >
VectorBase< R > & operator*= (const S &x)
 Scaling. More...
 
template<class S >
VectorBase< R > & operator/= (const S &x)
 Division. More...
 
operator* (const VectorBase< R > &vec) const
 Inner product. More...
 
operator* (const SVectorBase< R > &vec) const
 Inner product. More...
 
operator* (const SSVectorBase< R > &vec) const
 Inner product. More...
 
maxAbs () const
 Maximum absolute value, i.e., infinity norm. More...
 
minAbs () const
 Minimum absolute value. More...
 
length () const
 Floating point approximation of euclidian norm (without any approximation guarantee). More...
 
length2 () const
 Squared norm. More...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const VectorBase< T > &vec)
 Addition of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const SVectorBase< T > &vec)
 Addition of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multSub (const S &x, const SVectorBase< T > &vec)
 Subtraction of scaled vector. More...
 
template<class S , class T >
VectorBase< R > & multAdd (const S &x, const SSVectorBase< T > &vec)
 Addition of scaled vector. More...
 

Protected Attributes

Data
std::vector< R > val
 Values of vector. More...
 

Friends

template<typename S >
class VectorBase
 

Access

bool operator== (const VectorBase< R > &vec1, const VectorBase< R > &vec2)
 Equality operator. More...
 
int dim () const
 Dimension of vector. More...
 
R & operator[] (int n)
 Return n 'th value by reference. More...
 
const R & operator[] (int n) const
 Return n 'th value. More...
 
const std::vector< R > & vec ()
 Return underlying std::vector. More...
 

Utilities

VectorBase< R > operator- (const VectorBase< R > &vec)
 
R * get_ptr ()
 Conversion to C-style pointer. More...
 
const R * get_const_ptr () const
 Conversion to C-style pointer. More...
 
std::vector< R >::const_iterator begin () const
 
std::vector< R >::iterator begin ()
 
std::vector< R >::const_iterator end () const
 
std::vector< R >::iterator end ()
 
int memSize () const
 
void reDim (int newdim, const bool setZero=true)
 Resets VectorBase's dimension to newdim. More...
 
void reSize (int newsize)
 Resets VectorBase's memory size to newsize. More...
 
const VectorBase< R > operator- (const VectorBase< R > &vec) const
 
const VectorBase< R > operator+ (const VectorBase< R > &v) const
 

Detailed Description

template<class R>
class soplex::VectorBase< R >

Dense vector.

Class VectorBase provides dense linear algebra vectors. Internally, VectorBase wraps std::vector.

After construction, the values of a VectorBase can be accessed with the subscript operator[](). Safety is provided by qchecking of array bound when accessing elements with the subscript operator[]() (only when compiled without -DNDEBUG).

A VectorBase is distinguished from a simple array of Reals or Rationals by providing a set of mathematical operations.

The following mathematical operations are provided by class VectorBase (VectorBase a, b; R x):

OperationDescription  
-= subtraction a -= b
+= addition a += b
* scalar product x = a * b
*= scaling a *= x
maxAbs() infinity norm a.maxAbs() == \(\|a\|_{\infty}\)
minAbs()

a.minAbs() == \(\min |a_i|\)

length() euclidian norm a.length() == \(\sqrt{a^2}\)
length2()square norm a.length2() == \(a^2\)
multAdd(x,b)add scaled vector a += x * b

When using any of these operations, the vectors involved must be of the same dimension. Also an SVectorBase b is allowed if it does not contain nonzeros with index greater than the dimension of a.q

Definition at line 85 of file vectorbase.h.

Constructor & Destructor Documentation

◆ VectorBase() [1/6]

Constructor.

There is no default constructor since the storage for a VectorBase must be provided externally. Storage must be passed as a memory block val at construction. It must be large enough to fit at least dimen values.

Definition at line 117 of file vectorbase.h.

◆ VectorBase() [2/6]

VectorBase ( int  dimen,
R *  p_val 
)

Definition at line 124 of file vectorbase.h.

References VectorBase< R >::val.

◆ VectorBase() [3/6]

VectorBase ( int  p_dimen)
explicit

Definition at line 130 of file vectorbase.h.

References VectorBase< R >::val.

◆ VectorBase() [4/6]

VectorBase ( const VectorBase< S > &  vec)

Definition at line 138 of file vectorbase.h.

References VectorBase< R >::operator=().

◆ VectorBase() [5/6]

VectorBase ( const VectorBase< R > &&  vec)
noexcept

Definition at line 144 of file vectorbase.h.

◆ VectorBase() [6/6]

VectorBase ( const VectorBase< R > &  vec)

Definition at line 149 of file vectorbase.h.

Member Function Documentation

◆ assign() [1/2]

VectorBase< R > & assign ( const SSVectorBase< S > &  vec)

Assign values of vec.

Assigns all nonzeros of vec to the vector. All other values remain unchanged.

Definition at line 126 of file basevectors.h.

References SSVectorBase< R >::dim(), SSVectorBase< R >::indexMem(), SSVectorBase< R >::isSetup(), SSVectorBase< R >::size(), and VectorBase< R >::val.

◆ assign() [2/2]

VectorBase< R > & assign ( const SVectorBase< S > &  vec)

Assign values of vec.

Assigns all nonzeros of vec to the vector. All other values remain unchanged.

Definition at line 86 of file basevectors.h.

References SVectorBase< R >::index(), SVectorBase< R >::size(), and SVectorBase< R >::value().

◆ begin() [1/2]

std::vector< R >::iterator begin ( )

Definition at line 514 of file vectorbase.h.

References VectorBase< R >::val.

◆ begin() [2/2]

std::vector< R >::const_iterator begin ( ) const

Definition at line 509 of file vectorbase.h.

References VectorBase< R >::val.

◆ clear()

void clear ( )

◆ dim()

◆ end() [1/2]

std::vector< R >::iterator end ( )

Definition at line 525 of file vectorbase.h.

References VectorBase< R >::val.

◆ end() [2/2]

std::vector< R >::const_iterator end ( ) const

Definition at line 520 of file vectorbase.h.

References VectorBase< R >::val.

◆ get_const_ptr()

const R * get_const_ptr ( ) const

Conversion to C-style pointer.

This function serves for using a VectorBase in an C-style function. It returns a pointer to the first value of the array.

Definition at line 503 of file vectorbase.h.

References VectorBase< R >::val.

◆ get_ptr()

R * get_ptr ( )

Conversion to C-style pointer.

This function serves for using a VectorBase in an C-style function. It returns a pointer to the first value of the array.

Todo:
check whether this non-const c-style access should indeed be public

Definition at line 494 of file vectorbase.h.

References VectorBase< R >::val.

Referenced by SSVectorBase< R >::get_ptr(), and SLUFactorRational::SLUFactorRational().

◆ isConsistent()

bool isConsistent ( ) const

Consistency check.

Definition at line 622 of file vectorbase.h.

Referenced by SSVectorBase< R >::isConsistent().

◆ length()

R length ( ) const

Floating point approximation of euclidian norm (without any approximation guarantee).

Definition at line 445 of file vectorbase.h.

References VectorBase< R >::length2(), and soplex::spxSqrt().

◆ length2()

R length2 ( ) const

Squared norm.

Definition at line 451 of file vectorbase.h.

Referenced by VectorBase< R >::length(), and SSVectorBase< R >::length2().

◆ maxAbs()

R maxAbs ( ) const

Maximum absolute value, i.e., infinity norm.

Definition at line 405 of file vectorbase.h.

References VectorBase< R >::dim(), soplex::spxAbs(), and VectorBase< R >::val.

Referenced by SSVectorBase< R >::maxAbs().

◆ memSize()

int memSize ( ) const

Definition at line 535 of file vectorbase.h.

References VectorBase< R >::val.

◆ minAbs()

R minAbs ( ) const

Minimum absolute value.

Definition at line 425 of file vectorbase.h.

References VectorBase< R >::dim(), soplex::spxAbs(), and VectorBase< R >::val.

◆ multAdd() [1/3]

VectorBase< R > & multAdd ( const S &  x,
const SSVectorBase< T > &  vec 
)

◆ multAdd() [2/3]

VectorBase< R > & multAdd ( const S &  x,
const SVectorBase< T > &  vec 
)

Addition of scaled vector.

Definition at line 280 of file basevectors.h.

References SVectorBase< R >::index(), SVectorBase< R >::size(), and SVectorBase< R >::value().

◆ multAdd() [3/3]

VectorBase< R > & multAdd ( const S &  x,
const VectorBase< T > &  vec 
)

◆ multSub()

VectorBase< R > & multSub ( const S &  x,
const SVectorBase< T > &  vec 
)

Subtraction of scaled vector.

Definition at line 297 of file basevectors.h.

References SVectorBase< R >::index(), SVectorBase< R >::size(), and SVectorBase< R >::value().

Referenced by SPxLPBase< R >::subDualActivity().

◆ operator*() [1/4]

R operator* ( const SSVectorBase< R > &  vec) const

Inner product.

Definition at line 252 of file basevectors.h.

References SSVectorBase< R >::dim().

◆ operator*() [2/4]

R operator* ( const SVectorBase< R > &  vec) const

◆ operator*() [3/4]

R operator* ( const VectorBase< R > &  vec) const

Inner product.

Definition at line 386 of file vectorbase.h.

References VectorBase< R >::dim(), VectorBase< R >::val, and VectorBase< R >::vec().

◆ operator*() [4/4]

Rational operator* ( const VectorBase< Rational > &  vec) const

Inner product.

Definition at line 632 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ operator*=()

VectorBase< R > & operator*= ( const S &  x)

Scaling.

Definition at line 360 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ operator+()

const VectorBase< R > operator+ ( const VectorBase< R > &  v) const

Definition at line 588 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ operator+=() [1/3]

◆ operator+=() [2/3]

VectorBase< R > & operator+= ( const SVectorBase< S > &  vec)

Addition.

Definition at line 152 of file basevectors.h.

◆ operator+=() [3/3]

VectorBase< R > & operator+= ( const VectorBase< S > &  vec)

Addition.

Definition at line 316 of file vectorbase.h.

References VectorBase< R >::dim(), VectorBase< R >::val, and VectorBase< R >::vec().

Referenced by SSVectorBase< R >::operator+=().

◆ operator-()

const VectorBase< R > operator- ( const VectorBase< R > &  vec) const

◆ operator-=() [1/3]

◆ operator-=() [2/3]

VectorBase< R > & operator-= ( const SVectorBase< S > &  vec)

Subtraction.

Definition at line 194 of file basevectors.h.

References SVectorBase< R >::index(), SVectorBase< R >::size(), and SVectorBase< R >::value().

◆ operator-=() [3/3]

VectorBase< R > & operator-= ( const VectorBase< S > &  vec)

Subtraction.

Definition at line 338 of file vectorbase.h.

References VectorBase< R >::dim(), VectorBase< R >::val, and VectorBase< R >::vec().

Referenced by SSVectorBase< R >::operator-=().

◆ operator/=()

VectorBase< R > & operator/= ( const S &  x)

Division.

Definition at line 373 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ operator=() [1/5]

VectorBase< R > & operator= ( const SSVectorBase< S > &  vec)

Assignment operator.

Assigning an SSVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is diffent in method assign().

Todo:
do we need this also in non-template version, because SSVectorBase can be automatically cast to VectorBase?

Assigning an SSVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is different in method assign().

Definition at line 106 of file basevectors.h.

References SSVectorBase< R >::isSetup().

◆ operator=() [2/5]

VectorBase< R > & operator= ( const SVectorBase< S > &  vec)

Assignment operator.

Assigning an SVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is diffent in method assign().

Assigning an SVectorBase to a VectorBase using operator=() will set all values to 0 except the nonzeros of vec. This is different in method assign().

Definition at line 66 of file basevectors.h.

References SVectorBase< R >::index(), SVectorBase< R >::size(), and SVectorBase< R >::value().

◆ operator=() [3/5]

VectorBase< R > & operator= ( const VectorBase< R > &&  vec)

Move assignment operator.

Definition at line 187 of file vectorbase.h.

References VectorBase< R >::val, and VectorBase< R >::vec().

◆ operator=() [4/5]

VectorBase< R > & operator= ( const VectorBase< R > &  vec)

Assignment operator.

Definition at line 174 of file vectorbase.h.

References VectorBase< R >::val, and VectorBase< R >::vec().

◆ operator=() [5/5]

VectorBase< R > & operator= ( const VectorBase< S > &  vec)

◆ operator[]() [1/2]

R & operator[] ( int  n)

Return n 'th value by reference.

Definition at line 276 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ operator[]() [2/2]

const R & operator[] ( int  n) const

Return n 'th value.

Definition at line 283 of file vectorbase.h.

References VectorBase< R >::dim(), and VectorBase< R >::val.

◆ reDim()

void reDim ( int  newdim,
const bool  setZero = true 
)

◆ reSize()

void reSize ( int  newsize)

Resets VectorBase's memory size to newsize.

Definition at line 560 of file vectorbase.h.

References VectorBase< R >::val.

Referenced by SSVectorBase< R >::reMem().

◆ scaleAssign() [1/2]

VectorBase< R > & scaleAssign ( const int *  scaleExp,
const VectorBase< R > &  vec,
bool  negateExp = false 
)

scale and assign

Definition at line 211 of file vectorbase.h.

References VectorBase< R >::dim(), soplex::spxLdexp(), VectorBase< R >::val, and VectorBase< R >::vec().

◆ scaleAssign() [2/2]

VectorBase< R > & scaleAssign ( int  scaleExp,
const VectorBase< R > &  vec 
)

scale and assign

Definition at line 194 of file vectorbase.h.

References VectorBase< R >::dim(), soplex::spxLdexp(), VectorBase< R >::val, and VectorBase< R >::vec().

◆ vec()

Friends And Related Function Documentation

◆ operator-

VectorBase< R > operator- ( const VectorBase< R > &  vec)
friend

Definition at line 605 of file vectorbase.h.

◆ operator==

bool operator== ( const VectorBase< R > &  vec1,
const VectorBase< R > &  vec2 
)
friend

Equality operator.

Definition at line 290 of file vectorbase.h.

◆ VectorBase

friend class VectorBase
friend

Definition at line 91 of file vectorbase.h.

Member Data Documentation

◆ val