18 #define COL_MAJ_ORDER 1
47 Matrix(std::initializer_list<std::initializer_list<double>> init);
50 operator=(std::initializer_list<std::initializer_list<double>> init);
78 void reshape(
size_t newrows,
size_t newcols);
92 const double &
operator()(
size_t row,
size_t col)
const;
115 void fill(
double value);
123 std::default_random_engine::result_type seed =
124 std::default_random_engine::default_seed);
150 std::default_random_engine::result_type seed =
151 std::default_random_engine::default_seed);
206 storage_t::const_iterator
end()
const {
return storage.end(); }
225 void print(std::ostream &os, uint8_t precision = 0,
226 uint8_t width = 0)
const;
253 Vector(std::initializer_list<double> init) { *
this = init; }
294 std::default_random_engine::result_type seed =
295 std::default_random_engine::default_seed);
332 double dot(
Vector &&b) && {
return dot(std::move(*
this), std::move(b)); }
379 return cross(std::move(*
this), std::move(b));
389 double norm2() const &;
409 RowVector(std::initializer_list<double> init) { *
this = init; }
450 std::default_random_engine::result_type seed =
451 std::default_random_engine::default_seed);
521 double norm2() const &;
541 SquareMatrix(std::initializer_list<std::initializer_list<double>> init);
550 operator=(std::initializer_list<std::initializer_list<double>> init);
570 static void transpose_inplace(
Matrix &A);
592 std::default_random_engine::result_type seed =
593 std::default_random_engine::default_seed);
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.
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).
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.
static void cross_inplace(Vector &a, const Vector &b)
Compute the cross product of two 3-vectors, overwriting the first vector with the result.
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.
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...
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,.
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.
static Vector constant(size_t size, double value)
Create a vector filled with a constant value.
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.
static Vector zeros(size_t size)
Create a vector filled with zeros.
static double dot(const Vector &a, const Vector &b)
Compute the dot product of two vectors.
static Vector cross(const Vector &a, const Vector &b)
Compute the cross product of two 3-vectors.
Vector()=default
Default constructor.
double norm2() const &
Compute the 2-norm of the vector.
double dot(Vector &&b) const &
Compute the dot product of this vector with another vector.
static double dot_unchecked(const Matrix &a, const Matrix &b)
Compute the dot product of two vectors.
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...
static Vector ones(size_t size)
Create a vector filled with ones.
Vector & operator=(std::initializer_list< double > init)
Assign a list of values to the column vector.
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.