Functions on Matrices
Base Module

Functions on vectors and matrices. More...

## Functions

template<class T>
int | itpp::length (const Vec< T > &v)
| Length of vector.
template<class T>
int | itpp::size (const Vec< T > &v)
| Length of vector.
template<class T>
T | itpp::sum (const Vec< T > &v)
| Sum of all elements in the vector.
template<class T>
Vec< T > | itpp::sum (const Mat< T > &m, int dim=1)
| Sum of elements in the matrix `m`, either along columns or rows.
template<class T>
T | itpp::sumsum (const Mat< T > &X)
| Sum of all elements in the given matrix. Fast version of sum(sum(X)).
template<class T>
T | itpp::sum_sqr (const Vec< T > &v)
| Sum of square of the elements in a vector.
template<class T>
Vec< T > | itpp::sum_sqr (const Mat< T > &m, int dim=1)
| Sum of the square of elements in the matrix `m`.
template<class T>
Vec< T > | itpp::cumsum (const Vec< T > &v)
| Cumulative sum of all elements in the vector.
template<class T>
Mat< T > | itpp::cumsum (const Mat< T > &m, int dim=1)
| Cumulative sum of elements in the matrix `m`.
template<class T>
T | itpp::prod (const Vec< T > &v)
| The product of all elements in the vector.
template<class T>
Vec< T > | itpp::prod (const Mat< T > &m, int dim=1)
| Product of elements in the matrix `m`.
template<class T>
Vec< T > | itpp::cross (const Vec< T > &v1, const Vec< T > &v2)
| Vector cross product. Vectors need to be of size 3.
template<class T>
Vec< T > | itpp::zero_pad (const Vec< T > &v, int n)
| Zero-pad a vector to size n.
template<class T>
Vec< T > | itpp::zero_pad (const Vec< T > &v)
| Zero-pad a vector to the nearest greater power of two.
template<class T>
Mat< T > | itpp::zero_pad (const Mat< T > &m, int rows, int cols)
| Zero-pad a matrix to size rows x cols.
template<class T>
T | itpp::index_zero_pad (const Vec< T > &v, const int index)
template<class T>
void | itpp::transpose (const Mat< T > &m, Mat< T > &out)
| Transposition of the matrix `m` returning the transposed matrix in `out`.
template<class T>
Mat< T > | itpp::transpose (const Mat< T > &m)
| Transposition of the matrix `m`.
template<class T>
void | itpp::hermitian_transpose (const Mat< T > &m, Mat< T > &out)
template<class T>
Mat< T > | itpp::hermitian_transpose (const Mat< T > &m)
| Hermitian transpose (complex conjugate transpose) of the matrix `m`.
template<class Num_T>
bool | itpp::is_hermitian (const Mat< Num_T > &X)
| Returns true if matrix `X` is hermitian, false otherwise.
template<class Num_T>
bool | itpp::is_unitary (const Mat< Num_T > &X)
| Returns true if matrix `X` is unitary, false otherwise.
template<class Num_T>
Mat< Num_T > | itpp::kron (const Mat< Num_T > &X, const Mat< Num_T > &Y)
| Computes the Kronecker product of two matrices.
ITPP_EXPORT cmat | itpp::sqrtm (const cmat &A)
| Square root of the complex square matrix `A`.
ITPP_EXPORT cmat | itpp::sqrtm (const mat &A)
| Square root of the real square matrix `A`.
template<class T>
int | itpp::rank (const Mat< T > &m, double tol=-1.0)
| Calculate the rank of matrix `m`.
template<>
int | itpp::rank (const imat &m, double tol)
| Specialisation of rank() function.
template<>
int | itpp::rank (const smat &m, double tol)
| Specialisation of rank() function.
template<>
int | itpp::rank (const bmat &, double)
| Specialisation of rank() function.
template<class T>
Vec< T > | repmat (const Vec< T > &v, int n)
| Creates a vector with `n` copies of the vector `v`.
template<class T>
Mat< T > | repmat (const Mat< T > &data, int m, int n)
| Creates a matrix with `m` by `n` copies of the matrix `data`.
template<class T>
Mat< T > | repmat (const Vec< T > &v, int m, int n, bool transpose=false)
| Returns a matrix with `m` by `n` copies of the vector `data`.

## Detailed Description

Functions on vectors and matrices.

## Function Documentation

## length()

template<class T>

int itpp::length | ( | const Vec< T > & | v | ) |

Length of vector.

Definition at line 51 of file matfunc.h.

References itpp::Vec< Num_T >::length().

