Class SiconosVector

Contents

Class SiconosVector#

Defined in Program listing for file kernel/src/utils/SiconosAlgebra/SiconosVector.hpp

class SiconosVector : public std::enable_shared_from_this<SiconosVector>#

Vectors of double.

(Interface to various types of Boost-Ublas vectors).

Two possible types: Siconos::DENSE (default) and Siconos:SPARSE.

Public Types

typedef SiconosVectorIterator iterator#

for iterator interface

typedef SiconosVectorConstIterator const_iterator#

for iterator interface

Public Functions

SiconosVector()#

Creates a zero-size vector.

SiconosVector(unsigned row, Siconos::UBLAS_TYPE type = Siconos::DENSE)#

creates a vector, all components set to zero.

Parameters:
  • row – the size of the vector

  • type – the type of vector (dense or sparse)

SiconosVector(unsigned row, double val, Siconos::UBLAS_TYPE type = Siconos::DENSE)#

creates a vector and initializes its content with a single value

Parameters:
  • row – size of the new vector

  • val – value to initialize its content

  • type – type of vector (dense or sparse)

SiconosVector(const std::vector<double> &vec, Siconos::UBLAS_TYPE type = Siconos::DENSE)#

creates a dense vector from a copy of a stl vector.

Parameters:
  • vec – vector to be copied

  • type – of the vector (dense or sparse)

SiconosVector(const SiconosVector &v)#

copy constructor

Parameters:

v – source vector to be copied

SiconosVector(const DenseVect &v)#

creates a dense vector, with a copy.

Parameters:

v – source vector (ublas dense)

SiconosVector(const SparseVect &v)#

creates a sparse vector, with a copy.

Parameters:

v – source vector (ublas sparse)

SiconosVector(const std::string &filename, bool is_ascii)#

creates a vector from data in a file

Parameters:
  • filename – file name (possibly with path)

  • is_ascii – file format (true if ascii, false if binary)

SiconosVector(const SiconosVector &v1, const SiconosVector &v2)#

constructor from the concatenation of two vectors

Parameters:
  • v1 – the first vector

  • v2 – the second vector

explicit SiconosVector(const BlockVector &input)#

constructor from a BlockVector.

explicit to forbid implicit conversion/conversion constructor.

Parameters:

input – source vector

~SiconosVector()#

destructor

unsigned int size() const#

get the vector size, ie the total number of (double) elements in the vector

Returns:

unsigned int

inline Siconos::UBLAS_TYPE num() const#

Get the type number of the current vector.

Returns:

an unsigned int

inline DenseVect *dense() const#

get a pointer to the ublas embedded vector if it’s type is Dense

Returns:

a DenseVect*

SparseVect *sparse() const#

get a pointer to the ublas embedded vector if it’s type is Sparse

Returns:

a SparseVect*

double *getArray() const#
Returns:

the array of double values of the vector

void zero()#

sets all the values of the vector to 0.0

void resize(unsigned int size, bool preserve = true)#

Resize the vector.

The existing elements may be preseved if specified.

Parameters:
  • size – new size of the vector

  • preserve – true if the content of the vector must be preserved.

double normInf() const#
Returns:

the infinite norm of the vector

double norm2() const#
Returns:

the Euclidian norm of the vector

double vector_sum() const#
Returns:

the sum of all elements of the vector

void display(void) const#

display vector content

void fill(double a)#

set all values of the vector to input value.

Parameters:

a – input value

std::string toString() const#
Returns:

the content of the vector as a string

iterator begin()#
Returns:

an iterator pointing to the first element in the vector.

const_iterator begin() const#
Returns:

an iterator pointing to the first element in the vector.

iterator end()#
Returns:

an iterator referring to the past-the-end element in the vector container.

const_iterator end() const#
Returns:

an iterator referring to the past-the-end element in the vector container.

operator std::vector<double>()#

cast a SiconosVector into a std::vector<double> (performs copy)

double getValue(unsigned int i) const#

Get a component of the vector.

Parameters:

i – index of the required component

Returns:

the component value

void setValue(unsigned int i, double value)#

set a component of the vector

Parameters:
  • i – index of the required component

  • value – of the component

double &operator()(unsigned int i)#

get a component of the vector

Parameters:

i – index of the required component

Returns:

value of the component

double operator()(unsigned int i) const#

get a component of the vector

Parameters:

i – index of the required component

Returns:

value of the component

void setBlock(unsigned int i, const SiconosVector &v)#

set a sub-block of the current vector

Parameters:
  • i – the beginning of the destination range

  • v – vector to be copied

void toBlock(SiconosVector &vOut, unsigned int sizeB, unsigned int startIn, unsigned int startOut) const#

copy a part of the vector into another

Parameters:
  • vOut – destination vector

  • sizeB – number of the elements to copy

  • startIn – the beginning of the range of elements to copy from

  • startOut – the beginning of the destination range

void addBlock(unsigned int i, const SiconosVector &v)#

add the input vector to a sub-block of the current vector

Parameters:
  • i – the beginning of the destination range

  • v – the source vector to be added

void subBlock(unsigned int i, const SiconosVector &v)#

subtract the input vector to a sub-block of the current vector

