13 #ifndef NO_IOSTREAM_SUPPORT
17 #ifndef NO_RANDOM_SUPPORT
26 #define COL_MAJ_ORDER 1
32 #ifndef NO_ARDUINO_PRINT_SUPPORT
59 Matrix(std::initializer_list<std::initializer_list<double>> init);
62 operator=(std::initializer_list<std::initializer_list<double>> init);
90 void reshape(
size_t newrows,
size_t newcols);
104 const double &
operator()(
size_t row,
size_t col)
const;
127 void fill(
double value);
133 #ifndef NO_RANDOM_SUPPORT
136 std::default_random_engine::result_type seed =
137 std::default_random_engine::default_seed);
161 #ifndef NO_RANDOM_SUPPORT
165 std::default_random_engine::result_type seed =
166 std::default_random_engine::default_seed);
222 storage_t::const_iterator
end()
const {
return storage.end(); }
232 #ifndef NO_IOSTREAM_SUPPORT
242 void print(std::ostream &os, uint8_t precision = 0,
243 uint8_t width = 0)
const;
246 #ifndef NO_ARDUINO_PRINT_SUPPORT
256 void print(Print &
print, uint8_t precision = 0, uint8_t width = 0)
const;
290 Vector(std::initializer_list<double> init) { *
this = init; }
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);
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);
372 double dot(
Vector &&b) && {
return dot(std::move(*
this), std::move(b)); }
383 static void cross_inplace_unchecked(
Matrix &a,
const Matrix &b);
387 static void cross_inplace_unchecked_neg(
Matrix &a,
const Matrix &b);
397 static void cross_inplace_neg(
Vector &a,
const Vector &b);
419 return cross(std::move(*
this), std::move(b));
429 double norm2() const &;
449 RowVector(std::initializer_list<double> init) { *
this = init; }
489 #ifndef NO_RANDOM_SUPPORT
492 std::default_random_engine::result_type seed =
493 std::default_random_engine::default_seed);
564 double norm2() const &;
584 SquareMatrix(std::initializer_list<std::initializer_list<double>> init);
593 operator=(std::initializer_list<std::initializer_list<double>> init);
613 static void transpose_inplace(
Matrix &A);
633 #ifndef NO_RANDOM_SUPPORT
636 std::default_random_engine::result_type seed =
637 std::default_random_engine::default_seed);
645 #ifndef NO_IOSTREAM_SUPPORT
651 #ifndef NO_ARDUINO_PRINT_SUPPORT
Preprocessor logic for configuring the library to make it compatible with the Arduino environment.
storage_t::const_iterator begin() const
Get the iterator to the first element of the matrix.
static Matrix constant(size_t rows, size_t cols, double value)
Create a matrix filled with a constant value.
static Matrix identity(size_t rows, size_t cols)
Create an identity matrix.
size_t printTo(Print &print) const override
Implements the Arduino Printable interface.
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.
storage_t::iterator end()
Get the iterator to the element past the end of the matrix.
Matrix & operator=(const Matrix &)=default
Default copy assignment.
std::ostream & operator<<(std::ostream &os, const Matrix &M)
Print a matrix.
static Matrix zeros(size_t rows, size_t cols)
Create a matrix filled with zeros.
const double & operator()(size_t index) const
Get the element at the given position in the linearized matrix.
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.
storage_t::const_iterator cend() const
Get the iterator to the element past the end of the matrix.
void swap_columns(size_t a, size_t b)
Swap two columns of the matrix.
Matrix reshaped(size_t newrows, size_t newcols) const
Create a reshaped copy of the matrix.
bool operator==(const Matrix &other) const
Check for equality of two matrices.
double & operator()(size_t row, size_t col)
Get the element at the given position in the matrix.
size_t num_elems() const
Get the number of elements in the matrix:
static Matrix ones(size_t rows, size_t cols)
Create a matrix filled with ones.
void swap_rows(size_t a, size_t b)
Swap two rows of the matrix.
Matrix()=default
Default constructor.
size_t rows() const
Get the number of rows of the matrix.
util::storage_t< double > storage_t
Container to store the elements of the matrix internally.
storage_t::const_iterator cbegin() const
Get the iterator to the first element of the matrix.
void clear_and_deallocate()
Set the number of rows and columns to zero, and deallocate the storage.
void reshape(size_t newrows, size_t newcols)
Reshape the matrix.
double & operator()(size_t index)
Get the element at the given position in the linearized matrix.
Matrix & operator=(std::initializer_list< std::initializer_list< double >> init)
Assign the given values to the matrix.
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).
double normFro() const &
Compute the Frobenius norm of the matrix.
size_t cols() const
Get the number of columns of the matrix.
storage_t::iterator begin()
Get the iterator to the first element of the matrix.
bool operator!=(const Matrix &other) const
Check for inequality of two matrices.
void fill(double value)
Fill the matrix with a constant value.
storage_t::const_iterator end() const
Get the iterator to the element past the end of the matrix.
void print(std::ostream &os, uint8_t precision=0, uint8_t width=0) const
Print a matrix.
A row vector (1×n matrix).
size_t size() const
Get the number of elements in the vector.
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.
void resize(size_t size)
Resize the vector.
double dot(RowVector &&b) const &
Compute the dot product of this vector with another vector.
RowVector(size_t size)
Create a row vector of the given size.
double dot(const RowVector &b) &&
Compute the dot product of this vector with another vector.
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.
double dot(const RowVector &b) const &
Compute the dot product of this vector with another vector.
SquareMatrix(size_t size)
Create a square matrix of zeros.
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.
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).
double dot(const Vector &b) &&
Compute the dot product of this vector with another vector.
size_t size() const
Get the number of elements in the vector.
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.
Vector cross(const Vector &b) const &
Compute the cross product of this 3-vector with another 3-vector.
double dot(Vector &&b) &&
Compute the dot product of this vector with another vector.
Vector && cross(const Vector &b) &&
Compute the cross product of this 3-vector with another 3-vector,.
Vector && cross(Vector &&b) &&
Compute the cross product of this 3-vector with another 3-vector,.
void resize(size_t size)
Resize the vector.
Vector && cross(Vector &&b) const &
Compute the cross product of this 3-vector with another 3-vector,.
Vector(size_t size)
Create a column vector of the given size.
Vector()=default
Default constructor.
double dot(Vector &&b) const &
Compute the dot product of this vector with another vector.
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.
Matrix operator+(const Matrix &A, const Matrix &B)
Matrix addition.
void operator+=(Matrix &A, const Matrix &B)
Matrix operator*(const Matrix &A, const Matrix &B)
Matrix multiplication.
void operator-=(Matrix &A, const Matrix &B)
Matrix operator-(const Matrix &A, const Matrix &B)
Matrix subtraction.
Matrix transpose(const Matrix &in)
Matrix transpose for rectangular or square matrices and row or column vectors.
Matrix explicit_transpose(const Matrix &in)
Matrix transpose for general matrices.
void operator/=(Matrix &A, double s)
Matrix operator/(const Matrix &A, double s)
Scalar division.
void operator*=(Matrix &A, double s)
std::vector< T > storage_t
Container to store the elements of a matrix internally.