Referenced by itpp::BCH::BCH(), itpp::LDPC_Parity::check_connectivity(), itpp::LDPC_Parity::check_for_cycles(), itpp::LDPC_Parity_Unstructured::compute_CR(), itpp::LDPC_Generator_Systematic::construct(), itpp::LDPC_Parity_Unstructured::cycle_removal_MGW(), dec2bin(), itpp::Hamming_Code::decode(), itpp::LDPC_Code::decoder_parameterization(), itpp::OFDM::demodulate(), itpp::Modulator_NCD::demodulate_soft_bits(), itpp::Modulator_NRD::demodulate_soft_bits(), itpp::LDPC_Parity::display_stats(), itpp::Hamming_Code::encode(), itpp::Rec_Syst_Conv_Code::encode(), itpp::Rec_Syst_Conv_Code::encode_tail(), fir1(), itpp::LDPC_Parity_Unstructured::generate_random_H(), itpp::Multilateration::get_crlb(), itpp::GF2mat::GF2mat(), itpp::GF2mat::GF2mat(), itpp::Rec_Syst_Conv_Code::log_decode(), itpp::Rec_Syst_Conv_Code::log_decode_n2(), itpp::OFDM::modulate(), itpp::Modulator_NCD::modulate_bits(), itpp::Modulator_NRD::modulate_bits(), itpp::BSC::operator()(), itpp::GF2mat::operator*, itpp::GF2mat::permute_cols(), itpp::GF2mat::permute_rows(), itpp::Modulator_ND::probabilities(), itpp::Convolutional_Code::reverse_int(), itpp::GF2mat::set_col(), itpp::ND_UPAM::set_M(), itpp::ND_UPSK::set_M(), itpp::ND_UQAM::set_M(), itpp::GF2mat::set_row(), itpp::Convolutional_Code::set_truncation_length(), itpp::ND_UPAM::sphere_decoding(), itpp::GF2mat::T_fact_update_addcol(), itpp::LLR_calc_unit::to_double(), itpp::LLR_calc_unit::to_qllr(), waterfilling(), itpp::Convolutional_Code::weight_int(), and zigzag_space().

## size()

template<class T>

int itpp::size | ( | const Vec< T > & | v | ) |

Length of vector.

Definition at line 55 of file matfunc.h.

References itpp::Vec< Num_T >::length().

