itpp::Array< T > Class Template Reference
Base Module » Array, Vector and Matrix Classes

General array class. More...

`#include <itpp/base/array.h>`

## Public Member Functions

| Array (const Factory &f=DEFAULT_FACTORY)
| Default constructor. An element factory `f` can be specified.
| Array (int n, const Factory &f=DEFAULT_FACTORY)
| Create an Array of size `n`. An element factory `f` can be specified.
| Array (const Array< T > &a, const Factory &f=DEFAULT_FACTORY)
| Copy constructor. An element factory `f` can be specified.
| Array (const std::string &values, const Factory &f=DEFAULT_FACTORY)
| Create an Array from string. An element factory `f` can be specified.
| Array (const char *values, const Factory &f=DEFAULT_FACTORY)
| Create an Array from char*. An element factory `f` can be specified.
virtual | ~Array ()
| Destructor.
T & | operator() (int i)
| Get the `i` element.
const T & | operator() (int i) const
| Get the `i` element.
const Array< T > | operator() (int i1, int i2) const
| Sub-array from element `i1` to element `i2`.
const Array< T > | operator() (const Array< int > &indices) const
| Sub-array with the elements given by the integer Array.
Array< T > | left (int n) const
| Get `n` left elements of the array.
Array< T > | right (int n) const
| Get `n` right elements of the array.
Array< T > | mid (int pos, int n) const
| Get `n` elements of the array starting from `pos`.
Array< T > & | operator= (const T &e)
| Assignment operator.
Array< T > & | operator= (const Array< T > &a)
| Assignment operator.
Array< T > & | operator= (const char *values)
| Assignment operator.
int | size () const
| Returns the number of data elements in the array object.
int | length () const
| Returns the number of data elements in the array object.
void | set_size (int n, bool copy=false)
| Resizing an Array<T>.
void | set_length (int n, bool copy=false)
| Resizing an Array<T>.
T | shift_right (const T &e)
| Shift in data at position 0. Return data from the last position.
const Array< T > | shift_right (const Array< T > &a)
| Shift in array at position 0. Return data from the last position.
T | shift_left (const T &e)
| Shift in data at the last position. Return data from position 0.
const Array< T > | shift_left (const Array< T > &a)
| Shift in array at the last position. Return data from position 0.
void | swap (int i, int j)
| Swap elements i and j.
void | set_subarray (int i1, int i2, const Array< T > &a)
| Set the subarray defined by indicies i1 to i2 to Array<T> a.
void | set_subarray (int i1, int i2, const T &t)
| Set the subarray defined by indicies i1 to i2 the element value t.

## Protected Member Functions

void | alloc (int n)
| Allocate storage for an array of length `n`.
void | free ()
| Free the storage space allocated by the array.
bool | in_range (int i) const
| Check whether index `i` is in the allowed range.

## Protected Attributes

int | ndata
| The current number of elements in the Array.
T * | data
| A pointer to the data area.
const Factory & | factory
| Element factory (by default set to DEFAULT_FACTORY).

## Friends

const Array< T > | concat (const Array< T > &a1, const T &e)
| Append element `e` to the end of the Array `a`.
const Array< T > | concat (const T &e, const Array< T > &a)
| Concat element `e` to the beginning of the Array `a`.
const Array< T > | concat (const Array< T > &a1, const Array< T > &a2)
| Concat Arrays `a1` and `a2`.
const Array< T > | concat (const Array< T > &a1, const Array< T > &a2, const Array< T > &a3)
| Concat Arrays `a1`, `a2` and `a3`.

## Related Symbols

(Note that these are not member symbols.)
template<class T>
std::ostream & | operator<< (std::ostream &os, const Array< T > &a)
| Output stream for Array<T>. T must have ostream operator<< defined.
template<class T>
std::istream & | operator>> (std::istream &is, Array< T > &a)
| Input stream for Array<T>. T must have istream operator>> defined.
template<class T>
void | set_array (Array< T > &a, const char *values)
| Assign a C-style string to an Array<T>. T must have istream operator>> defined.
template<class T>
void | set_array (Array< T > &a, const std::string &str)
| Assign a string to an Array<T>. T must have istream operator>> defined.

