itpp::Vec< Num_T > Class Template Reference
[Array, Vector and Matrix Classes]

Vector Class (Templated). More...

#include <vec.h>

List of all members.

Public Types

typedef Num_T value_type
 The type of the vector values.

Public Member Functions

 Vec (const Factory &f=DEFAULT_FACTORY)
 Default constructor. An element factory f can be specified.
 Vec (int size, const Factory &f=DEFAULT_FACTORY)
 Constructor with size parameter. An element factory f can be specified.
 Vec (const Vec< Num_T > &v)
 Copy constructor.
 Vec (const Vec< Num_T > &v, const Factory &f)
 Copy constructor, which takes an element factory f as an additional argument.
 Vec (const char *str, const Factory &f=DEFAULT_FACTORY)
 Constructor taking a char string as input. An element factory f can be specified.
 Vec (const std::string &str, const Factory &f=DEFAULT_FACTORY)
 Constructor taking a string as input. An element factory f can be specified.
 Vec (const Num_T *c_array, int size, const Factory &f=DEFAULT_FACTORY)
 Constructor taking a C-array as input. Copies all data. An element factory f can be specified.
 ~Vec ()
 Destructor.
int length () const
 The size of the vector.
int size () const
 The size of the vector.
void set_size (int size, bool copy=false)
 Set length of vector. if copy = true then keeping the old values.
void set_length (int size, bool copy=false)
 Set length of vector. if copy = true then keeping the old values.
void zeros ()
 Set the vector to the all zero vector.
void clear ()
 Set the vector to the all zero vector.
void ones ()
 Set the vector to the all one vector.
void set (const char *str)
 Set the vector equal to the values in the str string.
void set (const std::string &str)
 Set the vector equal to the values in the str string.
const Num_T & operator[] (int i) const
 C-style index operator. First element is 0.
const Num_T & operator() (int i) const
 Index operator. First element is 0.
Num_T & operator[] (int i)
 C-style index operator. First element is 0.
Num_T & operator() (int i)
 Index operator. First element is 0.
Vec< Num_T > operator() (int i1, int i2) const
 Sub-vector with elements from i1 to i2. Index -1 indicates the last element.
Vec< Num_T > operator() (const Vec< int > &indexlist) const
 Sub-vector with elements given by the list of indices indexlist.
Vec< Num_T > operator() (const Vec< bin > &binlist) const
 Sub-vector with elements with indexes where binlist is 1.
const Num_T & get (int i) const
 Accessor-style method. First element is 0.
Vec< Num_T > get (int i1, int i2) const
 Get the elements from i1 to i2. Index -1 indicates the last element.
Vec< Num_T > get (const Vec< int > &indexlist) const
 Get the elements given by the list of indices indexlist.
Vec< Num_T > get (const Vec< bin > &binlist) const
 Get the elements with indexes where binlist is 1.
void set (int i, Num_T t)
 Modifier-style method. First element is 0.
Mat< Num_T > transpose () const
 Matrix transpose. Converts to a matrix with the vector in the first row.
Mat< Num_T > T () const
 Matrix transpose. Converts to a matrix with the vector in the first row.
Mat< Num_T > hermitian_transpose () const
 Hermitian matrix transpose. Converts to a matrix with the conjugate of the vector in the first row.
Mat< Num_T > H () const
 Hermitian matrix transpose. Converts to a matrix with the conjugate of the vector in the first row.
Vec< Num_T > & operator+= (const Vec< Num_T > &v)
 Addition of vector.
Vec< Num_T > & operator+= (Num_T t)
 Addition of scalar.
Vec< Num_T > & operator-= (const Vec< Num_T > &v)
 Subtraction of vector.
Vec< Num_T > & operator-= (Num_T t)
 Subtraction of scalar.
Vec< Num_T > & operator*= (Num_T t)
 Multiply with a scalar.
Vec< Num_T > & operator/= (Num_T t)
 Elementwise division.
Vec< Num_T > & operator/= (const Vec< Num_T > &v)
 Elementwise division.
Vec< Num_T > right (int nr) const
 Get the right nr elements from the vector.
