Geophysical Inversion and Modeling Library  v1.0.10-11-g5965775b
GIMLI::Vector< ValueType > Class Template Reference

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

+ Collaboration diagram for GIMLI::Vector< ValueType >:

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 > operator() (const BVector &bv) 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, 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 &a)
 
void add (const ElementMatrix< double > &A, const Vector< double > &a)
 
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)
 
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 nThreads () 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
 
template<>
void add (const ElementMatrix< double > &A)
 
template<>
void add (const ElementMatrix< double > &A, const double &a)
 
template<>
void add (const ElementMatrix< double > &A, const RVector &a)
 
template<>
void clean ()
 
template<>
DLLEXPORT void add (const ElementMatrix< double > &A)
 
template<>
DLLEXPORT void add (const ElementMatrix< double > &A, const double &a)
 
template<>
DLLEXPORT void add (const ElementMatrix< double > &A, const RVector &a)
 

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_
 
int nThreads_
 
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)

Constructor & Destructor Documentation

◆ 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

◆ add() [1/4]

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

Add Values from an ElementMatrix. For vectors only the first row will be taken.

Referenced by GIMLI::Vector< bool >::load().

◆ add() [2/4]

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

Add Values from an ElementMatrix. For vectors only the first row will be taken. Optional scale with scalar.

◆ add() [3/4]

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

Add Values from an ElementMatrix. For vectors only the first row will be taken. Optional scale with values from vector.

◆ add() [4/4]

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

Implement specialized type traits in vector.cpp

◆ addVal() [1/3]

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 +=

Referenced by GIMLI::BlockMatrix< ValueType >::addMatrixEntry().

◆ addVal() [2/3]

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.

◆ addVal() [3/3]

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

Add val to index idx.

◆ clean()

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

Fill the whole vector with function expr(i)

Fill Vector with 0.0. Don't change size.

Referenced by GIMLI::Mesh::findCellsAlongRay().

◆ clear()

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

◆ 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>
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.

Referenced by GIMLI::DCSRMultiElectrodeModelling::checkPrimpotentials_(), GIMLI::DCMultiElectrodeModelling::createDefaultStartModel(), GIMLI::HarmonicModelling::createJacobian(), GIMLI::increasingRange(), GIMLI::increasingRange2(), and GIMLI::DC1dModelling::init_().

◆ fill() [2/3]

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

Fill the whole vector with val.

◆ fill() [3/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)

◆ 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.

Referenced by GIMLI::BlockMatrix< ValueType >::addMatrixEntry().

◆ load()

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.

Referenced by GIMLI::loadVec().

◆ 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() ( 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()() [2/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()() [3/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-()

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>
Vector< ValueType >& GIMLI::Vector< ValueType >::operator= ( const Vector< ValueType > &  v)
inline

Assignment operator. Creates a new vector as copy of v

◆ operator=() [2/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=() [3/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.

◆ reserve()

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

Reserve memory. Old data are preserved

Referenced by GIMLI::RegionManager::addRegion(), and GIMLI::find().

◆ resize()

◆ 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
filenamestring of the file name
IOFormatenum, either Ascii for human readable format, or Binary for fast save and load.

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

◆ setVal() [1/9]

◆ setVal() [2/9]

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/9]

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() [4/9]

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() [5/9]

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() [6/9]

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() [7/9]

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/9]

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.

◆ setVal() [9/9]

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