Geophysical Inversion and Modelling Library  v1.5.2-5-g042d7f36
GIMLI::Vector< ValueType > Class Template Reference

One dimensional array aka Vector of limited size. More...

## Public Types

typedef ValueType ValType

typedef VectorIterator< ValueType > iterator

## Public Member Functions

Vector ()

Vector (Index n)

Vector (Index n, const ValueType &val)

Vector (const std::string &filename, IOFormat format=Ascii)

Vector (const Vector< ValueType > &v)

Vector (const Vector< ValueType > &v, Index start, Index end)

template<class A >
Vector (const __VectorExpr< ValueType, A > &v)

Vector (const std::vector< ValueType > &v)

template<class ValueType2 >
Vector (const Vector< ValueType2 > &v)

~Vector ()

Vector< ValueType > & operator= (const Vector< ValueType > &v)

template<class A >
Vector< ValueType > & operator= (const __VectorExpr< ValueType, A > &v)

Vector< ValueType > & operator= (const ValueType &val)

Vector< ValueType > copy () const

const ValueType & operator[] (const Index i) const

ValueType & operator[] (const Index i)

const Vector< ValueType > operator[] (const IndexArray &i) const

Vector< ValueType > operator[] (const IndexArray &i)

Vector< ValueType > operator[] (const BVector &b)

Vector< ValueType > operator() (Index start, SIndex end) const

Vector< ValueType > operator() (const std::pair< Index, SIndex > &pair) const

Vector< ValueType > operator() (const IndexArray &iArray) const

Vector< ValueType > operator() (const SIndexArray &siArray) const

Vector< ValueType > operator() (const IVector &iVec) const

template<class IndexContainer >
Vector< ValueType > get_ (const IndexContainer &idx) const

Vector< ValueType > get_ (const BVector &bv) const

Vector< ValueType > getVUI_ (const IndexArray &iA) const

Vector< ValueType > getVSI_ (const IVector &iA) const

template<class T >
operator std::vector< T > ()

Vector< ValueType > & setVal (const ValueType &val)

Vector< ValueType > & setVal (const ValueType &val, const BVector &bv)

Vector< ValueType > & setVal (const ValueType &val, Index i)

Vector< ValueType > & setVal (const ValueType &val, Index start, SIndex end)

Vector< ValueType > & setVal (const ValueType &val, const std::pair< Index, SIndex > &pair)

Vector< ValueType > & setVal (const ValueType &val, const IndexArray &ids)

Vector< ValueType > & setVal (const Vector< ValueType > &vals, const IndexArray &ids)

Vector< ValueType > & setVal (const Vector< ValueType > &vals, Index start)

Vector< ValueType > & setVal (const Vector< ValueType > &vals, Index start, Index end)

Vector< ValueType > & setVal (const Vector< ValueType > &vals, const std::pair< Index, SIndex > &pair)

Vector< ValueType > & push_back (const ValueType &v)

Vector< ValueType > & addVal (const Vector< ValueType > &vals, Index start, Index end)

Vector< ValueType > & addVal (const Vector< ValueType > &vals, const std::pair< Index, SIndex > &pair)

Vector< ValueType > & addVal (const Vector< ValueType > &vals, const IndexArray &idx)

Vector< ValueType > & addVal (const ValueType &val, Index i)

void add (const ElementMatrix< double > &A)

void add (const ElementMatrix< double > &A, const double &scale)

void add (const ElementMatrix< double > &A, const Pos &scale)

void add (const ElementMatrix< double > &A, const RMatrix &scale)

void add (const ElementMatrix< double > &A, const Vector< double > &scale)

const ValueType & getVal (Index i) const

Vector< ValueType > getVal (Index start, SIndex end) const

Vector< ValueType > getVal (const std::pair< Index, SIndex > &pair) const

BVector operator< (const Vector< ValueType > &v) const

Vector< ValueType > operator- () const

void resize (Index n, ValueType fill)

