Chemical Data Processing Library C++ API - Version 1.4.0
Matrix.hpp
Go to the documentation of this file.
1 /*
2  * Matrix.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_MATRIX_HPP
28 #define CDPL_MATH_MATRIX_HPP
29 
30 #include <cstddef>
31 #include <cstdint>
32 #include <algorithm>
33 #include <vector>
34 #include <limits>
35 #include <unordered_map>
36 #include <type_traits>
37 #include <utility>
38 #include <initializer_list>
39 #include <memory>
40 
41 #include "CDPL/Math/Check.hpp"
45 #include "CDPL/Math/Functional.hpp"
46 #include "CDPL/Math/TypeTraits.hpp"
49 #include "CDPL/Base/Exceptions.hpp"
50 
51 
52 namespace CDPL
53 {
54 
55  namespace Math
56  {
57 
62  template <typename M>
63  class MatrixReference : public MatrixExpression<MatrixReference<M> >
64  {
65 
67 
68  public:
70  typedef M MatrixType;
72  typedef typename M::ValueType ValueType;
74  typedef typename std::conditional<std::is_const<M>::value,
75  typename M::ConstReference,
76  typename M::Reference>::type Reference;
78  typedef typename M::ConstReference ConstReference;
80  typedef typename M::SizeType SizeType;
82  typedef typename M::DifferenceType DifferenceType;
86  typedef const SelfType ConstClosureType;
87 
93  data(m) {}
94 
102  {
103  return data(i, j);
104  }
105 
113  {
114  return data(i, j);
115  }
116 
122  {
123  return data.getSize1();
124  }
125 
131  {
132  return data.getSize2();
133  }
134 
140  {
141  return data.getMaxSize();
142  }
143 
149  {
150  return data.getMaxSize1();
151  }
152 
158  {
159  return data.getMaxSize2();
160  }
161 
166  bool isEmpty() const
167  {
168  return data.isEmpty();
169  }
170 
175  const MatrixType& getData() const
176  {
177  return data;
178  }
179 
185  {
186  return data;
187  }
188 
195  {
196  data.operator=(r.data);
197  return *this;
198  }
199 
206  template <typename E>
208  {
209  data.operator=(e);
210  return *this;
211  }
212 
219  template <typename E>
221  {
222  data.operator+=(e);
223  return *this;
224  }
225 
232  template <typename E>
234  {
235  data.operator-=(e);
236  return *this;
237  }
238 
245  template <typename T>
246  typename std::enable_if<IsScalar<T>::value, MatrixReference>::type& operator*=(const T& t)
247  {
248  data.operator*=(t);
249  return *this;
250  }
251 
258  template <typename T>
259  typename std::enable_if<IsScalar<T>::value, MatrixReference>::type& operator/=(const T& t)
260  {
261  data.operator/=(t);
262  return *this;
263  }
264 
271  template <typename E>
273  {
274  data.assign(e);
275  return *this;
276  }
277 
284  template <typename E>
286  {
287  data.plusAssign(e);
288  return *this;
289  }
290 
297  template <typename E>
299  {
300  data.minusAssign(e);
301  return *this;
302  }
303 
309  {
310  data.swap(r.data);
311  }
312 
318  friend void swap(MatrixReference& r1, MatrixReference& r2)
319  {
320  r1.swap(r2);
321  }
322 
323  private:
324  MatrixType& data;
325  };
326 
327  template <typename T, typename A>
328  class Matrix;
329  template <typename T, typename A>
330  class Vector;
331 
336  template <typename T>
337  class InitListMatrix : public MatrixContainer<InitListMatrix<T> >
338  {
339 
340  public:
344  typedef std::initializer_list<std::initializer_list<T> > InitializerListType;
346  typedef typename InitializerListType::value_type::value_type ValueType;
348  typedef typename InitializerListType::value_type::const_reference ConstReference;
350  typedef typename InitializerListType::value_type::reference Reference;
352  typedef typename InitializerListType::size_type SizeType;
354  typedef typename std::ptrdiff_t DifferenceType;
358  typedef const SelfType ConstClosureType;
363 
372  list(l), size2(0)
373  {
374  for (const auto& r : l)
375  size2 = std::max(size2, r.size());
376  }
377 
386  {
387  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
388 
389  if (j >= (list.begin() + i)->size())
390  return zero;
391 
392  return *((list.begin() + i)->begin() + j);
393  }
394 
403  {
404  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
405 
406  if (j >= (list.begin() + i)->size())
407  return zero;
408 
409  return *((list.begin() + i)->begin() + j);
410  }
411 
417  {
418  return list.size();
419  }
420 
426  {
427  return size2;
428  }
429 
434  bool isEmpty() const
435  {
436  return (size2 == 0 || list.size() == 0);
437  }
438 
439  private:
440  InitializerListType list;
441  SizeType size2;
442  static const ValueType zero;
443  };
444 
445  template <typename T>
446  const typename InitListMatrix<T>::ValueType InitListMatrix<T>::zero = InitListMatrix<T>::ValueType();
447 
453  template <typename T, typename A = std::vector<T> >
454  class Matrix : public MatrixContainer<Matrix<T, A> >
455  {
456 
457  typedef Matrix<T, A> SelfType;
458 
459  public:
461  typedef T ValueType;
463  typedef T& Reference;
465  typedef const T& ConstReference;
467  typedef typename A::size_type SizeType;
469  typedef typename A::difference_type DifferenceType;
471  typedef A ArrayType;
473  typedef T* Pointer;
475  typedef const T* ConstPointer;
485  typedef std::shared_ptr<SelfType> SharedPointer;
487  typedef std::initializer_list<std::initializer_list<T> > InitializerListType;
488 
493  size1(0), size2(0), data() {}
494 
501  size1(m), size2(n), data(storageSize(m, n)) {}
502 
510  size1(m), size2(n), data(storageSize(m, n), v) {}
511 
516  Matrix(const Matrix& m):
517  size1(m.size1), size2(m.size2), data(m.data) {}
518 
524  size1(0), size2(0), data()
525  {
526  swap(m);
527  }
528 
538  size1(0), size2(0), data()
539  {
540  assign(l);
541  }
542 
548  template <typename E>
550  size1(e().getSize1()), size2(e().getSize2()), data(storageSize(e().getSize1(), e().getSize2()))
551  {
552  matrixAssignMatrix<ScalarAssignment>(*this, e);
553  }
554 
563  {
564  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
565  return data[i * getSize2() + j];
566  }
567 
576  {
577  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
578  return data[i * getSize2() + j];
579  }
580 
585  bool isEmpty() const
586  {
587  return data.empty();
588  }
589 
595  {
596  return size1;
597  }
598 
604  {
605  return size2;
606  }
607 
613  {
614  return data.max_size();
615  }
616 
622  {
623  return data;
624  }
625 
630  const ArrayType& getData() const
631  {
632  return data;
633  }
634 
641  {
642  data = m.data;
643  size1 = m.size1;
644  size2 = m.size2;
645  return *this;
646  }
647 
654  {
655  swap(m);
656  return *this;
657  }
658 
665  template <typename C>
667  {
668  return assign(c);
669  }
670 
677  {
678  return assign(l);
679  }
680 
687  template <typename E>
689  {
690  Matrix tmp(e);
691  swap(tmp);
692  return *this;
693  }
694 
701  template <typename C>
703  {
704  return plusAssign(c);
705  }
706 
713  {
714  return plusAssign(l);
715  }
716 
723  template <typename E>
725  {
726  Matrix tmp(*this + e);
727  swap(tmp);
728  return *this;
729  }
730 
737  template <typename C>
739  {
740  return minusAssign(c);
741  }
742 
749  {
750  return minusAssign(l);
751  }
752 
759  template <typename E>
761  {
762  Matrix tmp(*this - e);
763  swap(tmp);
764  return *this;
765  }
766 
773  template <typename T1>
774  typename std::enable_if<IsScalar<T1>::value, Matrix>::type& operator*=(const T1& t)
775  {
776  matrixAssignScalar<ScalarMultiplicationAssignment>(*this, t);
777  return *this;
778  }
779 
786  template <typename T1>
787  typename std::enable_if<IsScalar<T1>::value, Matrix>::type& operator/=(const T1& t)
788  {
789  matrixAssignScalar<ScalarDivisionAssignment>(*this, t);
790  return *this;
791  }
792 
799  template <typename E>
801  {
802  resize(e().getSize1(), e().getSize2(), false);
803  matrixAssignMatrix<ScalarAssignment>(*this, e);
804  return *this;
805  }
806 
813  {
815  resize(ilm.getSize1(), ilm.getSize2(), false);
816  matrixAssignMatrix<ScalarAssignment>(*this, ilm);
817  return *this;
818  }
819 
826  template <typename E>
828  {
829  matrixAssignMatrix<ScalarAdditionAssignment>(*this, e);
830  return *this;
831  }
832 
839  {
840  matrixAssignMatrix<ScalarAdditionAssignment>(*this, InitListMatrix<ValueType>(l));
841  return *this;
842  }
843 
850  template <typename E>
852  {
853  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, e);
854  return *this;
855  }
856 
863  {
864  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, InitListMatrix<ValueType>(l));
865  return *this;
866  }
867 
872  void swap(Matrix& m)
873  {
874  if (this != &m) {
875  std::swap(data, m.data);
876  std::swap(size1, m.size1);
877  std::swap(size2, m.size2);
878  }
879  }
880 
886  friend void swap(Matrix& m1, Matrix& m2)
887  {
888  m1.swap(m2);
889  }
890 
895  void clear(const ValueType& v = ValueType())
896  {
897  std::fill(data.begin(), data.end(), v);
898  }
899 
907  void resize(SizeType m, SizeType n, bool preserve = true, const ValueType& v = ValueType())
908  {
909  if (size1 == m && size2 == n)
910  return;
911 
912  if (preserve) {
913  Matrix tmp(m, n, v);
914 
915  for (SizeType i = 0, min_size1 = std::min(size1, m); i < min_size1; i++)
916  for (SizeType j = 0, min_size2 = std::min(size2, n); j < min_size2; j++)
917  tmp(i, j) = (*this)(i, j);
918 
919  swap(tmp);
920 
921  } else {
922  data.resize(storageSize(m, n), v);
923  size1 = m;
924  size2 = n;
925  }
926  }
927 
928  private:
929  SizeType storageSize(SizeType m, SizeType n)
930  {
931  CDPL_MATH_CHECK(n == 0 || m <= data.max_size() / n, "Maximum size exceeded", Base::SizeError);
932  return (m * n);
933  }
934 
935  SizeType size1;
936  SizeType size2;
937  ArrayType data;
938  };
939 
945  template <typename T, typename A = std::unordered_map<std::uint64_t, T> >
946  class SparseMatrix : public MatrixContainer<SparseMatrix<T, A> >
947  {
948 
949  typedef SparseMatrix<T> SelfType;
950 
951  public:
953  typedef T ValueType;
955  typedef typename A::key_type KeyType;
959  typedef const T& ConstReference;
961  typedef std::uint32_t SizeType;
963  typedef std::ptrdiff_t DifferenceType;
965  typedef A ArrayType;
967  typedef T* Pointer;
969  typedef const T* ConstPointer;
979  typedef std::shared_ptr<SelfType> SharedPointer;
981  typedef std::initializer_list<std::initializer_list<T> > InitializerListType;
982 
987  size1(0), size2(0), data() {}
988 
996  size1(m), size2(n), data()
997  {
998  CDPL_MATH_CHECK((n == 0 || m <= data.max_size() / n), "Maximum size exceeded", Base::SizeError);
999  }
1000 
1006  size1(m.size1), size2(m.size2), data(m.data) {}
1007 
1013  size1(0), size2(0), data()
1014  {
1015  swap(m);
1016  }
1017 
1023  size1(0), size2(0), data()
1024  {
1025  assign(l);
1026  }
1027 
1034  template <typename E>
1036  size1(e().getSize1()), size2(e().getSize2()), data()
1037  {
1038  CDPL_MATH_CHECK((size1 == 0 || size2 <= data.max_size() / size1), "Maximum size exceeded", Base::SizeError);
1039  matrixAssignMatrix<ScalarAssignment>(*this, e);
1040  }
1041 
1050  {
1051  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
1052 
1053  return Reference(*this, makeKey(i, j));
1054  }
1055 
1064  {
1065  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
1066 
1067  typename ArrayType::const_iterator it = data.find(makeKey(i, j));
1068 
1069  if (it == data.end())
1070  return zero;
1071 
1072  return it->second;
1073  }
1074 
1080  {
1081  return data.size();
1082  }
1083 
1088  bool isEmpty() const
1089  {
1090  return (size1 == 0 || size2 == 0);
1091  }
1092 
1098  {
1099  return size1;
1100  }
1101 
1107  {
1108  return size2;
1109  }
1110 
1115  typename ArrayType::size_type getMaxSize() const
1116  {
1117  return data.max_size();
1118  }
1119 
1125  {
1126  return data;
1127  }
1128 
1133  const ArrayType& getData() const
1134  {
1135  return data;
1136  }
1137 
1144  {
1145  data = m.data;
1146  size1 = m.size1;
1147  size2 = m.size2;
1148  return *this;
1149  }
1150 
1157  {
1158  swap(m);
1159  return *this;
1160  }
1161 
1168  template <typename C>
1170  {
1171  return assign(c);
1172  }
1173 
1180  {
1181  return assign(l);
1182  }
1183 
1190  template <typename E>
1192  {
1193  SparseMatrix tmp(e);
1194  swap(tmp);
1195  return *this;
1196  }
1197 
1204  template <typename C>
1206  {
1207  return plusAssign(c);
1208  }
1209 
1216  {
1217  return plusAssign(l);
1218  }
1219 
1226  template <typename E>
1228  {
1229  SparseMatrix tmp(*this + e);
1230  swap(tmp);
1231  return *this;
1232  }
1233 
1240  template <typename C>
1242  {
1243  return minusAssign(c);
1244  }
1245 
1252  {
1253  return minusAssign(l);
1254  }
1255 
1262  template <typename E>
1264  {
1265  SparseMatrix tmp(*this - e);
1266  swap(tmp);
1267  return *this;
1268  }
1269 
1276  template <typename T1>
1277  typename std::enable_if<IsScalar<T1>::value, SparseMatrix>::type& operator*=(const T1& t)
1278  {
1279  matrixAssignScalar<ScalarMultiplicationAssignment>(*this, t);
1280  return *this;
1281  }
1282 
1289  template <typename T1>
1290  typename std::enable_if<IsScalar<T1>::value, SparseMatrix>::type& operator/=(const T1& t)
1291  {
1292  matrixAssignScalar<ScalarDivisionAssignment>(*this, t);
1293  return *this;
1294  }
1295 
1302  template <typename E>
1304  {
1305  resize(e().getSize1(), e().getSize2());
1306  matrixAssignMatrix<ScalarAssignment>(*this, e);
1307  return *this;
1308  }
1309 
1316  {
1318  resize(ilm.getSize1(), ilm.getSize2());
1319  matrixAssignMatrix<ScalarAssignment>(*this, ilm);
1320  return *this;
1321  }
1322 
1329  template <typename E>
1331  {
1332  matrixAssignMatrix<ScalarAdditionAssignment>(*this, e);
1333  return *this;
1334  }
1335 
1342  {
1343  matrixAssignMatrix<ScalarAdditionAssignment>(*this, InitListMatrix<ValueType>(l));
1344  return *this;
1345  }
1346 
1353  template <typename E>
1355  {
1356  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, e);
1357  return *this;
1358  }
1359 
1366  {
1367  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, InitListMatrix<ValueType>(l));
1368  return *this;
1369  }
1370 
1376  {
1377  if (this != &m) {
1378  std::swap(data, m.data);
1379  std::swap(size1, m.size1);
1380  std::swap(size2, m.size2);
1381  }
1382  }
1383 
1389  friend void swap(SparseMatrix& m1, SparseMatrix& m2)
1390  {
1391  m1.swap(m2);
1392  }
1393 
1397  void clear()
1398  {
1399  data.clear();
1400  }
1401 
1409  {
1410  CDPL_MATH_CHECK((n == 0 || m <= data.max_size() / n), "Maximum size exceeded", Base::SizeError);
1411 
1412  for (typename ArrayType::iterator it = data.begin(); it != data.end();) {
1413  const KeyType& key = it->first;
1414 
1415  if (getRowIdx(key) >= m || getColIdx(key) >= n)
1416  it = data.erase(it);
1417  else
1418  ++it;
1419  }
1420 
1421  size1 = m;
1422  size2 = n;
1423  }
1424 
1425  private:
1426  static KeyType makeKey(SizeType i, SizeType j)
1427  {
1428  return ((KeyType(i) << (sizeof(SizeType) * 8)) + j);
1429  }
1430 
1431  static SizeType getRowIdx(const KeyType& key)
1432  {
1433  return (key >> (sizeof(SizeType) * 8));
1434  }
1435 
1436  static SizeType getColIdx(const KeyType& key)
1437  {
1438  return (key & KeyType(~SizeType()));
1439  }
1440 
1441  SizeType size1;
1442  SizeType size2;
1443  ArrayType data;
1444  static const ValueType zero;
1445  };
1446 
1447  template <typename T, typename A>
1448  const typename SparseMatrix<T, A>::ValueType SparseMatrix<T, A>::zero = SparseMatrix<T, A>::ValueType();
1449 
1450  template <typename T, std::size_t N>
1451  class BoundedVector;
1452 
1459  template <typename T, std::size_t M, std::size_t N>
1460  class BoundedMatrix : public MatrixContainer<BoundedMatrix<T, M, N> >
1461  {
1462 
1464 
1465  public:
1467  typedef T ValueType;
1469  typedef T& Reference;
1471  typedef const T& ConstReference;
1473  typedef std::size_t SizeType;
1475  typedef std::ptrdiff_t DifferenceType;
1477  typedef ValueType ArrayType[M][N];
1479  typedef T (*ArrayPointer)[N];
1481  typedef const T (*ConstArrayPointer)[N];
1483  typedef T* Pointer;
1485  typedef const T* ConstPointer;
1495  typedef std::shared_ptr<SelfType> SharedPointer;
1497  typedef std::initializer_list<std::initializer_list<T> > InitializerListType;
1498 
1500  static const SizeType MaxSize1 = M;
1502  static const SizeType MaxSize2 = N;
1503 
1508  size1(0), size2(0) {}
1509 
1517  size1(0), size2(0)
1518  {
1519  resize(m, n);
1520  }
1521 
1530  size1(0), size2(0)
1531  {
1532  resize(m, n, v);
1533  }
1534 
1540  size1(m.size1), size2(m.size2)
1541  {
1542  for (SizeType i = 0; i < size1; i++)
1543  std::copy(m.data[i], m.data[i] + size2, data[i]);
1544  }
1545 
1552  size1(0), size2(0)
1553  {
1554  assign(l);
1555  }
1556 
1563  template <typename E>
1565  size1(0), size2(0)
1566  {
1567  resize(e().getSize1(), e().getSize2());
1568  matrixAssignMatrix<ScalarAssignment>(*this, e);
1569  }
1570 
1579  {
1580  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
1581  return data[i][j];
1582  }
1583 
1592  {
1593  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
1594  return data[i][j];
1595  }
1596 
1601  bool isEmpty() const
1602  {
1603  return (size1 == 0 || size2 == 0);
1604  }
1605 
1611  {
1612  return size1;
1613  }
1614 
1620  {
1621  return size2;
1622  }
1623 
1629  {
1630  return M;
1631  }
1632 
1638  {
1639  return N;
1640  }
1641 
1647  {
1648  return data;
1649  }
1650 
1656  {
1657  return data;
1658  }
1659 
1666  {
1667  if (this != &m) {
1668  for (SizeType i = 0; i < m.size1; i++)
1669  std::copy(m.data[i], m.data[i] + m.size2, data[i]);
1670 
1671  size1 = m.size1;
1672  size2 = m.size2;
1673  }
1674 
1675  return *this;
1676  }
1677 
1684  template <typename C>
1686  {
1687  return assign(c);
1688  }
1689 
1697  {
1698  return assign(l);
1699  }
1700 
1708  template <typename E>
1710  {
1711  BoundedMatrix tmp(e);
1712  return this-> operator=(tmp);
1713  }
1714 
1721  template <typename C>
1723  {
1724  return plusAssign(c);
1725  }
1726 
1733  {
1734  return plusAssign(l);
1735  }
1736 
1743  template <typename E>
1745  {
1746  BoundedMatrix tmp(*this + e);
1747  return this-> operator=(tmp);
1748  }
1749 
1756  template <typename C>
1758  {
1759  return minusAssign(c);
1760  }
1761 
1768  {
1769  return minusAssign(l);
1770  }
1771 
1778  template <typename E>
1780  {
1781  BoundedMatrix tmp(*this - e);
1782  return this-> operator=(tmp);
1783  }
1784 
1791  template <typename T1>
1792  typename std::enable_if<IsScalar<T1>::value, BoundedMatrix>::type& operator*=(const T1& v)
1793  {
1794  matrixAssignScalar<ScalarMultiplicationAssignment>(*this, v);
1795  return *this;
1796  }
1797 
1804  template <typename T1>
1805  typename std::enable_if<IsScalar<T1>::value, BoundedMatrix>::type& operator/=(const T1& v)
1806  {
1807  matrixAssignScalar<ScalarDivisionAssignment>(*this, v);
1808  return *this;
1809  }
1810 
1818  template <typename E>
1820  {
1821  resize(e().getSize1(), e().getSize2());
1822  matrixAssignMatrix<ScalarAssignment>(*this, e);
1823  return *this;
1824  }
1825 
1833  {
1835  resize(ilm.getSize1(), ilm.getSize2());
1836  matrixAssignMatrix<ScalarAssignment>(*this, ilm);
1837  return *this;
1838  }
1839 
1846  template <typename E>
1848  {
1849  matrixAssignMatrix<ScalarAdditionAssignment>(*this, e);
1850  return *this;
1851  }
1852 
1859  {
1860  matrixAssignMatrix<ScalarAdditionAssignment>(*this, InitListMatrix<ValueType>(l));
1861  return *this;
1862  }
1863 
1870  template <typename E>
1872  {
1873  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, e);
1874  return *this;
1875  }
1876 
1883  {
1884  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, InitListMatrix<ValueType>(l));
1885  return *this;
1886  }
1887 
1893  {
1894  if (this != &m) {
1895  SizeType max_size1 = std::max(size1, m.size1);
1896  SizeType max_size2 = std::max(size2, m.size2);
1897 
1898  for (SizeType i = 0; i < max_size1; i++)
1899  std::swap_ranges(data[i], data[i] + max_size2, m.data[i]);
1900 
1901  std::swap(size1, m.size1);
1902  std::swap(size2, m.size2);
1903  }
1904  }
1905 
1911  friend void swap(BoundedMatrix& m1, BoundedMatrix& m2)
1912  {
1913  m1.swap(m2);
1914  }
1915 
1920  void clear(const ValueType& v = ValueType())
1921  {
1922  for (SizeType i = 0; i < size1; i++)
1923  std::fill(data[i], data[i] + size2, v);
1924  }
1925 
1933  {
1936 
1937  size1 = m;
1938  size2 = n;
1939  }
1940 
1948  void resize(SizeType m, SizeType n, const ValueType& v)
1949  {
1952 
1953  if (n > size2) {
1954  SizeType min_size1 = std::min(size1, m);
1955 
1956  for (SizeType i = 0; i < min_size1; i++)
1957  std::fill(data[i] + size2, data[i] + n, v);
1958  }
1959 
1960  if (m > size1)
1961  for (SizeType i = size1; i < m; i++)
1962  std::fill(data[i], data[i] + n, v);
1963 
1964  size1 = m;
1965  size2 = n;
1966  }
1967 
1968  private:
1969  SizeType size1;
1970  SizeType size2;
1971  ArrayType data;
1972  };
1973 
1974  template <typename T, std::size_t M, std::size_t N>
1976  template <typename T, std::size_t M, std::size_t N>
1978 
1985  template <typename T, std::size_t M, std::size_t N>
1986  class CMatrix : public MatrixContainer<CMatrix<T, M, N> >
1987  {
1988 
1989  typedef CMatrix<T, M, N> SelfType;
1990 
1991  public:
1993  typedef T ValueType;
1995  typedef T& Reference;
1997  typedef const T& ConstReference;
1999  typedef std::size_t SizeType;
2001  typedef std::ptrdiff_t DifferenceType;
2003  typedef ValueType ArrayType[M][N];
2005  typedef T (*ArrayPointer)[N];
2007  typedef const T (*ConstArrayPointer)[N];
2009  typedef T* Pointer;
2011  typedef const T* ConstPointer;
2021  typedef std::shared_ptr<SelfType> SharedPointer;
2023  typedef std::initializer_list<std::initializer_list<T> > InitializerListType;
2024 
2026  static const SizeType Size1 = M;
2028  static const SizeType Size2 = N;
2029 
2034  {
2035  for (SizeType i = 0; i < M; i++)
2036  std::fill(data[i], data[i] + N, ValueType());
2037  }
2038 
2043  explicit CMatrix(const ValueType& v)
2044  {
2045  for (SizeType i = 0; i < M; i++)
2046  std::fill(data[i], data[i] + N, v);
2047  }
2048 
2054  {
2055  for (SizeType i = 0; i < M; i++)
2056  std::copy(m.data[i], m.data[i] + N, data[i]);
2057  }
2058 
2064  {
2065  assign(l);
2066  }
2067 
2073  template <typename E>
2075  {
2076  matrixAssignMatrix<ScalarAssignment>(*this, e);
2077  }
2078 
2087  {
2088  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
2089  return data[i][j];
2090  }
2091 
2100  {
2101  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
2102  return data[i][j];
2103  }
2104 
2109  bool isEmpty() const
2110  {
2111  return (M == 0 || N == 0);
2112  }
2113 
2119  {
2120  return M;
2121  }
2122 
2128  {
2129  return N;
2130  }
2131 
2137  {
2138  return M;
2139  }
2140 
2146  {
2147  return N;
2148  }
2149 
2155  {
2156  return data;
2157  }
2158 
2164  {
2165  return data;
2166  }
2167 
2174  {
2175  if (this != &m) {
2176  for (SizeType i = 0; i < M; i++)
2177  std::copy(m.data[i], m.data[i] + N, data[i]);
2178  }
2179 
2180  return *this;
2181  }
2182 
2189  template <typename C>
2191  {
2192  return assign(c);
2193  }
2194 
2200  template <typename T1>
2202  {
2203  return assign(l);
2204  }
2205 
2212  template <typename E>
2214  {
2215  CMatrix tmp(e);
2216  return this->operator=(tmp);
2217  }
2218 
2225  template <typename C>
2227  {
2228  return plusAssign(c);
2229  }
2230 
2237  {
2238  return plusAssign(l);
2239  }
2240 
2247  template <typename E>
2249  {
2250  CMatrix tmp(*this + e);
2251  return this->operator=(tmp);
2252  }
2253 
2260  template <typename C>
2262  {
2263  return minusAssign(c);
2264  }
2265 
2272  {
2273  return minusAssign(l);
2274  }
2275 
2282  template <typename E>
2284  {
2285  CMatrix tmp(*this - e);
2286  return this->operator=(tmp);
2287  }
2288 
2295  template <typename T1>
2296  typename std::enable_if<IsScalar<T1>::value, CMatrix>::type& operator*=(const T1& t)
2297  {
2298  matrixAssignScalar<ScalarMultiplicationAssignment>(*this, t);
2299  return *this;
2300  }
2301 
2308  template <typename T1>
2309  typename std::enable_if<IsScalar<T1>::value, CMatrix>::type& operator/=(const T1& t)
2310  {
2311  matrixAssignScalar<ScalarDivisionAssignment>(*this, t);
2312  return *this;
2313  }
2314 
2321  template <typename E>
2323  {
2324  matrixAssignMatrix<ScalarAssignment>(*this, e);
2325  return *this;
2326  }
2327 
2335  {
2337 
2338  for (SizeType i = 0; i < n_rows; i++) {
2339  const auto& row = *(l.begin() + i);
2340 
2341  if (row.size() < N) {
2342  std::copy(row.begin(), row.end(), data[i]);
2343  std::fill(data[i] + row.size(), data[i] + N, ValueType());
2344 
2345  } else {
2347  std::copy(row.begin(), row.begin() + N, data[i]);
2348  }
2349  }
2350 
2351  for (SizeType i = n_rows; i < M; i++)
2352  std::fill(data[i], data[i] + N, ValueType());
2353 
2354  return *this;
2355  }
2356 
2363  template <typename E>
2365  {
2366  matrixAssignMatrix<ScalarAdditionAssignment>(*this, e);
2367  return *this;
2368  }
2369 
2376  {
2377  matrixAssignMatrix<ScalarAdditionAssignment>(*this, InitListMatrix<ValueType>(l));
2378  return *this;
2379  }
2380 
2387  template <typename E>
2389  {
2390  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, e);
2391  return *this;
2392  }
2393 
2400  {
2401  matrixAssignMatrix<ScalarSubtractionAssignment>(*this, InitListMatrix<ValueType>(l));
2402  return *this;
2403  }
2404 
2409  void swap(CMatrix& m)
2410  {
2411  if (this != &m) {
2412  for (SizeType i = 0; i < M; i++)
2413  std::swap_ranges(data[i], data[i] + N, m.data[i]);
2414  }
2415  }
2416 
2422  friend void swap(CMatrix& m1, CMatrix& m2)
2423  {
2424  m1.swap(m2);
2425  }
2426 
2431  void clear(const ValueType& v = ValueType())
2432  {
2433  for (SizeType i = 0; i < M; i++)
2434  std::fill(data[i], data[i] + N, v);
2435  }
2436 
2437  private:
2438  ArrayType data;
2439  };
2440 
2441  template <typename T, std::size_t M, std::size_t N>
2443  template <typename T, std::size_t M, std::size_t N>
2445 
2450  template <typename T>
2451  class ZeroMatrix : public MatrixContainer<ZeroMatrix<T> >
2452  {
2453 
2454  typedef ZeroMatrix<T> SelfType;
2455 
2456  public:
2458  typedef T ValueType;
2460  typedef const T& Reference;
2462  typedef const T& ConstReference;
2464  typedef std::size_t SizeType;
2466  typedef std::ptrdiff_t DifferenceType;
2475 
2480  size1(0), size2(0) {}
2481 
2488  size1(m), size2(n) {}
2489 
2495  size1(m.size1), size2(m.size2) {}
2496 
2505  {
2506  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
2507  return zero;
2508  }
2509 
2514  bool isEmpty() const
2515  {
2516  return (size1 == 0 || size2 == 0);
2517  }
2518 
2524  {
2525  return size1;
2526  }
2527 
2533  {
2534  return size2;
2535  }
2536 
2542  {
2543  return std::numeric_limits<SizeType>::max();
2544  }
2545 
2551  {
2552  return std::numeric_limits<SizeType>::max();
2553  }
2554 
2561  {
2562  if (this != &m) {
2563  size1 = m.size1;
2564  size2 = m.size2;
2565  }
2566 
2567  return *this;
2568  }
2569 
2575  {
2576  if (this != &m) {
2577  std::swap(size1, m.size1);
2578  std::swap(size2, m.size2);
2579  }
2580  }
2581 
2587  friend void swap(ZeroMatrix& m1, ZeroMatrix& m2)
2588  {
2589  m1.swap(m2);
2590  }
2591 
2598  {
2599  size1 = m;
2600  size2 = n;
2601  }
2602 
2603  private:
2604  SizeType size1;
2605  SizeType size2;
2606  static const ValueType zero;
2607  };
2608 
2609  template <typename T>
2610  const typename ZeroMatrix<T>::ValueType ZeroMatrix<T>::zero = ZeroMatrix<T>::ValueType();
2611 
2616  template <typename T>
2617  class ScalarMatrix : public MatrixContainer<ScalarMatrix<T> >
2618  {
2619 
2620  typedef ScalarMatrix<T> SelfType;
2621 
2622  public:
2624  typedef T ValueType;
2626  typedef const T& Reference;
2628  typedef const T& ConstReference;
2630  typedef std::size_t SizeType;
2632  typedef std::ptrdiff_t DifferenceType;
2641 
2646  size1(0), size2(0), value() {}
2647 
2655  size1(m), size2(n), value(v) {}
2656 
2662  size1(m.size1), size2(m.size2), value(m.value) {}
2663 
2672  {
2673  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
2674  return value;
2675  }
2676 
2681  bool isEmpty() const
2682  {
2683  return (size1 == 0 || size2 == 0);
2684  }
2685 
2691  {
2692  return size1;
2693  }
2694 
2700  {
2701  return size2;
2702  }
2703 
2709  {
2710  return std::numeric_limits<SizeType>::max();
2711  }
2712 
2718  {
2719  return std::numeric_limits<SizeType>::max();
2720  }
2721 
2728  {
2729  if (this != &m) {
2730  size1 = m.size1;
2731  size2 = m.size2;
2732  value = m.value;
2733  }
2734 
2735  return *this;
2736  }
2737 
2743  {
2744  if (this != &m) {
2745  std::swap(size1, m.size1);
2746  std::swap(size2, m.size2);
2747  std::swap(value, m.value);
2748  }
2749  }
2750 
2756  friend void swap(ScalarMatrix& m1, ScalarMatrix& m2)
2757  {
2758  m1.swap(m2);
2759  }
2760 
2767  {
2768  size1 = m;
2769  size2 = n;
2770  }
2771 
2772  private:
2773  SizeType size1;
2774  SizeType size2;
2775  ValueType value;
2776  };
2777 
2782  template <typename T>
2783  class IdentityMatrix : public MatrixContainer<IdentityMatrix<T> >
2784  {
2785 
2786  typedef IdentityMatrix<T> SelfType;
2787 
2788  public:
2790  typedef T ValueType;
2792  typedef const T& Reference;
2794  typedef const T& ConstReference;
2796  typedef std::size_t SizeType;
2798  typedef std::ptrdiff_t DifferenceType;
2807 
2812  size1(0), size2(0) {}
2813 
2820  size1(m), size2(n) {}
2821 
2827  size1(m.size1), size2(m.size2) {}
2828 
2837  {
2838  CDPL_MATH_CHECK(i < getSize1() && j < getSize2(), "Index out of range", Base::IndexError);
2839  return (i == j ? one : zero);
2840  }
2841 
2846  bool isEmpty() const
2847  {
2848  return (size1 == 0 || size2 == 0);
2849  }
2850 
2856  {
2857  return size1;
2858  }
2859 
2865  {
2866  return size2;
2867  }
2868 
2874  {
2875  return std::numeric_limits<SizeType>::max();
2876  }
2877 
2883  {
2884  return std::numeric_limits<SizeType>::max();
2885  }
2886 
2893  {
2894  if (this != &m) {
2895  size1 = m.size1;
2896  size2 = m.size2;
2897  }
2898 
2899  return *this;
2900  }
2901 
2907  {
2908  if (this != &m) {
2909  std::swap(size1, m.size1);
2910  std::swap(size2, m.size2);
2911  }
2912  }
2913 
2919  friend void swap(IdentityMatrix& m1, IdentityMatrix& m2)
2920  {
2921  m1.swap(m2);
2922  }
2923 
2930  {
2931  size1 = m;
2932  size2 = n;
2933  }
2934 
2935  private:
2936  SizeType size1;
2937  SizeType size2;
2938  static const ValueType zero;
2939  static const ValueType one;
2940  };
2941 
2942  template <typename T>
2943  const typename IdentityMatrix<T>::ValueType IdentityMatrix<T>::zero = IdentityMatrix<T>::ValueType();
2944  template <typename T>
2945  const typename IdentityMatrix<T>::ValueType IdentityMatrix<T>::one = IdentityMatrix<T>::ValueType(1);
2946 
2951  template <typename M>
2953  {};
2954 
2959  template <typename M>
2961  {};
2962 
2967  template <typename M>
2969  {};
2970 
2975  template <typename M>
2977  {};
2978 
2985  template <typename E>
2986  typename E::ValueType
2988  {
2989  typedef typename E::ValueType ValueType;
2990  typedef typename Matrix<ValueType>::SizeType SizeType;
2991 
2992  Matrix<ValueType> lu(e);
2993  std::vector<SizeType> pv(lu.getSize1());
2994  std::size_t num_row_swaps;
2995 
2996  luDecompose(lu, pv, num_row_swaps);
2997 
2998  ValueType res(1);
2999  SizeType size = std::min(lu.getSize1(), lu.getSize2());
3000 
3001  for (SizeType i = 0; i < size; i++)
3002  res *= lu(i, i);
3003 
3004  return (num_row_swaps % 2 == 0 ? res : -res);
3005  }
3006 
3013  template <typename C>
3014  typename C::ValueType
3016  {
3017  typedef typename C::ValueType ValueType;
3018  typedef typename MatrixTemporaryTraits<C>::Type CTemporaryType;
3019  typedef typename CTemporaryType::SizeType SizeType;
3020 
3021  CTemporaryType lu(c);
3022  std::vector<SizeType> pv(lu.getSize1());
3023  std::size_t num_row_swaps;
3024 
3025  luDecompose(lu, pv, num_row_swaps);
3026 
3027  ValueType res(1);
3028  SizeType size = std::min(lu.getSize1(), lu.getSize2());
3029 
3030  for (SizeType i = 0; i < size; i++)
3031  res *= lu(i, i);
3032 
3033  return (num_row_swaps % 2 == 0 ? res : -res);
3034  }
3035 
3044  template <typename E, typename C>
3045  bool
3047  {
3048  typedef typename C::ValueType ValueType;
3049  typedef typename MatrixTemporaryTraits<C>::Type CTemporaryType;
3050  typedef typename CTemporaryType::SizeType SizeType;
3051 
3052  CTemporaryType lu(e);
3053  std::vector<SizeType> pv(lu.getSize1());
3054  std::size_t num_row_swaps;
3055 
3056  if (luDecompose(lu, pv, num_row_swaps) > 0)
3057  return false;
3058 
3059  c().assign(IdentityMatrix<ValueType>(lu.getSize1(), lu.getSize2()));
3060 
3061  return luSubstitute(lu, pv, c);
3062  }
3063 
3070  template <typename C>
3071  bool
3073  {
3074  return invert(c, c);
3075  }
3076 
3081 
3086 
3091 
3096 
3101 
3106 
3111 
3116 
3121 
3126 
3131 
3136 
3141 
3146 
3151 
3156 
3161 
3166 
3171 
3176 
3181 
3186 
3191 
3196 
3201 
3206 
3211 
3216 
3221 
3226 
3231 
3236  } // namespace Math
3237 } // namespace CDPL
3238 
3239 #endif // CDPL_MATH_MATRIX_HPP
Definition of exception classes.
Definition of various preprocessor macros for error checking.
#define CDPL_MATH_CHECK_MAX_SIZE(size, max_size, e)
Throws the exception e if size exceeds max_size, otherwise returns std::min(size, max_size).
Definition: Check.hpp:96
#define CDPL_MATH_CHECK(expr, msg, e)
Throws the exception e with message msg when the boolean expression expr evaluates to false.
Definition: Check.hpp:47
Definition of a proxy type for direct assignment of vector and matrix expressions.
Definition of various functors.
Implementation of matrix LU-decomposition and associated operations.
Implementation of matrix assignment routines.
Definition of various matrix expression types and operations.
Definition of an element proxy for sparse data types.
Definition of type traits.
Thrown to indicate that an index is out of range.
Definition: Base/Exceptions.hpp:152
Thrown to indicate that the size of a (multidimensional) array is not correct.
Definition: Base/Exceptions.hpp:133
Variable-size matrix with fixed upper capacities M N stored in a stack-allocated array.
Definition: Matrix.hpp:1461
BoundedMatrix & operator-=(InitializerListType l)
Subtracts the rows in l element-wise from this bounded matrix.
Definition: Matrix.hpp:1767
std::initializer_list< std::initializer_list< T > > InitializerListType
The initializer-list-of-rows type accepted by constructors and assignment.
Definition: Matrix.hpp:1497
SizeType getSize1() const
Returns the current row count.
Definition: Matrix.hpp:1610
T(* ArrayPointer)[N]
Pointer-to-row type for raw access to the element array.
Definition: Matrix.hpp:1479
SizeType getSize2() const
Returns the current column count.
Definition: Matrix.hpp:1619
BoundedMatrix(const BoundedMatrix &m)
Constructs a copy of the bounded matrix m.
Definition: Matrix.hpp:1539
T * Pointer
Pointer type to a single element.
Definition: Matrix.hpp:1483
friend void swap(BoundedMatrix &m1, BoundedMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:1911
BoundedMatrix & operator=(InitializerListType l)
Assigns the rows in l to this bounded matrix (resizes to match, respecting the bounds).
Definition: Matrix.hpp:1696
void clear(const ValueType &v=ValueType())
Sets every element of the matrix to the value v (dimensions unchanged).
Definition: Matrix.hpp:1920
BoundedMatrix & operator+=(const MatrixContainer< C > &c)
Adds the contents of the matrix container c element-wise to this bounded matrix (no alias check neede...
Definition: Matrix.hpp:1722
void swap(BoundedMatrix &m)
Swaps the contents of this bounded matrix with those of m.
Definition: Matrix.hpp:1892
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:1489
std::enable_if< IsScalar< T1 >::value, BoundedMatrix >::type & operator*=(const T1 &v)
Multiplies every element by the scalar v.
Definition: Matrix.hpp:1792
BoundedMatrix & minusAssign(InitializerListType l)
Subtracts the rows in l element-wise from this matrix without intermediate temporary.
Definition: Matrix.hpp:1882
std::enable_if< IsScalar< T1 >::value, BoundedMatrix >::type & operator/=(const T1 &v)
Divides every element by the scalar v.
Definition: Matrix.hpp:1805
std::size_t SizeType
The unsigned size type.
Definition: Matrix.hpp:1473
BoundedMatrix & operator-=(const MatrixExpression< E > &e)
Subtracts the matrix expression e element-wise from this bounded matrix (via a temporary to handle al...
Definition: Matrix.hpp:1779
static const SizeType MaxSize1
The compile-time maximum number of rows M.
Definition: Matrix.hpp:1500
BoundedMatrix & operator=(const MatrixExpression< E > &e)
Assigns the matrix expression e to this bounded matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:1709
const T & ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:1471
const T(* ConstArrayPointer)[N]
Constant pointer-to-row type for raw access to the element array.
Definition: Matrix.hpp:1481
BoundedMatrix & operator+=(const MatrixExpression< E > &e)
Adds the matrix expression e element-wise to this bounded matrix (via a temporary to handle aliasing)...
Definition: Matrix.hpp:1744
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated BoundedMatrix instances.
Definition: Matrix.hpp:1495
BoundedMatrix(const MatrixExpression< E > &e)
Constructs a bounded matrix from the matrix expression e.
Definition: Matrix.hpp:1564
BoundedMatrix & operator-=(const MatrixContainer< C > &c)
Subtracts the contents of the matrix container c element-wise from this bounded matrix (no alias chec...
Definition: Matrix.hpp:1757
ConstArrayPointer getData() const
Returns a const pointer-to-row to the contiguous 2D element array.
Definition: Matrix.hpp:1655
BoundedMatrix & plusAssign(const MatrixExpression< E > &e)
Adds the elements of the matrix expression e to this matrix without intermediate temporary.
Definition: Matrix.hpp:1847
T & Reference
Mutable reference type to an element.
Definition: Matrix.hpp:1469
BoundedMatrix & assign(const MatrixExpression< E > &e)
Resizes this matrix to match e and assigns its elements without intermediate temporary.
Definition: Matrix.hpp:1819
void resize(SizeType m, SizeType n, const ValueType &v)
Resizes the matrix to elements; newly added cells are set to v.
Definition: Matrix.hpp:1948
BoundedMatrix(SizeType m, SizeType n, const ValueType &v)
Constructs a bounded matrix of size with every element initialized to v.
Definition: Matrix.hpp:1529
BoundedMatrix & assign(InitializerListType l)
Resizes this matrix to match l and assigns its elements.
Definition: Matrix.hpp:1832
BoundedMatrix & operator+=(InitializerListType l)
Adds the rows in l element-wise to this bounded matrix.
Definition: Matrix.hpp:1732
T ValueType
The scalar value type.
Definition: Matrix.hpp:1467
const T * ConstPointer
Constant pointer type to a single element.
Definition: Matrix.hpp:1485
BoundedMatrix & plusAssign(InitializerListType l)
Adds the rows in l element-wise to this matrix without intermediate temporary.
Definition: Matrix.hpp:1858
Reference operator()(SizeType i, SizeType j)
Returns a mutable reference to the element at (i, j).
Definition: Matrix.hpp:1578
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at (i, j).
Definition: Matrix.hpp:1591
SelfType MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:1491
BoundedVector< T, M *N > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix (a bounded vector of cap...
Definition: Matrix.hpp:1493
BoundedMatrix(InitializerListType l)
Constructs a bounded matrix from the initializer list of rows l.
Definition: Matrix.hpp:1551
BoundedMatrix()
Constructs an empty bounded matrix (zero rows, zero columns).
Definition: Matrix.hpp:1507
BoundedMatrix(SizeType m, SizeType n)
Constructs a bounded matrix of size with value-initialized elements.
Definition: Matrix.hpp:1516
static const SizeType MaxSize2
The compile-time maximum number of columns N.
Definition: Matrix.hpp:1502
ArrayPointer getData()
Returns a mutable pointer-to-row to the contiguous 2D element array.
Definition: Matrix.hpp:1646
SizeType getMaxSize2() const
Returns the compile-time maximum column count N.
Definition: Matrix.hpp:1637
void resize(SizeType m, SizeType n)
Resizes the matrix to elements (new elements are left value-uninitialized).
Definition: Matrix.hpp:1932
SizeType getMaxSize1() const
Returns the compile-time maximum row count M.
Definition: Matrix.hpp:1628
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:1487
BoundedMatrix & operator=(const MatrixContainer< C > &c)
Assigns the contents of the matrix container c to this bounded matrix (no alias check needed).
Definition: Matrix.hpp:1685
ValueType ArrayType[M][N]
The fixed-capacity 2D C-array type used for in-memory storage.
Definition: Matrix.hpp:1477
BoundedMatrix & operator=(const BoundedMatrix &m)
Copy-assigns the elements of m to this bounded matrix.
Definition: Matrix.hpp:1665
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:1475
BoundedMatrix & minusAssign(const MatrixExpression< E > &e)
Subtracts the elements of the matrix expression e from this matrix without intermediate temporary.
Definition: Matrix.hpp:1871
bool isEmpty() const
Tells whether the matrix is empty.
Definition: Matrix.hpp:1601
Variable-size vector with a fixed upper capacity N stored in a stack-allocated array.
Definition: Vector.hpp:1388
Fixed-size dense matrix of dimensions M N backed by a 2D C-array (no dynamic allocation).
Definition: Matrix.hpp:1987
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2013
T * Pointer
Pointer type to a single element.
Definition: Matrix.hpp:2009
CMatrix & operator-=(const MatrixContainer< C > &c)
Subtracts the contents of the matrix container c element-wise from this fixed-size matrix (no alias c...
Definition: Matrix.hpp:2261
CMatrix & operator=(InitializerListType l)
Assigns the rows in l to this fixed-size matrix (clipped or zero-padded to M N).
Definition: Matrix.hpp:2201
SizeType getSize2() const
Returns the fixed column count N.
Definition: Matrix.hpp:2127
CMatrix & assign(InitializerListType l)
Assigns the rows in l to this fixed-size matrix (clipped or zero-padded to M N).
Definition: Matrix.hpp:2334
ValueType ArrayType[M][N]
The fixed-size 2D C-array type used for in-memory storage of M N elements.
Definition: Matrix.hpp:2003
ConstArrayPointer getData() const
Returns a const pointer-to-row to the contiguous 2D element array.
Definition: Matrix.hpp:2163
ArrayPointer getData()
Returns a mutable pointer-to-row to the contiguous 2D element array.
Definition: Matrix.hpp:2154
std::initializer_list< std::initializer_list< T > > InitializerListType
The initializer-list-of-rows type accepted by constructors and assignment.
Definition: Matrix.hpp:2023
T(* ArrayPointer)[N]
Pointer-to-row type for raw access to the element array.
Definition: Matrix.hpp:2005
CMatrix & operator+=(const MatrixExpression< E > &e)
Adds the matrix expression e element-wise to this fixed-size matrix (via a temporary to handle aliasi...
Definition: Matrix.hpp:2248
BoundedVector< T, M *N > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix.
Definition: Matrix.hpp:2019
CMatrix & minusAssign(const MatrixExpression< E > &e)
Subtracts the elements of the matrix expression e from this matrix without intermediate temporary.
Definition: Matrix.hpp:2388
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at (i, j).
Definition: Matrix.hpp:2099
CMatrix(const ValueType &v)
Constructs an matrix with every element initialized to v.
Definition: Matrix.hpp:2043
CMatrix()
Constructs a zero-initialized matrix.
Definition: Matrix.hpp:2033
std::enable_if< IsScalar< T1 >::value, CMatrix >::type & operator*=(const T1 &t)
Multiplies every element by the scalar t.
Definition: Matrix.hpp:2296
Reference operator()(SizeType i, SizeType j)
Returns a mutable reference to the element at (i, j).
Definition: Matrix.hpp:2086
void clear(const ValueType &v=ValueType())
Sets every element of the matrix to the value v.
Definition: Matrix.hpp:2431
std::size_t SizeType
The unsigned size type.
Definition: Matrix.hpp:1999
CMatrix(const MatrixExpression< E > &e)
Constructs a fixed-size matrix from the matrix expression e.
Definition: Matrix.hpp:2074
CMatrix(InitializerListType l)
Constructs a fixed-size matrix with the contents of the initializer list of rows l.
Definition: Matrix.hpp:2063
CMatrix & operator-=(InitializerListType l)
Subtracts the rows in l element-wise from this fixed-size matrix.
Definition: Matrix.hpp:2271
bool isEmpty() const
Tells whether the matrix is empty (M or N is zero).
Definition: Matrix.hpp:2109
T ValueType
The scalar value type.
Definition: Matrix.hpp:1993
std::enable_if< IsScalar< T1 >::value, CMatrix >::type & operator/=(const T1 &t)
Divides every element by the scalar t.
Definition: Matrix.hpp:2309
const T * ConstPointer
Constant pointer type to a single element.
Definition: Matrix.hpp:2011
void swap(CMatrix &m)
Swaps the contents of this fixed-size matrix with those of m.
Definition: Matrix.hpp:2409
CMatrix & operator=(const CMatrix &m)
Copy-assigns the elements of m to this fixed-size matrix.
Definition: Matrix.hpp:2173
CMatrix & operator=(const MatrixContainer< C > &c)
Assigns the contents of the matrix container c to this fixed-size matrix (no alias check needed).
Definition: Matrix.hpp:2190
const T(* ConstArrayPointer)[N]
Constant pointer-to-row type for raw access to the element array.
Definition: Matrix.hpp:2007
SizeType getMaxSize1() const
Returns the fixed row count M (capacity equals size for Math::CMatrix).
Definition: Matrix.hpp:2136
SizeType getMaxSize2() const
Returns the fixed column count N (capacity equals size for Math::CMatrix).
Definition: Matrix.hpp:2145
CMatrix & operator+=(InitializerListType l)
Adds the rows in l element-wise to this fixed-size matrix.
Definition: Matrix.hpp:2236
static const SizeType Size1
The compile-time fixed row count M.
Definition: Matrix.hpp:2026
CMatrix & plusAssign(InitializerListType l)
Adds the rows in l element-wise to this matrix without intermediate temporary.
Definition: Matrix.hpp:2375
CMatrix & operator-=(const MatrixExpression< E > &e)
Subtracts the matrix expression e element-wise from this fixed-size matrix (via a temporary to handle...
Definition: Matrix.hpp:2283
const T & ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:1997
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated CMatrix instances.
Definition: Matrix.hpp:2021
CMatrix(const CMatrix &m)
Constructs a copy of the fixed-size matrix m.
Definition: Matrix.hpp:2053
CMatrix & assign(const MatrixExpression< E > &e)
Assigns the elements of the matrix expression e to this fixed-size matrix without intermediate tempor...
Definition: Matrix.hpp:2322
friend void swap(CMatrix &m1, CMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:2422
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2015
SizeType getSize1() const
Returns the fixed row count M.
Definition: Matrix.hpp:2118
CMatrix & operator+=(const MatrixContainer< C > &c)
Adds the contents of the matrix container c element-wise to this fixed-size matrix (no alias check ne...
Definition: Matrix.hpp:2226
T & Reference
Mutable reference type to an element.
Definition: Matrix.hpp:1995
BoundedMatrix< T, M, N > MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery (a Math::BoundedMatrix of equal ...
Definition: Matrix.hpp:2017
CMatrix & minusAssign(InitializerListType l)
Subtracts the rows in l element-wise from this matrix without intermediate temporary.
Definition: Matrix.hpp:2399
CMatrix & operator=(const MatrixExpression< E > &e)
Assigns the matrix expression e to this fixed-size matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:2213
CMatrix & plusAssign(const MatrixExpression< E > &e)
Adds the elements of the matrix expression e to this matrix without intermediate temporary.
Definition: Matrix.hpp:2364
static const SizeType Size2
The compile-time fixed column count N.
Definition: Matrix.hpp:2028
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:2001
Constant identity-matrix expression ( on the diagonal, elsewhere).
Definition: Matrix.hpp:2784
SizeType getMaxSize2() const
Returns the maximum representable column count.
Definition: Matrix.hpp:2882
T ValueType
The scalar value type.
Definition: Matrix.hpp:2790
IdentityMatrix & operator=(const IdentityMatrix &m)
Copy-assigns the dimensions from m.
Definition: Matrix.hpp:2892
const T & Reference
Reference type (always a const reference — elements are immutable).
Definition: Matrix.hpp:2792
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to either 1 (if i equals j) or 0.
Definition: Matrix.hpp:2836
void resize(SizeType m, SizeType n)
Resizes the dimensions to .
Definition: Matrix.hpp:2929
IdentityMatrix(SizeType m, SizeType n)
Constructs an identity matrix of size (1 on the diagonal, 0 elsewhere).
Definition: Matrix.hpp:2819
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2802
SizeType getMaxSize1() const
Returns the maximum representable row count.
Definition: Matrix.hpp:2873
bool isEmpty() const
Tells whether the matrix is empty.
Definition: Matrix.hpp:2846
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2800
SizeType getSize1() const
Returns the logical number of rows.
Definition: Matrix.hpp:2855
friend void swap(IdentityMatrix &m1, IdentityMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:2919
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:2798
IdentityMatrix()
Constructs an empty identity matrix.
Definition: Matrix.hpp:2811
Matrix< T > MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:2804
IdentityMatrix(const IdentityMatrix &m)
Constructs a copy of the identity matrix m.
Definition: Matrix.hpp:2826
std::size_t SizeType
The unsigned size type.
Definition: Matrix.hpp:2796
void swap(IdentityMatrix &m)
Swaps the dimensions with m.
Definition: Matrix.hpp:2906
SizeType getSize2() const
Returns the logical number of columns.
Definition: Matrix.hpp:2864
const T & ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:2794
Vector< T, std::vector< T > > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix.
Definition: Matrix.hpp:2806
Lightweight matrix container that wraps a nested std::initializer_list of T values.
Definition: Matrix.hpp:338
Matrix< T, std::vector< T > > MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:360
std::initializer_list< std::initializer_list< T > > InitializerListType
The nested std::initializer_list type wrapped by this matrix.
Definition: Matrix.hpp:344
SizeType getSize2() const
Returns the number of columns (the longest row length).
Definition: Matrix.hpp:425
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:354
Reference operator()(SizeType i, SizeType j)
Returns a mutable reference to the element at row i and column j.
Definition: Matrix.hpp:385
InitializerListType::value_type::reference Reference
Mutable reference type to an element.
Definition: Matrix.hpp:350
bool isEmpty() const
Tells whether the matrix is empty (zero rows or zero columns).
Definition: Matrix.hpp:434
InitListMatrix(InitializerListType l)
Constructs an InitListMatrix wrapping the nested initializer list l.
Definition: Matrix.hpp:371
InitListMatrix SelfType
Convenience alias for this instantiation.
Definition: Matrix.hpp:342
Vector< T, std::vector< T > > VectorTemporaryType
Concrete temporary vector type used by expression-template machinery.
Definition: Matrix.hpp:362
InitializerListType::value_type::const_reference ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:348
SelfType ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:356
const SelfType ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:358
InitializerListType::size_type SizeType
The unsigned size type.
Definition: Matrix.hpp:352
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at row i and column j.
Definition: Matrix.hpp:402
InitializerListType::value_type::value_type ValueType
The scalar value type.
Definition: Matrix.hpp:346
SizeType getSize1() const
Returns the number of rows.
Definition: Matrix.hpp:416
Refinement of Math::MatrixExpression marking the derived type as a concrete (writable) matrix contain...
Definition: Expression.hpp:250
CRTP base class for all matrix expression types.
Definition: Expression.hpp:104
Lightweight matrix expression that proxies a reference to an underlying matrix container.
Definition: Matrix.hpp:64
M::ConstReference ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:78
Reference operator()(SizeType i, SizeType j)
Returns a mutable reference to the element at (i, j).
Definition: Matrix.hpp:101
MatrixReference & operator=(const MatrixReference &r)
Copy-assigns the wrapped matrix from the matrix referenced by r.
Definition: Matrix.hpp:194
std::conditional< std::is_const< M >::value, typename M::ConstReference, typename M::Reference >::type Reference
Mutable reference type (degrades to ConstReference when the wrapped matrix is const).
Definition: Matrix.hpp:76
bool isEmpty() const
Tells whether the wrapped matrix is empty.
Definition: Matrix.hpp:166
MatrixReference & assign(const MatrixExpression< E > &e)
Assigns the matrix expression e to the wrapped matrix without intermediate temporary.
Definition: Matrix.hpp:272
const MatrixType & getData() const
Returns a const reference to the wrapped matrix.
Definition: Matrix.hpp:175
friend void swap(MatrixReference &r1, MatrixReference &r2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:318
std::enable_if< IsScalar< T >::value, MatrixReference >::type & operator*=(const T &t)
Multiplies every element of the wrapped matrix by the scalar t.
Definition: Matrix.hpp:246
SizeType getMaxSize() const
Returns the wrapped matrix's maximum total element count.
Definition: Matrix.hpp:139
M::SizeType SizeType
The unsigned size type of the wrapped matrix.
Definition: Matrix.hpp:80
MatrixReference & operator-=(const MatrixExpression< E > &e)
Subtracts the matrix expression e element-wise from the wrapped matrix.
Definition: Matrix.hpp:233
SizeType getMaxSize1() const
Returns the wrapped matrix's maximum number of rows.
Definition: Matrix.hpp:148
MatrixReference & operator=(const MatrixExpression< E > &e)
Assigns the matrix expression e to the wrapped matrix.
Definition: Matrix.hpp:207
std::enable_if< IsScalar< T >::value, MatrixReference >::type & operator/=(const T &t)
Divides every element of the wrapped matrix by the scalar t.
Definition: Matrix.hpp:259
MatrixReference & operator+=(const MatrixExpression< E > &e)
Adds the matrix expression e element-wise to the wrapped matrix.
Definition: Matrix.hpp:220
SizeType getSize1() const
Returns the wrapped matrix's number of rows.
Definition: Matrix.hpp:121
const SelfType ConstClosureType
Constant closure type used when this proxy appears inside another expression.
Definition: Matrix.hpp:86
MatrixReference & minusAssign(const MatrixExpression< E > &e)
Subtracts the matrix expression e from the wrapped matrix without intermediate temporary.
Definition: Matrix.hpp:298
MatrixReference(MatrixType &m)
Constructs the reference proxy referring to m.
Definition: Matrix.hpp:92
SizeType getSize2() const
Returns the wrapped matrix's number of columns.
Definition: Matrix.hpp:130
MatrixReference & plusAssign(const MatrixExpression< E > &e)
Adds the matrix expression e to the wrapped matrix without intermediate temporary.
Definition: Matrix.hpp:285
SelfType ClosureType
Closure type used when this proxy appears inside another expression.
Definition: Matrix.hpp:84
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at (i, j).
Definition: Matrix.hpp:112
M::ValueType ValueType
The element value type of the wrapped matrix.
Definition: Matrix.hpp:72
M MatrixType
The wrapped matrix type.
Definition: Matrix.hpp:70
void swap(MatrixReference &r)
Swaps the contents of the two wrapped matrices.
Definition: Matrix.hpp:308
M::DifferenceType DifferenceType
The signed difference type of the wrapped matrix.
Definition: Matrix.hpp:82
SizeType getMaxSize2() const
Returns the wrapped matrix's maximum number of columns.
Definition: Matrix.hpp:157
MatrixType & getData()
Returns a reference to the wrapped matrix.
Definition: Matrix.hpp:184
Dynamically-sized dense row-major matrix with configurable underlying storage.
Definition: Matrix.hpp:455
A::size_type SizeType
The unsigned size type used by the underlying storage container.
Definition: Matrix.hpp:467
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:477
Matrix(SizeType m, SizeType n, const ValueType &v)
Constructs an m × n matrix with every element initialized to v.
Definition: Matrix.hpp:509
std::enable_if< IsScalar< T1 >::value, Matrix >::type & operator/=(const T1 &t)
Divides every element by the scalar t.
Definition: Matrix.hpp:787
SizeType getSize2() const
Returns the number of columns.
Definition: Matrix.hpp:603
Matrix(const MatrixExpression< E > &e)
Constructs the matrix from the matrix expression e (materializing the expression result).
Definition: Matrix.hpp:549
Matrix & operator+=(InitializerListType l)
Adds the rows in l element-wise to this matrix.
Definition: Matrix.hpp:712
std::enable_if< IsScalar< T1 >::value, Matrix >::type & operator*=(const T1 &t)
Multiplies every element by the scalar t.
Definition: Matrix.hpp:774
SizeType getSize1() const
Returns the number of rows.
Definition: Matrix.hpp:594
bool isEmpty() const
Tells whether the matrix is empty.
Definition: Matrix.hpp:585
Matrix & operator=(const MatrixExpression< E > &e)
Assigns the matrix expression e to this matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:688
Matrix(Matrix &&m)
Move-constructs a matrix from m (m is left in a valid empty state).
Definition: Matrix.hpp:523
Matrix(const Matrix &m)
Constructs a copy of the matrix m.
Definition: Matrix.hpp:516
Matrix & assign(InitializerListType l)
Resizes this matrix to match l and assigns its elements.
Definition: Matrix.hpp:812
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Matrix instances.
Definition: Matrix.hpp:485
Vector< T, A > VectorTemporaryType
Concrete temporary vector type compatible with this matrix's value type and storage.
Definition: Matrix.hpp:483
const ArrayType & getData() const
Returns a const reference to the underlying storage container (row-major linear layout).
Definition: Matrix.hpp:630
Matrix & operator-=(const MatrixExpression< E > &e)
Subtracts the matrix expression e element-wise from this matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:760
Matrix & operator=(const MatrixContainer< C > &c)
Assigns the contents of the matrix container c to this matrix (no alias check needed).
Definition: Matrix.hpp:666
Matrix()
Constructs an empty matrix (zero rows and zero columns).
Definition: Matrix.hpp:492
Matrix(InitializerListType l)
Constructs the matrix from a brace-initializer list of rows.
Definition: Matrix.hpp:537
const T & ConstReference
Constant reference type to an element.
Definition: Matrix.hpp:465
Matrix & plusAssign(InitializerListType l)
Adds the rows in l element-wise to this matrix without intermediate temporary.
Definition: Matrix.hpp:838
const T * ConstPointer
Constant pointer type for raw element access.
Definition: Matrix.hpp:475
Matrix & operator-=(const MatrixContainer< C > &c)
Subtracts the contents of the matrix container c element-wise from this matrix (no alias check needed...
Definition: Matrix.hpp:738
SizeType getMaxSize() const
Returns the maximum total element count the underlying storage container can hold.
Definition: Matrix.hpp:612
T * Pointer
Pointer type for raw element access.
Definition: Matrix.hpp:473
Reference operator()(SizeType i, SizeType j)
Returns a mutable reference to the element at (i, j).
Definition: Matrix.hpp:562
SelfType MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:481
friend void swap(Matrix &m1, Matrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:886
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at (i, j).
Definition: Matrix.hpp:575
void swap(Matrix &m)
Swaps the contents of this matrix with those of m.
Definition: Matrix.hpp:872
Matrix & assign(const MatrixExpression< E > &e)
Resizes this matrix to match the dimensions of e and assigns its elements (without intermediate tempo...
Definition: Matrix.hpp:800
Matrix & operator-=(InitializerListType l)
Subtracts the rows in l element-wise from this matrix.
Definition: Matrix.hpp:748
Matrix & operator=(Matrix &&m)
Move-assigns the contents of m to this matrix.
Definition: Matrix.hpp:653
A ArrayType
The underlying storage container type (row-major linear storage).
Definition: Matrix.hpp:471
void resize(SizeType m, SizeType n, bool preserve=true, const ValueType &v=ValueType())
Resizes the matrix to elements.
Definition: Matrix.hpp:907
Matrix & operator=(const Matrix &m)
Copy-assigns the contents of m to this matrix.
Definition: Matrix.hpp:640
Matrix & operator=(InitializerListType l)
Assigns the rows in l to this matrix (resizes to match).
Definition: Matrix.hpp:676
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:479
std::initializer_list< std::initializer_list< T > > InitializerListType
Type of the brace-initializer list of lists accepted by the corresponding constructor (one inner list...
Definition: Matrix.hpp:487
Matrix & plusAssign(const MatrixExpression< E > &e)
Adds the elements of the matrix expression e to this matrix without intermediate temporary.
Definition: Matrix.hpp:827
T & Reference
Mutable reference type to an element.
Definition: Matrix.hpp:463
Matrix & operator+=(const MatrixExpression< E > &e)
Adds the matrix expression e element-wise to this matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:724
T ValueType
The scalar value type stored in the matrix.
Definition: Matrix.hpp:461
Matrix(SizeType m, SizeType n)
Constructs an m × n matrix with default-initialized elements.
Definition: Matrix.hpp:500
ArrayType & getData()
Returns a mutable reference to the underlying storage container (row-major linear layout).
Definition: Matrix.hpp:621
Matrix & minusAssign(InitializerListType l)
Subtracts the rows in l element-wise from this matrix without intermediate temporary.
Definition: Matrix.hpp:862
A::difference_type DifferenceType
The signed difference type used by the underlying storage container.
Definition: Matrix.hpp:469
Matrix & minusAssign(const MatrixExpression< E > &e)
Subtracts the elements of the matrix expression e from this matrix without intermediate temporary.
Definition: Matrix.hpp:851
Matrix & operator+=(const MatrixContainer< C > &c)
Adds the contents of the matrix container c element-wise to this matrix (no alias check needed).
Definition: Matrix.hpp:702
void clear(const ValueType &v=ValueType())
Sets every element of the matrix to the value v.
Definition: Matrix.hpp:895
Constant matrix expression in which every entry equals the same scalar value.
Definition: Matrix.hpp:2618
std::size_t SizeType
The unsigned size type.
Definition: Matrix.hpp:2630
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:2632
SizeType getMaxSize2() const
Returns the maximum representable column count.
Definition: Matrix.hpp:2717
SizeType getSize2() const
Returns the logical number of columns.
Definition: Matrix.hpp:2699
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the common entry value.
Definition: Matrix.hpp:2671
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2636
ScalarMatrix(const ScalarMatrix &m)
Constructs a copy of the scalar matrix m.
Definition: Matrix.hpp:2661
void swap(ScalarMatrix &m)
Swaps the dimensions and common value with m.
Definition: Matrix.hpp:2742
const T & ConstReference
Constant reference type to the common value.
Definition: Matrix.hpp:2628
friend void swap(ScalarMatrix &m1, ScalarMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:2756
SizeType getSize1() const
Returns the logical number of rows.
Definition: Matrix.hpp:2690
Vector< T, std::vector< T > > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix.
Definition: Matrix.hpp:2640
SizeType getMaxSize1() const
Returns the maximum representable row count.
Definition: Matrix.hpp:2708
void resize(SizeType m, SizeType n)
Resizes the dimensions to .
Definition: Matrix.hpp:2766
T ValueType
The scalar value type.
Definition: Matrix.hpp:2624
bool isEmpty() const
Tells whether the matrix is empty.
Definition: Matrix.hpp:2681
ScalarMatrix()
Constructs an empty scalar matrix.
Definition: Matrix.hpp:2645
Matrix< T > MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:2638
ScalarMatrix & operator=(const ScalarMatrix &m)
Copy-assigns the dimensions and common value from m.
Definition: Matrix.hpp:2727
ScalarMatrix(SizeType m, SizeType n, const ValueType &v=ValueType())
Constructs a scalar matrix of size in which every entry equals v.
Definition: Matrix.hpp:2654
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2634
const T & Reference
Reference type (always a const reference — elements are immutable).
Definition: Matrix.hpp:2626
Proxy that exposes a single (key, value) entry of a sparse container as a writable reference.
Definition: SparseContainerElement.hpp:52
Sparse matrix that stores only non-default entries keyed by a packed (row, column) identifier.
Definition: Matrix.hpp:947
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:973
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:963
ArrayType::size_type getMaxSize() const
Returns the maximum number of stored entries the underlying associative container can hold.
Definition: Matrix.hpp:1115
SparseMatrix & operator=(const MatrixExpression< E > &e)
Assigns the matrix expression e to this sparse matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:1191
std::enable_if< IsScalar< T1 >::value, SparseMatrix >::type & operator*=(const T1 &t)
Multiplies every stored entry by the scalar t.
Definition: Matrix.hpp:1277
const T * ConstPointer
Constant pointer type for raw access to stored entries.
Definition: Matrix.hpp:969
SparseContainerElement< SelfType > Reference
Mutable reference type (a proxy object that inserts on assignment to a previously-absent cell).
Definition: Matrix.hpp:957
SparseMatrix & operator=(const SparseMatrix &m)
Copy-assigns the contents of m to this sparse matrix.
Definition: Matrix.hpp:1143
T ValueType
The scalar value type.
Definition: Matrix.hpp:953
const T & ConstReference
Constant reference type to a stored element value.
Definition: Matrix.hpp:959
void resize(SizeType m, SizeType n)
Resizes the logical dimensions to , dropping any stored entries that fall outside the new bounds.
Definition: Matrix.hpp:1408
SparseMatrix & assign(InitializerListType l)
Resizes this matrix to match l and assigns its elements.
Definition: Matrix.hpp:1315
Reference operator()(SizeType i, SizeType j)
Returns a mutable proxy reference to the element at (i, j).
Definition: Matrix.hpp:1049
SparseMatrix()
Constructs an empty sparse matrix (zero rows, zero columns, no stored entries).
Definition: Matrix.hpp:986
void clear()
Removes all explicitly stored entries (the logical dimensions remain unchanged).
Definition: Matrix.hpp:1397
std::initializer_list< std::initializer_list< T > > InitializerListType
The initializer-list-of-rows type accepted by constructors and assignment.
Definition: Matrix.hpp:981
SizeType getSize1() const
Returns the logical number of rows.
Definition: Matrix.hpp:1097
SparseMatrix & operator=(SparseMatrix &&m)
Move-assigns the contents of m to this sparse matrix.
Definition: Matrix.hpp:1156
SelfType MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:975
SparseMatrix & operator+=(InitializerListType l)
Adds the rows in l element-wise to this sparse matrix.
Definition: Matrix.hpp:1215
SparseMatrix & minusAssign(InitializerListType l)
Subtracts the rows in l element-wise from this matrix without intermediate temporary.
Definition: Matrix.hpp:1365
void swap(SparseMatrix &m)
Swaps the contents of this sparse matrix with those of m.
Definition: Matrix.hpp:1375
SparseMatrix(SizeType m, SizeType n)
Constructs a sparse matrix of size with no stored entries.
Definition: Matrix.hpp:995
std::enable_if< IsScalar< T1 >::value, SparseMatrix >::type & operator/=(const T1 &t)
Divides every stored entry by the scalar t.
Definition: Matrix.hpp:1290
SparseMatrix & operator-=(const MatrixExpression< E > &e)
Subtracts the matrix expression e element-wise from this sparse matrix (via a temporary to handle ali...
Definition: Matrix.hpp:1263
SparseMatrix(const SparseMatrix &m)
Constructs a copy of the sparse matrix m.
Definition: Matrix.hpp:1005
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the element at (i, j).
Definition: Matrix.hpp:1063
SparseMatrix & assign(const MatrixExpression< E > &e)
Resizes this matrix to match e and assigns its elements without intermediate temporary.
Definition: Matrix.hpp:1303
const ArrayType & getData() const
Returns a const reference to the underlying associative container of stored entries.
Definition: Matrix.hpp:1133
SparseMatrix & operator-=(InitializerListType l)
Subtracts the rows in l element-wise from this sparse matrix.
Definition: Matrix.hpp:1251
SparseMatrix(SparseMatrix &&m)
Move-constructs a sparse matrix from m (m is left in a valid empty state).
Definition: Matrix.hpp:1012
A ArrayType
The underlying associative container type.
Definition: Matrix.hpp:965
SizeType getSize2() const
Returns the logical number of columns.
Definition: Matrix.hpp:1106
T * Pointer
Pointer type for raw access to stored entries.
Definition: Matrix.hpp:967
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:971
std::shared_ptr< SelfType > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SparseMatrix instances.
Definition: Matrix.hpp:979
SparseMatrix & operator-=(const MatrixContainer< C > &c)
Subtracts the contents of the matrix container c element-wise from this sparse matrix (no alias check...
Definition: Matrix.hpp:1241
SparseMatrix(InitializerListType l)
Constructs a sparse matrix from the initializer list of rows l.
Definition: Matrix.hpp:1022
SparseMatrix & operator=(InitializerListType l)
Assigns the rows in l to this sparse matrix (resizes to match).
Definition: Matrix.hpp:1179
SparseMatrix & plusAssign(const MatrixExpression< E > &e)
Adds the elements of the matrix expression e to this matrix without intermediate temporary.
Definition: Matrix.hpp:1330
SparseMatrix & plusAssign(InitializerListType l)
Adds the rows in l element-wise to this matrix without intermediate temporary.
Definition: Matrix.hpp:1341
friend void swap(SparseMatrix &m1, SparseMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:1389
SparseMatrix & operator+=(const MatrixContainer< C > &c)
Adds the contents of the matrix container c element-wise to this sparse matrix (no alias check needed...
Definition: Matrix.hpp:1205
SizeType getNumElements() const
Returns the number of explicitly stored (non-default) entries.
Definition: Matrix.hpp:1079
ArrayType & getData()
Returns a mutable reference to the underlying associative container of stored entries.
Definition: Matrix.hpp:1124
Vector< T, std::vector< T > > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix.
Definition: Matrix.hpp:977
SparseMatrix(const MatrixExpression< E > &e)
Constructs a sparse matrix from the matrix expression e.
Definition: Matrix.hpp:1035
SparseMatrix & operator+=(const MatrixExpression< E > &e)
Adds the matrix expression e element-wise to this sparse matrix (via a temporary to handle aliasing).
Definition: Matrix.hpp:1227
SparseMatrix & minusAssign(const MatrixExpression< E > &e)
Subtracts the elements of the matrix expression e from this matrix without intermediate temporary.
Definition: Matrix.hpp:1354
bool isEmpty() const
Tells whether the matrix is empty (zero rows or zero columns).
Definition: Matrix.hpp:1088
A::key_type KeyType
The packed (row, column) key type used by the underlying associative container.
Definition: Matrix.hpp:955
std::uint32_t SizeType
The unsigned size type.
Definition: Matrix.hpp:961
SparseMatrix & operator=(const MatrixContainer< C > &c)
Assigns the contents of the matrix container c to this sparse matrix (no alias check needed).
Definition: Matrix.hpp:1169
Dynamically-sized dense vector with configurable underlying storage.
Definition: Vector.hpp:430
Constant matrix expression whose entries are all zero.
Definition: Matrix.hpp:2452
friend void swap(ZeroMatrix &m1, ZeroMatrix &m2)
ADL-enabled free-function form of swap().
Definition: Matrix.hpp:2587
T ValueType
The scalar value type.
Definition: Matrix.hpp:2458
std::ptrdiff_t DifferenceType
The signed difference type.
Definition: Matrix.hpp:2466
const T & ConstReference
Constant reference type to the zero element.
Definition: Matrix.hpp:2462
SizeType getSize1() const
Returns the logical number of rows.
Definition: Matrix.hpp:2523
SizeType getMaxSize2() const
Returns the maximum representable column count.
Definition: Matrix.hpp:2550
ConstReference operator()(SizeType i, SizeType j) const
Returns a const reference to the zero element.
Definition: Matrix.hpp:2504
Vector< T, std::vector< T > > VectorTemporaryType
Concrete temporary vector type used when assembling vectors from this matrix.
Definition: Matrix.hpp:2474
bool isEmpty() const
Tells whether the matrix is empty (either dimension is zero).
Definition: Matrix.hpp:2514
const T & Reference
Reference type (always a const reference — all elements are zero).
Definition: Matrix.hpp:2460
SizeType getSize2() const
Returns the logical number of columns.
Definition: Matrix.hpp:2532
void swap(ZeroMatrix &m)
Swaps the dimensions with m.
Definition: Matrix.hpp:2574
void resize(SizeType m, SizeType n)
Resizes the dimensions to .
Definition: Matrix.hpp:2597
const MatrixReference< const SelfType > ConstClosureType
Constant closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2470
ZeroMatrix & operator=(const ZeroMatrix &m)
Copy-assigns the dimensions from m.
Definition: Matrix.hpp:2560
Matrix< T > MatrixTemporaryType
Concrete temporary matrix type used by expression-template machinery.
Definition: Matrix.hpp:2472
SizeType getMaxSize1() const
Returns the maximum representable row count.
Definition: Matrix.hpp:2541
ZeroMatrix(const ZeroMatrix &m)
Constructs a copy of the zero matrix m.
Definition: Matrix.hpp:2494
ZeroMatrix()
Constructs an empty zero matrix.
Definition: Matrix.hpp:2479
MatrixReference< SelfType > ClosureType
Closure type used when this matrix appears inside another expression.
Definition: Matrix.hpp:2468
std::size_t SizeType
The unsigned size type.
Definition: Matrix.hpp:2464
ZeroMatrix(SizeType m, SizeType n)
Constructs a zero matrix of size .
Definition: Matrix.hpp:2487
constexpr unsigned int A
Generic type that covers any element except hydrogen.
Definition: AtomType.hpp:637
constexpr unsigned int M
Generic type that covers any element that is a metal.
Definition: AtomType.hpp:657
constexpr unsigned int N
Specifies Nitrogen.
Definition: AtomType.hpp:97
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int r
Specifies that the stereocenter has r configuration.
Definition: CIPDescriptor.hpp:76
constexpr unsigned int m
Specifies that the stereocenter has m configuration.
Definition: CIPDescriptor.hpp:116
CMatrix< long, 2, 2 > Matrix2L
Bounded 2x2 matrix holding signed integers of type long.
Definition: Matrix.hpp:3190
CMatrix< float, 3, 3 > Matrix3F
Bounded 3x3 matrix holding floating point values of type float.
Definition: Matrix.hpp:3165
ZeroMatrix< double > DZeroMatrix
Memory-efficient immutable matrix where all elements have the value zero of type double.
Definition: Matrix.hpp:3085
bool luSubstitute(const MatrixExpression< E1 > &lu, VectorExpression< E2 > &b)
Solves for b in place, given the LU decomposition lu (without pivoting).
Definition: LUDecomposition.hpp:195
CMatrix< unsigned long, 3, 3 > Matrix3UL
Bounded 3x3 matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3210
Matrix< double > DMatrix
Unbounded dense matrix holding floating point values of type double..
Definition: Matrix.hpp:3145
ScalarMatrix< float > FScalarMatrix
Memory-efficient immutable matrix where all elements have the same value of type float.
Definition: Matrix.hpp:3100
ZeroMatrix< long > LZeroMatrix
Memory-efficient immutable matrix where all elements have the value zero of type long.
Definition: Matrix.hpp:3090
ScalarMatrix< double > DScalarMatrix
Memory-efficient immutable matrix where all elements have the same value of type double.
Definition: Matrix.hpp:3105
SparseMatrix< unsigned long > SparseULMatrix
Unbounded sparse matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3235
ZeroMatrix< float > FZeroMatrix
Memory-efficient immutable matrix where all elements have the value zero of type float.
Definition: Matrix.hpp:3080
IdentityMatrix< double > DIdentityMatrix
Memory-efficient immutable identity matrix with element values of type double.
Definition: Matrix.hpp:3125
CMatrix< long, 3, 3 > Matrix3L
Bounded 3x3 matrix holding signed integers of type long.
Definition: Matrix.hpp:3195
Matrix< unsigned long > ULMatrix
Unbounded dense matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3155
CMatrix< double, 2, 2 > Matrix2D
Bounded 2x2 matrix holding floating point values of type double.
Definition: Matrix.hpp:3175
SparseMatrix< float > SparseFMatrix
Unbounded sparse matrix holding floating point values of type float..
Definition: Matrix.hpp:3220
IdentityMatrix< long > LIdentityMatrix
Memory-efficient immutable identity matrix with element values of type long.
Definition: Matrix.hpp:3130
MatrixRow< M > row(MatrixExpression< M > &e, typename MatrixRow< M >::SizeType i)
Returns a mutable row proxy for row i of the matrix expression e.
Definition: MatrixProxy.hpp:1231
E::ValueType det(const MatrixExpression< E > &e)
Returns the determinant of the matrix expression e.
Definition: Matrix.hpp:2987
CMatrix< unsigned long, 4, 4 > Matrix4UL
Bounded 4x4 matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3215
CMatrix< double, 4, 4 > Matrix4D
Bounded 4x4 matrix holding floating point values of type double.
Definition: Matrix.hpp:3185
SparseMatrix< long > SparseLMatrix
Unbounded sparse matrix holding signed integers of type long.
Definition: Matrix.hpp:3230
CMatrix< float, 4, 4 > Matrix4F
Bounded 4x4 matrix holding floating point values of type float.
Definition: Matrix.hpp:3170
Matrix< long > LMatrix
Unbounded dense matrix holding signed integers of type long.
Definition: Matrix.hpp:3150
Matrix< float > FMatrix
Unbounded dense matrix holding floating point values of type float..
Definition: Matrix.hpp:3140
IdentityMatrix< unsigned long > ULIdentityMatrix
Memory-efficient immutable identity matrix with element values of type unsigned long.
Definition: Matrix.hpp:3135
ZeroMatrix< unsigned long > ULZeroMatrix
Memory-efficient immutable matrix where all elements have the value zero of type unsigned long.
Definition: Matrix.hpp:3095
CMatrix< long, 4, 4 > Matrix4L
Bounded 4x4 matrix holding signed integers of type long.
Definition: Matrix.hpp:3200
CMatrix< double, 3, 3 > Matrix3D
Bounded 3x3 matrix holding floating point values of type double.
Definition: Matrix.hpp:3180
SparseMatrix< double > SparseDMatrix
Unbounded sparse matrix holding floating point values of type double..
Definition: Matrix.hpp:3225
ScalarMatrix< unsigned long > ULScalarMatrix
Memory-efficient immutable matrix where all elements have the same value of type unsigned long.
Definition: Matrix.hpp:3115
IdentityMatrix< float > FIdentityMatrix
Memory-efficient immutable identity matrix with element values of type float.
Definition: Matrix.hpp:3120
bool invert(const MatrixExpression< E > &e, MatrixContainer< C > &c)
Computes the inverse of the matrix expression e and stores it in c.
Definition: Matrix.hpp:3046
E::SizeType luDecompose(MatrixExpression< E > &e)
Computes an in-place LU decomposition of the matrix e without partial pivoting.
Definition: LUDecomposition.hpp:51
CMatrix< unsigned long, 2, 2 > Matrix2UL
Bounded 2x2 matrix holding unsigned integers of type unsigned long.
Definition: Matrix.hpp:3205
CMatrix< float, 2, 2 > Matrix2F
Bounded 2x2 matrix holding floating point values of type float.
Definition: Matrix.hpp:3160
ScalarMatrix< long > LScalarMatrix
Memory-efficient immutable matrix where all elements have the same value of type long.
Definition: Matrix.hpp:3110
The namespace of the Chemical Data Processing Library.
Selects a concrete temporary matrix type compatible with the matrix expression M.
Definition: TypeTraits.hpp:313
M::MatrixTemporaryType Type
The concrete temporary matrix type compatible with the matrix expression M.
Definition: TypeTraits.hpp:316
Selects a concrete temporary vector type compatible with the vector expression V.
Definition: TypeTraits.hpp:301