Linear Algebra  arduino
Accessible implementations of linear algebra algorithms
Matrix.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <algorithm> // std::fill, std::transform
6 #include <cassert> // assert
7 #include <cmath> // std::sqrt
8 #include <functional> // std::plus, std::minus
9 #include <numeric> // std::inner_product
10 #include <utility> // std::swap
11 #include <vector> // std::vector
12 
13 #ifndef NO_IOSTREAM_SUPPORT
14 #include <iosfwd> // std::ostream
15 #endif
16 
17 #ifndef NO_RANDOM_SUPPORT
18 #include <random> // std::uniform_real_distribution
19 #endif
20 
21 using std::size_t;
22 
23 #include "util/MatrixStorage.hpp"
24 
25 #ifndef COL_MAJ_ORDER
26 #define COL_MAJ_ORDER 1
27 #endif
28 
31 
32 #ifndef NO_ARDUINO_PRINT_SUPPORT
34 class Matrix : public Printable {
35 #else
36 class Matrix {
37 #endif
38 
41 
42  protected:
44  explicit Matrix(storage_t &&storage, size_t rows, size_t cols);
46  explicit Matrix(const storage_t &storage, size_t rows, size_t cols);
47 
48  public:
51 
53  Matrix() = default;
54 
56  Matrix(size_t rows, size_t cols);
57 
59  Matrix(std::initializer_list<std::initializer_list<double>> init);
61  Matrix &
62  operator=(std::initializer_list<std::initializer_list<double>> init);
63 
65  Matrix(const Matrix &) = default;
67  Matrix(Matrix &&);
68 
70  Matrix &operator=(const Matrix &) = default;
72  Matrix &operator=(Matrix &&);
73 
75 
76  public:
79 
81  size_t rows() const { return rows_; }
83  size_t cols() const { return cols_; }
85  size_t num_elems() const { return storage.size(); }
86 
90  void reshape(size_t newrows, size_t newcols);
93  Matrix reshaped(size_t newrows, size_t newcols) const;
94 
96 
97  public:
100 
102  double &operator()(size_t row, size_t col);
104  const double &operator()(size_t row, size_t col) const;
105 
107  double &operator()(size_t index) { return storage[index]; }
109  const double &operator()(size_t index) const { return storage[index]; }
110 
112 
113  public:
116 
118  void clear_and_deallocate();
119 
121 
122  public:
125 
127  void fill(double value);
128 
131  void fill_identity();
132 
133 #ifndef NO_RANDOM_SUPPORT
135  void fill_random(double min = 0, double max = 1,
136  std::default_random_engine::result_type seed =
137  std::default_random_engine::default_seed);
138 #endif
139 
141 
142  public:
145 
147  static Matrix ones(size_t rows, size_t cols);
148 
150  static Matrix zeros(size_t rows, size_t cols);
151 
153  static Matrix constant(size_t rows, size_t cols, double value);
154 
156  static Matrix identity(size_t rows, size_t cols);
157 
159  static Matrix identity(size_t rows);
160 
161 #ifndef NO_RANDOM_SUPPORT
163  static Matrix random(size_t rows, size_t cols, double min = 0,
164  double max = 1,
165  std::default_random_engine::result_type seed =
166  std::default_random_engine::default_seed);
167 #endif
168 
170 
171  public:
174 
176  void swap_rows(size_t a, size_t b);
178  void swap_columns(size_t a, size_t b);
179 
181 
182  public:
185 
189  bool operator==(const Matrix &other) const;
193  bool operator!=(const Matrix &other) const { return !(*this == other); }
194 
196 
197  public:
200 
202  double normFro() const &;
204  double normFro() &&;
205 
207 
208  public:
211 
213  storage_t::iterator begin() { return storage.begin(); }
215  storage_t::const_iterator begin() const { return storage.begin(); }
217  storage_t::const_iterator cbegin() const { return storage.begin(); }
218 
220  storage_t::iterator end() { return storage.end(); }
222  storage_t::const_iterator end() const { return storage.end(); }
224  storage_t::const_iterator cend() const { return storage.end(); }
225 
227 
228  public:
231 
232 #ifndef NO_IOSTREAM_SUPPORT
242  void print(std::ostream &os, uint8_t precision = 0,
243  uint8_t width = 0) const;
244 #endif
245 
246 #ifndef NO_ARDUINO_PRINT_SUPPORT
256  void print(Print &print, uint8_t precision = 0, uint8_t width = 0) const;
257 
259  size_t printTo(Print &print) const override {
260  this->print(print);
261  return 0;
262  }
263 #endif
264 
266 
267  protected:
268  size_t rows_ = 0, cols_ = 0;
270 
271  friend class Vector;
272  friend class RowVector;
273 };
274 
275 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
276 
278 class Vector : public Matrix {
279  public:
282 
284  Vector() = default;
285 
287  Vector(size_t size) : Matrix(size, 1) {}
288 
290  Vector(std::initializer_list<double> init) { *this = init; }
291 
293  Vector &operator=(std::initializer_list<double> init);
294 
296  explicit Vector(const Matrix &matrix);
298  explicit Vector(Matrix &&matrix);
299 
301 
302  public:
305 
307  void resize(size_t size) { storage.resize(size); }
308 
310  size_t size() const { return num_elems(); }
311 
313  void reshape(size_t, size_t) = delete;
315  Matrix reshaped(size_t, size_t) = delete;
316 
318 
319  public:
322 
324  static Vector ones(size_t size);
326  static Vector zeros(size_t size);
328  static Vector constant(size_t size, double value);
329 
330 #ifndef NO_RANDOM_SUPPORT
332  static Vector random(size_t size, double min = 0, double max = 1,
333  std::default_random_engine::result_type seed =
334  std::default_random_engine::default_seed);
335 #endif
336 
338 
339  public:
342 
345  static double dot_unchecked(const Matrix &a, const Matrix &b);
348  static double dot_unchecked(Matrix &&a, const Matrix &b);
351  static double dot_unchecked(const Matrix &a, Matrix &&b);
354  static double dot_unchecked(Matrix &&a, Matrix &&b);
355 
357  static double dot(const Vector &a, const Vector &b);
359  static double dot(Vector &&a, const Vector &b);
361  static double dot(const Vector &a, Vector &&b);
363  static double dot(Vector &&a, Vector &&b);
364 
366  double dot(const Vector &b) const & { return dot(*this, b); }
368  double dot(const Vector &b) && { return dot(std::move(*this), b); }
370  double dot(Vector &&b) const & { return dot(*this, std::move(b)); }
372  double dot(Vector &&b) && { return dot(std::move(*this), std::move(b)); }
373 
375 
376  public:
379 
383  static void cross_inplace_unchecked(Matrix &a, const Matrix &b);
387  static void cross_inplace_unchecked_neg(Matrix &a, const Matrix &b);
388 
391  static void cross_inplace(Vector &a, const Vector &b);
394  static void cross_inplace(Vector &a, Vector &&b);
397  static void cross_inplace_neg(Vector &a, const Vector &b);
400  static void cross_inplace_neg(Vector &a, Vector &&b);
401 
403  static Vector cross(const Vector &a, const Vector &b);
405  static Vector &&cross(Vector &&a, const Vector &b);
407  static Vector &&cross(const Vector &a, Vector &&b);
409  static Vector &&cross(Vector &&a, Vector &&b);
410 
412  Vector cross(const Vector &b) const & { return cross(*this, b); }
414  Vector &&cross(const Vector &b) && { return cross(std::move(*this), b); }
416  Vector &&cross(Vector &&b) const & { return cross(*this, std::move(b)); }
418  Vector &&cross(Vector &&b) && {
419  return cross(std::move(*this), std::move(b));
420  }
421 
423 
424  public:
427 
429  double norm2() const &;
431  double norm2() &&;
432 
434 };
435 
437 class RowVector : public Matrix {
438  public:
441 
443  RowVector() = default;
444 
446  RowVector(size_t size) : Matrix(1, size) {}
447 
449  RowVector(std::initializer_list<double> init) { *this = init; }
450 
452  RowVector &operator=(std::initializer_list<double> init);
453 
455  explicit RowVector(const Matrix &matrix);
457  explicit RowVector(Matrix &&matrix);
458 
460 
461  public:
464 
466  void resize(size_t size) { storage.resize(size); }
467 
469  size_t size() const { return num_elems(); }
470 
472  void reshape(size_t, size_t) = delete;
474  Matrix reshaped(size_t, size_t) = delete;
475 
477 
478  public:
481 
483  static RowVector ones(size_t size);
485  static RowVector zeros(size_t size);
487  static RowVector constant(size_t size, double value);
488 
489 #ifndef NO_RANDOM_SUPPORT
491  static RowVector random(size_t size, double min = 0, double max = 1,
492  std::default_random_engine::result_type seed =
493  std::default_random_engine::default_seed);
494 #endif
495 
497 
498  public:
501 
503  static double dot(const RowVector &a, const RowVector &b);
505  static double dot(RowVector &&a, const RowVector &b);
507  static double dot(const RowVector &a, RowVector &&b);
509  static double dot(RowVector &&a, RowVector &&b);
510 
512  double dot(const RowVector &b) const & { return dot(*this, b); }
514  double dot(const RowVector &b) && { return dot(std::move(*this), b); }
516  double dot(RowVector &&b) const & { return dot(*this, std::move(b)); }
518  double dot(RowVector &&b) && { return dot(std::move(*this), std::move(b)); }
519 
521 
522  public:
525 
528  static void cross_inplace(RowVector &a, const RowVector &b);
531  static void cross_inplace(RowVector &a, RowVector &&b);
534  static void cross_inplace_neg(RowVector &a, const RowVector &b);
537  static void cross_inplace_neg(RowVector &a, RowVector &&b);
538 
540  static RowVector cross(const RowVector &a, const RowVector &b);
542  static RowVector &&cross(RowVector &&a, const RowVector &b);
544  static RowVector &&cross(const RowVector &a, RowVector &&b);
546  static RowVector &&cross(RowVector &&a, RowVector &&b);
547 
549  RowVector cross(const RowVector &b) const &;
551  RowVector &&cross(const RowVector &b) &&;
553  RowVector &&cross(RowVector &&b) const &;
555  RowVector &&cross(RowVector &&b) &&;
556 
558 
559  public:
562 
564  double norm2() const &;
566  double norm2() &&;
567 
569 };
570 
572 class SquareMatrix : public Matrix {
573  public:
576 
578  SquareMatrix() = default;
579 
581  SquareMatrix(size_t size) : Matrix(size, size) {}
582 
584  SquareMatrix(std::initializer_list<std::initializer_list<double>> init);
585 
587  explicit SquareMatrix(Matrix &&matrix);
589  explicit SquareMatrix(const Matrix &matrix);
590 
592  SquareMatrix &
593  operator=(std::initializer_list<std::initializer_list<double>> init);
594 
596 
597  public:
600 
602  void reshape(size_t, size_t) = delete;
604  Matrix reshaped(size_t, size_t) = delete;
605 
607 
608  public:
611 
613  static void transpose_inplace(Matrix &A);
616 
618 
619  public:
622 
624  static SquareMatrix ones(size_t rows);
626  static SquareMatrix zeros(size_t rows);
628  static SquareMatrix constant(size_t rows, double value);
629 
631  static SquareMatrix identity(size_t rows);
632 
633 #ifndef NO_RANDOM_SUPPORT
635  static SquareMatrix random(size_t rows, double min = 0, double max = 1,
636  std::default_random_engine::result_type seed =
637  std::default_random_engine::default_seed);
638 #endif
639 
641 };
642 
644 
645 #ifndef NO_IOSTREAM_SUPPORT
648 std::ostream &operator<<(std::ostream &os, const Matrix &M);
649 #endif
650 
651 #ifndef NO_ARDUINO_PRINT_SUPPORT
654 Print &operator<<(Print &p, const Matrix &M);
655 #endif
656 
657 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
658 
661 
665 
667 Matrix operator*(const Matrix &A, const Matrix &B);
669 Matrix operator*(Matrix &&A, const Matrix &B);
671 Matrix operator*(const Matrix &A, Matrix &&B);
673 Matrix operator*(Matrix &&A, Matrix &&B);
674 
676 SquareMatrix operator*(const SquareMatrix &A, const SquareMatrix &B);
683 
685 Vector operator*(const Matrix &A, const Vector &b);
687 Vector operator*(Matrix &&A, const Vector &b);
689 Vector operator*(const Matrix &A, Vector &&b);
691 Vector operator*(Matrix &&A, Vector &&b);
692 
694 RowVector operator*(const RowVector &a, const Matrix &B);
696 RowVector operator*(RowVector &&a, const Matrix &B);
698 RowVector operator*(const RowVector &a, Matrix &&B);
701 
703 double operator*(const RowVector &a, const Vector &b);
705 double operator*(RowVector &&a, const Vector &b);
707 double operator*(const RowVector &a, Vector &&b);
709 double operator*(RowVector &&a, Vector &&b);
710 
712 
713 // -------------------------------------------------------------------------- //
714 
718 
720 Matrix operator+(const Matrix &A, const Matrix &B);
721 
722 void operator+=(Matrix &A, const Matrix &B);
723 Matrix &&operator+(Matrix &&A, const Matrix &B);
724 Matrix &&operator+(const Matrix &A, Matrix &&B);
725 Matrix &&operator+(Matrix &&A, Matrix &&B);
726 Vector &&operator+(Vector &&a, const Vector &b);
727 Vector &&operator+(const Vector &a, Vector &&b);
728 Vector &&operator+(Vector &&a, Vector &&b);
729 RowVector &&operator+(RowVector &&a, const RowVector &b);
730 RowVector &&operator+(const RowVector &a, RowVector &&b);
735 Vector operator+(const Vector &a, const Vector &b);
736 RowVector operator+(const RowVector &a, const RowVector &b);
737 SquareMatrix operator+(const SquareMatrix &a, const SquareMatrix &b);
738 
740 
741 // -------------------------------------------------------------------------- //
742 
746 
748 Matrix operator-(const Matrix &A, const Matrix &B);
749 void operator-=(Matrix &A, const Matrix &B);
750 Matrix &&operator-(Matrix &&A, const Matrix &B);
751 Matrix &&operator-(const Matrix &A, Matrix &&B);
752 Matrix &&operator-(Matrix &&A, Matrix &&B);
753 Vector &&operator-(Vector &&a, const Vector &b);
754 Vector &&operator-(const Vector &a, Vector &&b);
755 Vector &&operator-(Vector &&a, Vector &&b);
756 RowVector &&operator-(RowVector &&a, const RowVector &b);
757 RowVector &&operator-(const RowVector &a, RowVector &&b);
762 Vector operator-(const Vector &a, const Vector &b);
763 RowVector operator-(const RowVector &a, const RowVector &b);
764 SquareMatrix operator-(const SquareMatrix &a, const SquareMatrix &b);
765 
767 
768 // -------------------------------------------------------------------------- //
769 
773 
775 Matrix operator-(const Matrix &A);
776 Matrix &&operator-(Matrix &&A);
777 Vector &&operator-(Vector &&a);
780 Vector operator-(const Vector &a);
781 RowVector operator-(const RowVector &a);
783 
785 
786 // -------------------------------------------------------------------------- //
787 
791 
793 Matrix operator*(const Matrix &A, double s);
794 void operator*=(Matrix &A, double s);
795 Matrix &&operator*(Matrix &&A, double s);
796 Vector operator*(const Vector &a, double s);
797 RowVector operator*(const RowVector &a, double s);
798 SquareMatrix operator*(const SquareMatrix &a, double s);
799 Vector &&operator*(Vector &&a, double s);
800 RowVector &&operator*(RowVector &&a, double s);
801 SquareMatrix &&operator*(SquareMatrix &&a, double s);
802 
803 Matrix operator*(double s, const Matrix &A);
804 Matrix &&operator*(double s, Matrix &&A);
805 Vector operator*(double s, const Vector &a);
806 RowVector operator*(double s, const RowVector &a);
807 SquareMatrix operator*(double s, const SquareMatrix &a);
808 Vector &&operator*(double s, Vector &&a);
809 RowVector &&operator*(double s, RowVector &&a);
810 SquareMatrix &&operator*(double s, SquareMatrix &&a);
811 
813 
814 // -------------------------------------------------------------------------- //
815 
819 
821 Matrix operator/(const Matrix &A, double s);
822 void operator/=(Matrix &A, double s);
823 Matrix &&operator/(Matrix &&A, double s);
824 Vector operator/(const Vector &a, double s);
825 RowVector operator/(const RowVector &a, double s);
826 SquareMatrix operator/(const SquareMatrix &a, double s);
827 Vector &&operator/(Vector &&a, double s);
828 RowVector &&operator/(RowVector &&a, double s);
829 SquareMatrix &&operator/(SquareMatrix &&a, double s);
830 
832 
834 
835 // -------------------------------------------------------------------------- //
836 
839 
843 
845 Matrix explicit_transpose(const Matrix &in);
846 
849 Matrix transpose(const Matrix &in);
852 Matrix &&transpose(Matrix &&in);
853 
858 
860 RowVector transpose(const Vector &in);
864 Vector transpose(const RowVector &in);
867 
869 
Preprocessor logic for configuring the library to make it compatible with the Arduino environment.
General matrix class.
Definition: Matrix.hpp:34
storage_t::const_iterator begin() const
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:215
static Matrix constant(size_t rows, size_t cols, double value)
Create a matrix filled with a constant value.
Definition: Matrix.cpp:157
static Matrix identity(size_t rows, size_t cols)
Create an identity matrix.
Definition: Matrix.cpp:163
size_t printTo(Print &print) const override
Implements the Arduino Printable interface.
Definition: Matrix.hpp:259
static Matrix random(size_t rows, size_t cols, double min=0, double max=1, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Create a matrix with uniformly distributed random values.
Definition: Matrix.cpp:172
storage_t::iterator end()
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:220
Matrix & operator=(const Matrix &)=default
Default copy assignment.
std::ostream & operator<<(std::ostream &os, const Matrix &M)
Print a matrix.
Definition: Matrix.cpp:255
static Matrix zeros(size_t rows, size_t cols)
Create a matrix filled with zeros.
Definition: Matrix.cpp:152
const double & operator()(size_t index) const
Get the element at the given position in the linearized matrix.
Definition: Matrix.hpp:109
void fill_random(double min=0, double max=1, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Fill the matrix with uniformly distributed random values.
Definition: Matrix.cpp:136
friend class RowVector
Definition: Matrix.hpp:272
storage_t storage
Definition: Matrix.hpp:269
storage_t::const_iterator cend() const
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:224
size_t rows_
Definition: Matrix.hpp:268
void swap_columns(size_t a, size_t b)
Swap two columns of the matrix.
Definition: Matrix.cpp:184
Matrix reshaped(size_t newrows, size_t newcols) const
Create a reshaped copy of the matrix.
Definition: Matrix.cpp:84
bool operator==(const Matrix &other) const
Check for equality of two matrices.
Definition: Matrix.cpp:198
double & operator()(size_t row, size_t col)
Get the element at the given position in the matrix.
Definition: Matrix.cpp:94
size_t num_elems() const
Get the number of elements in the matrix:
Definition: Matrix.hpp:85
static Matrix ones(size_t rows, size_t cols)
Create a matrix filled with ones.
Definition: Matrix.cpp:148
void swap_rows(size_t a, size_t b)
Swap two rows of the matrix.
Definition: Matrix.cpp:189
friend class Vector
Definition: Matrix.hpp:271
Matrix()=default
Default constructor.
size_t rows() const
Get the number of rows of the matrix.
Definition: Matrix.hpp:81
util::storage_t< double > storage_t
Container to store the elements of the matrix internally.
Definition: Matrix.hpp:40
storage_t::const_iterator cbegin() const
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:217
void clear_and_deallocate()
Set the number of rows and columns to zero, and deallocate the storage.
Definition: Matrix.cpp:114
void reshape(size_t newrows, size_t newcols)
Reshape the matrix.
Definition: Matrix.cpp:78
double & operator()(size_t index)
Get the element at the given position in the linearized matrix.
Definition: Matrix.hpp:107
Matrix & operator=(std::initializer_list< std::initializer_list< double >> init)
Assign the given values to the matrix.
Definition: Matrix.cpp:45
Matrix(const Matrix &)=default
Default copy constructor.
void fill_identity()
Fill the matrix as an identity matrix (all zeros except the diagonal which is one).
Definition: Matrix.cpp:129
double normFro() const &
Compute the Frobenius norm of the matrix.
Definition: Matrix.cpp:219
size_t cols() const
Get the number of columns of the matrix.
Definition: Matrix.hpp:83
size_t cols_
Definition: Matrix.hpp:268
storage_t::iterator begin()
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:213
bool operator!=(const Matrix &other) const
Check for inequality of two matrices.
Definition: Matrix.hpp:193
void fill(double value)
Fill the matrix with a constant value.
Definition: Matrix.cpp:125
storage_t::const_iterator end() const
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:222
void print(std::ostream &os, uint8_t precision=0, uint8_t width=0) const
Print a matrix.
Definition: Matrix.cpp:242
A row vector (1×n matrix).
Definition: Matrix.hpp:437
size_t size() const
Get the number of elements in the vector.
Definition: Matrix.hpp:469
Matrix reshaped(size_t, size_t)=delete
Reshaping a vector to a matrix requires an explicit cast.
RowVector(std::initializer_list< double > init)
Create a row vector from the given list of values.
Definition: Matrix.hpp:449
void resize(size_t size)
Resize the vector.
Definition: Matrix.hpp:466
double dot(RowVector &&b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:516
RowVector(size_t size)
Create a row vector of the given size.
Definition: Matrix.hpp:446
double dot(const RowVector &b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:514
RowVector()=default
Default constructor.
void reshape(size_t, size_t)=delete
Reshaping a vector to a matrix requires an explicit cast.
double dot(RowVector &&b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:518
double dot(const RowVector &b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:512
Square matrix class.
Definition: Matrix.hpp:572
SquareMatrix(size_t size)
Create a square matrix of zeros.
Definition: Matrix.hpp:581
Matrix reshaped(size_t, size_t)=delete
Reshaping a square matrix to a general matrix requires an explicit cast.
SquareMatrix()=default
Default constructor.
void transpose_inplace()
Transpose the matrix in-place.
Definition: Matrix.hpp:615
void reshape(size_t, size_t)=delete
Reshaping a square matrix to a general matrix requires an explicit cast.
A column vector (n×1 matrix).
Definition: Matrix.hpp:278
double dot(const Vector &b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:368
size_t size() const
Get the number of elements in the vector.
Definition: Matrix.hpp:310
Matrix reshaped(size_t, size_t)=delete
Reshaping a vector to a matrix requires an explicit cast.
double dot(const Vector &b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:366
Vector cross(const Vector &b) const &
Compute the cross product of this 3-vector with another 3-vector.
Definition: Matrix.hpp:412
double dot(Vector &&b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:372
Vector && cross(const Vector &b) &&
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:414
Vector && cross(Vector &&b) &&
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:418
void resize(size_t size)
Resize the vector.
Definition: Matrix.hpp:307
Vector && cross(Vector &&b) const &
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:416
Vector(size_t size)
Create a column vector of the given size.
Definition: Matrix.hpp:287
Vector()=default
Default constructor.
double dot(Vector &&b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:370
void reshape(size_t, size_t)=delete
Reshaping a vector to a matrix requires an explicit cast.
Vector(std::initializer_list< double > init)
Create a column vector from the given list of values.
Definition: Matrix.hpp:290
Matrix operator+(const Matrix &A, const Matrix &B)
Matrix addition.
Definition: Matrix.cpp:720
void operator+=(Matrix &A, const Matrix &B)
Definition: Matrix.cpp:730
Matrix operator*(const Matrix &A, const Matrix &B)
Matrix multiplication.
Definition: Matrix.cpp:622
void operator-=(Matrix &A, const Matrix &B)
Definition: Matrix.cpp:820
Matrix operator-(const Matrix &A, const Matrix &B)
Matrix subtraction.
Definition: Matrix.cpp:810
Matrix transpose(const Matrix &in)
Matrix transpose for rectangular or square matrices and row or column vectors.
Definition: Matrix.cpp:1064
Matrix explicit_transpose(const Matrix &in)
Matrix transpose for general matrices.
Definition: Matrix.cpp:1050
void operator/=(Matrix &A, double s)
Definition: Matrix.cpp:1011
Matrix operator/(const Matrix &A, double s)
Scalar division.
Definition: Matrix.cpp:1003
void operator*=(Matrix &A, double s)
Definition: Matrix.cpp:953
std::vector< T > storage_t
Container to store the elements of a matrix internally.