void resize (Index n)

void reserve (Index n)

template<class V >
Vector< ValueType > & fill (V *val)

Vector< ValueType > & fill (const ValueType &val)

template<class Ex >
Vector< ValueType > & fill (Expr< Ex > expr)

void assign (const Vector< ValueType > &v)

template<class ExprOP >
void assign (const ExprOP &v)

void clean ()

void clear ()

Vector< ValueType > & round (const ValueType &tolerance)

bool empty () const

Index size () const

Index capacity () const

Index singleCalcCount () const

ValueType * data ()

bool save (const std::string &filename, IOFormat format=Ascii) const

bool load (const std::string &filename, IOFormat format=Ascii)

VectorIterator< ValueType > beginPyIter () const

VectorIterator< ValueType > begin () const

VectorIterator< ValueType > end () const

Index hash () const

void add (const ElementMatrix< double > &A)

void add (const ElementMatrix< double > &A, const double &scale)

void add (const ElementMatrix< double > &A, const RVector3 &scale)

void add (const ElementMatrix< double > &A, const RMatrix &scale)

void add (const ElementMatrix< double > &A, const RVector &scale)

void clean ()

DLLEXPORT void clean ()

## Protected Member Functions

void free_ ()

void copy_ (const Vector< ValueType > &v)

template<class ExprOP >
void assign_ (const ExprOP &v)

## Protected Attributes

Index size_

ValueType * data_

Index capacity_

Index singleCalcCount_

## Static Protected Attributes

static const Index minSizePerThread = 10000

static const int maxThreads = 8

## Detailed Description

### template<class ValueType> class GIMLI::Vector< ValueType >

One dimensional array aka Vector of limited size.

One dimensional array aka Vector of limited size. Size limit depends on platform (32bit system maxsize = 2^32, 64bit system, maxsize=2^64)

## ◆ Vector() [1/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( )
inline

Construct one-dimensional array of size n. The vector is cleaned (filled with zero)

## ◆ Vector() [2/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( Index n, const ValueType & val )
inline

Construct one-dimensional array of size n, and fill it with val

## ◆ Vector() [3/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( const std::string & filename, IOFormat format = `Ascii` )
inline

Construct vector from file. Shortcut for Vector::load

## ◆ Vector() [4/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( const Vector< ValueType > & v )
inline

Copy constructor. Create new vector as a deep copy of v.

## ◆ Vector() [5/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( const Vector< ValueType > & v, Index start, Index end )
inline

Copy constructor. Create new vector as a deep copy of the slice v[start, end)

## ◆ Vector() [6/7]

template<class ValueType >
template<class A >
 GIMLI::Vector< ValueType >::Vector ( const __VectorExpr< ValueType, A > & v )
inline

Copy constructor. Create new vector from expression

## ◆ Vector() [7/7]

template<class ValueType >
 GIMLI::Vector< ValueType >::Vector ( const std::vector< ValueType > & v )
inline

Copy constructor. Create new vector as a deep copy of std::vector(Valuetype)

## ◆ ~Vector()

template<class ValueType >
 GIMLI::Vector< ValueType >::~Vector ( )
inline

Default destructor.

## Member Function Documentation

template<class ValueType >
 void GIMLI::Vector< ValueType >::add ( const ElementMatrix< double > & A )

template<class ValueType >
 void GIMLI::Vector< ValueType >::add ( const ElementMatrix< double > & A, const double & scale )

Add Values from an ElementMatrix. Optional scale with constant scalar.

template<class ValueType >
 void GIMLI::Vector< ValueType >::add ( const ElementMatrix< double > & A, const Pos & scale )

Add Values from an ElementMatrix. Optional scale constant Pos.

template<class ValueType >
 void GIMLI::Vector< ValueType >::add ( const ElementMatrix< double > & A, const RMatrix & scale )

Add Values from an ElementMatrix. Optional scale constant RMatrix.

 void GIMLI::Vector< double >::add ( const ElementMatrix< double > & A, const RVector< ValueType > & scale )

