itbase library is the core of
IT++ and it contains classes and functions for mathematics with scalars, vectors, and matrices. This document does not cover all the aspects of the
itbase library. It does however explain the most important things you need to know in order to start using IT++. Once you are more familiar with the
itbase library you will find the online reference manual more useful.
Apart from the standard C++ types e.g.
long, the following types are specific for
complex<double>: Contains real and imaginary parts of type
bin:Used for binary (0,1) data
A vector can in principle be of arbitrary type (that support addition, subtraction, multiplication and division), since the general vector class
Vec<TYPE> is templated. However, the most commonly used vector types are predefined. These predefined vector types are:
vec:Basic vector type containing
cvec:Vector type containing
ivec:Vector type containing
bvec:Vector type containing
svec:Vector type containing
The general vector class is used to define the specialized classes above. The
vec class is actually a
Vec<double>. We urge you to use these predefined classes instead of
Vec<TYPE> when ever possible.
The general matrix class is called
Mat<TYPE>. These predefined matrix types are:
mat:Basic matrix type containing double
cmat:Matrix type containing
imat:Matrix type containing
bmat:Matrix type containing
smat:Matrix type containing
As with vector, the general matrix class is used to define the specialized classes above. The
mat class is thus a
Mat<double>. We urge you to use these predefined classes instead of
Mat<TYPE> whenever possible.
Vectors and matrices in
IT++ are very similar. We therefore begin to describe the vector class in detail and then briefly explain the differences regarding matrices in the next section.
A vector containing elements of type
double is defined with:
However, this will not assign a size (memory) to the vector. To assign size 10 to the vector we may use:
where the second parameter in the
set_size call (
false) determines if you want to copy the contents of the old data area into the new resized one, or not. This may be useful when down-sizing a vector, but in this case it is not. It is also equivalent to use
Observe that a declared vector (or matrix) is not cleared (the element values are undefined). To clear a vector we simply write
To fill the vector with ones we write
It is possible to retrieve the length (size) of a vector in any of the following ways:
To assign values to a vector
A comma or a space character separates the vector elements. When assigning or retrieving a specific vector element use
for element number i. Vector elements are numbered such that a(0) denotes the first element. It is also possible to use square brackets as in the C language, i.e.
Parts or a vector are retrieved by
Alternatively you can use get() methods instead of () or  operators, e.g.
If you have a vector called index_list containing indexes (ivec) you may write
If you have a
bvec called e.g. bin_list you may write
Have a look at the following example:
When you run this program you will see
Below follows a listing of the most common vector manipulation commands that are available. All examples are given for an
ivec denoted my_ivec, but of course this will work for other vector types as well.
In order to convert e.g an
ivec to a
vec we can write some thing like
to_vec(my_ivec). The following converters are available:
There are several functions that operate on vectors. Some examples are:
Examples of functions that generate different kinds of vectors are:
zeros_b. There are several more than these. Please refer to the IT++ reference manual for a description of these.
Matrices are two-dimensional arrays, and most of their functionality is similar to that of vectors. The predefined matrix types are:
Below follows some examples that are specific for matrices only:
Define a matrix of type
double with 3 rows and 4 columns
Define a matrix of type
int with 2 rows and 3 columns. A comma (,) or space is used to separate columns and a semicolon (;) is used to separate rows.
Access to rows and columns with
Set rows and columns with
The size of a matrix
Access to parts of a matrix
Copy rows and columns
Swap rows and columns
The following converters are available:
itbase library contains, among other things, the
Array class. An
Array can contain any type of data. Below is an example of an
Array containing vectors (
Random vectors and matrices are easily obtained by using these predefined functions:
randb:Generates a random bit vector or matrix
randu:Generates a random uniform vector or matrix
randi:Generates a random index vector or matrix
randray:Generates a random Rayleigh vector or matrix
randrice:Generates a random Rice vector or matrix
randexp:Generates a random Exponential vector or matrix
randn:Generates a random Gaussian vector or matrix
randn_c:Generates a random complex Gaussian vector or matrix
The following discrete valued random number generators are available. More information about these can be found in the IT++ reference manual.
The following continuous valued random number generators are available.
The following deterministic sources are available:
The following filter classes are available:
The following filter functions are available:
The following signal processing functions are available:
Real_Timer class can be used to measure execution time of a program as in the following example:
The following example saves the variable a to the file
The following example reads the variable a from the file
my_file_name.it and prints it:
*.it files can be read and written in Matlab/Octave by using the
Also available is the class
it_ifile that can only be used for reading of files.