38#include <itpp/itexports.h>
79 it_assert((dim == 1) || (dim == 2),
"sum: dimension need to be 1 or 2");
85 for (
int i = 0;
i < m.cols();
i++)
91 for (
int i = 0;
i < m.rows();
i++)
136 it_assert((dim == 1) || (dim == 2),
"sum_sqr: dimension need to be 1 or 2");
142 for (
int i = 0;
i < m.cols();
i++)
148 for (
int i = 0;
i < m.rows();
i++)
178 it_assert((dim == 1) || (dim == 2),
"cumsum: dimension need to be 1 or 2");
182 for (
int i = 0;
i < m.cols();
i++)
186 for (
int i = 0;
i < m.rows();
i++)
197 it_assert(
v.
size() >= 1,
"prod: size of vector should be at least 1");
216 it_assert((dim == 1) || (dim == 2),
"prod: dimension need to be 1 or 2");
220 it_assert((m.cols() >= 1) && (m.rows() >= 1),
221 "prod: number of columns should be at least 1");
224 for (
int i = 0;
i < m.cols();
i++)
228 it_assert((m.cols() >= 1) && (m.rows() >= 1),
229 "prod: number of rows should be at least 1");
232 for (
int i = 0;
i < m.rows();
i++)
243 "cross: vectors should be of size 3");
247 r(0) =
v1(1) *
v2(2) -
v1(2) *
v2(1);
248 r(1) =
v1(2) *
v2(0) -
v1(0) *
v2(2);
249 r(2) =
v1(0) *
v2(1) -
v1(1) *
v2(0);
261 v2.set_subvector(0,
v);
263 v2.set_subvector(
v.
size(), n - 1, T(0));
281 it_assert((rows >= m.rows()) && (cols >= m.cols()),
282 "zero_pad() cannot shrink the matrix!");
284 m2.set_submatrix(0, 0, m);
286 m2.set_submatrix(0, m.rows() - 1, m.cols(), cols - 1, T(0));
288 m2.set_submatrix(m.rows(), rows - 1, 0, cols - 1, T(0));
299 if (index >= 0 && index <
v.
size())
376 it_assert(n > 0,
"repmat(): Wrong repetition parameter");
380 for (
int j = 0;
j < n; ++
j) {
399 it_assert((m > 0) && (n > 0),
"repmat(): Wrong repetition parameters");
405 for (
int i = 0;
i < m; ++
i) {
406 for (
int j = 0;
j < n; ++
j) {
424template<
class T>
inline
447 for (
int i = 0;
i <
X.rows();
i++)
448 for (
int j = 0;
j <
X.cols();
j++)
497 if ((rows == 0) || (cols == 0))
533 it_error(
"rank(bmat): Function not implemented for GF(2) algebra");
562 for (
int i =
v.
size() - 1;
i >= 0;
i--)
565 for (
int i =
v.
size() - 1;
i >= 0;
i--)
585 for (
int i =
v.
size() - 1;
i >= 0;
i--)
599 Vec<T> t(std::min(m.rows(), m.cols()));
601 for (
int i = 0;
i < t.
size();
i++)
624 for (
int i = 0;
i < n - 1;
i++) {
628 m(n - 1, n - 1) =
main(n - 1);
650 for (
int i = 0;
i < n - 1;
i++) {
654 m(n - 1, n - 1) =
main(n - 1);
668 it_assert(m.rows() == m.cols(),
"bidiag(): Matrix must be square!");
673 for (
int i = 0;
i < n - 1;
i++) {
677 main(n - 1) = m(n - 1, n - 1);
697 for (
int i = 0;
i < n - 1;
i++) {
702 m(n - 1, n - 1) =
main(n - 1);
724 for (
int i = 0;
i < n - 1;
i++) {
729 m(n - 1, n - 1) =
main(n - 1);
743 it_assert(m.rows() == m.cols(),
"tridiag(): Matrix must be square!");
749 for (
int i = 0;
i < n - 1;
i++) {
754 main(n - 1) = m(n - 1, n - 1);
782 for (
i = 0;
i < s;
i++)
791 int i,
j, n = 0, r = m.rows(),
c = m.cols();
794 for (
i = 0;
i < r;
i++)
795 for (
j = 0;
j <
c;
j++)
805 int i,
j, n = 0, r = m.rows(),
c = m.cols();
808 for (
j = 0;
j <
c;
j++)
809 for (
i = 0;
i < r;
i++)
824 it_assert_debug(m.rows()*m.cols() == rows*cols,
"Mat<T>::reshape: Sizes must match");
827 for (
j = 0;
j < m.cols();
j++) {
828 for (
i = 0;
i < m.rows();
i++) {
851 for (
j = 0;
j < cols;
j++) {
852 for (
i = 0;
i < rows;
i++) {
int size() const
Returns the number of data elements in the array object.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
int length() const
Returns the number of data elements in the array object.
Binary arithmetic (boolean) class.
Elementary mathematical functions - header file.
T trace(const Mat< T > &m)
The trace of the matrix m, i.e. the sum of the diagonal elements.
Mat< T > tridiag(const Vec< T > &main, const Vec< T > &sup, const Vec< T > &sub)
Returns a matrix with the elements of main on the diagonal, the elements of sup on the diagonal row a...
Mat< T > diag(const Vec< T > &v, const int K=0)
Create a diagonal matrix using vector v as its diagonal.
Mat< T > bidiag(const Vec< T > &main, const Vec< T > &sup)
Returns a matrix with the elements of the input vector main on the diagonal and the elements of the i...
#define it_error(s)
Abort unconditionally.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
#define it_assert(t, s)
Abort if t is not true.
bool inv(const mat &X, mat &Y)
Inverse of real square matrix.
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
int levels2bits(int n)
Calculate the number of bits needed to represent n different values (levels).
T index_zero_pad(const Vec< T > &v, const int index)
Mat< Num_T > kron(const Mat< Num_T > &X, const Mat< Num_T > &Y)
Computes the Kronecker product of two matrices.
int size(const Vec< T > &v)
Length of vector.
T sumsum(const Mat< T > &X)
Sum of all elements in the given matrix. Fast version of sum(sum(X))
ITPP_EXPORT cmat sqrtm(const cmat &A)
Square root of the complex square matrix A.
bool is_unitary(const Mat< Num_T > &X)
Returns true if matrix X is unitary, false otherwise.
Vec< T > zero_pad(const Vec< T > &v, int n)
Zero-pad a vector to size n.
Vec< T > cumsum(const Vec< T > &v)
Cumulative sum of all elements in the vector.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
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.
int rank(const Mat< T > &m, double tol=-1.0)
Calculate the rank of matrix m.
bool is_hermitian(const Mat< Num_T > &X)
Returns true if matrix X is hermitian, false otherwise.
void transpose(const Mat< T > &m, Mat< T > &out)
Transposition of the matrix m returning the transposed matrix in out.
T sum_sqr(const Vec< T > &v)
Sum of square of the elements in a vector.
Vec< T > repmat(const Vec< T > &v, int n)
Creates a vector with n copies of the vector v.
int length(const Vec< T > &v)
Length of vector.
void hermitian_transpose(const Mat< T > &m, Mat< T > &out)
Mat< T > repmat(const Mat< T > &data, int m, int n)
Creates a matrix with m by n copies of the matrix data.
T prod(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.
bool svd(const mat &A, vec &S)
Get singular values s of a real matrix A using SVD.
Vec< T > rvectorize(const Mat< T > &m)
Row vectorize the matrix [(0,0) (0,1) ... (N-1,N-2) (N-1,N-1)].
Vec< T > cvectorize(const Mat< T > &m)
Column vectorize the matrix [(0,0) (1,0) ... (N-2,N-1) (N-1,N-1)].
Vec< T > reverse(const Vec< T > &in)
Reverse the input vector.
Mat< T > reshape(const Mat< T > &m, int rows, int cols)
Reshape the matrix into an rows*cols matrix.
Definitions of matrix inversion routines.
Logarithmic and exponenential functions - header file.
Matrix Class Definitions.
Mat< bin > bmat
bin matrix
mat to_mat(const Mat< T > &m)
Converts a Mat<T> to mat.
ITPP_EXPORT bool any(const bvec &testvec)
Returns true if any element is one and false otherwise.
const double eps
Constant eps.
ITPP_EXPORT bool all(const bvec &testvec)
Returns true if all elements are ones and false otherwise.
Definitions of Singular Value Decompositions.