ASL
Matrix_< T > Class Template Reference

Detailed Description

template<class T>
class asl::Matrix_< T >

A matrix supporting basic arithmetic operations.

With two predefined specializations: Matrix for doubles and Matrixf for floats.

Matrix A = { // this makes a 2x2 matrix
{ 1, -1 },
{ 2, 3 }
};
Matrix b = { 5, 1 }; // this makes a column matrix (a vector)

You can operate with matrices:

auto C = A.inverse() * A + b * b.transposed();

And you can solve linear systems, even using least-squares, if more equations than unknowns:

auto x = solve(A, b); // solution to linear system A * x = b
Matrix_< T > solve(const Matrix_< T > &A, const Matrix_< T > &b)
Solves the matrix equation A*x=b and returns x; if b is a matrix (not a column) then the equation is ...
Definition: Matrix.h:381

#include <Matrix.h>

Inheritance diagram for Matrix_< T >:
Array2< T >

Public Member Functions

 Matrix_ (int rows, int cols=1)
 Creates a matrix with size rows x cols.
 
 Matrix_ (int rows, int cols, const T &value)
 Creates a matrix with size rows x cols and initializes all items with value.
 
 Matrix_ (int rows, int cols, const T *p)
 Creates a matrix of rows x cols elements and copies them from the pointer p (row-wise)
 
 Matrix_ (int rows, int cols, std::initializer_list< T > a)
 Creates a matrix with size rows x cols and the given elements.
 
 Matrix_ (std::initializer_list< std::initializer_list< T > > a)
 Creates a matrix with given list of lists of elements.
 
 Matrix_ (std::initializer_list< T > a)
 Creates a column matrix with given list of elements.
 
trace () const
 Returns the trace of this matrix.
 
template<class K >
Matrix_< K > with () const
 Returns a copy of this matrix with elements converted to the given type.
 
Matrix_ clone () const
 Returns an independent copy of this matrix.
 
Matrix_ slice (int i1, int i2, int j1, int j2) const
 Returns a sub-matrix consisting of a rows [i1, i2) and columns [j1, j2)
 
Matrix_ row (int i) const
 Returns the i-th row.
 
Matrix_ col (int j) const
 Returns the j-th column.
 
Matrix_ transposed () const
 Returns this matrix transposed.
 
Matrix_ inverse () const
 Computes the inverse of this matrix, if it exists; the matrix must be square.
 
Matrix_ pseudoinverse () const
 Computes the pseudoinverse of this matrix.
 
Matrix_ operator* (const Matrix_ &b) const
 Computes the product of this matrix and b.
 
Matrix_ transposed (const Matrix_ &b) const
 Computes the product of this matrix transposed and b (same as A.transposed() * B but a bit faster)
 
Matrix_ operator+ (const Matrix_ &b) const
 Computes the sum of this matrix and b.
 
Matrix_ operator- (const Matrix_ &b) const
 Computes the subtraction of this matrix and b.
 
Matrix_ operator* (T s) const
 Computes the product of this matrix by scalar s.
 
void operator+= (const Matrix_ &b)
 Adds a matrix to this.
 
void operator-= (const Matrix_ &b)
 Subtracts a matrix from this.
 
void operator*= (T s)
 Multiplies this matrix by a scalar.
 
Matrix_ operator- () const
 Returns this matrix negated (multiplied by -1)
 
normSq () const
 Returns the matrix Frobenius norm squared.
 
norm () const
 Returns the matrix Frobenius norm.
 
- Public Member Functions inherited from Array2< T >
 Array2 ()
 Creates an empty array.
 
 Array2 (int rows, int cols)
 Creates an array with size rows x cols.
 
 Array2 (int rows, int cols, const T &value)
 Creates an array with size rows x cols and initializes all items with value.
 
 Array2 (int rows, int cols, const T *p)
 Creates an array of rows x cols elements and copies them from the pointer p (row-wise)
 
 Array2 (int rows, int cols, std::initializer_list< T > a)
 Creates an array with size rows x cols and the given elements.
 
 Array2 (std::initializer_list< std::initializer_list< T > > a)
 Creates an array with given list of lists of elements.
 
template<class K >
Array2< K > with () const
 Creates a copy of this array with items converted to type K.
 
Array< T > & data ()
 Returns the internal array holding all values (row-major) More...
 
const Array< T > & data () const
 Returns the internal array holding all values (row-major) More...
 
Array< T > & array ()
 Returns the internal array holding all values (row-major)
 
const Array< T > & array () const
 Returns the internal array holding all values (row-major)
 
bool operator== (const Array2 &b) const
 Returns true if both arrays are equal.
 
bool operator!= (const Array2 &b) const
 Returns true if both arrays are not equal.
 
Array2 clone () const
 Returns an independent copy of this array.
 
Array2 slice (int i1, int i2, int j1, int j2) const
 Returns a sub-array consisting of a rows [i1, i2) and columns [j1, j2)
 
Array2resize (int r, int c)
 Resizes the matrix to r x c.
 
int rows () const
 Returns the number of rows.
 
int cols () const
 Returns the number of columns.
 
T & operator() (int i, int j)
 Returns the item at row i, column j.
 
void set (const T &x)
 Sets all array items to value x.
 

Static Public Member Functions

static Matrix_ identity (int n)
 Returns an identity matrix of the given size.
 

The documentation for this class was generated from the following file: