SOFA API  ca70b0f0
Open source framework for multi-physics simuation
sofa::linearalgebra::BaseVector Class Referenceabstract

#include <BaseVector.h>

Inheritance diagram for sofa::linearalgebra::BaseVector:

Detailed Description

Generic vector API, allowing to fill and use a vector independently of the linear algebra library in use.

Note that accessing values using this class is rather slow and should only be used in codes where the provided genericity is necessary.

Public Member Functions

virtual ~BaseVector ()
 
virtual Index size (void) const =0
 Number of elements. More...
 
virtual SReal element (Index i) const =0
 Read the value of element i. More...
 
virtual void resize (Index dim)=0
 Resize the vector, and reset all values to 0. More...
 
virtual void clear ()=0
 Reset all values to 0. More...
 
virtual void set (Index i, SReal v)=0
 Write the value of element i. More...
 
virtual void add (Index i, SReal v)=0
 Add v to the existing value of element i. More...
 
virtual const floatelements (Index i0, Index n, float *src) const
 Get the values of n elements, starting at element i0, into given float buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual const double * elements (Index i0, Index n, double *src) const
 Get the values of n elements, starting at element i0, into given double buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual const int * elements (Index i0, Index n, int *src) const
 Get the values of n elements, starting at element i0, into given int buffer, or return the pointer to the data if the in-memory format is compatible. More...
 
virtual void set (Index i0, Index n, const float *src)
 Write the values of n float elements, starting at element i0. More...
 
virtual void set (Index i0, Index n, const double *src)
 Write the values of n double elements, starting at element i0. More...
 
virtual void set (Index i0, Index n, const int *src)
 Write the values of n int elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const float *src)
 Add to the values of n float elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const double *src)
 Add to the values of n double elements, starting at element i0. More...
 
virtual void add (Index i0, Index n, const int *src)
 Add to the values of n int elements, starting at element i0. More...
 
virtual void clear (Index i)
 Reset the value of element i to 0. More...
 

Protected Member Functions

template<class T >
const T * elementsDefaultImpl (Index i0, Index n, T *buffer) const
 
template<class T >
void setDefaultImpl (Index i0, Index n, const T *src)
 
template<class T >
void addDefaultImpl (Index i0, Index n, const T *src)
 

Friends

SOFA_LINEARALGEBRA_API std::ostream & operator<< (std::ostream &out, const BaseVector &v)
 Declare that the operator << exists but is defined in BaseVector.cpp. More...
 

Get information about the content and structure of this vector

enum  ElementType { ELEMENT_UNKNOWN = 0 , ELEMENT_FLOAT , ELEMENT_INT }
 
virtual ElementType getElementType () const
 
virtual std::size_t getElementSize () const
 
virtual bool isFull () const
 Return true if this vector is full, i.a. all elements are stored in memory. More...
 
bool isSparse () const
 

Constructor details

◆ ~BaseVector()

virtual sofa::linearalgebra::BaseVector::~BaseVector ( )
inlinevirtual

Function details

◆ add() [1/4]

virtual void sofa::linearalgebra::BaseVector::add ( Index  i,
SReal  v 
)
pure virtual

◆ add() [2/4]

virtual void sofa::linearalgebra::BaseVector::add ( Index  i0,
Index  n,
const double *  src 
)
inlinevirtual

Add to the values of n double elements, starting at element i0.

◆ add() [3/4]

virtual void sofa::linearalgebra::BaseVector::add ( Index  i0,
Index  n,
const float src 
)
inlinevirtual

Add to the values of n float elements, starting at element i0.

◆ add() [4/4]

virtual void sofa::linearalgebra::BaseVector::add ( Index  i0,
Index  n,
const int *  src 
)
inlinevirtual

Add to the values of n int elements, starting at element i0.

◆ addDefaultImpl()

template<class T >
void sofa::linearalgebra::BaseVector::addDefaultImpl ( Index  i0,
Index  n,
const T *  src 
)
inlineprotected

◆ clear() [1/2]

virtual void sofa::linearalgebra::BaseVector::clear ( )
pure virtual

◆ clear() [2/2]

virtual void sofa::linearalgebra::BaseVector::clear ( Index  i)
inlinevirtual

◆ element()

virtual SReal sofa::linearalgebra::BaseVector::element ( Index  i) const
pure virtual

◆ elements() [1/3]

virtual const double* sofa::linearalgebra::BaseVector::elements ( Index  i0,
Index  n,
double *  src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given double buffer, or return the pointer to the data if the in-memory format is compatible.

◆ elements() [2/3]

virtual const float* sofa::linearalgebra::BaseVector::elements ( Index  i0,
Index  n,
float src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given float buffer, or return the pointer to the data if the in-memory format is compatible.

◆ elements() [3/3]

virtual const int* sofa::linearalgebra::BaseVector::elements ( Index  i0,
Index  n,
int *  src 
) const
inlinevirtual

Get the values of n elements, starting at element i0, into given int buffer, or return the pointer to the data if the in-memory format is compatible.

◆ elementsDefaultImpl()

template<class T >
const T* sofa::linearalgebra::BaseVector::elementsDefaultImpl ( Index  i0,
Index  n,
T *  buffer 
) const
inlineprotected

◆ getElementSize()

virtual std::size_t sofa::linearalgebra::BaseVector::getElementSize ( ) const
inlinevirtual
Returns
size of elements stored in this matrix

◆ getElementType()

virtual ElementType sofa::linearalgebra::BaseVector::getElementType ( ) const
inlinevirtual
Returns
type of elements stored in this matrix

◆ isFull()

virtual bool sofa::linearalgebra::BaseVector::isFull ( ) const
inlinevirtual

Return true if this vector is full, i.a. all elements are stored in memory.

◆ isSparse()

bool sofa::linearalgebra::BaseVector::isSparse ( ) const
inline

Return true if this vector is sparse, i.a. only some of the elements are stored in memory. This is the exact opposite to isFull().

◆ resize()

virtual void sofa::linearalgebra::BaseVector::resize ( Index  dim)
pure virtual

◆ set() [1/4]

virtual void sofa::linearalgebra::BaseVector::set ( Index  i,
SReal  v 
)
pure virtual

◆ set() [2/4]

virtual void sofa::linearalgebra::BaseVector::set ( Index  i0,
Index  n,
const double *  src 
)
inlinevirtual

Write the values of n double elements, starting at element i0.

◆ set() [3/4]

virtual void sofa::linearalgebra::BaseVector::set ( Index  i0,
Index  n,
const float src 
)
inlinevirtual

Write the values of n float elements, starting at element i0.

◆ set() [4/4]

virtual void sofa::linearalgebra::BaseVector::set ( Index  i0,
Index  n,
const int *  src 
)
inlinevirtual

Write the values of n int elements, starting at element i0.

◆ setDefaultImpl()

template<class T >
void sofa::linearalgebra::BaseVector::setDefaultImpl ( Index  i0,
Index  n,
const T *  src 
)
inlineprotected

◆ size()

virtual Index sofa::linearalgebra::BaseVector::size ( void  ) const
pure virtual

Enum details

◆ ElementType

Enumerator
ELEMENT_UNKNOWN 
ELEMENT_FLOAT 
ELEMENT_INT 

Related details

◆ operator<<

SOFA_LINEARALGEBRA_API std::ostream& operator<< ( std::ostream &  out,
const BaseVector v 
)
friend

Declare that the operator << exists but is defined in BaseVector.cpp.