Linear Algebra
arduino
Accessible implementations of linear algebra algorithms
|
#include <include/linalg/Matrix.hpp>
A column vector (n×1 matrix).
Definition at line 278 of file Matrix.hpp.
Constructors and assignment | |
Vector ()=default | |
Default constructor. More... | |
Vector (size_t size) | |
Create a column vector of the given size. More... | |
Vector (std::initializer_list< double > init) | |
Create a column vector from the given list of values. More... | |
Vector & | operator= (std::initializer_list< double > init) |
Assign a list of values to the column vector. More... | |
Vector (const Matrix &matrix) | |
Convert an m×n matrix to a mn column vector. More... | |
Vector (Matrix &&matrix) | |
Convert an m×n matrix to a mn column vector. More... | |
Vector size | |
void | resize (size_t size) |
Resize the vector. More... | |
size_t | size () const |
Get the number of elements in the vector. More... | |
void | reshape (size_t, size_t)=delete |
Reshaping a vector to a matrix requires an explicit cast. More... | |
Matrix | reshaped (size_t, size_t)=delete |
Reshaping a vector to a matrix requires an explicit cast. More... | |
Dot products | |
double | dot (const Vector &b) const & |
Compute the dot product of this vector with another vector. More... | |
double | dot (const Vector &b) && |
Compute the dot product of this vector with another vector. More... | |
double | dot (Vector &&b) const & |
Compute the dot product of this vector with another vector. More... | |
double | dot (Vector &&b) && |
Compute the dot product of this vector with another vector. More... | |
static double | dot_unchecked (const Matrix &a, const Matrix &b) |
Compute the dot product of two vectors. More... | |
static double | dot_unchecked (Matrix &&a, const Matrix &b) |
Compute the dot product of two vectors. More... | |
static double | dot_unchecked (const Matrix &a, Matrix &&b) |
Compute the dot product of two vectors. More... | |
static double | dot_unchecked (Matrix &&a, Matrix &&b) |
Compute the dot product of two vectors. More... | |
static double | dot (const Vector &a, const Vector &b) |
Compute the dot product of two vectors. More... | |
static double | dot (Vector &&a, const Vector &b) |
Compute the dot product of two vectors. More... | |
static double | dot (const Vector &a, Vector &&b) |
Compute the dot product of two vectors. More... | |
static double | dot (Vector &&a, Vector &&b) |
Compute the dot product of two vectors. More... | |
Cross products | |
Vector | cross (const Vector &b) const & |
Compute the cross product of this 3-vector with another 3-vector. More... | |
Vector && | cross (const Vector &b) && |
Compute the cross product of this 3-vector with another 3-vector,. More... | |
Vector && | cross (Vector &&b) const & |
Compute the cross product of this 3-vector with another 3-vector,. More... | |
Vector && | cross (Vector &&b) && |
Compute the cross product of this 3-vector with another 3-vector,. More... | |
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. More... | |
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 result. More... | |
static void | cross_inplace (Vector &a, const Vector &b) |
Compute the cross product of two 3-vectors, overwriting the first vector with the result. More... | |
static void | cross_inplace (Vector &a, Vector &&b) |
Compute the cross product of two 3-vectors, overwriting the first vector with the result. More... | |
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 result. More... | |
static void | cross_inplace_neg (Vector &a, Vector &&b) |
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the result. More... | |
static Vector | cross (const Vector &a, const Vector &b) |
Compute the cross product of two 3-vectors. More... | |
static Vector && | cross (Vector &&a, const Vector &b) |
Compute the cross product of two 3-vectors. More... | |
static Vector && | cross (const Vector &a, Vector &&b) |
Compute the cross product of two 3-vectors. More... | |
static Vector && | cross (Vector &&a, Vector &&b) |
Compute the cross product of two 3-vectors. More... | |
Vector norms | |
double | norm2 () const & |
Compute the 2-norm of the vector. More... | |
double | norm2 () && |
Compute the 2-norm of the vector. More... | |
Matrix size | |
size_t | rows () const |
Get the number of rows of the matrix. More... | |
size_t | cols () const |
Get the number of columns of the matrix. More... | |
size_t | num_elems () const |
Get the number of elements in the matrix: More... | |
Matrix | reshaped (size_t newrows, size_t newcols) const |
Create a reshaped copy of the matrix. More... | |
Element access | |
double & | operator() (size_t row, size_t col) |
Get the element at the given position in the matrix. More... | |
const double & | operator() (size_t row, size_t col) const |
Get the element at the given position in the matrix. More... | |
double & | operator() (size_t index) |
Get the element at the given position in the linearized matrix. More... | |
const double & | operator() (size_t index) const |
Get the element at the given position in the linearized matrix. More... | |
Memory management | |
void | clear_and_deallocate () |
Set the number of rows and columns to zero, and deallocate the storage. More... | |
Filling matrices | |
void | fill (double value) |
Fill the matrix with a constant value. More... | |
void | fill_identity () |
Fill the matrix as an identity matrix (all zeros except the diagonal which is one). More... | |
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. More... | |
Swapping rows and columns | |
void | swap_rows (size_t a, size_t b) |
Swap two rows of the matrix. More... | |
void | swap_columns (size_t a, size_t b) |
Swap two columns of the matrix. More... | |
Comparison | |
bool | operator== (const Matrix &other) const |
Check for equality of two matrices. More... | |
bool | operator!= (const Matrix &other) const |
Check for inequality of two matrices. More... | |
Matrix norms | |
double | normFro () const & |
Compute the Frobenius norm of the matrix. More... | |
double | normFro () && |
Compute the Frobenius norm of the matrix. More... | |
Iterators | |
storage_t::iterator | begin () |
Get the iterator to the first element of the matrix. More... | |
storage_t::const_iterator | begin () const |
Get the iterator to the first element of the matrix. More... | |
storage_t::const_iterator | cbegin () const |
Get the iterator to the first element of the matrix. More... | |
storage_t::iterator | end () |
Get the iterator to the element past the end of the matrix. More... | |
storage_t::const_iterator | end () const |
Get the iterator to the element past the end of the matrix. More... | |
storage_t::const_iterator | cend () const |
Get the iterator to the element past the end of the matrix. More... | |
Printing | |
void | print (std::ostream &os, uint8_t precision=0, uint8_t width=0) const |
Print a matrix. More... | |
void | print (Print &print, uint8_t precision=0, uint8_t width=0) const |
Print a matrix. More... | |
size_t | printTo (Print &print) const override |
Implements the Arduino Printable interface. More... | |
Creating special vectors | |
static Vector | ones (size_t size) |
Create a vector filled with ones. More... | |
static Vector | zeros (size_t size) |
Create a vector filled with zeros. More... | |
static Vector | constant (size_t size, double value) |
Create a vector filled with a constant value. More... | |
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. More... | |
Create special matrices | |
static Matrix | ones (size_t rows, size_t cols) |
Create a matrix filled with ones. More... | |
static Matrix | zeros (size_t rows, size_t cols) |
Create a matrix filled with zeros. More... | |
static Matrix | constant (size_t rows, size_t cols, double value) |
Create a matrix filled with a constant value. More... | |
static Matrix | identity (size_t rows, size_t cols) |
Create an identity matrix. More... | |
static Matrix | identity (size_t rows) |
Create a square identity matrix. More... | |
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. More... | |
Protected Attributes | |
size_t | rows_ = 0 |
size_t | cols_ = 0 |
storage_t | storage |
Private Types | |
using | storage_t = util::storage_t< double > |
Container to store the elements of the matrix internally. More... | |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &os, const Matrix &M) |
Print a matrix. More... | |
Print & | operator<< (Print &p, const Matrix &M) |
Print a matrix. More... | |
|
privateinherited |
Container to store the elements of the matrix internally.
Definition at line 40 of file Matrix.hpp.
|
default |
Default constructor.
|
inline |
Create a column vector of the given size.
Definition at line 287 of file Matrix.hpp.
|
inline |
Create a column vector from the given list of values.
Definition at line 290 of file Matrix.hpp.
Convert an m×n matrix to a mn column vector.
Definition at line 269 of file Matrix.cpp.
Convert an m×n matrix to a mn column vector.
Definition at line 272 of file Matrix.cpp.
Vector & operator= | ( | std::initializer_list< double > | init | ) |
Assign a list of values to the column vector.
Definition at line 275 of file Matrix.cpp.
|
inline |
Resize the vector.
Definition at line 307 of file Matrix.hpp.
|
inline |
Get the number of elements in the vector.
Definition at line 310 of file Matrix.hpp.
|
delete |
Reshaping a vector to a matrix requires an explicit cast.
|
delete |
Reshaping a vector to a matrix requires an explicit cast.
|
static |
Create a vector filled with ones.
Definition at line 287 of file Matrix.cpp.
|
static |
Create a vector filled with zeros.
Definition at line 289 of file Matrix.cpp.
|
static |
Create a vector filled with a constant value.
Definition at line 291 of file Matrix.cpp.
|
static |
Create a vector with uniformly distributed random values.
Definition at line 296 of file Matrix.cpp.
Compute the dot product of two vectors.
Reinterprets matrices as vectors.
Definition at line 306 of file Matrix.cpp.
Compute the dot product of two vectors.
Reinterprets matrices as vectors.
Definition at line 311 of file Matrix.cpp.
Compute the dot product of two vectors.
Reinterprets matrices as vectors.
Definition at line 317 of file Matrix.cpp.
Compute the dot product of two vectors.
Reinterprets matrices as vectors.
Definition at line 321 of file Matrix.cpp.
Compute the dot product of two vectors.
Definition at line 329 of file Matrix.cpp.
Compute the dot product of two vectors.
Definition at line 333 of file Matrix.cpp.
Compute the dot product of two vectors.
Definition at line 337 of file Matrix.cpp.
Compute the dot product of two vectors.
Definition at line 341 of file Matrix.cpp.
|
inline |
Compute the dot product of this vector with another vector.
Definition at line 366 of file Matrix.hpp.
|
inline |
Compute the dot product of this vector with another vector.
Definition at line 368 of file Matrix.hpp.
|
inline |
Compute the dot product of this vector with another vector.
Definition at line 370 of file Matrix.hpp.
|
inline |
Compute the dot product of this vector with another vector.
Definition at line 372 of file Matrix.hpp.
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
Reinterprets matrices as vectors (so it can be used with row vectors as well).
Definition at line 349 of file Matrix.cpp.
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the result.
Reinterprets matrices as vectors (so it can be used with row vectors as well).
Definition at line 360 of file Matrix.cpp.
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
Definition at line 371 of file Matrix.cpp.
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
Definition at line 375 of file Matrix.cpp.
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the result.
Definition at line 379 of file Matrix.cpp.
Compute the opposite of the cross product of two 3-vectors, overwriting the first vector with the result.
Definition at line 383 of file Matrix.cpp.
Compute the cross product of two 3-vectors.
Definition at line 388 of file Matrix.cpp.
Compute the cross product of two 3-vectors.
Definition at line 394 of file Matrix.cpp.
Compute the cross product of two 3-vectors.
Definition at line 399 of file Matrix.cpp.
Compute the cross product of two 3-vectors.
Definition at line 404 of file Matrix.cpp.
Compute the cross product of this 3-vector with another 3-vector.
Definition at line 412 of file Matrix.hpp.
Compute the cross product of this 3-vector with another 3-vector,.
Definition at line 414 of file Matrix.hpp.
Compute the cross product of this 3-vector with another 3-vector,.
Definition at line 416 of file Matrix.hpp.
Compute the cross product of this 3-vector with another 3-vector,.
Definition at line 418 of file Matrix.hpp.
double norm2 | ( | ) | const & |
Compute the 2-norm of the vector.
Definition at line 413 of file Matrix.cpp.
double norm2 | ( | ) | && |
Compute the 2-norm of the vector.
Definition at line 421 of file Matrix.cpp.
|
inlineinherited |
|
inlineinherited |
Get the number of columns of the matrix.
Definition at line 83 of file Matrix.hpp.
|
inlineinherited |
Get the number of elements in the matrix:
Definition at line 85 of file Matrix.hpp.
|
inherited |
|
inherited |
Get the element at the given position in the matrix.
Definition at line 94 of file Matrix.cpp.
|
inherited |
Get the element at the given position in the matrix.
Definition at line 102 of file Matrix.cpp.
|
inlineinherited |
Get the element at the given position in the linearized matrix.
Definition at line 107 of file Matrix.hpp.
|
inlineinherited |
Get the element at the given position in the linearized matrix.
Definition at line 109 of file Matrix.hpp.
|
inherited |
Set the number of rows and columns to zero, and deallocate the storage.
Definition at line 114 of file Matrix.cpp.
|
inherited |
Fill the matrix with a constant value.
Definition at line 125 of file Matrix.cpp.
|
inherited |
Fill the matrix as an identity matrix (all zeros except the diagonal which is one).
Definition at line 129 of file Matrix.cpp.
|
inherited |
Fill the matrix with uniformly distributed random values.
Definition at line 136 of file Matrix.cpp.
|
staticinherited |
|
staticinherited |
|
staticinherited |
Create a matrix filled with a constant value.
Definition at line 157 of file Matrix.cpp.
|
staticinherited |
|
staticinherited |
Create a square identity matrix.
Definition at line 169 of file Matrix.cpp.
|
staticinherited |
Create a matrix with uniformly distributed random values.
Definition at line 172 of file Matrix.cpp.
|
inherited |
Swap two rows of the matrix.
Definition at line 189 of file Matrix.cpp.
|
inherited |
Swap two columns of the matrix.
Definition at line 184 of file Matrix.cpp.
|
inherited |
Check for equality of two matrices.
Definition at line 198 of file Matrix.cpp.
|
inlineinherited |
Check for inequality of two matrices.
Definition at line 193 of file Matrix.hpp.
|
inherited |
Compute the Frobenius norm of the matrix.
Definition at line 219 of file Matrix.cpp.
|
inherited |
Compute the Frobenius norm of the matrix.
Definition at line 228 of file Matrix.cpp.
|
inlineinherited |
Get the iterator to the first element of the matrix.
Definition at line 213 of file Matrix.hpp.
|
inlineinherited |
Get the iterator to the first element of the matrix.
Definition at line 215 of file Matrix.hpp.
|
inlineinherited |
Get the iterator to the first element of the matrix.
Definition at line 217 of file Matrix.hpp.
|
inlineinherited |
Get the iterator to the element past the end of the matrix.
Definition at line 220 of file Matrix.hpp.
|
inlineinherited |
Get the iterator to the element past the end of the matrix.
Definition at line 222 of file Matrix.hpp.
|
inlineinherited |
Get the iterator to the element past the end of the matrix.
Definition at line 224 of file Matrix.hpp.
|
inherited |
Print a matrix.
os | The stream to print to. |
precision | The number of significant figures to print. (0 = auto) |
width | The width of each element (number of characters). (0 = auto) |
Definition at line 242 of file Matrix.cpp.
|
inherited |
Print a matrix.
The printer to print to. | |
precision | The number of significant figures to print. (0 = auto) |
width | The width of each element (number of characters). (0 = auto) |
Definition at line 48 of file ArduinoMatrixPrinter.cpp.
|
inlineoverrideinherited |
Implements the Arduino Printable interface.
Definition at line 259 of file Matrix.hpp.
|
related |
Print a matrix.
Definition at line 255 of file Matrix.cpp.
|
related |
Print a matrix.
Definition at line 62 of file ArduinoMatrixPrinter.cpp.
|
protectedinherited |
Definition at line 268 of file Matrix.hpp.
|
protectedinherited |
Definition at line 268 of file Matrix.hpp.
|
protectedinherited |
Definition at line 269 of file Matrix.hpp.