Parameters:
  • i – the beginning of the destination range

  • v – the source vector to be added

unsigned copyData(double *data) const#

copy the vector into an array

Parameters:

data – the memory where to copy the data

Returns:

the number of element written (size of the vector)

SiconosVector &operator=(const SiconosVector &v)#

operator =

Parameters:

v – the vector to be copied

Returns:

SiconosVector&

SiconosVector &operator=(const BlockVector &b)#

operator =

Parameters:

b – the vector to be copied

Returns:

SiconosVector&

SiconosVector &operator=(const DenseVect &v)#

operator =

Parameters:

v – the vector to be copied

Returns:

SiconosVector&

SiconosVector &operator=(const SparseVect &sp)#

operator =

Parameters:

sp – the vector to be copied

Returns:

SiconosVector&

SiconosVector &operator=(const double *d)#

operator =

Parameters:

d – data to put the in vector

Returns:

SiconosVector&

SiconosVector &operator+=(const SiconosVector &v)#

operator +=

Parameters:

v – the vector to add

Returns:

SiconosVector&

SiconosVector &operator+=(const BlockVector &v)#

operator +=

Parameters:

v – the vector to add

Returns:

SiconosVector&

SiconosVector &operator-=(const SiconosVector &v)#

operator -=

Parameters:

v – the vector to subtract

Returns:

SiconosVector&

SiconosVector &operator-=(const BlockVector &v)#

operator -=

Parameters:

v – the vector to subtract

Returns:

SiconosVector&

Friends

friend std::ostream &operator<<(std::ostream &os, const SiconosVector &sv)#

send data of the vector to an ostream

Parameters:
Returns:

The same output stream

friend bool operator==(const SiconosVector&, const SiconosVector&)#

A==B when (A-B).normInf()<tolerance.

Parameters:

2SiconosVector

Returns:

a boolean

friend SiconosVector operator*(double, const SiconosVector&)#

multiplication of a vector by a scalar

Parameters:
Returns:

a SiconosVector

friend SiconosVector operator*(const SiconosVector&, double)#

multiplication of a vector by a double

Parameters:
Returns:

a SiconosVector

friend SiconosVector operator/(const SiconosVector&, double)#

division of the vector by a double

Parameters:
Returns:

a SiconosVector

friend SiconosVector operator+(const SiconosVector&, const SiconosVector&)#

Addition of two vectors.

Parameters:
Returns:

a SiconosVector

friend void add(const SiconosVector&, const SiconosVector&, SiconosVector&)#

computes z = x + y

Parameters:
friend SiconosVector operator-(const SiconosVector&, const SiconosVector&)#

Subtraction of two vectors.

Parameters:
Returns:

a SiconosVector

friend void sub(const SiconosVector&, const SiconosVector&, SiconosVector&)#

computes z = x - y

Parameters:
friend void axpby(double, const SiconosVector&, double, SiconosVector&)#

computes y = a*x + b*y with blas axpy.

Parameters:
friend void axpy(double, const SiconosVector&, SiconosVector&)#

computes y = a*x + y with blas axpy.

Parameters:
friend double inner_prod(const SiconosVector&, const SiconosVector&)#

compute dot product m1.m2

Parameters:

2 – SiconosVectors

Returns:

a double

friend SimpleMatrix outer_prod(const SiconosVector&, const SiconosVector&)#

compute the product m1 * trans(m2)

Parameters:

2 – SiconosVectors

Returns:

a SimpleMatrix

friend void scal(double, const SiconosVector&, SiconosVector&, bool)#

multiplication of a vector by a scalar, y = a*x (init = true) or y += a*x (init = false)

Parameters:
friend void subscal(double, const SiconosVector&, SiconosVector&, const Index&, bool)#

multiplication of a vector by a scalar, sub_y = a*sub_x (init = true) or sub_y += a*sub_x (init = false)

Parameters:
  • a – a double

  • x – a SiconosVector (IN)

  • y – a SiconosVector (IN-OUT)

  • coord – an Index = [r0x r1x r0y r1y]; subX is the sub-vector of x, for row numbers between r0x and r1x-1. The same for y with riy.

  • init – if true sub_y = a*sub_x else sub_y += a*sub_x (default true)

friend void cross_product(const SiconosVector&, const SiconosVector&, SiconosVector&)#

cross product

Parameters:
  • V1 – a SiconosVector of dimention 3.

  • V2 – aSiconosVector of dimention 3.

  • VOUT – aSiconosVector of dimention 3, the resulting cross product between V1 and V2.

friend void abs_wise(const SiconosVector&, SiconosVector&)#

get an absolute vector

Parameters:
friend void getMax(const SiconosVector&, double&, unsigned int&)#

get maximal element of a vector

Parameters:
  • 1, aSiconosVector (Input).

  • 2, a – double variable giving the maximum element (Output).

  • 3, an – unsigned int variable giving the position of the maximum element (Output)

friend void getMin(const SiconosVector&, double&, unsigned int&)#

get minimum element of a vector

Parameters:
  • 1, aSiconosVector (Input).

  • 2, a – double variable giving the minimum element (Output).

  • 3, an – unsigned int variable giving the position of the minimum element (Output)