File kernel/src/utils/SiconosAlgebra/SiconosVector.hpp

Go to the source code of this file

class SiconosVector : public std11::enable_shared_from_this<SiconosVector>
#include <SiconosVector.hpp>

Vectors of double.

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

Used to handle vectors of double.

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

You can find an overview on how to build and use vectors and matrices in siconos users’ guide .

Public Types

typedef SiconosVectorConstIterator const_iterator

for iterator interface

typedef SiconosVectorIterator iterator

for iterator interface

Public Functions

SiconosVector()

Default constructor.

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

constructor with the type and the dimension of the Boost vector

Parameters
  • row: the size of the vector
  • type: the type of vector

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

constructor with the dimension of the Boost vector, a default value and the type.

Parameters
  • row: the size of the vector
  • val: value for initiliazing the vector
  • type: the type of vector

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

constructor with a std::vector of the values and the type of the boost vector.

Parameters
  • vec: a std::vector<double>
  • type: an Siconos::UBLAS_TYPE

SiconosVector(const SiconosVector &v)

copy constructor

Parameters

SiconosVector(const BlockVector &vIn)
SiconosVector(const DenseVect &v)

constructor with a DenseVect vector (see SiconosAlgebra.hpp for details)

Parameters
  • v: a DenseVect

SiconosVector(const SparseVect &v)

constructor with a SparseVect vector (see SiconosAlgebra.hpp for details)

Parameters
  • v: a SparseVect

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

constructor with an input file

Parameters
  • filename: a std::string which contain the file path
  • is_ascii: a boolean to indicate if the file is in ascii

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

constructor for the concatenation of two vectors

Parameters
  • v1: the first vector
  • v2: the second vector

~SiconosVector()

destructor

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

add the input vector to the elements starting from position i.

Parameters

iterator begin()

for iterator interface

const_iterator begin() const

for iterator interface

unsigned copyData(double *data) const

copy the data to double* (dense only)

Return
the number of element written (size of the vector)
Parameters
  • data: the memory where to copy the data

DenseVect *dense(unsigned int pos = 0) const

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

Return
a DenseVect*
Parameters
  • pos: unsigned int: position of the required vector (useless for SiconosVector, default = 0)

void display(void) const

display data on standard output

iterator end()

for iterator interface

const_iterator end() const

for iterator interface

void exp(SiconosVector &input)

component-wise exponential of a vector

Parameters
  • input: vector such that result (this) = exp(input)

void exp_in_place()

component-wise exponential of a vector, in-place.

this = exp(this)

void fill(double a)

set all values of the vector component to input value.

Parameters
  • a: double

double *getArray() const

return the array of double values of the vector

Return
a pointer to the array

const DenseVect getDense(unsigned int pos = 0) const

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

Return
a DenseVect
Parameters
  • pos: unsigned int: position of the required vector (useless for SiconosVector, default = 0)

const SparseVect getSparse(unsigned int pos = 0) const

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

Return
a SparseVect
Parameters
  • pos: unsigned int: position of the required vector (useless for SiconosVector, default = 0)

double getValue(unsigned int i) const

get the element at position i in the vector

Return
a double
Parameters
  • i: an unsigned int

bool isBlock() const

true if the vector is block else false.

Return
a bool.

double norm2() const

return the Euclidian norm of the vector

Return
a double

double normInf() const

compute the infinite norm of the vector

Return
a double

unsigned int num() const

Get the type number of the current vector.

Return
an unsigned int

operator std::vector<double>()

cast an SiconosVector to an std::vector<double> (performs copy)

double &operator()(unsigned int i)

get the element at position i in the vector

Return
a double
Parameters
  • i: an integer

double operator()(unsigned int i) const

get the element at position i in the vector

Return
a double
Parameters
  • i: an integer

SiconosVector &operator+=(const SiconosVector &v)

operator +=

Return
SiconosVector&
Parameters

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

operator -=

Return
SiconosVector&
Parameters

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

operator =

Return
SiconosVector&
Parameters

SiconosVector &operator=(const BlockVector &b)

operator =

Return
SiconosVector&
Parameters

SiconosVector &operator=(const DenseVect &v)

operator =

Return
SiconosVector&
Parameters
  • v: a DenseVect : the vector to be copied

SiconosVector &operator=(const SparseVect &sp)

operator =

Return
SiconosVector&
Parameters
  • sp: the vector to be copied

SiconosVector &operator=(const double *d)

operator =

Return
SiconosVector&
Parameters
  • d: data to put the in vector

SP::SiconosVector operator[](unsigned int i)

get the vector at position i(ie this for Simple and block i for BlockVector)

Return
a SP::SiconosVector
Parameters
  • i: an unsigned integer

SPC::SiconosVector operator[](unsigned int i) const

get the vector at position i(ie this for Simple and block i for BlockVector)

Return
a SP::SiconosVector
Parameters
  • i: an unsigned integer

void resize(unsigned int nbcol, bool preserve = true)

resize the vector with nbcol columns.

The existing elements of the matrix are preseved when specified.

Parameters
  • nbcol:
  • preserve:
Exceptions

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

set the elements starting from position i with input vector

Parameters

void setValue(unsigned int i, double value)