Referenced by Ccvec2mxArray(), itpp::MOG_generic::check_array_uniformity(), Civec2mxArray(), Csvec2mxArray(), Cvec2mxArray(), eye(), eye(), eye_b(), eye_c(), eye_i(), hadamard(), impulse(), 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::low_level_read(), 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::low_level_read_hi(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile::low_level_read_hi(), itpp::it_ifile::low_level_read_lo(), itpp::it_ifile::low_level_read_lo(), itpp::it_ifile::low_level_read_lo(), itpp::it_ifile::low_level_read_lo(), itpp::it_file_old::low_level_write(), mxArray2bin(), mxArray2bvec(), mxArray2Ccvec(), mxArray2Civec(), mxArray2Csvec(), mxArray2Cvec(), mxArray2cvec(), mxArray2double(), mxArray2double_complex(), mxArray2int(), mxArray2ivec(), mxArray2short(), mxArray2svec(), mxArray2vec(), ones(), ones_b(), ones_c(), ones_i(), operator<<(), operator<<(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), operator>>(), orth(), itpp::it_file::pack(), pcamat(), randb(), randb(), randexp(), randi(), randn(), randn(), randn_c(), randn_c(), randray(), randrice(), randu(), randu(), RNG_get_state(), RNG_set_state(), itpp::Bernoulli_RNG::sample_vector(), itpp::Complex_Normal_RNG::sample_vector(), itpp::Normal_RNG::sample_vector(), itpp::Uniform_RNG::sample_vector(), selcol(), itpp::MOG_generic::set_diag_covs_internal(), itpp::MOG_generic::set_means_internal(), itpp::GF::set_size(), itpp::it_file::write_data_header(), itpp::it_file::write_data_header(), itpp::it_file_old::write_data_header(), itpp::it_file_old::write_data_header(), zeros(), zeros_b(), zeros_c(), and zeros_i().

## sum() [1/2]

template<class T>

T itpp::sum | ( | const Vec< T > & | v | ) |

Sum of all elements in the vector.

Definition at line 59 of file matfunc.h.

References itpp::Vec< Num_T >::length().

Referenced by itpp::Channel_Specification::calc_mean_excess_delay(), itpp::Channel_Specification::calc_rms_delay_spread(), cerf_rybicki(), cerf_series(), itpp::LDPC_Parity_Unstructured::compute_CR(), itpp::Modulator_NCD::demodulate_soft_bits(), itpp::Modulator_NCD::demodulate_soft_bits(), itpp::Modulator_NRD::demodulate_soft_bits(), itpp::Modulator_NRD::demodulate_soft_bits(), itpp::LDPC_Parity::display_stats(), itpp::BERC::estimate_delay(), extrinsic_mutual_info(), fir1(), fpica(), itpp::LDPC_Parity_Regular::generate(), itpp::Rice_Fading_Generator::generate(), itpp::LDPC_Parity_Unstructured::generate_random_H(), itpp::Multilateration::get_crlb(), house(), itpp::Modulator_NCD::init_soft_demodulator(), itpp::Modulator_NRD::init_soft_demodulator(), itpp::MOG_diag::lhood_internal(), itpp::MOG_generic::lhood_internal(), itpp::MOG_diag::log_lhood_internal(), itpp::MOG_generic::log_lhood_internal(), mean(), mean(), mean(), mean(), mean(), mean(), mean(), mean(), itpp::MOG_diag_EM_sup::ml_update_params(), itpp::Modulator_NCD::modulate_bits(), itpp::Modulator_NRD::modulate_bits(), norm(), norm(), itpp::Sparse_Vec< T >::operator*, itpp::Sparse_Vec< T >::operator*, itpp::Sparse_Vec< T >::operator*, quad(), itpp::MOG_generic::setup_weights(), itpp::ND_UPAM::sphere_decoding(), itpp::Sparse_Vec< T >::sqr(), sum(), sumcol(), trace(), variance(), variance(), and xcorr().

## sum() [2/2]

template<class T>

Vec< T > itpp::sum | ( | const Mat< T > & | m,
|  | int | dim = 1 )

Sum of elements in the matrix `m`, either along columns or rows.

sum(m) = sum(m, 1) returns a vector where the elements are sum over each column, whereas sum(m, 2) returns a vector where the elements are sum over each row.

Definition at line 77 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::get_col(), itpp::Mat< Num_T >::get_row(), it_assert, itpp::Mat< Num_T >::rows(), itpp::Vec< Num_T >::set_size(), and sum().

## sumsum()

template<class T>

T itpp::sumsum | ( | const Mat< T > & | X | ) |

Sum of all elements in the given matrix. Fast version of sum(sum(X)).

Definition at line 101 of file matfunc.h.

References itpp::Mat< Num_T >::_data(), and itpp::Mat< Num_T >::_datasize().

## sum_sqr() [1/2]

template<class T>

T itpp::sum_sqr | ( | const Vec< T > & | v | ) |

Sum of square of the elements in a vector.

Definition at line 116 of file matfunc.h.

References itpp::Vec< Num_T >::length().

Referenced by itpp::TDL_Channel::calc_mean_excess_delay(), itpp::TDL_Channel::calc_rms_delay_spread(), itpp::Multilateration::get_crlb(), and sum_sqr().

## sum_sqr() [2/2]

template<class T>

Vec< T > itpp::sum_sqr | ( | const Mat< T > & | m,
|  | int | dim = 1 )

Sum of the square of elements in the matrix `m`.

sum(m) = sum(m, 1) returns a vector where the elements are sum squared over each column, whereas sum(m, 2) returns a vector where the elements are sum squared over each row

Definition at line 134 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::get_col(), itpp::Mat< Num_T >::get_row(), it_assert, itpp::Mat< Num_T >::rows(), itpp::Vec< Num_T >::set_size(), and sum_sqr().

## cumsum() [1/2]

template<class T>

Vec< T > itpp::cumsum | ( | const Vec< T > & | v | ) |

Cumulative sum of all elements in the vector.

Definition at line 157 of file matfunc.h.

References itpp::Vec< Num_T >::size().

Referenced by cumsum(), itpp::Histogram< Num_T >::get_cdf(), itpp::Modulator_NCD::init_soft_demodulator(), and itpp::Modulator_NRD::init_soft_demodulator().

## cumsum() [2/2]

template<class T>

Mat< T > itpp::cumsum | ( | const Mat< T > & | m,
|  | int | dim = 1 )

Cumulative sum of elements in the matrix `m`.

cumsum(m) = cumsum(m, 1) returns a matrix where the elements are sums over each column, whereas cumsum(m, 2) returns a matrix where the elements are sums over each row

Definition at line 176 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), cumsum(), itpp::Mat< Num_T >::get_col(), itpp::Mat< Num_T >::get_row(), it_assert, itpp::Mat< Num_T >::rows(), itpp::Mat< Num_T >::set_col(), and itpp::Mat< Num_T >::set_row().

