35 #include <itpp/itexports.h> 41 template<
class Num_T>
class Vec;
43 template<
class Num_T>
class Mat;
56 Mat<Num_T>
operator+(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
59 Mat<Num_T>
operator+(
const Mat<Num_T> &m, Num_T t);
62 Mat<Num_T>
operator+(Num_T t,
const Mat<Num_T> &m);
66 Mat<Num_T>
operator-(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
69 Mat<Num_T>
operator-(
const Mat<Num_T> &m, Num_T t);
72 Mat<Num_T>
operator-(Num_T t,
const Mat<Num_T> &m);
75 Mat<Num_T>
operator-(
const Mat<Num_T> &m);
79 Mat<Num_T>
operator*(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
82 Vec<Num_T>
operator*(
const Mat<Num_T> &m,
const Vec<Num_T> &v);
85 Mat<Num_T>
operator*(
const Mat<Num_T> &m, Num_T t);
88 Mat<Num_T>
operator*(Num_T t,
const Mat<Num_T> &m);
92 Mat<Num_T>
elem_mult(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
95 void elem_mult_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
99 void elem_mult_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
100 const Mat<Num_T> &m3, Mat<Num_T> &out);
102 template<
class Num_T>
103 void elem_mult_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
104 const Mat<Num_T> &m3,
const Mat<Num_T> &m4,
107 template<
class Num_T>
110 template<
class Num_T>
111 Num_T
elem_mult_sum(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
114 template<
class Num_T>
115 Mat<Num_T>
operator/(
const Mat<Num_T> &m, Num_T t);
117 template<
class Num_T>
118 Mat<Num_T>
operator/(Num_T t,
const Mat<Num_T> &m);
121 template<
class Num_T>
122 Mat<Num_T>
elem_div(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
124 template<
class Num_T>
125 void elem_div_out(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2,
128 template<
class Num_T>
129 Num_T
elem_div_sum(
const Mat<Num_T> &m1,
const Mat<Num_T> &m2);
200 template<
class Num_T>
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);
279 Mat<Num_T> get(
int r1,
int r2,
int c1,
int c2)
const;
448 void alloc(
int rows,
int cols);
463 bool in_range(
int r,
int c)
const {
464 return ((r >= 0) && (r < no_rows) && (c >= 0) && (c < no_cols));
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)); }
526 template <
class Num_T>
527 std::ostream &operator<<(std::ostream &os, const Mat<Num_T> &m);
540 template <
class Num_T>
541 std::istream &
operator>>(std::istream &is, Mat<Num_T> &m);
547 template<
class Num_T>
inline 550 if ((rows > 0) && (cols > 0)) {
564 template<
class Num_T>
inline 574 template<
class Num_T>
inline 578 template<
class Num_T>
inline 582 it_assert_debug((rows >= 0) && (cols >= 0),
"Mat<>::Mat(): Wrong size");
586 template<
class Num_T>
inline 590 alloc(m.no_rows, m.no_cols);
591 copy_vector(m.datasize, m.data,
data);
594 template<
class Num_T>
inline 598 alloc(m.no_rows, m.no_cols);
599 copy_vector(m.datasize, m.data,
data);
602 template<
class Num_T>
inline 611 template<
class Num_T>
inline 618 template<
class Num_T>
inline 622 set(std::string(str));
625 template<
class Num_T>
634 for (
int i = 0; i <
rows; i++)
635 for (
int j = 0; j <
cols; j++)
639 template<
class Num_T>
inline 646 template<
class Num_T>
650 "Mat<>::set_size(): Wrong size");
655 if ((rows == 0) || (cols == 0)) {
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);
697 template<
class Num_T>
inline 704 template<
class Num_T>
inline 711 template<
class Num_T>
inline 715 "Mat<>::operator(): Indexing out of range");
719 template<
class Num_T>
inline 723 "Mat<>::operator(): Indexing out of range");
727 template<
class Num_T>
inline 734 template<
class Num_T>
inline 741 template<
class Num_T>
inline 744 return (*
this)(r, c);
747 template<
class Num_T>
inline 753 template<
class Num_T>
inline 756 it_assert_debug(in_range(r, c),
"Mat<>::set(): Indexing out of range");
761 template<
class Num_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)) {
792 if ((rows == maxrows) || (v_size !=
no_cols)) {
794 if (rows == maxrows) {
819 template<
class Num_T>
inline 822 set(std::string(str));
825 template<
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++)
840 copy_vector(s.no_rows,
data + r1 + (c1 + i)*
no_rows, s.data + i*s.no_rows);
845 template<
class Num_T>
inline 848 return (*
this)(r1, r2, c1, c2);
851 template<
class Num_T>
inline 854 it_assert_debug(row_in_range(r),
"Mat<>::get_row(): Index out of range");
861 template<
class Num_T>
865 "Mat<>::get_rows(): Wrong indexing");
868 for (
int i = 0; i < m.rows(); i++)
874 template<
class Num_T>
879 for (
int i = 0;i < indexlist.
size();i++) {
881 "Mat<>::get_rows(indexlist): Indexing out of range");
888 template<
class Num_T>
inline 891 it_assert_debug(col_in_range(c),
"Mat<>::get_col(): Index out of range");
899 template<
class Num_T>
903 "Mat<>::get_cols(): Wrong indexing");
906 for (
int i = 0; i < m.cols(); i++)
912 template<
class Num_T>
917 for (
int i = 0; i < indexlist.
size(); i++) {
919 "Mat<>::get_cols(indexlist): Indexing out of range");
926 template<
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");
935 template<
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");
945 template<
class Num_T>
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) {
959 template<
class Num_T>
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) {
974 template<
class Num_T>
inline 978 "Mat<>::copy_row(): Indexing out of range");
985 template<
class Num_T>
inline 989 "Mat<>::copy_col(): Indexing out of range");
996 template<
class Num_T>
inline 1000 "Mat<>::swap_rows(): Indexing out of range");
1007 template<
class Num_T>
inline 1011 "Mat<>::swap_cols(): Indexing out of range");
1018 template<
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.");
1027 template<
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++)
1035 copy_vector(m.no_rows, m.data + i*m.no_rows,
data + (c + i)*
no_rows + r);
1040 template<
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++) {
1052 for (
int j = r1; j <= r2; j++)
1057 template<
class Num_T>
1060 it_assert_debug(row_in_range(r),
"Mat<>::del_row(): Index out of range");
1063 for (
int i = 0 ; i < r ; i++) {
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);
1072 template<
class Num_T>
1076 "Mat<>::del_rows(): Indexing out of range");
1078 int no_del_rows = r2 - r1 + 1;
1080 for (
int i = 0; i < r1 ; ++i) {
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],
1089 template<
class Num_T>
1092 it_assert_debug(col_in_range(c),
"Mat<>::del_col(): Index out of range");
1097 copy_vector((
no_cols - c)*no_rows, &Temp.data[(c+1)*no_rows], &
data[c*no_rows]);
1100 template<
class Num_T>
1104 "Mat<>::del_cols(): Indexing out of range");
1106 int n_deleted_cols = c2 - c1 + 1;
1109 copy_vector((
no_cols - c1)*no_rows, &Temp.data[(c2+1)*no_rows], &
data[c1*no_rows]);
1112 template<
class Num_T>
1116 "Mat<>::ins_row(): Index out of range");
1118 "Mat<>::ins_row(): Wrong size of the input vector");
1127 for (
int i = 0 ; i < r ; i++) {
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);
1136 template<
class Num_T>
1140 "Mat<>::ins_col(): Index out of range");
1142 "Mat<>::ins_col(): Wrong size of the input vector");
1153 copy_vector((
no_cols - c - 1)*no_rows, &Temp.data[c*no_rows], &
data[(c+1)*no_rows]);
1156 template<
class Num_T>
inline 1162 template<
class Num_T>
inline 1168 template<
class Num_T>
1172 for (
int i = 0; i <
no_rows; ++i) {
1178 template<
class Num_T>
1182 for (
int i = 0; i <
no_rows; ++i) {
1193 template<
class Num_T>
1197 if (m1.no_cols == 0)
1199 if (m2.no_cols == 0)
1202 "Mat<>::concat_horizontal(): Wrong sizes");
1204 Mat<Num_T> temp(no_rows, m1.no_cols + m2.no_cols);
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)
1215 template<
class Num_T>
1219 if (m1.no_rows == 0)
1221 if (m2.no_rows == 0)
1224 "Mat<>::concat_vertical(): Wrong sizes");
1226 Mat<Num_T> temp(m1.no_rows + m2.no_rows, no_cols);
1227 for (
int i = 0; i <
no_cols; ++i) {
1228 copy_vector(m1.no_rows, &m1.data[i * m1.no_rows],
1229 &temp.data[i * temp.no_rows]);
1230 copy_vector(m2.no_rows, &m2.data[i * m2.no_rows],
1231 &temp.data[i * temp.no_rows + m1.no_rows]);
1236 template<
class Num_T>
inline 1244 template<
class Num_T>
inline 1248 set_size(m.no_rows, m.no_cols,
false);
1249 if (m.datasize != 0)
1250 copy_vector(m.datasize, m.data,
data);
1255 template<
class Num_T>
inline 1260 "Mat<>::operator=(): Wrong size of the input vector");
1266 template<
class Num_T>
inline 1273 template<
class Num_T>
inline 1276 set(std::string(str));
1282 template<
class Num_T>
1288 int i, j, m_pos = 0, pos = 0;
1290 for (i = 0; i <
no_cols; i++) {
1292 data[pos+j] += m.data[m_pos+j];
1300 template<
class Num_T>
inline 1308 template<
class Num_T>
1312 int i, j, m1_pos = 0, m2_pos = 0, r_pos = 0;
1314 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
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];
1321 m1_pos += m1.no_rows;
1322 m2_pos += m2.no_rows;
1330 template<
class Num_T>
1335 for (
int i = 0; i < r.datasize; i++)
1336 r.data[i] = m.data[i] + t;
1341 template<
class Num_T>
1346 for (
int i = 0; i < r.datasize; i++)
1347 r.data[i] = t + m.data[i];
1352 template<
class Num_T>
1355 int i, j, m_pos = 0, pos = 0;
1358 set_size(m.no_rows, m.no_cols,
false);
1359 for (i = 0; i <
no_cols; i++) {
1361 data[pos+j] = -m.data[m_pos+j];
1369 "Mat<>::operator-=(): Wrong sizes");
1370 for (i = 0; i <
no_cols; i++) {
1372 data[pos+j] -= m.data[m_pos+j];
1381 template<
class Num_T>
1385 int i, j, m1_pos = 0, m2_pos = 0, r_pos = 0;
1386 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
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];
1393 m1_pos += m1.no_rows;
1394 m2_pos += m2.no_rows;
1401 template<
class Num_T>
inline 1409 template<
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;
1426 template<
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];
1443 template<
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];
1460 template<
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;
1492 template<
class Num_T>
inline 1500 template<
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++);
1535 template<
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);
1556 template<> ITPP_EXPORT vec
operator*(
const mat &m,
const vec &v);
1557 template<> ITPP_EXPORT cvec
operator*(
const cmat &m,
const cvec &v);
1561 template<
class Num_T>
1566 const Num_T* m_data = m._data();
1567 Num_T* r_data = r._data();
1568 for (
int i = 0; i < r._datasize(); i++)
1569 r_data[i] = m_data[i] * t;
1575 template<
class Num_T>
inline 1581 template<
class Num_T>
inline 1589 template<
class Num_T>
1593 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
1594 "Mat<>::elem_mult_out(): Wrong sizes");
1595 out.set_size(m1.no_rows, m1.no_cols);
1596 for (
int i = 0; i < out.datasize; i++)
1597 out.data[i] = m1.data[i] * m2.data[i];
1600 template<
class Num_T>
1604 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_rows == m3.no_rows)
1605 && (m1.no_cols == m2.no_cols) && (m1.no_cols == m3.no_cols),
1606 "Mat<>::elem_mult_out(): Wrong sizes");
1607 out.set_size(m1.no_rows, m1.no_cols);
1608 for (
int i = 0; i < out.datasize; i++)
1609 out.data[i] = m1.data[i] * m2.data[i] * m3.data[i];
1612 template<
class Num_T>
1617 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_rows == m3.no_rows)
1618 && (m1.no_rows == m4.no_rows) && (m1.no_cols == m2.no_cols)
1619 && (m1.no_cols == m3.no_cols) && (m1.no_cols == m4.no_cols),
1620 "Mat<>::elem_mult_out(): Wrong sizes");
1621 out.set_size(m1.no_rows, m1.no_cols);
1622 for (
int i = 0; i < out.datasize; i++)
1623 out.data[i] = m1.data[i] * m2.data[i] * m3.data[i] * m4.data[i];
1626 template<
class Num_T>
1632 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
1633 "Mat<>::elem_mult_inplace(): Wrong sizes");
1634 for (
int i = 0; i < m2.datasize; i++)
1635 m2.data[i] *= m1.data[i];
1638 template<
class Num_T>
inline 1641 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
1642 "Mat<>::elem_mult_sum(): Wrong sizes");
1645 for (
int i = 0; i < m1.datasize; i++)
1646 acc += m1.data[i] * m2.data[i];
1651 template<
class Num_T>
inline 1659 template<
class Num_T>
inline 1663 "Mat<>::operator/=(): Wrong sizes");
1665 data[i] /= m.data[i];
1669 template<
class Num_T>
1673 for (
int i = 0; i < r.datasize; ++i)
1674 r.data[i] = m.data[i] / t;
1678 template<
class Num_T>
1682 for (
int i = 0; i < r.datasize; ++i)
1683 r.data[i] = t / m.data[i];
1687 template<
class Num_T>
inline 1695 template<
class Num_T>
1699 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
1700 "Mat<>::elem_div_out(): Wrong sizes");
1702 if ((out.no_rows != m1.no_rows) || (out.no_cols != m1.no_cols))
1703 out.set_size(m1.no_rows, m1.no_cols);
1705 for (
int i = 0; i < out.datasize; i++)
1706 out.data[i] = m1.data[i] / m2.data[i];
1709 template<
class Num_T>
inline 1712 it_assert_debug((m1.no_rows == m2.no_rows) && (m1.no_cols == m2.no_cols),
1713 "Mat<>::elem_div_sum(): Wrong sizes");
1716 for (
int i = 0; i < m1.datasize; i++)
1717 acc += m1.data[i] / m2.data[i];
1722 template<
class Num_T>
1727 if (
data[i] != m.data[i])
return false;
1732 template<
class Num_T>
1737 if (
data[i] != m.data[i])
return true;
1742 template <
class Num_T>
1743 std::ostream &operator<<(std::ostream &os, const Mat<Num_T> &m)
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;
1758 os <<
' ' << m.get_row(m.rows() - 1) <<
']';
1764 template <
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')) {
1839 m.set_size(0,
false);
1842 m.set(buffer.str());
1856 ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<double>;
1858 ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<int>;
1860 ITPP_EXPORT_TEMPLATE
template class ITPP_EXPORT
Mat<bin>;
1864 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator+(
const mat &m1,
const mat &m2);
1870 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator+(
const mat &m,
double t);
1871 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator+(
const cmat &m, std::complex<double> t);
1873 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator+(
const smat &m,
short t);
1876 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator+(
double t,
const mat &m);
1877 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator+(std::complex<double> t,
const cmat &m);
1879 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator+(
short t,
const smat &m);
1884 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator-(
const mat &m1,
const mat &m2);
1890 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator-(
const mat &m,
double t);
1891 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator-(
const cmat &m, std::complex<double> t);
1893 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator-(
const smat &m,
short t);
1896 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator-(
double t,
const mat &m);
1897 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator-(std::complex<double> t,
const cmat &m);
1899 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator-(
short t,
const smat &m);
1904 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator-(
const mat &m);
1916 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT ivec
operator*(
const imat &m,
const ivec &v);
1917 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT svec
operator*(
const smat &m,
const svec &v);
1918 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT bvec
operator*(
const bmat &m,
const bvec &v);
1920 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator*(
const mat &m,
double t);
1921 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator*(
const cmat &m, std::complex<double> t);
1923 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator*(
const smat &m,
short t);
1926 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator*(
double t,
const mat &m);
1927 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator*(std::complex<double> t,
const cmat &m);
1929 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator*(
short t,
const smat &m);
1934 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat elem_mult(
const mat &m1,
const mat &m2);
1950 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const mat &m1,
const mat &m2,
1951 const mat &m3,
mat &out);
1961 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_mult_out(
const mat &m1,
const mat &m2,
1962 const mat &m3,
const mat &m4,
mat &out);
1982 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
double elem_mult_sum(
const mat &m1,
const mat &m2);
1983 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::complex<double>
elem_mult_sum(
const cmat &m1,
1991 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator/(
double t,
const mat &m);
1992 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator/(std::complex<double> t,
const cmat &m);
1994 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator/(
short t,
const smat &m);
1997 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat operator/(
const mat &m,
double t);
1998 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
cmat operator/(
const cmat &m, std::complex<double> t);
2000 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
smat operator/(
const smat &m,
short t);
2005 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
mat elem_div(
const mat &m1,
const mat &m2);
2011 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
void elem_div_out(
const mat &m1,
const mat &m2,
mat &out);
2017 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT
double elem_div_sum(
const mat &m1,
const mat &m2);
2018 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::complex<double>
elem_div_sum(
const cmat &m1,
2040 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const mat &m);
2041 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const cmat &m);
2042 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const imat &m);
2043 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const smat &m);
2044 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::ostream &
operator<<(std::ostream &os,
const bmat &m);
2046 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
mat &m);
2047 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
cmat &m);
2048 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
imat &m);
2049 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
smat &m);
2050 ITPP_EXPORT_TEMPLATE
template ITPP_EXPORT std::istream &
operator>>(std::istream &is,
bmat &m);
2056 #endif // #ifndef MAT_H void del_cols(int c1, int c2)
Delete columns from c1 to c2.
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...
Mat< Num_T > elem_div(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise division of two matrices.
void alloc(int rows, int cols)
Allocate memory for the matrix.
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
int cols() const
The number of columns.
Mat< Num_T > transpose() const
Matrix transpose.
Mat< Num_T > operator/(const Mat< Num_T > &m, Num_T t)
Element-wise division by a scalar.
Mat< double > mat
Default Matrix Type.
Num_T * data
Protected data pointer.
Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Horizontal concatenation of two matrices.
Miscellaneous functions - header file.
void append_row(const Vec< Num_T > &v)
Append vector v to the bottom of the matrix. The matrix can be empty.
Mat< Num_T > H() const
Hermitian matrix transpose (conjugate transpose)
Num_T * _data()
Get the pointer to the internal structure. Not recommended for use.
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.
int size() const
The number of elements.
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.
int _datasize() const
Access to the internal data structure (not recommended to use)
int rows() const
The number of rows.
bool operator==(const Mat< Num_T > &m) const
Compare two matrices. False if wrong sizes or different values.
const Num_T & _elem(int i) const
Get element i using linear addressing (by rows) without boundary check (not recommended to use) ...
Mat< Num_T > & operator=(Num_T t)
Set all elements of the matrix equal to t.
friend 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.
void destroy_elements(T *&ptr, int n)
Destroy an array of Array, Vec or Mat elements.
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
friend 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. Fast version of sumsum(elem_div(A, B)).
void set(const std::string &str)
Set matrix equal to values in the string str.
void append_col(const Vec< Num_T > &v)
Append vector v to the right side of the matrix. The matrix can be empty.
bool operator!=(const Mat< Num_T > &m) const
Compare two matrices. True if different.
std::istream & operator>>(std::istream &is, Mat< Num_T > &m)
Input stream for matrices.
friend Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Concatenate the matrices m1 and m2 horizontally.
Mat< Num_T > get_rows(int r1, int r2) const
Get rows r1 through r2.
friend 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...
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
const Num_T & get(int r, int c) const
Get element (r,c) from matrix.
Mat< Num_T > & operator-=(const Mat< Num_T > &m)
Subtraction of matrix.
Base class for class factories.
Vec< Num_T > get_row(int r) const
Get row r.
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.
Mat< short int > smat
short int matrix
friend Mat< Num_T > operator+(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Addition of two matrices.
friend Mat< Num_T > operator/(const Mat< Num_T > &m, Num_T t)
Element-wise division by a scalar.
Num_T & _elem(int r, int c)
Get element (r,c) from matrix without boundary check (not recommended to use)
const Num_T * _data() const
Access to the internal data structure (not recommended to use)
void ins_row(int r, const Vec< Num_T > &v)
Insert vector v at row number r. The matrix can be empty.
Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of two matrices.
void ones()
Set matrix equal to the all one matrix.
void ins_col(int c, const Vec< Num_T > &v)
Insert vector v at column number c. The matrix can be empty.
void clear()
Set matrix equal to the all zero matrix.
void swap_cols(int c1, int c2)
Swap the columns c1 and c2.
friend 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.
friend 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, B).
Mat< std::complex< double > > cmat
Default Complex Matrix Type.
GF2mat operator+(const GF2mat &X, const GF2mat &Y)
GF(2) matrix addition.
const Num_T & operator()(int r, int c) const
Get element (r,c) from matrix.
const Factory DEFAULT_FACTORY
Default (dummy) factory.
const Num_T & _elem(int r, int c) const
Get element (r,c) from matrix without boundary check (not recommended to use)
void set_row(int r, const Vec< Num_T > &v)
Set row r to vector v.
Mat< Num_T > get_cols(int c1, int c2) const
Get columns c1 through c2.
Mat< Num_T > T() const
Matrix transpose.
Base class for class factories and memory allocation functions.
void set_rows(int r, const Mat< Num_T > &m)
Set rows to matrix m, staring from row r.
void swap_rows(int r1, int r2)
Swap the rows r1 and r2.
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 del_row(int r)
Delete row number r.
GF2mat operator*(const GF2mat &X, const GF2mat &Y)
GF(2) matrix multiplication.
Mat< Num_T > concat_vertical(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Vertical concatenation of two matrices.
int size() const
The size of the vector.
Error handling functions - header file.
void set_cols(int c, const Mat< Num_T > &m)
Set columns to matrix m, starting from column c.
void zeros()
Set matrix equal to the all zero matrix.
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, B).
Num_T * _data()
Access of the internal data structure (not recommended to use)
Num_T & _elem(int i)
Get element i using linear addressing (by rows) without boundary check (not recommended to use) ...
#define it_warning(s)
Display a warning message.
Mat(const Factory &f=DEFAULT_FACTORY)
Default constructor. An element factory f can be specified.
Binary arithmetic (boolean) class.
mat operator*(const float &s, const mat &m)
Multiplication operator for float and mat.
Mat< int > imat
Integer matrix.
Mat< Num_T > & operator*=(const Mat< Num_T > &m)
Matrix multiplication.
friend Mat< Num_T > concat_vertical(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Concatenate the matrices m1 and m2 vertically.
T to(double x)
Convert double to T.
const Factory & factory
Element factory (set to DEFAULT_FACTORY to use Num_T default constructors only)
Num_T value_type
The type of the matrix values.
Vec< Num_T > get_col(int c) const
Get column c.
void del_rows(int r1, int r2)
Delete rows from r1 to r2.
friend Mat< Num_T > operator-(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Subtraction of m2 from m1.
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...
friend Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
void copy_col(int to, int from)
Copy column from onto column to.
Mat< Num_T > hermitian_transpose() const
Hermitian matrix transpose (conjugate transpose)
Mat< Num_T > & operator/=(Num_T t)
Division by a scalar.
std::ostream & operator<<(std::ostream &os, const Mat< Num_T > &m)
Output stream for matrices.
void copy_row(int to, int from)
Copy row from onto row to.
friend 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. Fast version of sumsum(elem_div(A, B)).
void del_col(int c)
Delete column number c.
Mat< bin > bmat
bin matrix
Templated Vector Class Definitions.
void free()
Free the memory space of the matrix.