set the element at position i in the vector.

Parameters
  • i: an unsigned int
  • value:

void setVector(unsigned int num, const SiconosVector &v)

set SiconosVector number i (copy) with v (second arg) - Useful only for BlockVector (else equivalent to a single copy)

Parameters

void setVectorPtr(unsigned int num, SP::SiconosVector v)

set SiconosVector number i (pointer link) with v (second arg) - Useful only for BlockVector

Parameters

unsigned int size() const

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

Return
unsigned int

SparseVect *sparse(unsigned int pos = 0) const

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

Return
a SparseVect*
Parameters
  • pos: unsigned int: position of the required vector (useless for SiconosVector, default = 0)

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

subtract the input vector to the elements starting from position i.

Parameters

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

copy a part of the vector into another (usefull for converting a SiconosVector into a BlockVector

Parameters
  • vOut:
  • sizeB:
  • startIn:
  • startOut:

std::string toString() const

put data of the vector into a std::string

Return
std::string

SP::SiconosVector vector(unsigned int pos)

return the current object.

This function is really useful only for block vector

Return
a pointer to a SiconosVector
Parameters
  • pos:

SPC::SiconosVector vector(unsigned int pos) const

return the current object.

This function is really useful only for block vector

Return
a pointer to a SiconosVector
Parameters
  • pos:

double vector_sum() const

return the sum of all elements of the vector

Return
a double

void zero()

sets all the values of the vector to 0.0

Protected Functions

ACCEPT_SERIALIZATION(SiconosVector)

serialization hooks

Protected Attributes

bool _dense
VECTOR_UBLAS_TYPE vect

Union of pointers to the ublas vector type (dense or sparse)

Friends

void abs_wise(const SiconosVector &V, SiconosVector &Vabs)

get an absolute vector

Parameters

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

computes z = x + y

Parameters

void axpby(double, const SiconosVector&, double, SiconosVector&)

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

Parameters

void axpy(double, const SiconosVector&, SiconosVector&)

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

Parameters

void cross_product(const SiconosVector &V1, const SiconosVector &V2, SiconosVector &VOUT)

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.

void getMax(const SiconosVector&, double&, unsigned int&)

get maximal element of a vector

Parameters
  • 1a: SiconosVector (Input).
  • 2a: double variable giving the maximum element (Output).
  • 3an: unsigned int variable giving the position of the maximum element (Output)

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

get minimum element of a vector

Parameters
  • 1a: SiconosVector (Input).
  • 2a: double variable giving the minimum element (Output).
  • 3an: unsigned int variable giving the position of the minimum element (Output)

double inner_prod(const SiconosVector&, const SiconosVector&)

compute dot product m1.m2

Return
a double
Parameters
  • 2: SiconosVectors

friend IsBlock
friend IsDense
friend IsSparse
SiconosVector operator*(double, const SiconosVector&)

multiplication of a vector by a scalar

Return
a SiconosVector
Parameters

SiconosVector operator*(const SiconosVector&, double)

multiplication of a vector by a double

Return
a SiconosVector
Parameters

SiconosVector &operator*=(SiconosVector &v, const double &s)
SiconosVector operator+(const SiconosVector&, const SiconosVector&)

Addition of two vectors.

Return
a SiconosVector
Parameters

SiconosVector operator-(const SiconosVector&, const SiconosVector&)

Subtraction of two vectors.

Return
a SiconosVector
Parameters

SiconosVector operator/(const SiconosVector&, double)

division of the vector by a double

Return
a SiconosVector
Parameters
Exceptions

SiconosVector &operator/=(SiconosVector &v, const double &s)
std::ostream &operator<<(std::ostream &os, const SiconosVector &sv)

send data of the matrix to an ostream

Return
The same output stream
Parameters

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

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

Return
a boolean
Parameters

SimpleMatrix outer_prod(const SiconosVector&, const SiconosVector&)

compute the product m1 * trans(m2)

Return
a SimpleMatrix
Parameters
  • 2: SiconosVectors

void scal(double a, const SiconosVector &x, SiconosVector &y, bool init)

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

Parameters

void setBlock(const SiconosVector &vIn, SP::SiconosVector vOut, unsigned int sizeB, unsigned int startIn, unsigned int startOut)

Copy a part of a vector into a sublock of another vector.

Parameters
  • vIn: SiconosVector input vector (read only)
  • vOut: SiconosVector vector to be overwritten
  • sizeB: int size of the block to be copied
  • startIn: int starting index of the block to be copied (in input vector)
  • startOut: int starting index of the block to be overwritten (in output vector)
  • vIn: block to copy
  • vOut: vector to change (destination)
  • sizeB: size of the block to copy
  • startIn: starting position for the block (vIn)
  • startOut: starting position for the destination (vOut)

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

computes z = x - y

Parameters

void subscal(double a, const SiconosVector &x, SiconosVector &y, const Index &coord, bool init)

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)

union VECTOR_UBLAS_TYPE
#include <SiconosVector.hpp>

Union of DenseVect and SparseVect pointers - Siconos::DENSE, num = 1, SPARSE, num = 4.

Public Members

DenseVect *Dense
SparseVect *Sparse