## Detailed Description

template<class T>
class itpp::Array< T >

General array class.

Author
  Tobias Ringstrom and Adam Piatyszek

This class is a general linear array class for arbitrary types. The operations and functions are the same as for the vector `Vec` class (except for the arithmetics).

For rarely used types you will need to instantiate the class by

template class Array<type>;
itpp::Array::Array
Array(const Factory &f=DEFAULT_FACTORY)
Default constructor. An element factory f can be specified.
Definition array.h:217

The following example shows how to define an Array of vectors:

vec a = randn(10);
vec b = randn(20);
vec c = randn(30);
Array<vec> my_array(3);
my_array(0) = a;
my_array(1) = b;
my_array(2) = c;
itpp::randn
double randn(void)
Generates a random Gaussian (0,1) variable.
Definition random.h:831

For types T with istream `operator>>` defined special constructor or `operator=` or `set_array` functions (see Related Functions) can be used to assign a string literal to an Array. The string literal has the same format that is used by the istream/ostream operators:

// Initialise an array with three bit vectors
Array<bvec> B = "{[1 0 1] [0 0 1] [1 0 0 0 1]}";
// Declare an Array of Arrays of vectors
Array<Array<ivec> > an_array;
// Assign with an Array containing 2 Arrays,
// the first Array containing [1 2] and
// the second Array containing [3 4 5] and [6 7]
set_array(an_array, "{{[1 2]} {[3 4 5] [6 7]}}");
itpp::Array::set_array
void set_array(Array< T > &a, const char *values)
Assign a C-style string to an Array<T>. T must have istream operator>> defined.
Definition array.h:600

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

Definition at line 104 of file array.h.

## Constructor & Destructor Documentation

## Array() [1/5]

template<class T>

itpp::Array< T >::Array | ( | const Factory & | f = DEFAULT_FACTORY | ) |

inline explicit

Default constructor. An element factory `f` can be specified.

Definition at line 217 of file array.h.

References data, factory, and ndata.

Referenced by Array(), concat, concat, concat, concat, left(), mid(), operator()(), operator()(), operator=(), operator=(), operator=(), right(), set_subarray(), shift_left(), and shift_right().

## Array() [2/5]

template<class T>

itpp::Array< T >::Array | ( | int | n,
|  | const Factory & | f = DEFAULT_FACTORY )

inline

Create an Array of size `n`. An element factory `f` can be specified.

Definition at line 220 of file array.h.

References alloc(), data, factory, and ndata.

## Array() [3/5]

template<class T>

itpp::Array< T >::Array | ( | const Array< T > & | a,
|  | const Factory & | f = DEFAULT_FACTORY )

inline

Copy constructor. An element factory `f` can be specified.

Definition at line 226 of file array.h.

References alloc(), Array(), data, factory, and ndata.

## Array() [4/5]

template<class T>

itpp::Array< T >::Array | ( | const std::string & | values,
|  | const Factory & | f = DEFAULT_FACTORY )

inline

Create an Array from string. An element factory `f` can be specified.

Definition at line 235 of file array.h.

References data, factory, and ndata.

## Array() [5/5]

template<class T>

itpp::Array< T >::Array | ( | const char * | values,
|  | const Factory & | f = DEFAULT_FACTORY )

inline

Create an Array from char*. An element factory `f` can be specified.

Definition at line 243 of file array.h.

References data, factory, and ndata.

## ~Array()

template<class T>

itpp::Array< T >::~Array | ( |  | ) |

virtual

Destructor.

Definition at line 251 of file array.h.

References free().

## Member Function Documentation

## operator()() [1/4]

template<class T>

T & itpp::Array< T >::operator() | ( | int | i | ) |

inline

Get the `i` element.

Definition at line 290 of file array.h.

References data, in_range(), and it_assert_debug.

## operator()() [2/4]

template<class T>

const T & itpp::Array< T >::operator() | ( | int | i | ) | const

inline

Get the `i` element.

Definition at line 297 of file array.h.

References data, in_range(), and it_assert_debug.

## operator()() [3/4]

template<class T>

const Array< T > itpp::Array< T >::operator() | ( | int | i1,
|  | int | i2 ) const

