Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
TVector< VT > Class Template Reference

Templated vector class. More...

#include <vector.h>

Inheritance diagram for TVector< VT >:
cuspTVector< VT >

Public Member Functions

 TVector ()
 Constructor. Creates a vector of length 0.
 
 TVector (int dim)
 Constructor. Create a vector of length 'dim' and zero all elements. More...
 
 TVector (int dim, const VT s)
 Constructor. Creates a vector of length 'dim' and set all values to 's'. More...
 
 TVector (int dim, VT *values, CopyMode cmode=DEEP_COPY)
 Constructor. Create a vector of length 'dim' and initialise from 'values' array. More...
 
 TVector (int dim, const char *init)
 Constructor. Create a vector of length 'dim' and initialise values from a text string. More...
 
 TVector (const TVector< VT > &v)
 Copy constructor. Create vector as copy of another vector. More...
 
 TVector (const TVector< VT > &v, int ofs, int dim)
 Reference constructor. Create a vector which shares its data block with vector v. More...
 
 ~TVector ()
 Destructor. Delete vector and deallocate data block.
 
int Dim () const
 Returns the size of the vector. More...
 
VT & operator[] (int i) const
 Vector element access operator (read and write) More...
 
TVectoroperator= (const TVector &v)
 Assignment operator. More...
 
TVectoroperator= (VT s)
 Scalar assignment. All vector elements are set to 's'.
 
void Copy (const TVector &v)
 Vector copy. Replaces the vector with a copy of 'v'. More...
 
void Copy (const TVector &v, int tofs, int sofs, int n)
 Partial vector copy. Replaces the vector with a part of 'v'. More...
 
void New (int dim)
 Resize the vector. More...
 
void Clear ()
 Zeroes all elements. More...
 
void Relink (const TVector &v)
 Link the vector to the data block of another vector. More...
 
void Relink (const TVector &v, int ofs, int n)
 Link the vector to part of the data block of another vector. More...
 
void Relink (VT *values, int dim)
 Link vector to an external data array. More...
 
VT * data_buffer ()
 Direct access to vector data array. More...
 
const VT * data_buffer () const
 Direct access to vector data array. More...
 
bool Clip (VT vmin, VT vmax)
 Truncate vector elements to specified range. More...
 
void ShiftLeft (int n)
 Move vector elements left. More...
 
void ShiftRight (int n)
 Move vector elements right. More...
 
TVector operator+ (const TVector &v) const
 Element-wise addition of vectors. More...
 
TVector operator- (const TVector &v) const
 Element-wise subtraction of vectors. More...
 
TVector operator* (const TVector &v) const
 Element-wise multiplication of vectors. More...
 
TVector operator/ (const TVector &v) const
 Element-wise division of vectors. More...
 
TVector operator+ (const VT &s) const
 Element-wise addition with a scalar. More...
 
TVector operator- (const VT &s) const
 Element-wise subtraction of a scalar. More...
 
TVector operator* (const VT &s) const
 Element-wise multiplication with a scalar. More...
 
TVector operator/ (const VT &s) const
 Element-wise division by a scalar. More...
 
TVector operator- () const
 Unary minus. More...
 
VT operator& (const TVector &v) const
 Dot product of two vectors. More...
 
TVectoroperator+= (const TVector &v)
 Element-wise addition/assignment of vectors. More...
 
TVectoroperator-= (const TVector &v)
 Element-wise subtraction/assignment of vectors. More...
 
TVectoroperator*= (const TVector &v)
 Element-wise multiplication/assignment of vectors. More...
 
TVectoroperator/= (const TVector &v)
 Element-wise division/assignment of vectors. More...
 
TVectoroperator+= (const VT &s)
 Element-wise addition/assignment with a scalar. More...
 
TVectoroperator-= (const VT &s)
 Element-wise subtraction/assignment of a scalar. More...
 
TVectoroperator*= (const VT &s)
 Element-wise multiplication/assignment with a scalar. More...
 
TVectoroperator/= (const VT &s)
 Element-wise division/assignment of a scalar. More...
 
void Read (std::istream &is, int start=0, int n=-1)
 Read vector from stream. More...
 
void ReadIndexed (std::istream &is, int n=-1)
 Read indexed vector elements from stream. More...
 
void Scan (const char *cbuf, int nmax=0)
 Initialise vector elements from a string. More...
 

Protected Member Functions

