#include <vector.h>
Collaboration diagram for SPUC::Vec< T >:
Public Member Functions | |
Vec () | |
Constructor. | |
Vec (int size) | |
Constructor. | |
Vec (const Vec< T > &v) | |
Constructor. | |
Vec (const char *values) | |
Constructor. | |
Vec (const string &values) | |
Constructor. | |
Vec (T *c_array, int size) | |
Constructor taking a C-array as input. Copies all data. | |
~Vec () | |
Destructor. | |
int | length () const |
The size of the vector. | |
int | size () const |
The size of the vector. | |
void | set_length (int size, bool copy=false) |
Set length of vector. if copy = true then keeping the old values. | |
void | set_size (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. | |
bool | set (const char *str) |
Set the vector equal to the values in the str string. | |
bool | set (const string &str) |
Set the vector equal to the values in the str string. | |
T | operator[] (int i) const |
C-style index operator. First element is 0. | |
T | operator() (int i) const |
Index operator. First element is 0. | |
T & | operator[] (int i) |
C-style index operator. First element is 0. | |
T & | operator() (int i) |
Index operator. First element is 0. | |
const Vec< T > | operator() (int i1, int i2) const |
Sub-vector with elements from i1 to i2 . Index -1 indicates the last element. | |
const Vec< T > | operator() (const Vec< int > &indexlist) const |
Sub-vector where the elements are given by the list indexlist . | |
void | operator+= (const Vec< T > &v) |
Addition of vector. | |
void | operator+= (T t) |
Addition of scalar. | |
void | operator-= (const Vec< T > &v) |
Subtraction of vector. | |
void | operator-= (T t) |
Subtraction of scalar. | |
void | operator *= (T t) |
Multiply with a scalar. | |
void | operator/= (T t) |
Elementwise division. | |
void | operator/= (const Vec< T > &v) |
Elementwise division. | |
Vec< T > | get (const Vec< bin > &binlist) const |
Get the elements in the vector where binlist is 1 . | |
Vec< T > | right (int nr) const |
Get the right nr elements from the vector. | |
Vec< T > | left (int nr) const |
Get the left nr elements from the vector. | |
Vec< T > | mid (int start, int nr) const |
Get the middle part of vector from start including nr elements. | |
Vec< T > | split (int pos) |
Split the vector into two parts at element pos . Return the first part and keep the second. | |
void | shift_right (T In, int n=1) |
Shift in element In at position 0 n times. | |
void | shift_right (const Vec< T > &In) |
Shift in vector In at position 0. | |
void | shift_left (T In, int n=1) |
Shift out the n left elements and a the same time shift in the element at last position n times. | |
void | shift_left (const Vec< T > &In) |
Shift in vector In at last position. | |
void | set_subvector (int i1, int i2, const Vec< T > &v) |
Set subvector defined by indicies i1 to i2 to vector v. | |
void | set_subvector (int i1, int i2, const T t) |
Set subvector defined by indicies i1 to i2 to constant t. | |
void | replace_mid (int pos, const Vec< T > &v) |
Replace the elements from pos by the vector v . | |
void | del (int index) |
Delete element number index . | |
void | ins (int index, T in) |
Insert element in at index . | |
void | ins (int index, const Vec< T > &in) |
Insert vector in at index . | |
void | operator= (T t) |
Assign all elements in vector to t . | |
void | operator= (const Vec< T > &v) |
Assign vector the value and length of v . | |
void | operator= (const Mat< T > &m) |
Assign vector equal to the 1-dimensional matrix m . | |
void | operator= (const char *values) |
Assign vector the values in the string values . | |
Vec< bin > | operator== (const T value) |
Elementwise equal to the scalar. | |
Vec< bin > | operator!= (const T value) |
Elementwise not-equal to the scalar. | |
Vec< bin > | operator< (const T value) |
Elementwise less than the scalar. | |
Vec< bin > | operator<= (const T value) |
Elementwise less than and equal to the scalar. | |
Vec< bin > | operator> (const T value) |
Elementwise greater than the scalar. | |
Vec< bin > | operator>= (const T value) |
Elementwise greater than and equal to the scalar. | |
bool | operator== (const Vec< T > &v) const |
Compare two vectors. False if wrong sizes or different values. | |
bool | operator!= (const Vec< T > &v) const |
Compare two vectors. True if different. | |
T & | _elem (int i) |
Index operator without boundary check. Not recommended to use. | |
T | _elem (int i) const |
Index operator without boundary check. Not recommended to use. | |
T * | _data () |
Get the pointer to the internal structure. Not recommended to use. | |
const T * | _data () const |
Get the pointer to the internal structure. Not recommended to 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. | |
T * | data |
A pointer to the data area. | |
Friends | |
Vec< T > | operator+TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Addition of two vectors. | |
Vec< T > | operator+TEMPLATE_FUN (const Vec< T > &v, T t) |
Addition of a vector and a scalar. | |
Vec< T > | operator+TEMPLATE_FUN (T t, const Vec< T > &v) |
Addition of a scalar and a vector. | |
Vec< T > | operator-TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Subtraction of v2 from v1 . | |
Vec< T > | operator-TEMPLATE_FUN (const Vec< T > &v, T t) |
Subtraction of scalar from vector. | |
Vec< T > | operator-TEMPLATE_FUN (T t, const Vec< T > &v) |
Sutraction of vector from scalar. | |
Vec< T > | operator-TEMPLATE_FUN (const Vec< T > &v) |
Negation of vector. | |
T | operator *TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Inner (dot) product. | |
T dot | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Inner (dot) product. | |
T dot_prod | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Mat< T > outer_product | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Outer product of two vectors v1 and v2. | |
Vec< T > | operator *TEMPLATE_FUN (const Vec< T > &v, T t) |
Elementwise multiplication of vector and scalar. | |
Vec< T > | operator *TEMPLATE_FUN (T t, const Vec< T > &v) |
Elementwise multiplication of vector and scalar. | |
Vec< T > elem_mult | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Elementwise multiplication. | |
Vec< T > elem_mult | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2, const Vec< T > &v3) |
Elementwise multiplication of three vectors. | |
Vec< T > elem_mult | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2, const Vec< T > &v3, const Vec< T > &v4) |
Elementwise multiplication of four vectors. | |
Vec< T > | operator/TEMPLATE_FUN (const Vec< T > &v, T t) |
Elementwise division. | |
Vec< T > | operator/TEMPLATE_FUN (const T t, const Vec< T > &v) |
Elementwise division. | |
Vec< T > elem_div | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Elementwise division. | |
Vec< T > elem_div | TEMPLATE_FUN (const T t, const Vec< T > &v) |
Elementwise division. | |
Vec< T > concat | TEMPLATE_FUN (const Vec< T > &v, const T a) |
Append element a to the end of the vector v . | |
Vec< T > concat | TEMPLATE_FUN (const T a, const Vec< T > &v) |
Concat element a to the beginning of the vector v . | |
Vec< T > concat | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2) |
Concat vectors v1 and v2 . | |
Vec< T > concat | TEMPLATE_FUN (const Vec< T > &v1, const Vec< T > &v2, const Vec< T > &v3) |
Concat vectors v1 , v2 and v3 . | |
Related Functions | |
(Note that these are not member functions.) | |
typedef Vec< double > | vec |
Stream output of vector Definition of double vector type. | |
typedef Vec< complex< double > > | cvec |
Definition of double_complex vector type. | |
typedef Vec< int > | ivec |
Definition of integer vector type. | |
typedef Vec< long_long > | llvec |
Definition of long_long vector type. | |
typedef Vec< short int > | svec |
Definition of short vector type. | |
typedef Vec< bin > | bvec |
Definition of binary vector type. | |
int | length (const Vec< T > &v) |
Length of vector. | |
int | size (const Vec< T > &v) |
Length of vector. | |
T | sum (const Vec< T > &v) |
Sum of all elements in the vector. | |
T | sum_sqr (const Vec< T > &v) |
Sum of square of the elements in a vector. | |
T | max (const Vec< T > &v) |
Maximum value of vector. | |
T | min (const Vec< T > &in) |
Minimum value of vector. | |
int | max_index (const Vec< T > &in) |
Return the postion of the maximum element in the vector. | |
int | min_index (const Vec< T > &in) |
Return the postion of the minimum element in the vector. | |
T | product (const Vec< T > &v) |
The product of all elements in the vector. | |
Vec< T > | cross (const Vec< T > &v1, const Vec< T > &v2) |
Vector cross product. Vectors need to be of size 3. | |
double | mean (const vec &v) |
The mean value. | |
complex< double > | mean (const cvec &v) |
The mean value. | |
double | mean (const svec &v) |
The mean value. | |
double | mean (const ivec &v) |
The mean value. | |
double | geometric_mean (const Vec< T > &v) |
The geometric mean value. | |
double | median (const Vec< T > &v) |
The median. | |
double | norm (const Vec< T > &v) |
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2)). | |
double | norm (const cvec &v) |
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2)). | |
double | norm (const Vec< T > &v, int p) |
Calculate the p-norm: norm(v,p)=sum(abs(v).^2)^(1/p). | |
double | norm (const cvec &v, int p) |
Calculate the p-norm: norm(v,p)=sum(abs(v).^2)^(1/p). | |
double | energy (const Vec< T > &v) |
The variance of the elements in the vector. Normalized with N-1 to be unbiased.The variance of the elements in the vector. Normalized with N-1 to be unbiased.Calculate the energy: squared 2-norm. energy(v)=sum(v.^2). | |
Vec< T > | reverse (const Vec< T > &in) |
Reverse the input vector. | |
Vec< T > | repeat (const Vec< T > &v, int norepeats) |
Repeat each element in the vector norepeats times in sequence. | |
Vec< T > | apply_function (fT(*f)(fT), const Vec< T > &data) |
Apply arbitrary function to a vector. | |
void | sort (Vec< T > &data) |
Sort the the vector in increasing order. | |
ivec | sort_index (const Vec< T > &data) |
Return an index vector corresponding to a sorted vector (increasing order). | |
Vec< T > | zero_pad (const Vec< T > &v, int n) |
Zero-pad a vector to size n. | |
Vec< T > | zero_pad (const Vec< T > &v) |
Zero-pad a vector to the nearest greater power of two. | |
Mat< T > | zero_pad (const Mat< T > &v, int rows, int cols) |
Zero-pad a matrix to size rows x cols. | |
void | upsample (const Vec< T > &v, int usf, Vec< T > &u) |
Upsample a vector by incerting (usf-1) zeros after each sample. | |
Vec< T > | upsample (const Vec< T > &v, int usf) |
Upsample a vector by incerting (usf-1) zeros after each sample. | |
Vec< T > | vec_1 (T v0) |
Vector of length 1. | |
Vec< T > | vec_2 (T v0, T v1) |
Vector of length 2. | |
Vec< T > | vec_3 (T v0, T v1, T v2) |
Vector of length 3. |
bin
, short
, int
, double
, and double_complex
vectors and these are predefined as: bvec
, svec
, ivec
, vec
, and cvec
. double
and double_complex
are double
and complex<double>
respectively.Examples:
Vector Constructors: When constructing a vector without a length (memory) use
vec temp;
vec temp(invector);
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 are 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]
temp.set_size(new_length, false);
false
is used to indicate that the old values in temp
is not copied. If you 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 most left elements (the first) a.right(10); // The 10 most right elements (the last) a.mid(5, 7); // 7 elements starting from element 5
It is also possible to modify parts of a vector as e.g. in
a.del(5); // deletes element number 5 a.ins(3.4, 9); // inserts the element 3.4 at position 9 a.replace_mid(12, b); // replaces elements from 12 with the vector b
It is of course also possible to perform the common linear algebra methods 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 available as operations on the individual elements of the vectors. Please see the individual functions for more details.
|
Constructor.
|
|
Constructor.
Here is the call graph for this function: ![]() |
|
Constructor.
Here is the call graph for this function: ![]() |
|
Constructor.
Here is the call graph for this function: ![]() |
|
Constructor.
Here is the call graph for this function: ![]() |
|
Constructor taking a C-array as input. Copies all data.
Here is the call graph for this function: ![]() |
|
Destructor.
Here is the call graph for this function: ![]() |
|
Get the pointer to the internal structure. Not recommended to use.
|
|
Get the pointer to the internal structure. Not recommended to use.
|
|
Index operator without boundary check. Not recommended to use.
|
|
Index operator without boundary check. Not recommended to use.
|
|
Allocate storage for a vector of length
Here is the call graph for this function: ![]() |
|
Set the vector to the all zero vector.
Here is the call graph for this function: ![]() |
|
Delete element number
Here is the call graph for this function: ![]() |
|
Free the storage space allocated by the vector.
|
|
Get the elements in the vector where
Here is the call graph for this function: ![]() |
|
Insert vector
Here is the call graph for this function: ![]() |
|
Insert element
Here is the call graph for this function: ![]() |
|
Get the left
|
|
The size of the vector.
|
|
Get the middle part of vector from
|
|
Set the vector to the all one vector.
|
|
Multiply with a scalar.
|
|
Compare two vectors. True if different.
|
|
Elementwise not-equal to the scalar.
Here is the call graph for this function: ![]() |
|
Sub-vector where the elements are given by the list
Here is the call graph for this function: ![]() |
|
Sub-vector with elements from
|
|
Index operator. First element is 0.
|
|
Index operator. First element is 0.
|
|
Addition of scalar.
|
|
Addition of vector.
Here is the call graph for this function: ![]() |
|
Subtraction of scalar.
|
|
Subtraction of vector.
Here is the call graph for this function: ![]() |
|
Elementwise division.
|
|
Elementwise division.
|
|
Elementwise less than the scalar.
Here is the call graph for this function: ![]() |
|
Elementwise less than and equal to the scalar.
Here is the call graph for this function: ![]() |
|
Assign vector the values in the string
Here is the call graph for this function: ![]() |
|
Assign vector equal to the 1-dimensional matrix
Here is the call graph for this function: ![]() |
|
Assign vector the value and length of
Here is the call graph for this function: ![]() |
|
Assign all elements in vector to
|
|
Compare two vectors. False if wrong sizes or different values.
|
|
Elementwise equal to the scalar.
Here is the call graph for this function: ![]() |
|
Elementwise greater than the scalar.
Here is the call graph for this function: ![]() |
|
Elementwise greater than and equal to the scalar.
Here is the call graph for this function: ![]() |
|
C-style index operator. First element is 0.
|
|
C-style index operator. First element is 0.
|
|
Replace the elements from
|
|
Get the right
|
|
Set the vector equal to the values in the
Here is the call graph for this function: ![]() |
|
Set the vector equal to the values in the
Here is the call graph for this function: ![]() |
|
Set length of vector. if copy = true then keeping the old values.
Here is the call graph for this function: ![]() |
|
Set length of vector. if copy = true then keeping the old values.
Here is the call graph for this function: ![]() |
|
Set subvector defined by indicies i1 to i2 to constant t.
|
|
Set subvector defined by indicies i1 to i2 to vector v.
|
|
Shift in vector
|
|
Shift out the
|
|
Shift in vector
|
|
Shift in element
|
|
The size of the vector.
|
|
Split the vector into two parts at element
|
|
Set the vector to the all zero vector.
|
|
Apply arbitrary function to a vector.
|
|
Definition of binary vector type.
|
|
Vector cross product. Vectors need to be of size 3.
|
|
Definition of double_complex vector type.
|
|
The variance of the elements in the vector. Normalized with N-1 to be unbiased.The variance of the elements in the vector. Normalized with N-1 to be unbiased.Calculate the energy: squared 2-norm. energy(v)=sum(v.^2).
|
|
The geometric mean value.
|
|
Definition of integer vector type.
|
|
Length of vector.
Here is the call graph for this function: ![]() |
|
Definition of long_long vector type.
|
|
Maximum value of vector.
|
|
Return the postion of the maximum element in the vector.
|
|
The mean value.
|
|
The mean value.
|
|
The mean value.
|
|
The mean value.
|
|
The median.
|
|
Minimum value of vector.
|
|
Return the postion of the minimum element in the vector.
|
|
Calculate the p-norm: norm(v,p)=sum(abs(v).^2)^(1/p).
|
|
Calculate the p-norm: norm(v,p)=sum(abs(v).^2)^(1/p).
|
|
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2)).
|
|
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2)).
|
|
Elementwise multiplication of vector and scalar.
|
|
Elementwise multiplication of vector and scalar.
|
|
Inner (dot) product.
|
|
Addition of a scalar and a vector.
|
|
Addition of a vector and a scalar.
|
|
Addition of two vectors.
|
|
Negation of vector.
|
|
Sutraction of vector from scalar.
|
|
Subtraction of scalar from vector.
|
|
Subtraction of
|
|
Elementwise division.
|
|
Elementwise division.
|
|
The product of all elements in the vector.
|
|
Repeat each element in the vector norepeats times in sequence.
|
|
Reverse the input vector.
|
|
Length of vector.
Here is the call graph for this function: ![]() |
|
Sort the the vector in increasing order.
|
|
Return an index vector corresponding to a sorted vector (increasing order).
|
|
Sum of all elements in the vector.
|
|
Sum of square of the elements in a vector.
|
|
Definition of short vector type.
|
|
Concat vectors
|
|
Concat vectors
|
|
Concat element
|
|
Append element
|
|
Elementwise division.
|
|
Elementwise division.
|
|
Elementwise multiplication of four vectors.
|
|
Elementwise multiplication of three vectors.
|
|
Elementwise multiplication.
|
|
Outer product of two vectors v1 and v2.
|
|
|
|
Inner (dot) product.
|
|
Upsample a vector by incerting (usf-1) zeros after each sample.
|
|
Upsample a vector by incerting (usf-1) zeros after each sample.
|
|
Stream output of vector Definition of double vector type.
|
|
Vector of length 1.
|
|
Vector of length 2.
|
|
Vector of length 3.
|
|
Zero-pad a matrix to size rows x cols.
|
|
Zero-pad a vector to the nearest greater power of two.
|
|
Zero-pad a vector to size n.
|
|
A pointer to the data area.
|
|
The current number of elements in the vector.
|