35#include <itpp/itexports.h>
41template<
class Num_T>
class Vec;
43template<
class Num_T>
class Mat;
56Mat<Num_T>
operator+(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
59Mat<Num_T>
operator+(
const Mat<Num_T> &m, Num_T t);
62Mat<Num_T>
operator+(Num_T t,
const Mat<Num_T> &m);
66Mat<Num_T>
operator-(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
69Mat<Num_T>
operator-(
const Mat<Num_T> &m, Num_T t);
72Mat<Num_T>
operator-(Num_T t,
const Mat<Num_T> &m);
79Mat<Num_T>
operator*(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
82Vec<Num_T>
operator*(
const Mat<Num_T> &m,
const Vec<Num_T> &v);
85Mat<Num_T>
operator*(
const Mat<Num_T> &m, Num_T t);
88Mat<Num_T>
operator*(Num_T t,
const Mat<Num_T> &m);
92Mat<Num_T>
elem_mult(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
100 const Mat<Num_T> &m3, Mat<Num_T> &out);
103void elem_mult_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
104 const Mat<Num_T> &m3,
const Mat<Num_T> &m4,
111Num_T
elem_mult_sum(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
115Mat<Num_T>
operator/(
const Mat<Num_T> &m, Num_T t);
118Mat<Num_T>
operator/(Num_T t,
const Mat<Num_T> &m);
122Mat<Num_T>
elem_div(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
125void elem_div_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
129Num_T
elem_div_sum(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
228 Mat(
const Num_T *c_array,
int rows,
int cols,
bool row_major =
true,
249 void set(
const std::string &str);
251 void set(
const char *str);
262 const Num_T &
get(
int r,
int c)
const;
264 const Num_T &
get(
int i)
const;
266 void set(
int r,
int c, Num_T t);
463 bool in_range(
int r,
int c)
const {
467 bool row_in_range(
int r)
const {
return ((r >= 0) && (r <
no_rows)); }
469 bool col_in_range(
int c)
const {
return ((c >= 0) && (c <
no_cols)); }
471 bool in_range(
int i)
const {
return ((i >= 0) && (i <
datasize)); }
526template <
class Num_T>
540template <
class Num_T>
547template<
class Num_T>
inline
550 if ((rows > 0) && (cols > 0)) {
551 datasize = rows * cols;
564template<
class Num_T>
inline
574template<
class Num_T>
inline
576 datasize(0), no_rows(0), no_cols(0), data(0), factory(f) {}
578template<
class Num_T>
inline
580 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
586template<
class Num_T>
inline
588 datasize(0), no_rows(0), no_cols(0), data(0), factory(m.factory)
594template<
class Num_T>
inline
596 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
602template<
class Num_T>
inline
604 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
611template<
class Num_T>
inline
613 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
618template<
class Num_T>
inline
620 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
622 set(std::string(str));
628 datasize(0), no_rows(0), no_cols(0), data(0), factory(f)
634 for (
int i = 0; i <
rows; i++)
635 for (
int j = 0; j <
cols; j++)
639template<
class Num_T>
inline
650 "Mat<>::set_size(): Wrong size");
652 if ((no_rows == rows) && (no_cols == cols))
655 if ((rows == 0) || (cols == 0)) {
664 int old_datasize = datasize;
665 int old_rows = no_rows;
667 int min_r = (no_rows < rows) ? no_rows : rows;
668 int min_c = (no_cols < cols) ? no_cols : cols;
672 for (
int i = 0; i < min_c; ++i) {
673 copy_vector(min_r, &tmp[i*old_rows], &data[i*no_rows]);
676 for (
int i = min_r; i < rows; ++i)
677 for (
int j = 0; j < cols; ++j)
678 data[i+j*rows] = Num_T(0);
679 for (
int j = min_c; j < cols; ++j)
680 for (
int i = 0; i < min_r; ++i)
681 data[i+j*rows] = Num_T(0);
686 else if (datasize == rows * cols) {
697template<
class Num_T>
inline
700 for (
int i = 0; i < datasize; i++)
704template<
class Num_T>
inline
707 for (
int i = 0; i < datasize; i++)
711template<
class Num_T>
inline
715 "Mat<>::operator(): Indexing out of range");
716 return data[r+c*no_rows];
719template<
class Num_T>
inline
723 "Mat<>::operator(): Indexing out of range");
724 return data[r+c*no_rows];
727template<
class Num_T>
inline
734template<
class Num_T>
inline
741template<
class Num_T>
inline
744 return (*
this)(r, c);
747template<
class Num_T>
inline
753template<
class Num_T>
inline
756 it_assert_debug(in_range(r, c),
"Mat<>::set(): Indexing out of range");
757 data[r+c*no_rows] = t;
773 std::string::size_type beg = 0;
774 std::string::size_type end = 0;
775 while (end != std::string::npos) {
777 end = str.find(
';', beg);
780 int v_size = v.
size();
784 if ((end != std::string::npos) || (v_size > 0)) {
787 set_size(maxrows, v_size,
true);
792 if ((rows == maxrows) || (v_size != no_cols)) {
794 if (rows == maxrows) {
798 if (v_size > no_cols) {
799 set_size(maxrows, v_size,
true);
802 set_size(maxrows, no_cols,
true);
816 set_size(rows, no_cols,
true);
819template<
class Num_T>
inline
822 set(std::string(str));
825template<
class Num_T>
inline
828 if (r1 == -1) r1 = no_rows - 1;
829 if (r2 == -1) r2 = no_rows - 1;
830 if (c1 == -1) c1 = no_cols - 1;
831 if (c2 == -1) c2 = no_cols - 1;
834 (c1 >= 0) && (c1 <= c2) && (c2 < no_cols),
835 "Mat<>::operator()(r1, r2, c1, c2): Wrong indexing");
839 for (
int i = 0;i < s.
no_cols;i++)
845template<
class Num_T>
inline
848 return (*
this)(r1, r2, c1, c2);
851template<
class Num_T>
inline
854 it_assert_debug(row_in_range(r),
"Mat<>::get_row(): Index out of range");
857 copy_vector(no_cols, data + r, no_rows, a.
_data(), 1);
865 "Mat<>::get_rows(): Wrong indexing");
868 for (
int i = 0; i < m.
rows(); i++)
869 copy_vector(no_cols, data + i + r1, no_rows, m.
data + i, m.
no_rows);
879 for (
int i = 0;i < indexlist.
size();i++) {
881 "Mat<>::get_rows(indexlist): Indexing out of range");
882 copy_vector(no_cols, data + indexlist(i), no_rows, m.
data + i, m.
no_rows);
888template<
class Num_T>
inline
891 it_assert_debug(col_in_range(c),
"Mat<>::get_col(): Index out of range");
894 copy_vector(no_rows, data + c*no_rows, a.
_data());
903 "Mat<>::get_cols(): Wrong indexing");
906 for (
int i = 0; i < m.
cols(); i++)
907 copy_vector(no_rows, data + (i + c1)*no_rows, m.
data + i*m.
no_rows);
917 for (
int i = 0; i < indexlist.
size(); i++) {
919 "Mat<>::get_cols(indexlist): Indexing out of range");
920 copy_vector(no_rows, data + indexlist(i)*no_rows, m.
data + i*m.
no_rows);
926template<
class Num_T>
inline
929 it_assert_debug(row_in_range(r),
"Mat<>::set_row(): Index out of range");
931 "Mat<>::set_row(): Wrong size of input vector");
932 copy_vector(v.
size(), v.
_data(), 1, data + r, no_rows);
935template<
class Num_T>
inline
938 it_assert_debug(col_in_range(c),
"Mat<>::set_col(): Index out of range");
940 "Mat<>::set_col(): Wrong size of input vector");
941 copy_vector(v.
size(), v.
_data(), data + c*no_rows);
948 it_assert_debug(row_in_range(r),
"Mat<>::set_rows(): Index out of range");
950 "Mat<>::set_rows(): Column sizes do not match");
952 "Mat<>::set_rows(): Not enough rows");
954 for (
int i = 0; i < m.
rows(); ++i) {
955 copy_vector(no_cols, m.
data + i, m.
no_rows, data + i + r, no_rows);
962 it_assert_debug(col_in_range(c),
"Mat<>::set_cols(): Index out of range");
964 "Mat<>::set_cols(): Row sizes do not match");
966 "Mat<>::set_cols(): Not enough colums");
968 for (
int i = 0; i < m.
cols(); ++i) {
969 copy_vector(no_rows, m.
data + i*no_rows, data + (i + c)*no_rows);
974template<
class Num_T>
inline
978 "Mat<>::copy_row(): Indexing out of range");
982 copy_vector(no_cols, data + from, no_rows, data +
to, no_rows);
985template<
class Num_T>
inline
989 "Mat<>::copy_col(): Indexing out of range");
993 copy_vector(no_rows, data + from*no_rows, data +
to*no_rows);
996template<
class Num_T>
inline
1000 "Mat<>::swap_rows(): Indexing out of range");
1004 swap_vector(no_cols, data + r1, no_rows, data + r2, no_rows);
1007template<
class Num_T>
inline
1011 "Mat<>::swap_cols(): Indexing out of range");
1015 swap_vector(no_rows, data + c1*no_rows, data + c2*no_rows);
1018template<
class Num_T>
1021 it_warning(
"Mat<>::set_submatrix(r1, r2, r3, r4, m): This function is "
1022 "deprecated and might be removed from future IT++ releases. "
1023 "Please use Mat<>::set_submatrix(r, c, m) function instead.");
1024 set_submatrix(r1, c1, m);
1027template<
class Num_T>
inline
1031 (c >= 0) && (c + m.
no_cols <= no_cols),
1032 "Mat<>::set_submatrix(): Indexing out of range "
1033 "or wrong input matrix");
1034 for (
int i = 0; i < m.
no_cols; i++)
1040template<
class Num_T>
inline
1043 if (r1 == -1) r1 = no_rows - 1;
1044 if (r2 == -1) r2 = no_rows - 1;
1045 if (c1 == -1) c1 = no_cols - 1;
1046 if (c2 == -1) c2 = no_cols - 1;
1048 (c1 >= 0) && (c1 <= c2) && (c2 < no_cols),
1049 "Mat<>::set_submatrix(): Wrong indexing");
1050 for (
int i = c1; i <= c2; i++) {
1051 int pos = i * no_rows + r1;
1052 for (
int j = r1; j <= r2; j++)
1057template<
class Num_T>
1060 it_assert_debug(row_in_range(r),
"Mat<>::del_row(): Index out of range");
1062 set_size(no_rows - 1, no_cols,
false);
1063 for (
int i = 0 ; i < r ; i++) {
1064 copy_vector(no_cols, &Temp.
data[i], no_rows + 1, &data[i], no_rows);
1066 for (
int i = r ; i < no_rows ; i++) {
1067 copy_vector(no_cols, &Temp.
data[i+1], no_rows + 1, &data[i], no_rows);
1072template<
class Num_T>
1076 "Mat<>::del_rows(): Indexing out of range");
1078 int no_del_rows = r2 - r1 + 1;
1079 set_size(no_rows - no_del_rows, no_cols,
false);
1080 for (
int i = 0; i < r1 ; ++i) {
1081 copy_vector(no_cols, &Temp.
data[i], Temp.
no_rows, &data[i], no_rows);
1083 for (
int i = r2 + 1; i < Temp.
no_rows; ++i) {
1084 copy_vector(no_cols, &Temp.
data[i], Temp.
no_rows, &data[i-no_del_rows],
1089template<
class Num_T>
1092 it_assert_debug(col_in_range(c),
"Mat<>::del_col(): Index out of range");
1095 set_size(no_rows, no_cols - 1,
false);
1096 copy_vector(c*no_rows, Temp.
data, data);
1097 copy_vector((no_cols - c)*no_rows, &Temp.
data[(c+1)*no_rows], &data[c*no_rows]);
1100template<
class Num_T>
1104 "Mat<>::del_cols(): Indexing out of range");
1106 int n_deleted_cols = c2 - c1 + 1;
1107 set_size(no_rows, no_cols - n_deleted_cols,
false);
1108 copy_vector(c1*no_rows, Temp.
data, data);
1109 copy_vector((no_cols - c1)*no_rows, &Temp.
data[(c2+1)*no_rows], &data[c1*no_rows]);
1112template<
class Num_T>
1116 "Mat<>::ins_row(): Index out of range");
1118 "Mat<>::ins_row(): Wrong size of the input vector");
1125 set_size(no_rows + 1, no_cols,
false);
1127 for (
int i = 0 ; i < r ; i++) {
1128 copy_vector(no_cols, &Temp.
data[i], no_rows - 1, &data[i], no_rows);
1130 copy_vector(no_cols, v.
_data(), 1, &data[r], no_rows);
1131 for (
int i = r + 1 ; i < no_rows ; i++) {
1132 copy_vector(no_cols, &Temp.
data[i-1], no_rows - 1, &data[i], no_rows);
1136template<
class Num_T>
1140 "Mat<>::ins_col(): Index out of range");
1142 "Mat<>::ins_col(): Wrong size of the input vector");
1149 set_size(no_rows, no_cols + 1,
false);
1151 copy_vector(c*no_rows, Temp.
data, data);
1152 copy_vector(no_rows, v.
_data(), &data[c*no_rows]);
1153 copy_vector((no_cols - c - 1)*no_rows, &Temp.
data[c*no_rows], &data[(c+1)*no_rows]);
1156template<
class Num_T>
inline
1159 ins_row(no_rows, v);
1162template<
class Num_T>
inline
1165 ins_col(no_cols, v);
1168template<
class Num_T>
1172 for (
int i = 0; i < no_rows; ++i) {
1173 copy_vector(no_cols, &data[i], no_rows, &temp.
data[i * no_cols], 1);
1178template<
class Num_T>
1182 for (
int i = 0; i < no_rows; ++i) {
1183 copy_vector(no_cols, &data[i], no_rows, &temp.
data[i * no_cols], 1);
1190ITPP_EXPORT cmat cmat::hermitian_transpose()
const;
1193template<
class Num_T>
1202 "Mat<>::concat_horizontal(): Wrong sizes");
1205 for (
int i = 0; i < m1.
no_cols; ++i) {
1206 copy_vector(no_rows, &m1.
data[i * no_rows], &temp.
data[i * no_rows]);
1208 for (
int i = 0; i < m2.
no_cols; ++i) {
1209 copy_vector(no_rows, &m2.
data[i * no_rows], &temp.
data[(m1.
no_cols + i)
1215template<
class Num_T>
1224 "Mat<>::concat_vertical(): Wrong sizes");
1227 for (
int i = 0; i < no_cols; ++i) {
1236template<
class Num_T>
inline
1239 for (
int i = 0; i < datasize; i++)
1244template<
class Num_T>
inline
1255template<
class Num_T>
inline
1259 || ((no_cols == 1) && (no_rows == v.
size())),
1260 "Mat<>::operator=(): Wrong size of the input vector");
1261 set_size(v.
size(), 1,
false);
1266template<
class Num_T>
inline
1273template<
class Num_T>
inline
1276 set(std::string(str));
1282template<
class Num_T>
1288 int i, j, m_pos = 0, pos = 0;
1290 for (i = 0; i < no_cols; i++) {
1291 for (j = 0; j < no_rows; j++)
1292 data[pos+j] += m.
data[m_pos+j];
1300template<
class Num_T>
inline
1303 for (
int i = 0; i < datasize; i++)
1308template<
class Num_T>
1312 int i, j, m1_pos = 0, m2_pos = 0, r_pos = 0;
1315 "Mat<>::operator+(): Wrong sizes");
1317 for (i = 0; i < r.
no_cols; i++) {
1318 for (j = 0; j < r.
no_rows; j++)
1319 r.
data[r_pos+j] = m1.
data[m1_pos+j] + m2.
data[m2_pos+j];
1330template<
class Num_T>
1335 for (
int i = 0; i < r.
datasize; i++)
1341template<
class Num_T>
1346 for (
int i = 0; i < r.
datasize; i++)
1352template<
class Num_T>
1355 int i, j, m_pos = 0, pos = 0;
1357 if (datasize == 0) {
1359 for (i = 0; i < no_cols; i++) {
1360 for (j = 0; j < no_rows; j++)
1361 data[pos+j] = -m.
data[m_pos+j];
1369 "Mat<>::operator-=(): Wrong sizes");
1370 for (i = 0; i < no_cols; i++) {
1371 for (j = 0; j < no_rows; j++)
1372 data[pos+j] -= m.
data[m_pos+j];
1381template<
class Num_T>
1385 int i, j, m1_pos = 0, m2_pos = 0, r_pos = 0;
1387 "Mat<>::operator-(): Wrong sizes");
1389 for (i = 0; i < r.
no_cols; i++) {
1390 for (j = 0; j < r.
no_rows; j++)
1391 r.
data[r_pos+j] = m1.
data[m1_pos+j] - m2.
data[m2_pos+j];
1401template<
class Num_T>
inline
1404 for (
int i = 0; i < datasize; i++)
1409template<
class Num_T>
1413 int i, j, m_pos = 0, r_pos = 0;
1415 for (i = 0; i < r.
no_cols; i++) {
1416 for (j = 0; j < r.
no_rows; j++)
1417 r.
data[r_pos+j] = m.
data[m_pos+j] - t;
1426template<
class Num_T>
1430 int i, j, m_pos = 0, r_pos = 0;
1432 for (i = 0; i < r.
no_cols; i++) {
1433 for (j = 0; j < r.
no_rows; j++)
1434 r.
data[r_pos+j] = t - m.
data[m_pos+j];
1443template<
class Num_T>
1447 int i, j, m_pos = 0, r_pos = 0;
1449 for (i = 0; i < r.
no_cols; i++) {
1450 for (j = 0; j < r.
no_rows; j++)
1451 r.
data[r_pos+j] = -m.
data[m_pos+j];
1460template<
class Num_T>
1468 int i, j, k, r_pos = 0, pos = 0, m_pos = 0;
1470 for (i = 0; i < r.
no_cols; i++) {
1471 for (j = 0; j < r.
no_rows; j++) {
1474 for (k = 0; k < no_cols; k++) {
1475 tmp += data[pos+j] * m.
data[m_pos+k];
1478 r.
data[r_pos+j] = tmp;
1488template<> ITPP_EXPORT mat& mat::operator*=(
const mat &m);
1489template<> ITPP_EXPORT cmat& cmat::operator*=(
const cmat &m);
1492template<
class Num_T>
inline
1495 scal_vector(datasize, t, data);
1500template<
class Num_T>
1504 "Mat<>::operator*(): Wrong sizes");
1509 Num_T *tr = r.
_data();
1510 const Num_T *t1;
const Num_T *t2 = m2.
_data();
1512 for (i = 0; i < r.
cols(); i++) {
1513 for (j = 0; j < r.
rows(); j++) {
1515 t1 = m1.
_data() + j;
1516 for (k = m1.
cols(); k > 0; k--) {
1517 tmp += *(t1) * *(t2++);
1530template<> ITPP_EXPORT mat
operator*(
const mat &m1,
const mat &m2);
1531template<> ITPP_EXPORT cmat
operator*(
const cmat &m1,
const cmat &m2);
1535template<
class Num_T>
1539 "Mat<>::operator*(): Wrong sizes");
1543 for (i = 0; i < m.
rows(); i++) {
1546 for (k = 0; k < m.
cols(); k++) {
1547 r(i) += m.
_data()[m_pos+i] * v(k);
1556template<> ITPP_EXPORT vec
operator*(
const mat &m,
const vec &v);
1557template<> ITPP_EXPORT cvec
operator*(
const cmat &m,
const cvec &v);
1561template<
class Num_T>
1566 const Num_T* m_data = m.
_data();
1567 Num_T* r_data = r.
_data();
1569 r_data[i] = m_data[i] * t;
1575template<
class Num_T>
inline
1581template<
class Num_T>
inline
1589template<
class Num_T>
1594 "Mat<>::elem_mult_out(): Wrong sizes");
1596 for (
int i = 0; i < out.
datasize; i++)
1600template<
class Num_T>
1606 "Mat<>::elem_mult_out(): Wrong sizes");
1608 for (
int i = 0; i < out.
datasize; i++)
1612template<
class Num_T>
1620 "Mat<>::elem_mult_out(): Wrong sizes");
1622 for (
int i = 0; i < out.
datasize; i++)
1626template<
class Num_T>
1633 "Mat<>::elem_mult_inplace(): Wrong sizes");
1634 for (
int i = 0; i < m2.
datasize; i++)
1638template<
class Num_T>
inline
1642 "Mat<>::elem_mult_sum(): Wrong sizes");
1645 for (
int i = 0; i < m1.
datasize; i++)
1651template<
class Num_T>
inline
1654 for (
int i = 0; i < datasize; i++)
1659template<
class Num_T>
inline
1663 "Mat<>::operator/=(): Wrong sizes");
1664 for (
int i = 0; i < datasize; i++)
1665 data[i] /= m.
data[i];
1669template<
class Num_T>
1673 for (
int i = 0; i < r.
datasize; ++i)
1678template<
class Num_T>
1682 for (
int i = 0; i < r.
datasize; ++i)
1687template<
class Num_T>
inline
1695template<
class Num_T>
1700 "Mat<>::elem_div_out(): Wrong sizes");
1705 for (
int i = 0; i < out.
datasize; i++)
1709template<
class Num_T>
inline
1713 "Mat<>::elem_div_sum(): Wrong sizes");
1716 for (
int i = 0; i < m1.
datasize; i++)
1722template<
class Num_T>
1726 for (
int i = 0;i < datasize;i++) {
1727 if (data[i] != m.
data[i])
return false;
1732template<
class Num_T>
1736 for (
int i = 0;i < datasize;i++) {
1737 if (data[i] != m.
data[i])
return true;
1742template <
class Num_T>
1752 os <<
'[' << m.
get_row(0) <<
']';
1755 os <<
'[' << m.
get_row(0) << std::endl;
1756 for (i = 1; i < m.
rows() - 1; i++)
1757 os <<
' ' << m.
get_row(i) << std::endl;
1764template <
class Num_T>
1767 std::ostringstream buffer;
1768 bool started =
false;
1769 bool finished =
false;
1770 bool brackets =
false;
1771 bool within_double_brackets =
false;
1781 if (is.eof() || (c ==
'\n')) {
1784 is.setstate(std::ios_base::failbit);
1787 else if (!((c ==
'\n') && !started)) {
1791 else if ((c ==
' ') || (c ==
'\t')) {
1796 else if (c ==
'[') {
1797 if ((started && !brackets) || within_double_brackets) {
1799 is.setstate(std::ios_base::failbit);
1802 else if (!started) {
1807 within_double_brackets =
true;
1810 else if (c ==
']') {
1811 if (!started || !brackets) {
1813 is.setstate(std::ios_base::failbit);
1816 else if (within_double_brackets) {
1817 within_double_brackets =
false;
1823 while (!is.eof() && (((c =
static_cast<char>(is.peek())) ==
' ')
1827 if (!is.eof() && (c ==
'\n')) {
1842 m.
set(buffer.str());
1856ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<double>;
1858ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<int>;
1860ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<bin>;
1864ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator+(
const mat &m1,
const mat &m2);
1865ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator+(
const cmat &m1,
const cmat &m2);
1866ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator+(
const imat &m1,
const imat &m2);
1867ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator+(
const smat &m1,
const smat &m2);
1870ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator+(
const mat &m,
double t);
1871ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator+(
const cmat &m, std::complex<double> t);
1872ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator+(
const imat &m,
int t);
1873ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator+(
const smat &m,
short t);
1876ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator+(
double t,
const mat &m);
1877ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator+(std::complex<double> t,
const cmat &m);
1878ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator+(
int t,
const imat &m);
1879ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator+(
short t,
const smat &m);
1884ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator-(
const mat &m1,
const mat &m2);
1885ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator-(
const cmat &m1,
const cmat &m2);
1886ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator-(
const imat &m1,
const imat &m2);
1887ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator-(
const smat &m1,
const smat &m2);
1890ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator-(
const mat &m,
double t);
1891ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator-(
const cmat &m, std::complex<double> t);
1892ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator-(
const imat &m,
int t);
1893ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator-(
const smat &m,
short t);
1896ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator-(
double t,
const mat &m);
1897ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator-(std::complex<double> t,
const cmat &m);
1898ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator-(
int t,
const imat &m);
1899ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator-(
short t,
const smat &m);
1904ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator-(
const mat &m);
1905ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator-(
const cmat &m);
1906ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator-(
const imat &m);
1907ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator-(
const smat &m);
1912ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator*(
const imat &m1,
const imat &m2);
1913ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator*(
const smat &m1,
const smat &m2);
1916ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
operator*(
const imat &m,
const ivec &v);
1917ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
operator*(
const smat &m,
const svec &v);
1918ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
operator*(
const bmat &m,
const bvec &v);
1920ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator*(
const mat &m,
double t);
1921ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator*(
const cmat &m, std::complex<double> t);
1922ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator*(
const imat &m,
int t);
1923ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator*(
const smat &m,
short t);
1926ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator*(
double t,
const mat &m);
1927ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator*(std::complex<double> t,
const cmat &m);
1928ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator*(
int t,
const imat &m);
1929ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator*(
short t,
const smat &m);
1934ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
elem_mult(
const mat &m1,
const mat &m2);
1935ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
elem_mult(
const cmat &m1,
const cmat &m2);
1936ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
elem_mult(
const imat &m1,
const imat &m2);
1937ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
elem_mult(
const smat &m1,
const smat &m2);
1940ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const mat &m1,
const mat &m2, mat &out);
1941ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const cmat &m1,
const cmat &m2,
1943ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const imat &m1,
const imat &m2,
1945ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const smat &m1,
const smat &m2,
1950ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const mat &m1,
const mat &m2,
1951 const mat &m3, mat &out);
1952ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const cmat &m1,
const cmat &m2,
1953 const cmat &m3, cmat &out);
1954ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const imat &m1,
const imat &m2,
1955 const imat &m3, imat &out);
1956ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const smat &m1,
const smat &m2,
1957 const smat &m3, smat &out);
1961ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const mat &m1,
const mat &m2,
1962 const mat &m3,
const mat &m4, mat &out);
1963ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const cmat &m1,
const cmat &m2,
1964 const cmat &m3,
const cmat &m4,
1966ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const imat &m1,
const imat &m2,
1967 const imat &m3,
const imat &m4,
1969ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const smat &m1,
const smat &m2,
1970 const smat &m3,
const smat &m4,
1976ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_inplace(
const mat &m1, mat &m2);
1977ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_inplace(
const cmat &m1, cmat &m2);
1978ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_inplace(
const imat &m1, imat &m2);
1979ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_inplace(
const smat &m1, smat &m2);
1982ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
double elem_mult_sum(
const mat &m1,
const mat &m2);
1983ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::complex<double>
elem_mult_sum(
const cmat &m1,
1985ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
int elem_mult_sum(
const imat &m1,
const imat &m2);
1986ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
short elem_mult_sum(
const smat &m1,
const smat &m2);
1991ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator/(
double t,
const mat &m);
1992ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator/(std::complex<double> t,
const cmat &m);
1993ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator/(
int t,
const imat &m);
1994ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator/(
short t,
const smat &m);
1997ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
operator/(
const mat &m,
double t);
1998ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
operator/(
const cmat &m, std::complex<double> t);
1999ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
operator/(
const imat &m,
int t);
2000ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
operator/(
const smat &m,
short t);
2005ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
elem_div(
const mat &m1,
const mat &m2);
2006ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
elem_div(
const cmat &m1,
const cmat &m2);
2007ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
elem_div(
const imat &m1,
const imat &m2);
2008ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
elem_div(
const smat &m1,
const smat &m2);
2011ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_div_out(
const mat &m1,
const mat &m2, mat &out);
2012ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_div_out(
const cmat &m1,
const cmat &m2, cmat &out);
2013ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_div_out(
const imat &m1,
const imat &m2, imat &out);
2014ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_div_out(
const smat &m1,
const smat &m2, smat &out);
2017ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
double elem_div_sum(
const mat &m1,
const mat &m2);
2018ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::complex<double>
elem_div_sum(
const cmat &m1,
2020ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
int elem_div_sum(
const imat &m1,
const imat &m2);
2021ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
short elem_div_sum(
const smat &m1,
const smat &m2);
2026ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
concat_horizontal(
const mat &m1,
const mat &m2);
2027ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
concat_horizontal(
const cmat &m1,
const cmat &m2);
2028ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
concat_horizontal(
const imat &m1,
const imat &m2);
2029ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
concat_horizontal(
const smat &m1,
const smat &m2);
2032ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT mat
concat_vertical(
const mat &m1,
const mat &m2);
2033ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT cmat
concat_vertical(
const cmat &m1,
const cmat &m2);
2034ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT imat
concat_vertical(
const imat &m1,
const imat &m2);
2035ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT smat
concat_vertical(
const smat &m1,
const smat &m2);
2040ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const mat &m);
2041ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const cmat &m);
2042ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const imat &m);
2043ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const smat &m);
2044ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const bmat &m);
2046ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is, mat &m);
2047ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is, cmat &m);
2048ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is, imat &m);
2049ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is, smat &m);
2050ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
bmat &m);
Base class for class factories.
Mat< Num_T > & operator+=(Num_T t)
Addition of scalar to matrix.
Vec< Num_T > get_row(int r) const
Get row r.
void swap_rows(int r1, int r2)
Swap the rows r1 and r2.
void del_col(int c)
Delete column number c.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
void free()
Free the memory space of the matrix.
void clear()
Set matrix equal to the all zero matrix.
Mat< Num_T > & operator=(const Mat< Num_T > &m)
Set matrix equal to m.
const Num_T & get(int i) const
Get element i using linear addressing (by rows)
Mat< Num_T > & operator/=(Num_T t)
Division by a scalar.
Mat(const Factory &f=DEFAULT_FACTORY)
Default constructor. An element factory f can be specified.
Mat(const std::string &str, const Factory &f=DEFAULT_FACTORY)
Set matrix equal to values in string str. An element factory f can be specified.
void append_row(const Vec< Num_T > &v)
Append vector v to the bottom of the matrix. The matrix can be empty.
Num_T value_type
The type of the matrix values.
void set_submatrix(int r, int c, const Mat< Num_T > &m)
Set submatrix defined by upper-left element (r,c) and the size of matrix m to m.
Mat< Num_T > & operator-=(const Mat< Num_T > &m)
Subtraction of matrix.
Mat< Num_T > hermitian_transpose() const
Hermitian matrix transpose (conjugate transpose)
Mat< Num_T > H() const
Hermitian matrix transpose (conjugate transpose)
std::ostream & operator<<(std::ostream &os, const Mat< Num_T > &m)
Output stream for matrices.
Mat< Num_T > get(int r1, int r2, int c1, int c2) const
Sub-matrix from row r1 to row r2 and columns c1 to c2.
Mat(const char *str, const Factory &f=DEFAULT_FACTORY)
Set matrix equal to values in string str. An element factory f can be specified.
Mat< Num_T > operator()(int r1, int r2, int c1, int c2) const
Sub-matrix from row r1 to row r2 and columns c1 to c2.
const Num_T & _elem(int r, int c) const
Get element (r,c) from matrix without boundary check (not recommended to use)
bool operator==(const Mat< Num_T > &m) const
Compare two matrices. False if wrong sizes or different values.
void set_col(int c, const Vec< Num_T > &v)
Set column c to vector v.
Mat< Num_T > & operator+=(const Mat< Num_T > &m)
Addition of matrices.
void copy_col(int to, int from)
Copy column from onto column to.
Mat< Num_T > get_rows(int r1, int r2) const
Get rows r1 through r2.
void ins_row(int r, const Vec< Num_T > &v)
Insert vector v at row number r. The matrix can be empty.
void del_rows(int r1, int r2)
Delete rows from r1 to r2.
const Num_T & _elem(int i) const
Get element i using linear addressing (by rows) without boundary check (not recommended to use)
Mat(const Num_T *c_array, int rows, int cols, bool row_major=true, const Factory &f=DEFAULT_FACTORY)
Constructor taking a C-array as input. An element factory f can be specified.
Mat< double > mat
Default Matrix Type.
Mat(const Vec< Num_T > &v, const Factory &f=DEFAULT_FACTORY)
Construct a matrix from a column vector v. An element factory f can be specified.
void zeros()
Set matrix equal to the all zero matrix.
Mat< std::complex< double > > cmat
Default Complex Matrix Type.
void set(const std::string &str)
Set matrix equal to values in the string str.
void set_submatrix(int r1, int r2, int c1, int c2, const Mat< Num_T > &m)
This function is deprecated. Please use set_submatrix(int r, int c, const Mat<> &m) instead.
void ones()
Set matrix equal to the all one matrix.
int rows() const
The number of rows.
Num_T * data
Protected data pointer.
Mat< Num_T > & operator=(const Vec< Num_T > &v)
Set matrix equal to the vector v, assuming column vector.
Num_T & operator()(int i)
Get element i using linear addressing (by rows)
void copy_row(int to, int from)
Copy row from onto row to.
bool operator!=(const Mat< Num_T > &m) const
Compare two matrices. True if different.
int cols() const
The number of columns.
Mat< Num_T > T() const
Matrix transpose.
Mat(int rows, int cols, const Factory &f=DEFAULT_FACTORY)
Create a matrix of size (rows, cols). An element factory f can be specified.
int size() const
The number of elements.
Num_T & _elem(int r, int c)
Get element (r,c) from matrix without boundary check (not recommended to use)
void set_rows(int r, const Mat< Num_T > &m)
Set rows to matrix m, staring from row r.
int _datasize() const
Access to the internal data structure (not recommended to use)
Mat< Num_T > & operator=(const char *str)
Set matrix equal to values in the string str.
Mat< Num_T > & operator/=(const Mat< Num_T > &m)
Element-wise division with the current matrix.
Mat(const Mat< Num_T > &m)
Copy constructor.
Num_T & operator()(int r, int c)
Get element (r,c) from matrix.
const Num_T & operator()(int r, int c) const
Get element (r,c) from matrix.
void ins_col(int c, const Vec< Num_T > &v)
Insert vector v at column number c. The matrix can be empty.
void del_cols(int c1, int c2)
Delete columns from c1 to c2.
Mat< int > imat
Integer matrix.
void set(int r, int c, Num_T t)
Set element (r,c) of matrix.
Num_T & _elem(int i)
Get element i using linear addressing (by rows) without boundary check (not recommended to use)
Mat< Num_T > & operator*=(Num_T t)
Multiplication by a scalar.
const Factory & factory
Element factory (set to DEFAULT_FACTORY to use Num_T default constructors only)
const Num_T * _data() const
Access to the internal data structure (not recommended to use)
Mat< Num_T > get_cols(const Vec< int > &indexlist) const
Get the columns specified by indexlist.
Mat< Num_T > & operator=(Num_T t)
Set all elements of the matrix equal to t.
std::istream & operator>>(std::istream &is, Mat< Num_T > &m)
Input stream for matrices.
void append_col(const Vec< Num_T > &v)
Append vector v to the right side of the matrix. The matrix can be empty.
void swap_cols(int c1, int c2)
Swap the columns c1 and c2.
Mat< Num_T > transpose() const
Matrix transpose.
void alloc(int rows, int cols)
Allocate memory for the matrix.
Mat(const Mat< Num_T > &m, const Factory &f)
Constructor, similar to the copy constructor, but also takes an element factory f as argument.
void set_row(int r, const Vec< Num_T > &v)
Set row r to vector v.
void set_submatrix(int r1, int r2, int c1, int c2, Num_T t)
Set all elements of submatrix defined by rows r1,r2 and columns c1,c2 to value t.
void set_cols(int c, const Mat< Num_T > &m)
Set columns to matrix m, starting from column c.
const Num_T & operator()(int i) const
Get element i using linear addressing (by rows)
Mat< short int > smat
short int matrix
const Num_T & get(int r, int c) const
Get element (r,c) from matrix.
Mat< Num_T > get_cols(int c1, int c2) const
Get columns c1 through c2.
Vec< Num_T > get_col(int c) const
Get column c.
Mat< Num_T > & operator-=(Num_T t)
Subtraction of scalar from matrix.
Num_T * _data()
Access of the internal data structure (not recommended to use)
Mat< Num_T > & operator*=(const Mat< Num_T > &m)
Matrix multiplication.
Mat< Num_T > & operator=(const std::string &str)
Set matrix equal to values in the string str.
void del_row(int r)
Delete row number r.
Mat< Num_T > get_rows(const Vec< int > &indexlist) const
Get the rows specified by indexlist.
Num_T * _data()
Get the pointer to the internal structure. Not recommended for use.
int size() const
The size of the vector.
void set_size(int size, bool copy=false)
Set length of vector. if copy = true then keeping the old values.
Binary arithmetic (boolean) class.
Base class for class factories and memory allocation functions.
#define it_warning(s)
Display a warning message.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
T to(double x)
Convert double to T.
void set(const char *str)
Set matrix equal to values in the string str.
Error handling functions - header file.
Mat< bin > bmat
bin matrix
Miscellaneous functions - header file.
void elem_mult_inplace(const Mat< Num_T > &m1, Mat< Num_T > &m2)
In-place element wise multiplication of two matrices. Fast version of B = elem_mult(A,...
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Horizontal concatenation of two matrices.
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
GF2mat operator*(const GF2mat &X, const GF2mat &Y)
GF(2) matrix multiplication.
Mat< Num_T > operator/(const Mat< Num_T > &m, Num_T t)
Element-wise division by a scalar.
void destroy_elements(T *&ptr, int n)
Destroy an array of Array, Vec or Mat elements.
void elem_div_out(const Mat< Num_T > &m1, const Mat< Num_T > &m2, Mat< Num_T > &out)
Element wise division of two matrices, storing the result in matrix out.
std::istream & operator>>(std::istream &input, bin &outbin)
Input stream of bin.
Mat< Num_T > elem_div(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices.
Num_T elem_div_sum(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices, followed by summation of the resultant elements....
GF2mat operator+(const GF2mat &X, const GF2mat &Y)
GF(2) matrix addition.
const Factory DEFAULT_FACTORY
Default (dummy) factory.
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
Num_T elem_mult_sum(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices, followed by summation of the resultant elements....
Mat< Num_T > concat_vertical(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Vertical concatenation of two matrices.
void elem_mult_out(const Mat< Num_T > &m1, const Mat< Num_T > &m2, Mat< Num_T > &out)
Element wise multiplication of two matrices, storing the result in matrix out.
void create_elements(T *&ptr, int n, const Factory &)
Create an n-length array of T to be used as Array, Vec or Mat elements.
Templated Vector Class Definitions.