void Allocate (int dim)
 Allocate data buffer. More...
 
void Link (const TVector< VT > &vec)
 Link the vector to the data block of another vector. More...
 
void Link (const TVector< VT > &vec, int ofs, int dim)
 Link the vector to part of the data block of another vector. More...
 
void Link (VT *values, int dim)
 Link vector to an external data buffer. More...
 
void Unlink ()
 Unlink vector from its data block. More...
 

Protected Attributes

int size
 vector length
 
int * base_size
 pointer to length of linked data block
 
int * base_nref
 pointer to data block reference counter
 
VT * data
 pointer to first vector element
 
VT * base_data
 pointer to linked data block
 

Friends

bool operator== (const TVector< VT > &v1, const TVector< VT > &v2)
 Vector comparison (relational operator) More...
 
bool operator!= (const TVector< VT > &v1, const TVector< VT > &v2)
 Vector comparison (relational operator) More...
 
TVector< VT > inv (const TVector< VT > &v)
 Returns element-wise inverse vector 1/(*this)[i].
 
TVector< VT > sqr (const TVector< VT > &v)
 Returns element-wise square vector (*this)[i]^2.
 
TVector< VT > sqrt (const TVector< VT > &v)
 Returns element-wise square-root vector (*this)[i]^(1/2)
 
TVector< VT > pow (const TVector< VT > &v, const VT &s)
 Returns element-wise power vector (*this)[i]^s.
 
TVector< VT > log (const TVector< VT > &v)
 Returns element-wise natural logarithm vector ln((*this)[i])
 
TVector< VT > exp (const TVector< VT > &v)
 Returns element-wise base-e exponential vector exp((*this)[i])
 