## prod() [1/2]

template<class T>

T itpp::prod | ( | const Vec< T > & | v | ) |

The product of all elements in the vector.

Definition at line 195 of file matfunc.h.

References it_assert, and itpp::Vec< Num_T >::size().

Referenced by fact(), geometric_mean(), geometric_mean(), itpp::Modulator_NCD::init_soft_demodulator(), itpp::Modulator_NRD::init_soft_demodulator(), and prod().

## prod() [2/2]

template<class T>

Vec< T > itpp::prod | ( | const Mat< T > & | m,
|  | int | dim = 1 )

Product of elements in the matrix `m`.

prod(m) = prod(m, 1) returns a vector where the elements are products over each column, whereas prod(m, 2) returns a vector where the elements are products over each row

Definition at line 214 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::get_col(), itpp::Mat< Num_T >::get_row(), it_assert, prod(), itpp::Mat< Num_T >::rows(), and itpp::Vec< Num_T >::set_size().

## cross()

template<class T>

Vec< T > itpp::cross | ( | const Vec< T > & | v1,
|  | const Vec< T > & | v2 )

Vector cross product. Vectors need to be of size 3.

Definition at line 240 of file matfunc.h.

References it_assert, and itpp::Vec< Num_T >::size().

## zero_pad() [1/3]

template<class T>

Vec< T > itpp::zero_pad | ( | const Vec< T > & | v,
|  | int | n )

Zero-pad a vector to size n.

Definition at line 257 of file matfunc.h.

References it_assert, itpp::Vec< Num_T >::set_subvector(), and itpp::Vec< Num_T >::size().

Referenced by freqz(), freqz(), spectrum(), spectrum(), xcorr(), and zero_pad().

## zero_pad() [2/3]

template<class T>

Vec< T > itpp::zero_pad | ( | const Vec< T > & | v | ) |

Zero-pad a vector to the nearest greater power of two.

Definition at line 270 of file matfunc.h.

References levels2bits(), pow2i(), itpp::Vec< Num_T >::size(), and zero_pad().

## zero_pad() [3/3]

template<class T>

Mat< T > itpp::zero_pad | ( | const Mat< T > & | m,
|  | int | rows,
|  | int | cols )

Zero-pad a matrix to size rows x cols.

Definition at line 279 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), it_assert, itpp::Mat< Num_T >::rows(), and itpp::Mat< Num_T >::set_submatrix().

## index_zero_pad()

template<class T>

T itpp::index_zero_pad | ( | const Vec< T > & | v,
|  | const int | index )

Return zero if indexing outside the vector `v` otherwise return the element `index`

Definition at line 297 of file matfunc.h.

References itpp::Vec< Num_T >::size().

Referenced by xcorr_old().

## transpose() [1/2]

template<class T>

void itpp::transpose | ( | const Mat< T > & | m,
|  | Mat< T > & | out )

Transposition of the matrix `m` returning the transposed matrix in `out`.

Definition at line 308 of file matfunc.h.

References itpp::Mat< Num_T >::T().

Referenced by any(), itpp::LDPC_Generator_Systematic::construct(), dht2(), dwht2(), fpica(), itpp::GF2mat_sparse_alist::from_sparse(), itpp::LDPC_Parity::get_H(), mpower(), pcamat(), itpp::GF2mat_sparse_alist::to_sparse(), and itpp::Sparse_Mat< T >::transpose().

## transpose() [2/2]

template<class T>

Mat< T > itpp::transpose | ( | const Mat< T > & | m | ) |

Transposition of the matrix `m`.

Definition at line 312 of file matfunc.h.

References itpp::Mat< Num_T >::T().

## hermitian_transpose() [1/2]

template<class T>

void itpp::hermitian_transpose | ( | const Mat< T > & | m,
|  | Mat< T > & | out )

Hermitian transpose (complex conjugate transpose) of the matrix `m` returning the transposed matrix in `out`

Definition at line 318 of file matfunc.h.

References itpp::Mat< Num_T >::H().

## hermitian_transpose() [2/2]

template<class T>

Mat< T > itpp::hermitian_transpose | ( | const Mat< T > & | m | ) |

Hermitian transpose (complex conjugate transpose) of the matrix `m`.

Definition at line 322 of file matfunc.h.

References itpp::Mat< Num_T >::H().

## is_hermitian()

template<class Num_T>

bool itpp::is_hermitian | ( | const Mat< Num_T > & | X | ) |

Returns true if matrix `X` is hermitian, false otherwise.

Author
  M. Szalay

A square matrix is hermitian if

Definition at line 336 of file matfunc.h.