Vec< Num_T > left (int nr) const
 Get the left nr elements from the vector.
Vec< Num_T > mid (int start, int nr) const
 Get the middle part of vector from start including nr elements.
Vec< Num_T > split (int pos)
 Split the vector into two parts at element pos.
void shift_right (Num_T t, int n=1)
 Shift in element t at position 0 n times.
void shift_right (const Vec< Num_T > &v)
 Shift in vector v at position 0.
void shift_left (Num_T t, int n=1)
 Shift out the n left elements and at the same time shift in the element t at last position n times.
void shift_left (const Vec< Num_T > &v)
 Shift in vector v at last positions.
void set_subvector (int i1, int i2, const Vec< Num_T > &v)
 This function is deprecated. Please use set_subvector(i, v) instead.
void set_subvector (int i, const Vec< Num_T > &v)
 Set subvector to elements of vector v starting from element i.
void set_subvector (int i1, int i2, Num_T t)
 Set subvector defined by indices i1 and i2 to t.
void replace_mid (int i, const Vec< Num_T > &v)
 An alias function of set_subvector(i, &v).
void del (int i)
 Delete element number i.
void del (int i1, int i2)
 Delete elements from i1 to i2.
void ins (int i, Num_T t)
 Insert element t before element with index i (0 <= i <= datasize).
void ins (int i, const Vec< Num_T > &v)
 Insert vector v before element with index i (0 <= i <= datasize).
Vec< Num_T > & operator= (Num_T t)
 Assign all elements in vector to t.
Vec< Num_T > & operator= (const Vec< Num_T > &v)
 Assign vector the value and length of v.
Vec< Num_T > & operator= (const Mat< Num_T > &m)
 Assign vector equal to the 1-dimensional matrix m.
Vec< Num_T > & operator= (const char *str)
 Assign vector the values in the string str.
Vec< Num_T > & operator= (const std::string &str)
 Assign vector the values in the string str.
Vec< binoperator== (Num_T t) const
 Elementwise equal to the scalar t.
Vec< binoperator!= (Num_T t) const
 Elementwise not-equal to the scalar t.
Vec< binoperator< (Num_T t) const
 Elementwise less than the scalar t.
Vec< binoperator<= (Num_T t) const
 Elementwise less than and equal to the scalar t.
Vec< binoperator> (Num_T t) const
 Elementwise greater than the scalar t.
Vec< binoperator>= (Num_T t) const
 Elementwise greater than and equal to the scalar t.
bool operator== (const Vec< Num_T > &v) const
 Compare with vector v. Return false if sizes or values differ.
bool operator!= (const Vec< Num_T > &v) const
 Compare with vector v. Return true if sizes or values differ.
Num_T & _elem (int i)
 Index operator without boundary check. Not recommended for use.
const Num_T & _elem (int i) const
 Index operator without boundary check. Not recommended for use.
Num_T * _data ()
 Get the pointer to the internal structure. Not recommended for use.
const Num_T * _data () const
 Get the pointer to the internal structure. Not recommended for use.

Protected Member Functions

void alloc (int size)
 Allocate storage for a vector of length size.
void free ()
 Free the storage space allocated by the vector.

Protected Attributes

int datasize
 The current number of elements in the vector.
Num_T * data
 A pointer to the data area.
const Factoryfactory
 Element factory (set to DEFAULT_FACTORY to use Num_T default constructors only).

Friends