TVector< VT > conj (const TVector< VT > &v)
 Returns element-wise complex conjugate vector ((*this([i].re, -(*this)[i].im)
 
TVector< VT > sin (const TVector< VT > &v)
 Returns element-wise sine vector sin((*this)[i])
 
TVector< VT > cos (const TVector< VT > &v)
 Returns element-wise cosine vector cos((*this)[i])
 
TVector< VT > tan (const TVector< VT > &v)
 Returns element-wise tangent vector tan((*this)[i])
 
TVector< VT > asin (const TVector< VT > &v)
 Returns element-wise arc sine vector asin((*this)[i])
 
TVector< VT > acos (const TVector< VT > &v)
 Returns element-wise arc cosine vector acos((*this)[i])
 
TVector< VT > atan (const TVector< VT > &v)
 Returns element-wise arc tangent vector atan((*this)[i])
 
TVector< VT > sinh (const TVector< VT > &v)
 Returns element-wise hyperbolic sine vector sinh((*this)[i])
 
TVector< VT > cosh (const TVector< VT > &v)
 Returns element-wise hyperbolic cosine vector cosh((*this)[i])
 
TVector< VT > tanh (const TVector< VT > &v)
 Returns element-wise hyperbolic tangent vector tanh((*this)[i])
 
TVector< VT > asinh (const TVector< VT > &v)
 Returns element-wise inverse hyperbolic sine vector asinh((*this)[i])
 
TVector< VT > acosh (const TVector< VT > &v)
 Returns element-wise inverse hyperbolic cosine vector acosh((*this)[i])
 
TVector< VT > atanh (const TVector< VT > &v)
 Returns element-wise inverse hyperbolic tangent vector atanh(v[i]) More...
 
VT dot (const TVector< VT > &v1, const TVector< VT > &v2)
 Dot product of two vectors. More...
 
VT doth (const TVector< VT > &v1, const TVector< VT > &v2)
 Hermitian product of two vectors. More...
 
VT vmin (const TVector< VT > &v)
 Extract smallest element in vector. More...
 
VT vmax (const TVector< VT > &v)
 Extract largest element in vector. More...
 
TVector< VT > vsort (const TVector< VT > &v)
 Sort vector. More...
 
void vsort (const TVector< VT > &v, TVector< VT > &sorted_v, TVector< int > &sort_order)
 Sort vector. More...
 
VT sum (const TVector< VT > &v)
 Sum of elements. More...
 
VT mean (const TVector< VT > &v)
 Mean value of elements. More...
 
VT median (const TVector< VT > &v)
 Median value of elements. More...
 
VT variance (const TVector< VT > &v)
 Variance of element values. More...
 
VT stdv (const TVector< VT > &v)
 Standard deviation of element values. More...
 
double l1norm (const TVector< VT > &v)
 L1 norm of vector elements. More...
 
double l2norm (const TVector< VT > &v)
 L2 norm of vector elements. More...
 
double linfnorm (const TVector< VT > &v)
 L-infinity norm of vector elements. More...
 
double l2normsq (const TVector< VT > &v)
 Square of L2 norm of vector elements. More...
 
double length (const TVector< VT > &vec)
 Length of a vector (L2 norm of elements) More...
 
TVector< VT > & append (TVector< VT > &v1, const TVector< VT > &v2)
 Concatenate two vectors. More...
 
TVector< VT > cat (const TVector< VT > &v1, const TVector< VT > &v2)
 Concatenate two vectors. More...
 
TVector< VT > operator+ (const VT &s, const TVector< VT > &v)
 Element-wise addition of a scalar from the left. More...
 
TVector< VT > operator- (const VT &s, const TVector< VT > &v)
 Element-wise subtraction from a scalar from the left. More...
 
TVector< VT > operator* (const VT &s, const TVector< VT > &v)
 Element-wise multiplication with a scalar from the left. More...
 
TVector< VT > operator/ (const VT &s, const TVector< VT > &v)
 Element-wise division of a scalar by a vector. More...
 
bool visnan (const TVector< VT > &v)
 
std::ostream & operator<< (std::ostream &os, const TVector< VT > &v)
 Write vector to output stream. More...
 
std::istream & operator>> (std::istream &is, TVector< VT > &v)
 Read vector from input stream. More...
 
VT SparseDotp (const TVector< VT > &v1, idxtype *idx1, int nidx1, const TVector< VT > &v2, idxtype *idx2, int nidx2, int from, int to)
 Sparse dot product of two vectors. More...
 
TVector< double > UnfoldComplex (const TVector< VT > &v)
 Unfold real and imaginary parts of a complex vector. More...
 

Detailed Description

template<class VT>
class TVector< VT >

Templated vector class.

Vectors consist of a header block and a dynamically allocated data block. Multiple vectors can share a common data block (or parts thereof). Any changes to a common data block affect all associated vectors simultaneously.

The following template types are instantiated by default:

Constructor & Destructor Documentation

template<class VT>
TVector< VT >::TVector ( int  dim)

Constructor. Create a vector of length 'dim' and zero all elements.

Parameters
dimvector size (>= 0)
template<class VT>
TVector< VT >::TVector ( int  dim,
const VT  s 
)

Constructor. Creates a vector of length 'dim' and set all values to 's'.

Parameters
dimvector size (>= 0)
selement value
template<class VT>
TVector< VT >::TVector ( int  dim,
VT *  values,
CopyMode  cmode = DEEP_COPY 
)

Constructor. Create a vector of length 'dim' and initialise from 'values' array.

Parameters
dimvector size (>= 0)
valuesarray of element values
cmodeif set to SHALLOW_COPY, the value array is not copied into a local buffer but used directly.
Note
The 'values' array must contain at least 'dim' elements.
If cmode==SHALLOW_COPY, the buffer must exist for the lifetime of the vector, and the caller is responsible for cleaning it up after use.
template<class VT>
TVector< VT >::TVector ( int  dim,
const char *  init 
)

Constructor. Create a vector of length 'dim' and initialise values from a text string.

Parameters
dimvector size (>= 0)
inittext string containing list of vector elements
Note
init must contain a list of at least dim elements.
Elements must be in a format that is readable for the C++ stream-in operator ('>>') for the appropriate template type.
Elements must be separated by whitespace.
template<class VT>
TVector< VT >::TVector ( const TVector< VT > &  v)

Copy constructor. Create vector as copy of another vector.

Parameters
voriginal vector
template<class VT>
TVector< VT >::TVector ( const TVector< VT > &  v,
int  ofs,
int  dim 
)

Reference constructor. Create a vector which shares its data block with vector v.

Parameters
voriginal vector
ofsoffset into the data block of the original vector that is to be used as the first element of the reference vector
dimsize of the reference vector
Note
The new vector has length 'dim' and shares all elements from ofs <= i < ofs+dim with vector v.
Any changes to the original vector in that range also affect the new vector (and vice versa).
ofs+dim <= v.Dim() is required.
This constructor is not threadsafe if used by multiple threads referencing the same vector v.

Member Function Documentation

template<class VT>
void TVector< VT >::Allocate ( int  dim)
protected

Allocate data buffer.

Parameters
dimlength of new buffer
Remarks
Resets the length of the vector to dim and allocates a data buffer to store the element values.
Values are initialised to zero.
If the vector already had an associated data block, this must be detached with Unlink first.
See Also
Unlink(), New()

Referenced by TVector< std::complex< double > >::New().

template<class VT>
void TVector< VT >::Clear ( )

Zeroes all elements.

Remarks
Resets all elements to (VT)0, but does not resize the vector.
Equivalent to, but more efficient than *this = 0
template<class VT>
bool TVector< VT >::Clip ( VT  vmin,
VT  vmax 
)

Truncate vector elements to specified range.

  • Truncate all elements of the vector to the range vmin ... vmax.
  • Return value is true if any elements have been truncated.
  • This method is only defined for data types which support boolean comparisons.
template<class VT>
void TVector< VT >::Copy ( const TVector< VT > &  v)

Vector copy. Replaces the vector with a copy of 'v'.

  • This method calls the xCOPY BLAS functions for float and double types, if USE_BLAS_LEVEL1 is defined in toastdef.h

Referenced by TVector< std::complex< double > >::operator=().

template<class VT>
void TVector< VT >::Copy ( const TVector< VT > &  v,
int  tofs,
int  sofs,
int  n 
)

Partial vector copy. Replaces the vector with a part of 'v'.

  • A block of data of length n is copied from vector 'v' (starting at index 'sofs', into the data block of *this, starting at index 'tofs': (*this)[i+tofs]=v[i+sofs], i=0...Dim()-1.
  • The size of the target vector (*this) is not changed.
  • If the data chunk exceeds the limits of the source or target vector, then n is truncated as required.
  • If n < 0 then the chunk size is maximised.
  • This method calls the xCOPY BLAS functions for float and double types, if USE_BLAS_LEVEL1 is defined.
template<class VT>
VT* TVector< VT >::data_buffer ( )
inline

Direct access to vector data array.

  • Returns a pointer to the vector's data block to provide low-level access (read and write).
  • The pointer may become invalid if the vector re-allocates its buffer, e.g. after a call to New().
template<class VT>
const VT* TVector< VT >::data_buffer ( ) const
inline

Direct access to vector data array.

  • Returns a pointer to the vector's data block to provide low-level access (read only).
  • The pointer may become invalid if the vector re-allocates its buffer, e.g. after a call to New().
template<class VT>
int TVector< VT >::Dim ( ) const
inline

Returns the size of the vector.

Returns
Size (number of elements) of the vector.
template<class VT>
void TVector< VT >::Link ( const TVector< VT > &  vec)
protected

Link the vector to the data block of another vector.

Parameters
vecreferenced vector
Remarks
The two vectors share the same data block. Any changes to element values apply to both simultaneously.
A re-allocation of the data block of one of the vectors (e.g. as a result of resizing) disconnects the two vectors.
If the vector already had an associated data block, this must be detached with Unlink first.
See Also
Unlink(), Relink()
template<class VT>
void TVector< VT >::Link ( const TVector< VT > &  vec,
int  ofs,
int  dim 
)
protected

Link the vector to part of the data block of another vector.

Parameters
vecreferenced vector
ofsstarting index of the referenced block of elements (zero-based)
dimblock length
Remarks
The two vectors share part of their data block. Any changes to element values apply to boths simultaneously.
A re-allocation of the data block of one of the vectors (e.g. as a result of resizing) disconnects the two vectors.
If the vector already had an associated data block, this must be detached with Unlink first.
See Also
Unlink(), Relink()
template<class VT>
void TVector< VT >::Link ( VT *  values,
int  dim 
)
protected

Link vector to an external data buffer.

Parameters
valuesexternal data array of length >= dim
dimvector size
Note
The external buffer must be guaranteed to exist while linked by the vector.
template<class VT>
void TVector< VT >::New ( int  dim)
inline

Resize the vector.

Parameters
dimNew vector length
Remarks
Re-allocates the data block to size 'dim' and resets all values to zero.
See Also
Allocate(), Unlink()
template<class VT>
VT TVector< VT >::operator& ( const TVector< VT > &  v) const
inline

Dot product of two vectors.

Parameters
vRight-hand operand
Returns
dot product $\vec{*this}\cdot\vec{v} = \sum_i *this_i \cdot v_i$
Conditions:
this->Dim() == v.Dim()
Remarks
The operands are unchanged.
If USE_BLAS_LEVEL1 is set in toastdef.h, this calls BLAS functions ddot (for TVector<double>), sdot (for TVector<float>), or zdotu (for TVector<complex>)
See Also
dot()
template<class VT>
TVector TVector< VT >::operator* ( const TVector< VT > &  v) const

Element-wise multiplication of vectors.

  • Return value is *this[i] * v[i]
  • The operands are unchanged.
  • Operands must have the same length
template<class VT>
TVector TVector< VT >::operator* ( const VT &  s) const

Element-wise multiplication with a scalar.

  • Return value is *this[i] * s
  • The operands are unchanged.
template<class VT>
TVector& TVector< VT >::operator*= ( const TVector< VT > &  v)

Element-wise multiplication/assignment of vectors.

(*this)[i] *= v[i]

Parameters
vRight-hand operand (vector)
Returns
The result of the multiplication (the new value of *this)
template<class VT>
TVector& TVector< VT >::operator*= ( const VT &  s)

Element-wise multiplication/assignment with a scalar.

(*this)[i] *= s

Parameters
sRight-hand operand (scalar)
Returns
The result of the multiplication (the new value of *this)
template<class VT>
TVector TVector< VT >::operator+ ( const TVector< VT > &  v) const

Element-wise addition of vectors.

  • Return value is *this[i] + v[i]
  • The operands are unchanged.
  • Operands must have the same length
  • This method calls the xAXPY BLAS functions for float and double types, if USE_BLAS_LEVEL1 is defined.
template<class VT>
TVector TVector< VT >::operator+ ( const VT &  s) const

Element-wise addition with a scalar.

  • Return value is *this[i] + s
  • The operands are unchanged.
template<class VT>
TVector& TVector< VT >::operator+= ( const TVector< VT > &  v)

Element-wise addition/assignment of vectors.

(*this)[i] += v[i]

Parameters
vRight-hand operand (vector)
Returns
The result of the addition (the new value of *this)
template<class VT>
TVector& TVector< VT >::operator+= ( const VT &  s)

Element-wise addition/assignment with a scalar.

(*this)[i] += s

Parameters
sRight-hand operand (scalar)
Returns
The result of the addition (the new value of *this)
template<class VT>
TVector TVector< VT >::operator- ( const TVector< VT > &  v) const

Element-wise subtraction of vectors.

  • Return value is *this[i] - v[i]
  • The operands are unchanged.
  • Operands must have the same length
  • This method calls the xAXPY BLAS functions for float and double types, if USE_BLAS_LEVEL1 is defined.
template<class VT>
TVector TVector< VT >::operator- ( const VT &  s) const

Element-wise subtraction of a scalar.

  • Return value is *this[i] - s
  • The operands are unchanged.
template<class VT>
TVector TVector< VT >::operator- ( ) const

Unary minus.

  • Return value is -*this[i]
  • The operand is unchanged.
template<class VT>
TVector& TVector< VT >::operator-= ( const TVector< VT > &  v)

Element-wise subtraction/assignment of vectors.

(*this)[i] -= v[i]

Parameters
vRight-hand operand (vector)
Returns
The result of the subtraction (the new value of *this)
template<class VT>
TVector& TVector< VT >::operator-= ( const VT &  s)

Element-wise subtraction/assignment of a scalar.

(*this)[i] -= s

Parameters
sRight-hand operand (scalar)
Returns
The result of the subtraction (the new value of *this)
template<class VT>
TVector TVector< VT >::operator/ ( const TVector< VT > &  v) const

Element-wise division of vectors.

  • Return value is *this[i] / v[i]
  • The operands are unchanged.
  • Operands must have the same length
template<class VT>
TVector TVector< VT >::operator/ ( const VT &  s) const

Element-wise division by a scalar.

  • Return value is *this[i] / s
  • The operands are unchanged.
template<class VT>
TVector& TVector< VT >::operator/= ( const TVector< VT > &  v)

Element-wise division/assignment of vectors.

(*this)[i] /= v[i]

Parameters
vRight-hand operand (vector)
Returns
The result of the division (the new value of *this)
template<class VT>
TVector& TVector< VT >::operator/= ( const VT &  s)

Element-wise division/assignment of a scalar.

(*this)[i] /= s

Parameters
sRight-hand operand (scalar)
Returns
The result of the division (the new value of *this)
template<class VT>
TVector& TVector< VT >::operator= ( const TVector< VT > &  v)
inline

Assignment operator.

  • Sets the left-hand operator to 'v' and resizes, if required.
  • The return value of the operation is the copied vector, so that constructs like v1 = v2 = v0 are possible.
template<class VT>
VT& TVector< VT >::operator[] ( int  i) const

Vector element access operator (read and write)

Parameters
ielement index (0 <= i < TVector::Dim())
Note
The operator syntax is: x = v[i]
template<class VT>
void TVector< VT >::Read ( std::istream &  is,
int  start = 0,
int  n = -1 
)

Read vector from stream.

Parameters
isinput stream
startindex of first element to read
nmax. number of elements to read (-1 for all)
Remarks
This method allows to read a partial vector from a stream, by skipping the first elements (start > 0) and dropping the last elements (n < stored vector length)
See Also
operator>>()
template<class VT>
void TVector< VT >::ReadIndexed ( std::istream &  is,
int  n = -1 
)

Read indexed vector elements from stream.

Parameters
isinput stream
nvector length
Remarks
Resizes *this to length n and reads index-value pairs (white-space separated) from stream to fill it.
Indices are zero-based.
Unreferenced entries are set to 0.
The first value read from the stream is interpreted as the number of index-value pairs to follow.
If n < 0, the vector is assumed to be already of correct length (no resizing)
template<class VT>
void TVector< VT >::Relink ( const TVector< VT > &  v)

Link the vector to the data block of another vector.

  • Shares data with another vector.
  • This method unlinks the vector from its current data block and links it to the data block of 'v'. The original data block is removed from memory, unless it is referenced by another vector.
template<class VT>
void TVector< VT >::Relink ( const TVector< VT > &  v,
int  ofs,
int  n 
)

Link the vector to part of the data block of another vector.

  • Shares data with another vector.
  • This method unlinks the vector from its current data block and links it to a subset of the data block of 'v' of length 'n', starting at index ofs.
  • Requires
    • ofs >= 0
    • n > 0
    • ofs+n <= v.Dim()
template<class VT>
void TVector< VT >::Relink ( VT *  values,
int  dim 
)

Link vector to an external data array.

Parameters
valuesexternal array of length >= dim
dimvector size
Note
The external buffer is not copied into a local buffer but used directly. It must exist during the lifetime of the vector, or until it is linked to a different buffer.
template<class VT>
void TVector< VT >::Scan ( const char *  cbuf,
int  nmax = 0 
)

Initialise vector elements from a string.

Parameters
cbufASCII string of values (white-space separated)
nmaxMax number of values to read (or 0 for all)
Note
The string should NOT contain vector delimiters [].
Vector must be allocated beforehand (no resizing)
template<class VT>
void TVector< VT >::ShiftLeft ( int  n)

Move vector elements left.

  • Shifts all elements of the vector n places left (toward lower indices)
  • The n leftmost elements are dropped.
  • The n rightmost elements are reset to zero.
template<class VT>
void TVector< VT >::ShiftRight ( int  n)

Move vector elements right.

  • Shifts all elements of the vector n places right (toward higher indices)
  • The n rightmost elements are dropped.
  • The n leftmost elements are reset to zero.
template<class VT>
void TVector< VT >::Unlink ( )
protected

Unlink vector from its data block.

Remarks
This results in a (valid) vector of length zero.
See Also
New(), Clear()

Referenced by TVector< std::complex< double > >::New(), and TVector< std::complex< double > >::~TVector().

Friends And Related Function Documentation

template<class VT>
TVector<VT>& append ( TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Concatenate two vectors.

Appends the elements of the second argument (v2) to the end of the first argument (v1).

Returns
Result of the concatenation (the modified v1 argument)
Remarks
Argument v2 unchanged.
template<class VT>
TVector<VT> atanh ( const TVector< VT > &  v)
friend

Returns element-wise inverse hyperbolic tangent vector atanh(v[i])

Parameters
vvector argument
Returns
result vector
Conditions:
|v[i]| <= 1 is required for all elements of a real input vector
See Also
sinh, cosh, tanh, asinh, acosh
template<class VT>
TVector<VT> cat ( const TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Concatenate two vectors.

Creates a new vector by concatenating the two arguments.

Returns
The result of the concatenation, {v1,v2}
Note
Both arguments unchanged
template<class VT>
VT dot ( const TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Dot product of two vectors.

Parameters
v1first vector argument
v2second vector argument
Returns
dot product $ \vec{v1}\cdot\vec{v2}=\sum_i v1_i \cdot v2_i$
Conditions:
v1.Dim() == v2.Dim() (checked in DEBUG only)
Remarks
If USE_BLAS_LEVEL1 is set in toastdef.h, this calls BLAS functions ddot (for TVector<double>), sdot (for TVector<float>), or zdotu (for TVector<complex>)
See Also
operator&().

Referenced by TVector< std::complex< double > >::operator&().

template<class VT>
VT doth ( const TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Hermitian product of two vectors.

Returns
Hermitian product $ \sum_i v1_i^* \cdot v2_i$
Conditions:
v1.Dim() == v2.Dim() (checked in DEBUG only)
Remarks
For all template types other than complex, this function is identical to dot(). For complex, this returns the inner product of the complex conjugate of the first argument, and the second argument.
If USE_BLAS_LEVEL1 is set in toastdef.h, the function calls BLAS function zdotc.
template<class VT>
double l1norm ( const TVector< VT > &  v)
friend

L1 norm of vector elements.

Returns
$ \sum_i^{v.Dim()} | v_i | $
See Also
l2norm(), linfnorm()
template<class VT>
double l2norm ( const TVector< VT > &  v)
friend

L2 norm of vector elements.

Returns
$ \sqrt{\sum_i^{v.Dim()} v_i^2} $
See Also
length(), l2normsq(), l1norm(), linfnorm()
template<class VT>
double l2normsq ( const TVector< VT > &  v)
friend

Square of L2 norm of vector elements.

Returns
$ \sum_i^{v.Dim()} v_i^2 $
See Also
l2norm()
template<class VT>
double length ( const TVector< VT > &  vec)
friend

Length of a vector (L2 norm of elements)

Returns
$ \sqrt{\sum_i^{v.Dim()} v_i^2} $
Remarks
Synonymous to l2norm().
template<class VT>
double linfnorm ( const TVector< VT > &  v)
friend

L-infinity norm of vector elements.

Returns
$ \max_i | v_i | $
See Also
l1norm(), l2norm()
template<class VT>
VT mean ( const TVector< VT > &  v)
friend

Mean value of elements.

Returns
$ E(v) = (1/v.Dim()) \sum_i^{v.Dim()} v_i $
Condition
v.Dim >= 1
See Also
median(), variance(), stdv()
template<class VT>
VT median ( const TVector< VT > &  v)
friend

Median value of elements.

Returns a value from v such that at most half the values of v have values less than the median and at most half the have values greater than the median.

Remarks
If v.Dim() is even, returns the mean of the two middle values.
If v.Dim() == 0, returns 0.
See Also
mean()
template<class VT>
bool operator!= ( const TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Vector comparison (relational operator)

Parameters
v1left-hand vector operand
v2right-hand vector operand
Returns
Returns false if both vectors are identical, true otherwise.
template<class VT>
TVector<VT> operator* ( const VT &  s,
const TVector< VT > &  v 
)
friend

Element-wise multiplication with a scalar from the left.

Allows multiplication with a scalar from the left, in constructs like

w = s * v;
Parameters
sscalar value
vvector value
Returns
Result of the multiplication, {s*v[i]}
See Also
TVector::operator*()
template<class VT>
TVector<VT> operator+ ( const VT &  s,
const TVector< VT > &  v 
)
friend

Element-wise addition of a scalar from the left.

Allows adding scalars from the left, in constructs like

w = s + v;
Parameters
sscalar value
vvector value
Returns
Result of the addition, {s+v[i]}
See Also
TVector::operator+()
template<class VT>
TVector<VT> operator- ( const VT &  s,
const TVector< VT > &  v 
)
friend

Element-wise subtraction from a scalar from the left.

Allows subtraction from a scalar on the left, in constructs like

w = s - v;
Parameters
sscalar value
vvector value
Returns
Result of the subtraction, {s-v[i]}
See Also
TVector::operator-()
template<class VT>
TVector<VT> operator/ ( const VT &  s,
const TVector< VT > &  v 
)
friend

Element-wise division of a scalar by a vector.

Division of a scalar by a vector, in constructs like

w = s / v;
Parameters
sscalar value
vvector value
Returns
Result of the division, {s/v[i]}
See Also
TVector::operator/()
template<class VT>
std::ostream& operator<< ( std::ostream &  os,
const TVector< VT > &  v 
)
friend

Write vector to output stream.

Parameters
osoutput stream
vvector to be written
Returns
output stream (to allow chaining of output objects)
Note
The output is whitespace-separated ASCII text, enclosed by square brackets. Example:
[0 7.12 -3.1415]
For complex vectors, each complex entry follows the standard toast notation of separating the real and imaginary part with whitespace and enclosing in a <> bracket pair. Example:
[<0 0> <-3.1 44.123>]
template<class VT>
bool operator== ( const TVector< VT > &  v1,
const TVector< VT > &  v2 
)
friend

Vector comparison (relational operator)

Parameters
v1left-hand vector operand
v2right-hand vector operand
Returns
Returns true if both vectors are identical, false otherwise.
template<class VT>
std::istream& operator>> ( std::istream &  is,
TVector< VT > &  v 
)
friend

Read vector from input stream.

Parameters
isinput stream
vvector to be read
Returns
input stream (to allow chaining of input objects)
Note
The vector is resized to the appropriate length as required.
The expected format of the input stream is whitespace-separated ASCII text, enclosed by square brackets. Example:
[0 7.12 -3.1415]
For complex vectors, each complex entry follows the standard toast notation of separating the real and imaginary part with whitespace and enclosing in a <> bracket pair. Example:
[<0 0> <-3.1 44.123>]
template<class VT>
VT SparseDotp ( const TVector< VT > &  v1,
idxtype *  idx1,
int  nidx1,
const TVector< VT > &  v2,
idxtype *  idx2,
int  nidx2,
int  from,
int  to 
)
friend

Sparse dot product of two vectors.

Given vectors v1 and v2 and index lists idx1, idx2 of length nidx1 and nidx2, respectively, calculate the dot product using only the vector indices from the lists.

Parameters
v1first vector argument
idx1first index array
nidx1length of first index array
v2second vector argument
idx2second index array
nidx2length of second index array
fromlower index limit
tohigh index limit
Returns
sparse dot product
Note
idx1 and idx2 are assumed sorted (ascending)
template<class VT>
VT stdv ( const TVector< VT > &  v)
friend

Standard deviation of element values.

Returns
$ \sigma(v) = \sqrt{var(v)} $
See Also
mean(), variance()
template<class VT>
VT sum ( const TVector< VT > &  v)
friend

Sum of elements.

Returns
$ \sum_i^{v.Dim()} v_i $
template<class VT>
TVector<double> UnfoldComplex ( const TVector< VT > &  v)
friend

Unfold real and imaginary parts of a complex vector.

Parameters
vinput vector argument
Returns
Unfolded real vector
Note
For complex template types, this method creates a real output vector of twice the size of the input vector, containing the real and imaginary parts of the vector.
For real template types, this simply returns the input vector.
template<class VT>
VT variance ( const TVector< VT > &  v)
friend

Variance of element values.

Returns
$ var(v) = E((v-E(v))^2) = E(v^2) - (E(v))^2 $
See Also
mean(), stdv()
template<class VT>
VT vmax ( const TVector< VT > &  v)
friend

Extract largest element in vector.

Returns
$ \max_i v_i $
Remarks
Only works with template types that define relational operator >.
template<class VT>
VT vmin ( const TVector< VT > &  v)
friend

Extract smallest element in vector.

Returns
$ \min_i v_i $
Remarks
Only works with template types that define relational operator <.
template<class VT>
TVector<VT> vsort ( const TVector< VT > &  v)
friend

Sort vector.

Returns
Vector with elements of v sorted in ascending order.
Remarks
Uses a simple bubble sort algorithm
Input argument unchanged.
Only works with template types that define relational operator <.
template<class VT>
void vsort ( const TVector< VT > &  v,
TVector< VT > &  sorted_v,
TVector< int > &  sort_order 
)
friend

Sort vector.

Returns
Vector with elements of v sorted in ascending order.
Sort order vector.
Remarks
Uses a simple bubble sort algorithm
Input argument unchanged.
Only works with template types that define relational operator <.

The documentation for this class was generated from the following file: