Linear Algebra  master
Accessible implementations of linear algebra algorithms
Matrix.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm> // std::fill, std::transform
4 #include <cassert> // assert
5 #include <cmath> // std::sqrt
6 #include <functional> // std::plus, std::minus
7 #include <iosfwd> // std::ostream
8 #include <numeric> // std::inner_product
9 #include <random> // std::uniform_real_distribution
10 #include <utility> // std::swap
11 #include <vector> // std::vector
12 
13 using std::size_t;
14 
15 #include "util/MatrixStorage.hpp"
16 
17 #ifndef COL_MAJ_ORDER
18 #define COL_MAJ_ORDER 1
19 #endif
20 
23 
25 class Matrix {
26 
29 
30  protected:
32  explicit Matrix(storage_t &&storage, size_t rows, size_t cols);
34  explicit Matrix(const storage_t &storage, size_t rows, size_t cols);
35 
36  public:
39 
41  Matrix() = default;
42 
44  Matrix(size_t rows, size_t cols);
45 
47  Matrix(std::initializer_list<std::initializer_list<double>> init);
49  Matrix &
50  operator=(std::initializer_list<std::initializer_list<double>> init);
51 
53  Matrix(const Matrix &) = default;
55  Matrix(Matrix &&);
56 
58  Matrix &operator=(const Matrix &) = default;
60  Matrix &operator=(Matrix &&);
61 
63 
64  public:
67 
69  size_t rows() const { return rows_; }
71  size_t cols() const { return cols_; }
73  size_t num_elems() const { return storage.size(); }
74 
78  void reshape(size_t newrows, size_t newcols);
81  Matrix reshaped(size_t newrows, size_t newcols) const;
82 
84 
85  public:
88 
90  double &operator()(size_t row, size_t col);
92  const double &operator()(size_t row, size_t col) const;
93 
95  double &operator()(size_t index) { return storage[index]; }
97  const double &operator()(size_t index) const { return storage[index]; }
98 
100 
101  public:
104 
106  void clear_and_deallocate();
107 
109 
110  public:
113 
115  void fill(double value);
116 
119  void fill_identity();
120 
122  void fill_random(double min = 0, double max = 1,
123  std::default_random_engine::result_type seed =
124  std::default_random_engine::default_seed);
125 
127 
128  public:
131 
133  static Matrix ones(size_t rows, size_t cols);
134 
136  static Matrix zeros(size_t rows, size_t cols);
137 
139  static Matrix constant(size_t rows, size_t cols, double value);
140 
142  static Matrix identity(size_t rows, size_t cols);
143 
145  static Matrix identity(size_t rows);
146 
148  static Matrix random(size_t rows, size_t cols, double min = 0,
149  double max = 1,
150  std::default_random_engine::result_type seed =
151  std::default_random_engine::default_seed);
152 
154 
155  public:
158 
160  void swap_rows(size_t a, size_t b);
162  void swap_columns(size_t a, size_t b);
163 
165 
166  public:
169 
173  bool operator==(const Matrix &other) const;
177  bool operator!=(const Matrix &other) const { return !(*this == other); }
178 
180 
181  public:
184 
186  double normFro() const &;
188  double normFro() &&;
189 
191 
192  public:
195 
197  storage_t::iterator begin() { return storage.begin(); }
199  storage_t::const_iterator begin() const { return storage.begin(); }
201  storage_t::const_iterator cbegin() const { return storage.begin(); }
202 
204  storage_t::iterator end() { return storage.end(); }
206  storage_t::const_iterator end() const { return storage.end(); }
208  storage_t::const_iterator cend() const { return storage.end(); }
209 
211 
212  public:
215 
225  void print(std::ostream &os, uint8_t precision = 0,
226  uint8_t width = 0) const;
227 
229 
230  protected:
231  size_t rows_ = 0, cols_ = 0;
233 
234  friend class Vector;
235  friend class RowVector;
236 };
237 
238 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
239 
241 class Vector : public Matrix {
242  public:
245 
247  Vector() = default;
248 
250  Vector(size_t size) : Matrix(size, 1) {}
251 
253  Vector(std::initializer_list<double> init) { *this = init; }
254 
256  Vector &operator=(std::initializer_list<double> init);
257 
259  explicit Vector(const Matrix &matrix);
261  explicit Vector(Matrix &&matrix);
262 
264 
265  public:
268 
270  void resize(size_t size) { storage.resize(size); }
271 
273  size_t size() const { return num_elems(); }
274 
276  void reshape(size_t, size_t) = delete;
278  Matrix reshaped(size_t, size_t) = delete;
279 
281 
282  public:
285 
287  static Vector ones(size_t size);
289  static Vector zeros(size_t size);
291  static Vector constant(size_t size, double value);
293  static Vector random(size_t size, double min = 0, double max = 1,
294  std::default_random_engine::result_type seed =
295  std::default_random_engine::default_seed);
296 
298 
299  public:
302 
305  static double dot_unchecked(const Matrix &a, const Matrix &b);
308  static double dot_unchecked(Matrix &&a, const Matrix &b);
311  static double dot_unchecked(const Matrix &a, Matrix &&b);
314  static double dot_unchecked(Matrix &&a, Matrix &&b);
315 
317  static double dot(const Vector &a, const Vector &b);
319  static double dot(Vector &&a, const Vector &b);
321  static double dot(const Vector &a, Vector &&b);
323  static double dot(Vector &&a, Vector &&b);
324 
326  double dot(const Vector &b) const & { return dot(*this, b); }
328  double dot(const Vector &b) && { return dot(std::move(*this), b); }
330  double dot(Vector &&b) const & { return dot(*this, std::move(b)); }
332  double dot(Vector &&b) && { return dot(std::move(*this), std::move(b)); }
333 
335 
336  public:
339 
343  static void cross_inplace_unchecked(Matrix &a, const Matrix &b);
347  static void cross_inplace_unchecked_neg(Matrix &a, const Matrix &b);
348 
351  static void cross_inplace(Vector &a, const Vector &b);
354  static void cross_inplace(Vector &a, Vector &&b);
357  static void cross_inplace_neg(Vector &a, const Vector &b);
360  static void cross_inplace_neg(Vector &a, Vector &&b);
361 
363  static Vector cross(const Vector &a, const Vector &b);
365  static Vector &&cross(Vector &&a, const Vector &b);
367  static Vector &&cross(const Vector &a, Vector &&b);
369  static Vector &&cross(Vector &&a, Vector &&b);
370 
372  Vector cross(const Vector &b) const & { return cross(*this, b); }
374  Vector &&cross(const Vector &b) && { return cross(std::move(*this), b); }
376  Vector &&cross(Vector &&b) const & { return cross(*this, std::move(b)); }
378  Vector &&cross(Vector &&b) && {
379  return cross(std::move(*this), std::move(b));
380  }
381 
383 
384  public:
387 
389  double norm2() const &;
391  double norm2() &&;
392 
394 };
395 
397 class RowVector : public Matrix {
398  public:
401 
403  RowVector() = default;
404 
406  RowVector(size_t size) : Matrix(1, size) {}
407 
409  RowVector(std::initializer_list<double> init) { *this = init; }
410 
412  RowVector &operator=(std::initializer_list<double> init);
413 
415  explicit RowVector(const Matrix &matrix);
417  explicit RowVector(Matrix &&matrix);
418 
420 
421  public:
424 
426  void resize(size_t size) { storage.resize(size); }
427 
429  size_t size() const { return num_elems(); }
430 
432  void reshape(size_t, size_t) = delete;
434  Matrix reshaped(size_t, size_t) = delete;
435 
437 
438  public:
441 
443  static RowVector ones(size_t size);
445  static RowVector zeros(size_t size);
447  static RowVector constant(size_t size, double value);
449  static RowVector random(size_t size, double min = 0, double max = 1,
450  std::default_random_engine::result_type seed =
451  std::default_random_engine::default_seed);
452 
454 
455  public:
458 
460  static double dot(const RowVector &a, const RowVector &b);
462  static double dot(RowVector &&a, const RowVector &b);
464  static double dot(const RowVector &a, RowVector &&b);
466  static double dot(RowVector &&a, RowVector &&b);
467 
469  double dot(const RowVector &b) const & { return dot(*this, b); }
471  double dot(const RowVector &b) && { return dot(std::move(*this), b); }
473  double dot(RowVector &&b) const & { return dot(*this, std::move(b)); }
475  double dot(RowVector &&b) && { return dot(std::move(*this), std::move(b)); }
476 
478 
479  public:
482 
485  static void cross_inplace(RowVector &a, const RowVector &b);
488  static void cross_inplace(RowVector &a, RowVector &&b);
491  static void cross_inplace_neg(RowVector &a, const RowVector &b);
494  static void cross_inplace_neg(RowVector &a, RowVector &&b);
495 
497  static RowVector cross(const RowVector &a, const RowVector &b);
499  static RowVector &&cross(RowVector &&a, const RowVector &b);
501  static RowVector &&cross(const RowVector &a, RowVector &&b);
503  static RowVector &&cross(RowVector &&a, RowVector &&b);
504 
506  RowVector cross(const RowVector &b) const &;
508  RowVector &&cross(const RowVector &b) &&;
510  RowVector &&cross(RowVector &&b) const &;
512  RowVector &&cross(RowVector &&b) &&;
513 
515 
516  public:
519 
521  double norm2() const &;
523  double norm2() &&;
524 
526 };
527 
529 class SquareMatrix : public Matrix {
530  public:
533 
535  SquareMatrix() = default;
536 
539 
541  SquareMatrix(std::initializer_list<std::initializer_list<double>> init);
542 
544  explicit SquareMatrix(Matrix &&matrix);
546  explicit SquareMatrix(const Matrix &matrix);
547 
549  SquareMatrix &
550  operator=(std::initializer_list<std::initializer_list<double>> init);
551 
553 
554  public:
557 
559  void reshape(size_t, size_t) = delete;
561  Matrix reshaped(size_t, size_t) = delete;
562 
564 
565  public:
568 
570  static void transpose_inplace(Matrix &A);
573 
575 
576  public:
579 
581  static SquareMatrix ones(size_t rows);
583  static SquareMatrix zeros(size_t rows);
585  static SquareMatrix constant(size_t rows, double value);
586 
588  static SquareMatrix identity(size_t rows);
589 
591  static SquareMatrix random(size_t rows, double min = 0, double max = 1,
592  std::default_random_engine::result_type seed =
593  std::default_random_engine::default_seed);
594 
596 };
597 
599 
602 std::ostream &operator<<(std::ostream &os, const Matrix &M);
603 
604 // :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //
605 
608 
612 
614 Matrix operator*(const Matrix &A, const Matrix &B);
616 Matrix operator*(Matrix &&A, const Matrix &B);
618 Matrix operator*(const Matrix &A, Matrix &&B);
620 Matrix operator*(Matrix &&A, Matrix &&B);
621 
623 SquareMatrix operator*(const SquareMatrix &A, const SquareMatrix &B);
630 
632 Vector operator*(const Matrix &A, const Vector &b);
634 Vector operator*(Matrix &&A, const Vector &b);
636 Vector operator*(const Matrix &A, Vector &&b);
638 Vector operator*(Matrix &&A, Vector &&b);
639 
641 RowVector operator*(const RowVector &a, const Matrix &B);
643 RowVector operator*(RowVector &&a, const Matrix &B);
645 RowVector operator*(const RowVector &a, Matrix &&B);
648 
650 double operator*(const RowVector &a, const Vector &b);
652 double operator*(RowVector &&a, const Vector &b);
654 double operator*(const RowVector &a, Vector &&b);
656 double operator*(RowVector &&a, Vector &&b);
657 
659 
660 // -------------------------------------------------------------------------- //
661 
665 
667 Matrix operator+(const Matrix &A, const Matrix &B);
668 
669 void operator+=(Matrix &A, const Matrix &B);
670 Matrix &&operator+(Matrix &&A, const Matrix &B);
671 Matrix &&operator+(const Matrix &A, Matrix &&B);
672 Matrix &&operator+(Matrix &&A, Matrix &&B);
673 Vector &&operator+(Vector &&a, const Vector &b);
674 Vector &&operator+(const Vector &a, Vector &&b);
675 Vector &&operator+(Vector &&a, Vector &&b);
676 RowVector &&operator+(RowVector &&a, const RowVector &b);
677 RowVector &&operator+(const RowVector &a, RowVector &&b);
682 Vector operator+(const Vector &a, const Vector &b);
683 RowVector operator+(const RowVector &a, const RowVector &b);
684 SquareMatrix operator+(const SquareMatrix &a, const SquareMatrix &b);
685 
687 
688 // -------------------------------------------------------------------------- //
689 
693 
695 Matrix operator-(const Matrix &A, const Matrix &B);
696 void operator-=(Matrix &A, const Matrix &B);
697 Matrix &&operator-(Matrix &&A, const Matrix &B);
698 Matrix &&operator-(const Matrix &A, Matrix &&B);
699 Matrix &&operator-(Matrix &&A, Matrix &&B);
700 Vector &&operator-(Vector &&a, const Vector &b);
701 Vector &&operator-(const Vector &a, Vector &&b);
702 Vector &&operator-(Vector &&a, Vector &&b);
703 RowVector &&operator-(RowVector &&a, const RowVector &b);
704 RowVector &&operator-(const RowVector &a, RowVector &&b);
709 Vector operator-(const Vector &a, const Vector &b);
710 RowVector operator-(const RowVector &a, const RowVector &b);
711 SquareMatrix operator-(const SquareMatrix &a, const SquareMatrix &b);
712 
714 
715 // -------------------------------------------------------------------------- //
716 
720 
722 Matrix operator-(const Matrix &A);
723 Matrix &&operator-(Matrix &&A);
724 Vector &&operator-(Vector &&a);
727 Vector operator-(const Vector &a);
728 RowVector operator-(const RowVector &a);
730 
732 
733 // -------------------------------------------------------------------------- //
734 
738 
740 Matrix operator*(const Matrix &A, double s);
741 void operator*=(Matrix &A, double s);
742 Matrix &&operator*(Matrix &&A, double s);
743 Vector operator*(const Vector &a, double s);
744 RowVector operator*(const RowVector &a, double s);
745 SquareMatrix operator*(const SquareMatrix &a, double s);
746 Vector &&operator*(Vector &&a, double s);
747 RowVector &&operator*(RowVector &&a, double s);
748 SquareMatrix &&operator*(SquareMatrix &&a, double s);
749 
750 Matrix operator*(double s, const Matrix &A);
751 Matrix &&operator*(double s, Matrix &&A);
752 Vector operator*(double s, const Vector &a);
753 RowVector operator*(double s, const RowVector &a);
754 SquareMatrix operator*(double s, const SquareMatrix &a);
755 Vector &&operator*(double s, Vector &&a);
756 RowVector &&operator*(double s, RowVector &&a);
757 SquareMatrix &&operator*(double s, SquareMatrix &&a);
758 
760 
761 // -------------------------------------------------------------------------- //
762 
766 
768 Matrix operator/(const Matrix &A, double s);
769 void operator/=(Matrix &A, double s);
770 Matrix &&operator/(Matrix &&A, double s);
771 Vector operator/(const Vector &a, double s);
772 RowVector operator/(const RowVector &a, double s);
773 SquareMatrix operator/(const SquareMatrix &a, double s);
774 Vector &&operator/(Vector &&a, double s);
775 RowVector &&operator/(RowVector &&a, double s);
776 SquareMatrix &&operator/(SquareMatrix &&a, double s);
777 
779 
781 
782 // -------------------------------------------------------------------------- //
783 
786 
790 
792 Matrix explicit_transpose(const Matrix &in);
793 
796 Matrix transpose(const Matrix &in);
799 Matrix &&transpose(Matrix &&in);
800 
805 
807 RowVector transpose(const Vector &in);
811 Vector transpose(const RowVector &in);
814 
816 
General matrix class.
Definition: Matrix.hpp:25
storage_t::const_iterator begin() const
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:199
static Matrix constant(size_t rows, size_t cols, double value)
Create a matrix filled with a constant value.
Definition: Matrix.cpp:151
static Matrix identity(size_t rows, size_t cols)
Create an identity matrix.
Definition: Matrix.cpp:157
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:165
storage_t::iterator end()
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:204
Matrix & operator=(const Matrix &)=default
Default copy assignment.
std::ostream & operator<<(std::ostream &os, const Matrix &M)
Print a matrix.
Definition: Matrix.cpp:245
static Matrix zeros(size_t rows, size_t cols)
Create a matrix filled with zeros.
Definition: Matrix.cpp:146
const double & operator()(size_t index) const
Get the element at the given position in the linearized matrix.
Definition: Matrix.hpp:97
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:131
friend class RowVector
Definition: Matrix.hpp:235
storage_t storage
Definition: Matrix.hpp:232
storage_t::const_iterator cend() const
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:208
size_t rows_
Definition: Matrix.hpp:231
void swap_columns(size_t a, size_t b)
Swap two columns of the matrix.
Definition: Matrix.cpp:176
Matrix reshaped(size_t newrows, size_t newcols) const
Create a reshaped copy of the matrix.
Definition: Matrix.cpp:80
bool operator==(const Matrix &other) const
Check for equality of two matrices.
Definition: Matrix.cpp:190
double & operator()(size_t row, size_t col)
Get the element at the given position in the matrix.
Definition: Matrix.cpp:90
size_t num_elems() const
Get the number of elements in the matrix:
Definition: Matrix.hpp:73
static Matrix ones(size_t rows, size_t cols)
Create a matrix filled with ones.
Definition: Matrix.cpp:142
void swap_rows(size_t a, size_t b)
Swap two rows of the matrix.
Definition: Matrix.cpp:181
Matrix()=default
Default constructor.
size_t rows() const
Get the number of rows of the matrix.
Definition: Matrix.hpp:69
util::storage_t< double > storage_t
Container to store the elements of the matrix internally.
Definition: Matrix.hpp:28
storage_t::const_iterator cbegin() const
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:201
void clear_and_deallocate()
Set the number of rows and columns to zero, and deallocate the storage.
Definition: Matrix.cpp:110
void reshape(size_t newrows, size_t newcols)
Reshape the matrix.
Definition: Matrix.cpp:74
double & operator()(size_t index)
Get the element at the given position in the linearized matrix.
Definition: Matrix.hpp:95
Matrix & operator=(std::initializer_list< std::initializer_list< double >> init)
Assign the given values to the matrix.
Definition: Matrix.cpp:41
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:125
double normFro() const &
Compute the Frobenius norm of the matrix.
Definition: Matrix.cpp:211
size_t cols() const
Get the number of columns of the matrix.
Definition: Matrix.hpp:71
size_t cols_
Definition: Matrix.hpp:231
storage_t::iterator begin()
Get the iterator to the first element of the matrix.
Definition: Matrix.hpp:197
bool operator!=(const Matrix &other) const
Check for inequality of two matrices.
Definition: Matrix.hpp:177
void fill(double value)
Fill the matrix with a constant value.
Definition: Matrix.cpp:121
storage_t::const_iterator end() const
Get the iterator to the element past the end of the matrix.
Definition: Matrix.hpp:206
void print(std::ostream &os, uint8_t precision=0, uint8_t width=0) const
Print a matrix.
Definition: Matrix.cpp:232
A row vector (1×n matrix).
Definition: Matrix.hpp:397
size_t size() const
Get the number of elements in the vector.
Definition: Matrix.hpp:429
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:409
void resize(size_t size)
Resize the vector.
Definition: Matrix.hpp:426
double dot(RowVector &&b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:473
RowVector(size_t size)
Create a row vector of the given size.
Definition: Matrix.hpp:406
double dot(const RowVector &b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:471
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:475
double dot(const RowVector &b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:469
Square matrix class.
Definition: Matrix.hpp:529
SquareMatrix(size_t size)
Create a square matrix of zeros.
Definition: Matrix.hpp:538
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:572
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:241
static void cross_inplace_unchecked(Matrix &a, const Matrix &b)
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
Definition: Matrix.cpp:335
static void cross_inplace(Vector &a, const Vector &b)
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
Definition: Matrix.cpp:357
double dot(const Vector &b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:328
size_t size() const
Get the number of elements in the vector.
Definition: Matrix.hpp:273
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:326
static void cross_inplace_unchecked_neg(Matrix &a, const Matrix &b)
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the res...
Definition: Matrix.cpp:346
Vector cross(const Vector &b) const &
Compute the cross product of this 3-vector with another 3-vector.
Definition: Matrix.hpp:372
double dot(Vector &&b) &&
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:332
Vector && cross(const Vector &b) &&
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:374
static Vector random(size_t size, double min=0, double max=1, std::default_random_engine::result_type seed=std::default_random_engine::default_seed)
Create a vector with uniformly distributed random values.
Definition: Matrix.cpp:283
static Vector constant(size_t size, double value)
Create a vector filled with a constant value.
Definition: Matrix.cpp:279
Vector && cross(Vector &&b) &&
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:378
void resize(size_t size)
Resize the vector.
Definition: Matrix.hpp:270
Vector && cross(Vector &&b) const &
Compute the cross product of this 3-vector with another 3-vector,.
Definition: Matrix.hpp:376
Vector(size_t size)
Create a column vector of the given size.
Definition: Matrix.hpp:250
static Vector zeros(size_t size)
Create a vector filled with zeros.
Definition: Matrix.cpp:277
static double dot(const Vector &a, const Vector &b)
Compute the dot product of two vectors.
Definition: Matrix.cpp:315
static Vector cross(const Vector &a, const Vector &b)
Compute the cross product of two 3-vectors.
Definition: Matrix.cpp:374
Vector()=default
Default constructor.
double norm2() const &
Compute the 2-norm of the vector.
Definition: Matrix.cpp:399
double dot(Vector &&b) const &
Compute the dot product of this vector with another vector.
Definition: Matrix.hpp:330
static double dot_unchecked(const Matrix &a, const Matrix &b)
Compute the dot product of two vectors.
Definition: Matrix.cpp:292
void reshape(size_t, size_t)=delete
Reshaping a vector to a matrix requires an explicit cast.
static void cross_inplace_neg(Vector &a, const Vector &b)
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the res...
Definition: Matrix.cpp:365
static Vector ones(size_t size)
Create a vector filled with ones.
Definition: Matrix.cpp:275
Vector & operator=(std::initializer_list< double > init)
Assign a list of values to the column vector.
Definition: Matrix.cpp:263
Vector(std::initializer_list< double > init)
Create a column vector from the given list of values.
Definition: Matrix.hpp:253
Matrix operator+(const Matrix &A, const Matrix &B)
Matrix addition.
Definition: Matrix.cpp:701
void operator+=(Matrix &A, const Matrix &B)
Definition: Matrix.cpp:711
Matrix operator*(const Matrix &A, const Matrix &B)
Matrix multiplication.
Definition: Matrix.cpp:603
void operator-=(Matrix &A, const Matrix &B)
Definition: Matrix.cpp:801
Matrix operator-(const Matrix &A, const Matrix &B)
Matrix subtraction.
Definition: Matrix.cpp:791
Matrix transpose(const Matrix &in)
Matrix transpose for rectangular or square matrices and row or column vectors.
Definition: Matrix.cpp:1045
Matrix explicit_transpose(const Matrix &in)
Matrix transpose for general matrices.
Definition: Matrix.cpp:1031
void operator/=(Matrix &A, double s)
Definition: Matrix.cpp:992
Matrix operator/(const Matrix &A, double s)
Scalar division.
Definition: Matrix.cpp:984
void operator*=(Matrix &A, double s)
Definition: Matrix.cpp:934
std::vector< T > storage_t
Container to store the elements of a matrix internally.