inline

Sub-array from element `i1` to element `i2`.

Definition at line 304 of file array.h.

References Array(), data, in_range(), it_assert_debug, and ndata.

## operator()() [4/4]

template<class T>

const Array< T > itpp::Array< T >::operator() | ( | const Array< int > & | indices | ) | const

inline

Sub-array with the elements given by the integer Array.

Definition at line 315 of file array.h.

References Array(), data, in_range(), it_assert_debug, and size().

## left()

template<class T>

Array< T > itpp::Array< T >::left | ( | int | n | ) | const

Get `n` left elements of the array.

Definition at line 357 of file array.h.

References Array(), data, in_range(), and it_assert_debug.

Referenced by itpp::Modulator_NCD::get_symbols(), and itpp::Modulator_NRD::get_symbols().

## right()

template<class T>

Array< T > itpp::Array< T >::right | ( | int | n | ) | const

Get `n` right elements of the array.

Definition at line 367 of file array.h.

References Array(), data, in_range(), it_assert_debug, and ndata.

## mid()

template<class T>

Array< T > itpp::Array< T >::mid | ( | int | pos,
|  | int | n ) const

Get `n` elements of the array starting from `pos`.

Definition at line 377 of file array.h.

References Array(), data, it_assert_debug, and ndata.

## operator=() [1/3]

template<class T>

Array< T > & itpp::Array< T >::operator= | ( | const T & | e | ) |

inline

Assignment operator.

Definition at line 338 of file array.h.

References Array(), data, ndata, and set_size().

## operator=() [2/3]

template<class T>

Array< T > & itpp::Array< T >::operator= | ( | const Array< T > & | a | ) |

inline

Assignment operator.

Definition at line 327 of file array.h.

References Array(), data, ndata, and set_size().

## operator=() [3/3]

template<class T>

Array< T > & itpp::Array< T >::operator= | ( | const char * | values | ) |

Assignment operator.

Definition at line 348 of file array.h.

References Array().

## size()

template<class T>

int itpp::Array< T >::size | ( |  | ) | const

inline

Returns the number of data elements in the array object.

Definition at line 155 of file array.h.

References ndata.