! warning this will lead to incorrect results with non constant scale ! use new fea style for correct integration

template<class ValueType >
 void GIMLI::Vector< ValueType >::add ( const ElementMatrix< double > & A, const Vector< double > & scale )

DEPRECATED Bad design (Per node values need to be interpolated to quadrature points first.)

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::addVal ( const ValueType & val, Index i )
inline

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::addVal ( const Vector< ValueType > & vals, const IndexArray & idx )
inline

Add values from vals at IndexArray idx. Throws length exception if sizes of vals and idx mismatch.

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::addVal ( const Vector< ValueType > & vals, Index start, Index end )
inline

Like setVal(vals, start, end) instead copy use +=

## ◆ clean()

template<class ValueType >
 void GIMLI::Vector< ValueType >::clean ( )
inline

Fill the whole vector with function expr(i) *‍/ template< class V > void fill(const V & val){ for (Index i = 0; i < size_; i ++) data_[i] = ValueType(val); }

```/*! Fill Vector with 0.0. Don't change size.
```

## ◆ clear()

template<class ValueType >
 void GIMLI::Vector< ValueType >::clear ( )
inline

Empty the vector. Frees memory and resize to 0.

## ◆ copy()

template<class ValueType >
 Vector< ValueType > GIMLI::Vector< ValueType >::copy ( ) const
inline

Return a deep copy. For numpy compatibility.

## ◆ fill() [1/3]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::fill ( const ValueType & val )
inline

Fill the whole vector with val.

## ◆ fill() [2/3]

template<class ValueType >
template<class Ex >
 Vector< ValueType >& GIMLI::Vector< ValueType >::fill ( Expr< Ex > expr )
inline

Fill the whole vector with function expr(i)

## ◆ fill() [3/3]

template<class ValueType >
template<class V >
 Vector< ValueType >& GIMLI::Vector< ValueType >::fill ( V * val )
inline

Fill the whole vector from the pointer of val. CAUTION!! There is no boundary check. Val must be properly ([val, val+this->size()))assigned.

## ◆ getVal()

template<class ValueType >
 const ValueType& GIMLI::Vector< ValueType >::getVal ( Index i ) const
inline

Get value for index i. Throws out of range exception if index check fails.

template<class ValueType >
 bool GIMLI::Vector< ValueType >::load ( const std::string & filename, IOFormat format = `Ascii` )
inline

Load the object from file. Returns true on success and in case of trouble an exception is thrown. The IOFormat flag will be overwritten if the filename have a proper file suffix. Ascii format is forced if VECTORASCSUFFIX is given. Binary format is forced if VECTORBINSUFFIX is set. See Vector< ValueType >::save for file format.

## ◆ operator std::vector< T >()

template<class ValueType >
template<class T >
 GIMLI::Vector< ValueType >::operator std::vector< T > ( )
inline

Implicit converter for Vector< T > = Vector< ValueType >

Implicit converter for std::vector < T > = Vector< ValueType >

## ◆ operator()() [1/3]

template<class ValueType >
 Vector< ValueType > GIMLI::Vector< ValueType >::operator() ( const IndexArray & iArray ) const
inline

Return a new vector that based on indices's. Throws exception if indices's are out of bound

## ◆ operator()() [2/3]

template<class ValueType >
 Vector< ValueType > GIMLI::Vector< ValueType >::operator() ( const SIndexArray & siArray ) const
inline

Return a new vector that based on indices's. Throws exception if indices's are out of bound.

## ◆ operator()() [3/3]

template<class ValueType >
 Vector< ValueType > GIMLI::Vector< ValueType >::operator() ( Index start, SIndex end ) const
inline

Return a new vector that match the slice [start, end). end == -1 or larger size() sets end = size. Throws exception on violating boundaries.

## ◆ operator-()