Vec< Num_T > operator+ (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Addition of two vectors.
Vec< Num_T > operator+ (const Vec< Num_T > &v, Num_T t)
 Addition of a vector and a scalar.
Vec< Num_T > operator+ (Num_T t, const Vec< Num_T > &v)
 Addition of a scalar and a vector.
Vec< Num_T > operator- (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Subtraction of v2 from v1.
Vec< Num_T > operator- (const Vec< Num_T > &v, Num_T t)
 Subtraction of scalar from vector.
Vec< Num_T > operator- (Num_T t, const Vec< Num_T > &v)
 Subtraction of vector from scalar.
Vec< Num_T > operator- (const Vec< Num_T > &v)
 Negation of vector.
Num_T operator* (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Inner (dot) product.
Num_T dot (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Inner (dot) product.
Mat< Num_T > outer_product (const Vec< Num_T > &v1, const Vec< Num_T > &v2, bool hermitian)
 Outer product of two vectors v1 and v2.
Vec< Num_T > operator* (const Vec< Num_T > &v, Num_T t)
 Elementwise multiplication of vector and scalar.
Vec< Num_T > operator* (Num_T t, const Vec< Num_T > &v)
 Elementwise multiplication of vector and scalar.
Vec< Num_T > elem_mult (const Vec< Num_T > &a, const Vec< Num_T > &b)
 Elementwise multiplication.
Vec< Num_T > elem_mult (const Vec< Num_T > &a, const Vec< Num_T > &b, const Vec< Num_T > &c)
 Elementwise multiplication of three vectors.
Vec< Num_T > elem_mult (const Vec< Num_T > &a, const Vec< Num_T > &b, const Vec< Num_T > &c, const Vec< Num_T > &d)
 Elementwise multiplication of four vectors.
void elem_mult_out (const Vec< Num_T > &a, const Vec< Num_T > &b, Vec< Num_T > &out)
 Elementwise multiplication, storing the result in vector out.
void elem_mult_out (const Vec< Num_T > &a, const Vec< Num_T > &b, const Vec< Num_T > &c, Vec< Num_T > &out)
 Elementwise multiplication of three vectors, storing the result in vector out.
void elem_mult_out (const Vec< Num_T > &a, const Vec< Num_T > &b, const Vec< Num_T > &c, const Vec< Num_T > &d, Vec< Num_T > &out)
 Elementwise multiplication of four vectors, storing the result in vector out.
void elem_mult_inplace (const Vec< Num_T > &a, Vec< Num_T > &b)
 In-place element-wise multiplication of two vectors. Fast version of b = elem_mult(a,b).
Num_T elem_mult_sum (const Vec< Num_T > &a, const Vec< Num_T > &b)
 Element-wise multiplication of two vectors, followed by summation of the resultant elements. Fast version of sum(elem_mult(a,b)).
Vec< Num_T > operator/ (const Vec< Num_T > &v, Num_T t)
 Elementwise division.
Vec< Num_T > operator/ (Num_T t, const Vec< Num_T > &v)
 Elementwise division.
Vec< Num_T > elem_div (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Elementwise division.
Vec< Num_T > elem_div (Num_T t, const Vec< Num_T > &v)
 This function is deprecated. Please use operator/(Num_T, const Vec<Num_T> &) instead.
void elem_div_out (const Vec< Num_T > &v1, const Vec< Num_T > &v2, Vec< Num_T > &out)
 Elementwise division.
Num_T elem_div_sum (const Vec< Num_T > &a, const Vec< Num_T > &b)
 Elementwise division, followed by summation of the resultant elements. Fast version of sum(elem_mult(a,b)).
Vec< Num_T > concat (const Vec< Num_T > &v, Num_T t)
 Append element t to the end of the vector v.
Vec< Num_T > concat (Num_T t, const Vec< Num_T > &v)
 Insert element t at the beginning of the vector v.
Vec< Num_T > concat (const Vec< Num_T > &v1, const Vec< Num_T > &v2)
 Concatenate vectors v1 and v2.
Vec< Num_T > concat (const Vec< Num_T > &v1, const Vec< Num_T > &v2, const Vec< Num_T > &v3)
 Concatenate vectors v1, v2 and v3.
Vec< Num_T > concat (const Vec< Num_T > &v1, const Vec< Num_T > &v2, const Vec< Num_T > &v3, const Vec< Num_T > &v4)
 Concatenate vectors v1, v2, v3 and v4.
Vec< Num_T > concat (const Vec< Num_T > &v1, const Vec< Num_T > &v2, const Vec< Num_T > &v3, const Vec< Num_T > &v4, const Vec< Num_T > &v5)
 Concatenate vectors v1, v2, v3, v4 and v5.

Related Functions

(Note that these are not member functions.)

typedef Vec< double > vec
 Definition of double vector type.
typedef Vec< std::complex
< double > > 
cvec
 Definition of complex<double> vector type.
typedef Vec< int > ivec
 Definition of integer vector type.
typedef Vec< short int > svec
 Definition of short vector type.
typedef Vec< binbvec
 Definition of binary vector type.
template<class T >
bvec to_bvec (const Vec< T > &v)
 Converts a Vec<T> to bvec.
template<class T >
svec to_svec (const Vec< T > &v)
 Converts a Vec<T> to svec.
template<class T >
ivec to_ivec (const Vec< T > &v)
 Converts a Vec<T> to ivec.
template<class T >
vec to_vec (const Vec< T > &v)
 Converts a Vec<T> to vec.
template<class T >
cvec to_cvec (const Vec< T > &v)
 Converts a Vec<T> to cvec.
template<class T >
cvec to_cvec (const Vec< T > &real, const Vec< T > &imag)
 Converts real and imaginary Vec<T> to cvec.
ivec to_ivec (int s)
 Converts an int to ivec.
vec to_vec (double s)
 Converts an double to vec.
cvec to_cvec (double real, double imag)
 Converts real and imaginary double to cvec.
template<class T >
Vec< T > repmat (const Vec< T > &v, int n)
 Creates a vector with n copies of the vector v.
vec operator+ (const float &s, const vec &v)
 Addition operator for float and vec.
vec operator+ (const short &s, const vec &v)
 Addition operator for short and vec.
vec operator+ (const int &s, const vec &v)
 Addition operator for int and vec.
vec operator+ (const vec &v, const float &s)
 Addition operator for vec and float.
vec operator+ (const vec &v, const short &s)
 Addition operator for vec and short.
vec operator+ (const vec &v, const int &s)
 Addition operator for vec and int.
vec operator- (const float &s, const vec &v)
 Subtraction operator for float and vec.
vec operator- (const short &s, const vec &v)
 Subtraction operator for short and vec.
vec operator- (const int &s, const vec &v)
 Subtraction operator for int and vec.
vec operator- (const vec &v, const float &s)
 Subtraction operator for vec and float.
vec operator- (const vec &v, const short &s)
 Subtraction operator for vec and short.
vec operator- (const vec &v, const int &s)
 Subtraction operator for vec and int.
vec operator* (const float &s, const vec &v)
 Multiplication operator for float and vec.
vec operator* (const short &s, const vec &v)
 Multiplication operator for short and vec.
vec operator* (const int &s, const vec &v)
 Multiplication operator for int and vec.
cvec operator* (const std::complex< double > &s, const vec &v)
 Multiplication operator for complex<double> and vec.
vec operator* (const vec &v, const float &s)
 Multiplication operator for vec and float.
vec operator* (const vec &v, const short &s)
 Multiplication operator for vec and short.
vec operator* (const vec &v, const int &s)
 Multiplication operator for vec and int.
cvec operator* (const vec &v, const std::complex< double > &s)
 Multiplication operator for vec and complex<double>.
vec operator/ (const vec &v, const float &s)
 Division operator for vec and float.
vec operator/ (const vec &v, const short &s)
 Division operator for vec and short.
vec operator/ (const vec &v, const int &s)
 Division operator for vec and int.
vec operator+ (const double &s, const ivec &v)
 Addition operator for double and ivec.
vec operator+ (const ivec &v, const double &s)
 Addition operator for ivec and double.
vec operator- (const double &s, const ivec &v)
 Subtraction operator for double and ivec.
vec operator- (const ivec &v, const double &s)
 Subtraction operator for ivec and double.
vec operator* (const double &s, const ivec &v)
 Multiplication operator for double and ivec.
vec operator* (const ivec &v, const double &s)
 Multiplication operator for ivec and double.
vec operator/ (const double &s, const ivec &v)
 Division operator for double and ivec.
vec operator/ (const ivec &v, const double &s)
 Division operator for ivec and double.
cvec operator+ (const std::complex< double > &s, const ivec &v)
 Addition operator for complex<double> and ivec.
cvec operator+ (const ivec &v, const std::complex< double > &s)
 Addition operator for ivec and complex<double>.
cvec operator- (const std::complex< double > &s, const ivec &v)
 Subtraction operator for complex<double> and ivec.
cvec operator- (const ivec &v, const std::complex< double > &s)
 Subtraction operator for ivec and complex<double>.
cvec operator* (const std::complex< double > &s, const ivec &v)
 Multiplication operator for complex<double> and ivec.
cvec operator* (const ivec &v, const std::complex< double > &s)
 Multiplication operator for ivec and complex<double>.
cvec operator/ (const std::complex< double > &s, const ivec &v)
 Division operator for complex<double> and ivec.
cvec operator/ (const ivec &v, const std::complex< double > &s)
 Division operator for ivec and complex<double>.
cvec operator+ (const double &s, const cvec &v)
 Addition operator for double and cvec.
cvec operator+ (const float &s, const cvec &v)
 Addition operator for float and cvec.
cvec operator+ (const short &s, const cvec &v)
 Addition operator for short and cvec.
cvec operator+ (const int &s, const cvec &v)
 Addition operator for int and cvec.
cvec operator+ (const cvec &v, const float &s)
 Addition operator for cvec and float.
cvec operator+ (const cvec &v, const double &s)
 Addition operator for cvec and double.
cvec operator+ (const cvec &v, const short &s)
 Addition operator for cvec and short.
cvec operator+ (const cvec &v, const int &s)
 Addition operator for cvec and int.
cvec operator- (const double &s, const cvec &v)
 Subtraction operator for double and cvec.
cvec operator- (const float &s, const cvec &v)
 Subtraction operator for float and cvec.
cvec operator- (const short &s, const cvec &v)
 Subtraction operator for short and cvec.
cvec operator- (const int &s, const cvec &v)
 Subtraction operator for int and cvec.
cvec operator- (const cvec &v, const float &s)
 Subtraction operator for cvec and float.
cvec operator- (const cvec &v, const double &s)
 Subtraction operator for cvec and double.
cvec operator- (const cvec &v, const short &s)
 Subtraction operator for cvec and short.
cvec operator- (const cvec &v, const int &s)
 Subtraction operator for cvec and int.
cvec operator* (const double &s, const cvec &v)
 Multiplication operator for double and cvec.
cvec operator* (const float &s, const cvec &v)
 Multiplication operator for float and cvec.
cvec operator* (const short &s, const cvec &v)
 Multiplication operator for short and cvec.
cvec operator* (const int &s, const cvec &v)
 Multiplication operator for int and cvec.
cvec operator* (const cvec &v, const float &s)
 Multiplication operator for cvec and float.
cvec operator* (const cvec &v, const double &s)
 Multiplication operator for cvec and double.
cvec operator* (const cvec &v, const short &s)
 Multiplication operator for cvec and short.
cvec operator* (const cvec &v, const int &s)
 Multiplication operator for cvec and int.
cvec operator/ (const cvec &v, const double &s)
 Division operator for cvec and double.
cvec operator/ (const double &s, const cvec &v)
 Division operator for double and cvec.
cvec operator/ (const cvec &v, const float &s)
 Division operator for cvec and float.
cvec operator/ (const cvec &v, const short &s)
 Division operator for cvec and short.
cvec operator/ (const cvec &v, const int &s)
 Division operator for cvec and int.
vec operator+ (const bvec &a, const vec &b)
 Addition operator for bvec and vec.
vec operator+ (const svec &a, const vec &b)
 Addition operator for svec and vec.
vec operator+ (const ivec &a, const vec &b)
 Addition operator for ivec and vec.
vec operator+ (const vec &a, const bvec &b)
 Addition operator for vec and bvec.
vec operator+ (const vec &a, const svec &b)
 Addition operator for vec and svec.
vec operator+ (const vec &a, const ivec &b)
 Addition operator for vec and ivec.
vec operator- (const bvec &a, const vec &b)
 Subtraction operator for bvec and vec.
vec operator- (const svec &a, const vec &b)
 Subtraction operator for svec and vec.
vec operator- (const ivec &a, const vec &b)
 Subtraction operator for ivec and vec.
vec operator- (const vec &a, const bvec &b)
 Subtraction operator for vec and bvec.
vec operator- (const vec &a, const svec &b)
 Subtraction operator for vec and svec.
vec operator- (const vec &a, const ivec &b)
 Subtraction operator for vec and ivec.
double operator* (const bvec &a, const vec &b)
 Multiplication operator for bvec and vec.
double operator* (const svec &a, const vec &b)
 Multiplication operator for svec and vec.
double operator* (const ivec &a, const vec &b)
 Multiplication operator for ivec and vec.
double operator* (const vec &a, const bvec &b)
 Multiplication operator for vec and bvec.
double operator* (const vec &a, const svec &b)
 Multiplication operator for vec and svec.
double operator* (const vec &a, const ivec &b)
 Multiplication operator for vec and ivec.
cvec operator+ (const bvec &a, const cvec &b)
 Addition operator for bvec and cvec.
cvec operator+ (const svec &a, const cvec &b)
 Addition operator for svec and cvec.
cvec operator+ (const ivec &a, const cvec &b)
 Addition operator for ivec and cvec.
cvec operator+ (const cvec &a, const bvec &b)
 Addition operator for cvec and bvec.
cvec operator+ (const cvec &a, const svec &b)
 Addition operator for cvec and svec.
cvec operator+ (const cvec &a, const ivec &b)
 Addition operator for cvec and ivec.
cvec operator- (const bvec &a, const cvec &b)
 Subtraction operator for bvec and cvec.
cvec operator- (const svec &a, const cvec &b)
 Subtraction operator for svec and cvec.
cvec operator- (const ivec &a, const cvec &b)
 Subtraction operator for ivec and cvec.
cvec operator- (const cvec &a, const bvec &b)
 Subtraction operator for cvec and bvec.
cvec operator- (const cvec &a, const svec &b)
 Subtraction operator for cvec and svec.
cvec operator- (const cvec &a, const ivec &b)
 Subtraction operator for cvec and ivec.
std::complex< double > operator* (const bvec &a, const cvec &b)
 Multiplication operator for bvec and cvec.
std::complex< double > operator* (const svec &a, const cvec &b)
 Multiplication operator for svec and cvec.
std::complex< double > operator* (const ivec &a, const cvec &b)
 Multiplication operator for ivec and cvec.
std::complex< double > operator* (const cvec &a, const bvec &b)
 Multiplication operator for cvec and bvec.
std::complex< double > operator* (const cvec &a, const svec &b)
 Multiplication operator for cvec and svec.
std::complex< double > operator* (const cvec &a, const ivec &b)
 Multiplication operator for cvec and ivec.
template<class T >
void sort (Vec< T > &data, SORTING_METHOD method=INTROSORT)
 Sort the data vector in increasing order.
template<class T >
ivec sort_index (const Vec< T > &data, SORTING_METHOD method=INTROSORT)
 Return an index vector corresponding to a sorted vector data in increasing order.
template<class T >
Vec< T > vec_1 (T v0)
 Vector of length 1.
template<class T >
Vec< T > vec_2 (T v0, T v1)
 Vector of length 2.
template<class T >
Vec< T > vec_3 (T v0, T v1, T v2)
 Vector of length 3.
template<class Num_T >
std::ostream & operator<< (std::ostream &os, const Vec< Num_T > &v)
 Stream output of vector.
template<class Num_T >
std::istream & operator>> (std::istream &is, Vec< Num_T > &v)
 Stream input of vector.


Detailed Description

template<class Num_T>
class itpp::Vec< Num_T >

Vector Class (Templated).

Author:
Tony Ottosson, Tobias Ringstrom, Adam Piatyszek and Conrad Sanderson
Vectors can be of arbitrary types, but conversions and functions are prepared for bin, short, int, double, and complex<double> vectors and these are predefined as: bvec, svec, ivec, vec, and cvec. double and complex<double> are double and complex<double> respectively.

Examples:

Vector Constructors: When constructing a vector without a length (memory) use

 vec temp; 
For construction of a vector of a given length use
 vec temp(length); 
It is also possible to assign the constructed vector the value and size of another vector by
 vec temp(invector); 
If you have explicit values you would like to assign to the vector it is possible to do this using strings as:
  vec a("0 0.7 5 9.3"); // that is a = [0, 0.7, 5, 9.3]
  vec a="0 0.7 5 9.3";  // the constructor is called implicitly
  ivec b="0:5";  // that is, b = [0, 1, 2, 3, 4, 5]
  vec c="3:2.5:13";  // that is, c = [3, 5.5, 8, 10.5, 13]
It is also possible to change length by
 temp.set_size(new_length, false); 
where false is used to indicate that the old values in temp are not copied. If you would like to preserve the values, use true.

There are a number of methods to access parts of a vector. Examples are

  a(5);     // Element number 5
  a(5,9);  // Elements 5, 6, 7, 8, and 9
  a.left(10);  // The 10 leftmost elements (the first)
  a.right(10); // The 10 rightmost elements (the last)
  a.mid(5, 7); // 7 elements starting from element 5

It is also possible to modify parts of a vector, as in e.g.

  a.del(5);    // deletes element number 5
  a.ins(3.4, 9); // inserts the element 3.4 at position 9
  a.set_subvector(12, b); // replaces elements from 12 with the vector b

It is, of course, also possible to perform common linear algebra operations, such as addition, subtraction, and scalar product (*). Observe though, that vectors are assumed to be column-vectors in operations with matrices.

Most elementary functions such as sin(), cosh(), log(), abs(), ..., are also available as operations on the individual elements of the vectors. Please see the individual functions for more details.

By default, the Vec elements are created using the default constructor for the element type. This can be changed by specifying a suitable Factory in the Vec constructor call; see Detailed Description for Factory.


Member Function Documentation

template<class Num_T >
Vec< Num_T > itpp::Vec< Num_T >::split ( int  pos  )  [inline]

Split the vector into two parts at element pos.

Return the first part containing elements 0 to pos-1, and keep the second part containing the remaining elements starting from pos (empty vector if pos is equal to the length of the vector).

References itpp::Vec< Num_T >::data, itpp::Vec< Num_T >::datasize, it_assert_debug, and itpp::Vec< Num_T >::set_size().


Friends And Related Function Documentation

template<class Num_T >
std::istream & operator>> ( std::istream &  is,
Vec< Num_T > &  v 
) [related]

Stream input of vector.

The input can be on the form "1 2 3" or "[1 2 3]", i.e. with or without brackets. The first form is compatible with the set method, while the second form is compatible with the ostream operator. The elements can be separated by blank space or commas. "[]" means an empty vector. "1:4" means "1 2 3 4". "1:3:10" means every third integer from 1 to 10, i.e. "1 4 7 10".

template<class Num_T>
Mat<Num_T> outer_product ( const Vec< Num_T > &  v1,
const Vec< Num_T > &  v2,
bool  hermitian = false 
) [friend]

Outer product of two vectors v1 and v2.

When v1 and v2 are complex vectors (cvec), the third boolean argument hermitian can be set to true to conjugate v2 (Matlab's v1 * v2' operation). This parameter is ignored for types other then cvec.

template<class T >
void sort ( Vec< T > &  data,
SORTING_METHOD  method = INTROSORT 
) [related]

Sort the data vector in increasing order.

Parameters:
data Vector to be sorted
method Sorting method: INTROSORT (default), QUICKSORT, HEAPSORT or INSERTSORT

References itpp::Vec< Num_T >::size(), and itpp::Sort< T >::sort().

template<class T >
ivec sort_index ( const Vec< T > &  data,
SORTING_METHOD  method = INTROSORT 
) [related]

Return an index vector corresponding to a sorted vector data in increasing order.

Parameters:
data Vector for which to return a sorted index vector
method Sorting method: INTROSORT (default), QUICKSORT, HEAPSORT or INSERTSORT

References itpp::Vec< Num_T >::size(), and itpp::Sort< T >::sort_index().


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

Generated on Tue Jun 2 10:02:19 2009 for mixpp by  doxygen 1.5.8