Referenced by itpp::MOG_diag::avg_log_lhood(), itpp::MOG_generic::avg_log_lhood(), itpp::TDL_Channel::calc_frequency_response(), itpp::TDL_Channel::calc_impulse_response(), itpp::MOG_generic::check_array_uniformity(), concat, concat, concat, concat, itpp::MOG_diag::enable_c_access(), itpp::MOG_diag::enable_c_access(), itpp::MOG_generic::init(), itpp::MOG_generic::init(), itpp::MOG_generic::init(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile_old::low_level_read(), itpp::it_ifile_old::low_level_read(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile_old::low_level_read_hi(), itpp::it_ifile::low_level_read_lo(), itpp::it_ifile_old::low_level_read_lo(), itpp::it_ifile_old::low_level_read_lo(), itpp::it_file::low_level_write(), itpp::it_file::low_level_write(), itpp::it_file::low_level_write(), itpp::it_file::low_level_write(), itpp::it_file::low_level_write(), itpp::it_file_old::low_level_write(), itpp::it_file_old::low_level_write(), itpp::it_file_old::low_level_write(), itpp::it_file_old::low_level_write(), itpp::lshift_fix(), itpp::MOG_diag_EM_sup::ml(), operator()(), itpp::Array< DOPPLER_SPECTRUM >::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::operator<<(), itpp::Array< DOPPLER_SPECTRUM >::operator>>(), itpp::Circular_Buffer< T >::put(), itpp::rshift_fix(), itpp::rshift_fix(), itpp::MOG_diag_kmeans_sup::run(), itpp::MOG_generic::set_diag_covs_internal(), itpp::set_fix(), itpp::set_fix(), itpp::set_fix(), itpp::set_fix(), itpp::MOG_generic::set_full_covs_internal(), itpp::MOG_generic::set_means_internal(), set_size(), itpp::to(), and itpp::unfix().

## length()

template<class T>

int itpp::Array< T >::length | ( |  | ) | const

inline

Returns the number of data elements in the array object.

Definition at line 157 of file array.h.

References ndata.

Referenced by itpp::BCH::BCH().

## set_size()

template<class T>

void itpp::Array< T >::set_size | ( | int | n,
|  | bool | copy = false )

Resizing an Array<T>.

Definition at line 257 of file array.h.

References alloc(), data, itpp::destroy_elements(), free(), it_assert_debug, itpp::min(), ndata, and size().

Referenced by itpp::BCH::BCH(), itpp::TDL_Channel::calc_frequency_response(), itpp::TDL_Channel::calc_impulse_response(), itpp::LDPC_Parity_Unstructured::cycle_removal_MGW(), itpp::TDL_Channel::discretize(), itpp::TDL_Channel::generate(), itpp::Circular_Buffer< T >::get(), itpp::Modulator_NCD::init_soft_demodulator(), itpp::Modulator_NRD::init_soft_demodulator(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile::low_level_read(), itpp::it_ifile_old::low_level_read(), itpp::it_ifile_old::low_level_read(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile_old::low_level_read_hi(), itpp::it_ifile::low_level_read_lo(), itpp::it_ifile_old::low_level_read_lo(), itpp::it_ifile_old::low_level_read_lo(), itpp::MOG_diag_EM_sup::ml(), itpp::GFX::operator*=(), operator=(), operator=(), itpp::Array< DOPPLER_SPECTRUM >::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::operator>>(), itpp::Circular_Buffer< T >::peek(), itpp::Circular_Buffer< T >::peek(), itpp::Circular_Buffer< T >::peek_reverse(), itpp::MOG_diag_kmeans_sup::run(), itpp::MOG_generic::set_diag_covs_unity_internal(), itpp::set_fix(), itpp::set_fix(), itpp::set_fix(), itpp::set_fix(), itpp::MOG_generic::set_full_covs_unity_internal(), set_length(), itpp::ND_UPAM::set_M(), itpp::ND_UPSK::set_M(), itpp::ND_UQAM::set_M(), itpp::MOG_generic::set_means_zero_internal(), and itpp::MOG_generic::setup_covs().

## set_length()

template<class T>

void itpp::Array< T >::set_length | ( | int | n,
|  | bool | copy = false )

inline

Resizing an Array<T>.

Definition at line 161 of file array.h.

References set_size().

## shift_right() [1/2]

template<class T>

T itpp::Array< T >::shift_right | ( | const T & | e | ) |

Shift in data at position 0. Return data from the last position.

Definition at line 388 of file array.h.

References data, it_assert_debug, and ndata.

## shift_right() [2/2]

template<class T>

const Array< T > itpp::Array< T >::shift_right | ( | const Array< T > & | a | ) |

Shift in array at position 0. Return data from the last position.

Definition at line 403 of file array.h.

References Array(), data, it_assert_debug, and ndata.

## shift_left() [1/2]

template<class T>

T itpp::Array< T >::shift_left | ( | const T & | e | ) |

Shift in data at the last position. Return data from position 0.

Definition at line 419 of file array.h.

References data, and ndata.

## shift_left() [2/2]

template<class T>

const Array< T > itpp::Array< T >::shift_left | ( | const Array< T > & | a | ) |

Shift in array at the last position. Return data from position 0.

Definition at line 431 of file array.h.

References Array(), data, it_assert_debug, and ndata.

## swap()

template<class T>

void itpp::Array< T >::swap | ( | int | i,
|  | int | j )

Swap elements i and j.

Definition at line 447 of file array.h.

References data, in_range(), and it_assert_debug.

## set_subarray() [1/2]

template<class T>

void itpp::Array< T >::set_subarray | ( | int | i1,
|  | int | i2,
|  | const Array< T > & | a )

Set the subarray defined by indicies i1 to i2 to Array<T> a.

Definition at line 458 of file array.h.

References Array(), data, in_range(), it_assert_debug, and ndata.

## set_subarray() [2/2]

template<class T>

void itpp::Array< T >::set_subarray | ( | int | i1,
|  | int | i2,
|  | const T & | t )

Set the subarray defined by indicies i1 to i2 the element value t.

Definition at line 472 of file array.h.

References data, in_range(), it_assert_debug, and ndata.

## alloc()

template<class T>

void itpp::Array< T >::alloc | ( | int | n | ) |

inline protected

Allocate storage for an array of length `n`.

Definition at line 197 of file array.h.

References itpp::create_elements(), data, factory, and ndata.

Referenced by Array(), Array(), and set_size().

## free()

template<class T>

void itpp::Array< T >::free | ( |  | ) |

inline protected

Free the storage space allocated by the array.

Definition at line 210 of file array.h.

References data, itpp::destroy_elements(), and ndata.

Referenced by set_size(), and ~Array().

## in_range()

template<class T>

bool itpp::Array< T >::in_range | ( | int | i | ) | const

inline protected

Check whether index `i` is in the allowed range.

Definition at line 185 of file array.h.

References ndata.

Referenced by left(), operator()(), operator()(), operator()(), operator()(), right(), set_subarray(), set_subarray(), and swap().

## Friends And Related Symbol Documentation

## concat [1/4]

template<class T>

const Array< T > concat | ( | const Array< T > & | a1,
|  | const T & | e )

friend

Append element `e` to the end of the Array `a`.

Definition at line 486 of file array.h.

References Array(), and size().

## concat [2/4]

template<class T>

const Array< T > concat | ( | const T & | e,
|  | const Array< T > & | a )

friend

Concat element `e` to the beginning of the Array `a`.

Definition at line 498 of file array.h.

References Array(), and size().

## concat [3/4]

template<class T>

const Array< T > concat | ( | const Array< T > & | a1,
|  | const Array< T > & | a2 )

friend

Concat Arrays `a1` and `a2`.

Definition at line 511 of file array.h.

References Array(), and size().

## concat [4/4]

template<class T>

const Array< T > concat | ( | const Array< T > & | a1,
|  | const Array< T > & | a2,
|  | const Array< T > & | a3 )

friend

Concat Arrays `a1`, `a2` and `a3`.

Definition at line 524 of file array.h.

References Array(), and size().

## operator<<()

template<class T>

std::ostream & operator<< | ( | std::ostream & | os,
|  | const Array< T > & | a )

related

Output stream for Array<T>. T must have ostream operator<< defined.

Definition at line 545 of file array.h.

## operator>>()

template<class T>

std::istream & operator>> | ( | std::istream & | is,
|  | Array< T > & | a )

related

Input stream for Array<T>. T must have istream operator>> defined.

Definition at line 562 of file array.h.

## set_array() [1/2]

template<class T>

void set_array | ( | Array< T > & | a,
|  | const char * | values )

related

Assign a C-style string to an Array<T>. T must have istream operator>> defined.

Definition at line 600 of file array.h.

## set_array() [2/2]

template<class T>

void set_array | ( | Array< T > & | a,
|  | const std::string & | str )

related

Assign a string to an Array<T>. T must have istream operator>> defined.

Definition at line 612 of file array.h.

## Member Data Documentation

## ndata

template<class T>

int itpp::Array< T >::ndata

protected

The current number of elements in the Array.

Definition at line 187 of file array.h.

Referenced by alloc(), Array(), Array(), Array(), Array(), Array(), free(), in_range(), length(), mid(), operator()(), operator=(), operator=(), right(), set_size(), set_subarray(), set_subarray(), shift_left(), shift_left(), shift_right(), shift_right(), and size().

## data

template<class T>

T* itpp::Array< T >::data

protected

A pointer to the data area.

Definition at line 189 of file array.h.

Referenced by alloc(), Array(), Array(), Array(), Array(), Array(), free(), left(), mid(), operator()(), operator()(), operator()(), operator()(), operator=(), operator=(), right(), set_size(), set_subarray(), set_subarray(), shift_left(), shift_left(), shift_right(), shift_right(), and swap().

## factory

template<class T>

const Factory& itpp::Array< T >::factory

protected

Element factory (by default set to DEFAULT_FACTORY).

Definition at line 191 of file array.h.

Referenced by alloc(), Array(), Array(), Array(), Array(), and Array().

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

- itpp/base/array.h

Generated on for IT++ by Doxygen 1.15.0