template<class ValueType >
 Vector< ValueType > GIMLI::Vector< ValueType >::operator- ( ) const
inline

Negation operator thats return a copy of this with negative values.

## ◆ operator=() [1/3]

template<class ValueType >
template<class A >
 Vector< ValueType >& GIMLI::Vector< ValueType >::operator= ( const __VectorExpr< ValueType, A > & v )
inline

Assignment operator. Creates a new vector as from expression.

## ◆ operator=() [2/3]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::operator= ( const ValueType & val )
inline

Assignment operator. Fill the existing vector with val. Shortcut for fill.

## ◆ operator=() [3/3]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::operator= ( const Vector< ValueType > & v )
inline

Assignment operator. Creates a new vector as copy of v

## ◆ reserve()

template<class ValueType >
 void GIMLI::Vector< ValueType >::reserve ( Index n )
inline

Reserve memory. Old data are preserved

Referenced by GIMLI::find().

## ◆ resize()

template<class ValueType >
 void GIMLI::Vector< ValueType >::resize ( Index n, ValueType fill )
inline

## ◆ round()

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::round ( const ValueType & tolerance )
inline

Round all values of this array to a given tolerance.

## ◆ save()

template<class ValueType >
 bool GIMLI::Vector< ValueType >::save ( const std::string & filename, IOFormat format = `Ascii` ) const
inline

Save the object to file. Returns true on success and in case of trouble an exception is thrown. The IOFormat flag will be overwritten if the filename have a proper file suffix. Ascii format is forced if VECTORASCSUFFIX is given. Binary format is forced if VECTORBINSUFFIX is set. If no suffix is provided VECTORASCSUFFIX or VECTORBINSUFFIX will be append.

Binary format is:
Unsigned int64 [8Byte] - length of the Array [0.. length)
ValueType [sizeof(ValueType)] - 0th value
...
ValueType [sizeof(ValueType)] - length -1 value

Ascii format is a simple list of the values

Parameters
 filename string of the file name IOFormat enum, either Ascii for human readable format, or Binary for fast save and load.

Referenced by GIMLI::DCMultiElectrodeModelling::response(), and GIMLI::saveVec().

## ◆ setVal() [1/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val )
inline

Set the value to the whole array. Same as fill(val)

## ◆ setVal() [2/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val, const BVector< ValueType > & bv )
inline

Set the val where bv is true. Throws out of length exception if sizes dismatch. Same as setVal(val, find(bv)) but faster.

## ◆ setVal() [3/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val, const IndexArray & ids )
inline

Set multiple values. Throws out of range exception if index check fails.

## ◆ setVal() [4/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val, const std::pair< Index, SIndex > & pair )
inline

Set value val from pair.start to pair.end

## ◆ setVal() [5/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val, Index i )
inline

Set the value val at index i. Throws out of range exception if index is not in [0, size).

## ◆ setVal() [6/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const ValueType & val, Index start, SIndex end )
inline

Set a value at slice range from [start, end). end will set to this->size() for < 0 or greater size(). start will set to end for < 0 or greater end

## ◆ setVal() [7/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const Vector< ValueType > & vals, const IndexArray & ids )
inline

Set multiple values from vals at index position iArray. Throws out of range exception if index check fails.

## ◆ setVal() [8/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const Vector< ValueType > & vals, const std::pair< Index, SIndex > & pair )
inline

Set all vals from pair.start to pair.end

## ◆ setVal() [9/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const Vector< ValueType > & vals, Index start )
inline

Insert vals from start index. Resize if necessary.

## ◆ setVal() [10/10]

template<class ValueType >
 Vector< ValueType >& GIMLI::Vector< ValueType >::setVal ( const Vector< ValueType > & vals, Index start, Index end )
inline

Set values from slice. If vals.size() == this.size() copy vals[start, end) -> this[start, end) else assume vals is a slice itsself, so copy vals[0, end-start] -> this[start, end) if end larger than this size() sets end = size. Throws exception on violating boundaries.