References itpp::Mat< Num_T >::H().

## is_unitary()

template<class Num_T>

bool itpp::is_unitary | ( | const Mat< Num_T > & | X | ) |

Returns true if matrix `X` is unitary, false otherwise.

Author
  M. Szalay

A square matrix is unitary if

Definition at line 355 of file matfunc.h.

References itpp::Mat< Num_T >::H(), and inv().

## kron()

template<class Num_T>

Mat< Num_T > itpp::kron | ( | const Mat< Num_T > & | X,
|  | const Mat< Num_T > & | Y )

Computes the Kronecker product of two matrices.

K = kron(X, Y) returns the Kronecker tensor product of `X` and `Y`. The result is a large array formed by taking all possible products between the elements of `X` and those of `Y`. If `X` is (m x n) and `Y` is (p x q), then kron(X, Y) is (m*p x n*q).

Author
  Adam Piatyszek

Definition at line 443 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::rows(), and itpp::Mat< Num_T >::set_submatrix().

## sqrtm() [1/2]

ITPP_EXPORT cmat itpp::sqrtm | ( | const cmat & | A | ) |

Square root of the complex square matrix `A`.

This function computes the matrix square root of the complex square matrix `A`. The implementation is based on the Matlab/Octave `sqrtm()` function.

Ref: N. J. Higham, "Numerical Analysis Report No. 336", Manchester Centre for Computational Mathematics, Manchester, England, January 1999

Author
  Adam Piatyszek

## sqrtm() [2/2]

ITPP_EXPORT cmat itpp::sqrtm | ( | const mat & | A | ) |

Square root of the real square matrix `A`.

This function computes the matrix square root of the real square matrix `A`. Please note that the returned matrix is complex. The implementation is based on the Matlab/Octave `sqrtm()` function.

Ref: N. J. Higham, "Numerical Analysis Report No. 336", Manchester Centre for Computational Mathematics, Manchester, England, January 1999

Author
  Adam Piatyszek

## rank() [1/4]

template<class T>

int itpp::rank | ( | const Mat< T > & | m,
|  | double | tol = -1.0 )

Calculate the rank of matrix `m`.

Author
  Martin Senst

Parameters

  m | Input matrix
  tol | Tolerance used for comparing the singular values with zero. If negative, it is automatically determined.

Definition at line 493 of file matfunc.h.

References itpp::Mat< Num_T >::cols(), eps, itpp::Mat< Num_T >::rows(), and svd().

Referenced by itpp::GF2mat::inverse(), rank(), rank(), itpp::GF2mat::row_rank(), and itpp::GF2mat::T_fact_update_bitflip().

## rank() [2/4]

template<>

int itpp::rank | ( | const imat & | m,
|  | double | tol )

inline

Specialisation of rank() function.

Definition at line 517 of file matfunc.h.

References rank(), and to_mat().

## rank() [3/4]

template<>

int itpp::rank | ( | const smat & | m,
|  | double | tol )

inline

Specialisation of rank() function.

Definition at line 524 of file matfunc.h.

References rank(), and to_mat().

## rank() [4/4]

template<>

int itpp::rank | ( | const bmat & | ,
|  | double | )

inline

Specialisation of rank() function.

Definition at line 531 of file matfunc.h.

References it_error.

## repmat() [1/3]

template<class T>

Vec< T > repmat | ( | const Vec< T > & | v,
|  | int | n )

related

Creates a vector with `n` copies of the vector `v`.

Author
  Martin Senst

Parameters

  v | Vector to be repeated
  n | Number of times to repeat `v`

Definition at line 374 of file matfunc.h.

## repmat() [2/3]

template<class T>

Mat< T > repmat | ( | const Mat< T > & | data,
|  | int | m,
|  | int | n )

related

Creates a matrix with `m` by `n` copies of the matrix `data`.

Author
  Mark Dobossy

Parameters

  data | Matrix to be repeated
  m | Number of times to repeat data vertically
  n | Number of times to repeat data horizontally

Definition at line 397 of file matfunc.h.

## repmat() [3/3]

template<class T>

Mat< T > repmat | ( | const Vec< T > & | v,
|  | int | m,
|  | int | n,
|  | bool | transpose = false )

related

Returns a matrix with `m` by `n` copies of the vector `data`.

Author
  Adam Piatyszek

Parameters

  v | Vector to be repeated
  m | Number of times to repeat data vertically
  n | Number of times to repeat data horizontally
  transpose | Specifies the input vector orientation (column vector by default)

Definition at line 425 of file matfunc.h.

Generated on for IT++ by Doxygen 1.15.0