JUCE  v5.1.1-3-g1a0b28c73
JUCE API
Matrix< ElementType > Class Template Reference

General matrix and vectors class, meant for classic math manipulation such as additions, multiplications, and linear systems of equations solving. More...

#include <juce_Matrix.h>

Collaboration diagram for Matrix< ElementType >:

Public Member Functions

 Matrix (size_t numRows, size_t numColumns)
 Creates a new matrix with a given number of rows and columns. More...
 
 Matrix (size_t numRows, size_t numColumns, const ElementType *dataPointer)
 Creates a new matrix with a given number of rows and columns, with initial data coming from an array, stored in row-major order. More...
 
 Matrix (const Matrix &)=default
 Creates a copy of another matrix. More...
 
 Matrix (Matrix &&) noexcept=default
 Moves a copy of another matrix. More...
 
ElementType * begin () noexcept
 
const ElementType * begin () const noexcept
 
void clear () noexcept
 Fills the contents of the matrix with zeroes. More...
 
ElementType * end () noexcept
 
const ElementType * end () const noexcept
 
size_t getNumColumns () const noexcept
 Returns the number of columns in the matrix. More...
 
size_t getNumRows () const noexcept
 Returns the number of rows in the matrix. More...
 
ElementType * getRawDataPointer () noexcept
 Returns a pointer to the raw data of the matrix object, ordered in row-major order (for modifying). More...
 
const ElementType * getRawDataPointer () const noexcept
 Returns a pointer to the raw data of the matrix object, ordered in row-major order (for reading). More...
 
Array< size_t > getSize () const noexcept
 Returns an Array of 2 integers with the number of rows and columns in the matrix. More...
 
Matrixhadarmard (const Matrix &other) noexcept
 Does a hadarmard product with the receiver and other and stores the result in the receiver. More...
 
bool isNullMatrix () const noexcept
 Tells if the matrix is a null matrix. More...
 
bool isOneColumnVector () const noexcept
 Tells if the matrix is a one column vector. More...
 
bool isOneRowVector () const noexcept
 Tells if the matrix is a one row vector. More...
 
bool isSquare () const noexcept
 Tells if the matrix is a square matrix. More...
 
bool isVector () const noexcept
 Tells if the matrix is a vector. More...
 
ElementType operator() (size_t row, size_t column) const noexcept
 Returns the value of the matrix at a given row and column (for reading). More...
 
ElementType & operator() (size_t row, size_t column) noexcept
 Returns the value of the matrix at a given row and column (for modifying). More...
 
Matrix operator* (ElementType scalar) const
 Scalar multiplication. More...
 
Matrix operator* (const Matrix &other) const
 Matrix multiplication. More...
 
Matrixoperator*= (ElementType scalar) noexcept
 Scalar multiplication. More...
 
Matrix operator+ (const Matrix &other) const
 Addition of two matrices. More...
 
Matrixoperator+= (const Matrix &other) noexcept
 Addition of two matrices. More...
 
Matrix operator- (const Matrix &other) const
 Addition of two matrices. More...
 
Matrixoperator-= (const Matrix &other) noexcept
 Subtraction of two matrices. More...
 
Matrixoperator= (const Matrix &)=default
 Creates a copy of another matrix. More...
 
Matrixoperator= (Matrix &&) noexcept=default
 Moves another matrix into this one. More...
 
bool operator== (const Matrix &other) const noexcept
 
bool solve (Matrix &b) const noexcept
 Solves a linear system of equations represented by this object and the argument b, using various algorithms depending on the size of the arguments. More...
 
MatrixswapColumns (size_t columnOne, size_t columnTwo) noexcept
 Swaps the contents of two columns in the matrix and returns a reference to itself. More...
 
MatrixswapRows (size_t rowOne, size_t rowTwo) noexcept
 Swaps the contents of two rows in the matrix and returns a reference to itself. More...
 
String toString () const
 Returns a String displaying in a convenient way the matrix contents. More...
 

Static Public Member Functions

static bool compare (const Matrix &a, const Matrix &b, ElementType tolerance=0) noexcept
 Compare to matrices with a given tolerance. More...
 
static Matrix hadarmard (const Matrix &a, const Matrix &b)
 Does a hadarmard product with a and b returns the result. More...
 
static Matrix hankel (const Matrix &vector, size_t size, size_t offset=0)
 Creates a squared size x size Hankel Matrix from a vector with an optional offset. More...
 
static Matrix identity (size_t size)
 Creates the identity matrix. More...
 
static Matrix toeplitz (const Matrix &vector, size_t size)
 Creates a Toeplitz Matrix from a vector with a given squared size. More...
 

Private Member Functions

template<typename BinaryOperation >
Matrixapply (const Matrix &other, BinaryOperation binaryOp)
 
void resize ()
 Resizes the matrix. More...
 

Private Attributes

size_t columns
 
Array< ElementType > data
 
Array< size_t > dataAcceleration
 
size_t rows
 

Detailed Description

template<typename ElementType>
class Matrix< ElementType >

General matrix and vectors class, meant for classic math manipulation such as additions, multiplications, and linear systems of equations solving.

See also
LinearAlgebra

Constructor & Destructor Documentation

◆ Matrix() [1/4]

template<typename ElementType >
Matrix< ElementType >::Matrix ( size_t  numRows,
size_t  numColumns 
)
inline

Creates a new matrix with a given number of rows and columns.

References Matrix< ElementType >::clear(), and Matrix< ElementType >::resize().

Referenced by Matrix< ElementType >::Matrix().

◆ Matrix() [2/4]

template<typename ElementType >
Matrix< ElementType >::Matrix ( size_t  numRows,
size_t  numColumns,
const ElementType *  dataPointer 
)
inline

◆ Matrix() [3/4]

template<typename ElementType >
Matrix< ElementType >::Matrix ( const Matrix< ElementType > &  )
default

Creates a copy of another matrix.

◆ Matrix() [4/4]

template<typename ElementType >
Matrix< ElementType >::Matrix ( Matrix< ElementType > &&  )
defaultnoexcept

Moves a copy of another matrix.

Member Function Documentation

◆ apply()

template<typename ElementType >
template<typename BinaryOperation >
Matrix& Matrix< ElementType >::apply ( const Matrix< ElementType > &  other,
BinaryOperation  binaryOp 
)
inlineprivate

◆ begin() [1/2]

template<typename ElementType >
ElementType* Matrix< ElementType >::begin ( )
inlinenoexcept

◆ begin() [2/2]

template<typename ElementType >
const ElementType* Matrix< ElementType >::begin ( ) const
inlinenoexcept

◆ clear()

◆ compare()

template<typename ElementType >
static bool Matrix< ElementType >::compare ( const Matrix< ElementType > &  a,
const Matrix< ElementType > &  b,
ElementType  tolerance = 0 
)
staticnoexcept

Compare to matrices with a given tolerance.

Referenced by Matrix< ElementType >::hadarmard(), and Matrix< ElementType >::operator==().

◆ end() [1/2]

template<typename ElementType >
ElementType* Matrix< ElementType >::end ( )
inlinenoexcept

◆ end() [2/2]

template<typename ElementType >
const ElementType* Matrix< ElementType >::end ( ) const
inlinenoexcept

◆ getNumColumns()

template<typename ElementType >
size_t Matrix< ElementType >::getNumColumns ( ) const
inlinenoexcept

Returns the number of columns in the matrix.

References Matrix< ElementType >::columns.

◆ getNumRows()

template<typename ElementType >
size_t Matrix< ElementType >::getNumRows ( ) const
inlinenoexcept

Returns the number of rows in the matrix.

References Matrix< ElementType >::rows.

◆ getRawDataPointer() [1/2]

template<typename ElementType >
ElementType* Matrix< ElementType >::getRawDataPointer ( )
inlinenoexcept

Returns a pointer to the raw data of the matrix object, ordered in row-major order (for modifying).

References Matrix< ElementType >::data, and Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getRawDataPointer().

Referenced by Matrix< ElementType >::apply().

◆ getRawDataPointer() [2/2]

template<typename ElementType >
const ElementType* Matrix< ElementType >::getRawDataPointer ( ) const
inlinenoexcept

Returns a pointer to the raw data of the matrix object, ordered in row-major order (for reading).

References Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::begin(), and Matrix< ElementType >::data.

◆ getSize()

template<typename ElementType >
Array<size_t> Matrix< ElementType >::getSize ( ) const
inlinenoexcept

Returns an Array of 2 integers with the number of rows and columns in the matrix.

References Matrix< ElementType >::columns, and Matrix< ElementType >::rows.

◆ hadarmard() [1/2]

template<typename ElementType >
Matrix& Matrix< ElementType >::hadarmard ( const Matrix< ElementType > &  other)
inlinenoexcept

Does a hadarmard product with the receiver and other and stores the result in the receiver.

References Matrix< ElementType >::apply().

Referenced by Matrix< ElementType >::hadarmard().

◆ hadarmard() [2/2]

template<typename ElementType >
static Matrix Matrix< ElementType >::hadarmard ( const Matrix< ElementType > &  a,
const Matrix< ElementType > &  b 
)
inlinestatic

Does a hadarmard product with a and b returns the result.

References Matrix< ElementType >::compare(), and Matrix< ElementType >::hadarmard().

◆ hankel()

template<typename ElementType >
static Matrix Matrix< ElementType >::hankel ( const Matrix< ElementType > &  vector,
size_t  size,
size_t  offset = 0 
)
static

Creates a squared size x size Hankel Matrix from a vector with an optional offset.

Parameters
vectorThe vector from which the Hankel matrix should be generated. Its number of rows should be at least 2 * (size - 1) + 1
sizeThe size of resulting square matrix.
offsetAn optional offset into the given vector.

Referenced by Matrix< ElementType >::Matrix().

◆ identity()

template<typename ElementType >
static Matrix Matrix< ElementType >::identity ( size_t  size)
static

Creates the identity matrix.

Referenced by Matrix< ElementType >::Matrix().

◆ isNullMatrix()

template<typename ElementType >
bool Matrix< ElementType >::isNullMatrix ( ) const
inlinenoexcept

◆ isOneColumnVector()

template<typename ElementType >
bool Matrix< ElementType >::isOneColumnVector ( ) const
inlinenoexcept

Tells if the matrix is a one column vector.

References Matrix< ElementType >::columns.

Referenced by Matrix< ElementType >::isVector().

◆ isOneRowVector()

template<typename ElementType >
bool Matrix< ElementType >::isOneRowVector ( ) const
inlinenoexcept

Tells if the matrix is a one row vector.

References Matrix< ElementType >::rows.

Referenced by Matrix< ElementType >::isVector().

◆ isSquare()

template<typename ElementType >
bool Matrix< ElementType >::isSquare ( ) const
inlinenoexcept

Tells if the matrix is a square matrix.

References Matrix< ElementType >::columns, and Matrix< ElementType >::rows.

◆ isVector()

template<typename ElementType >
bool Matrix< ElementType >::isVector ( ) const
inlinenoexcept

◆ operator()() [1/2]

template<typename ElementType >
ElementType Matrix< ElementType >::operator() ( size_t  row,
size_t  column 
) const
inlinenoexcept

◆ operator()() [2/2]

template<typename ElementType >
ElementType& Matrix< ElementType >::operator() ( size_t  row,
size_t  column 
)
inlinenoexcept

◆ operator*() [1/2]

template<typename ElementType >
Matrix Matrix< ElementType >::operator* ( ElementType  scalar) const
inline

Scalar multiplication.

◆ operator*() [2/2]

template<typename ElementType >
Matrix Matrix< ElementType >::operator* ( const Matrix< ElementType > &  other) const

Matrix multiplication.

◆ operator*=()

template<typename ElementType >
Matrix& Matrix< ElementType >::operator*= ( ElementType  scalar)
inlinenoexcept

Scalar multiplication.

References Matrix< ElementType >::begin(), and Matrix< ElementType >::end().

◆ operator+()

template<typename ElementType >
Matrix Matrix< ElementType >::operator+ ( const Matrix< ElementType > &  other) const
inline

Addition of two matrices.

◆ operator+=()

template<typename ElementType >
Matrix& Matrix< ElementType >::operator+= ( const Matrix< ElementType > &  other)
inlinenoexcept

Addition of two matrices.

References Matrix< ElementType >::apply().

◆ operator-()

template<typename ElementType >
Matrix Matrix< ElementType >::operator- ( const Matrix< ElementType > &  other) const
inline

Addition of two matrices.

◆ operator-=()

template<typename ElementType >
Matrix& Matrix< ElementType >::operator-= ( const Matrix< ElementType > &  other)
inlinenoexcept

Subtraction of two matrices.

References Matrix< ElementType >::apply().

◆ operator=() [1/2]

template<typename ElementType >
Matrix& Matrix< ElementType >::operator= ( const Matrix< ElementType > &  )
default

Creates a copy of another matrix.

Referenced by Matrix< ElementType >::Matrix().

◆ operator=() [2/2]

template<typename ElementType >
Matrix& Matrix< ElementType >::operator= ( Matrix< ElementType > &&  )
defaultnoexcept

Moves another matrix into this one.

◆ operator==()

template<typename ElementType >
bool Matrix< ElementType >::operator== ( const Matrix< ElementType > &  other) const
inlinenoexcept

◆ resize()

◆ solve()

template<typename ElementType >
bool Matrix< ElementType >::solve ( Matrix< ElementType > &  b) const
noexcept

Solves a linear system of equations represented by this object and the argument b, using various algorithms depending on the size of the arguments.

The matrix must be a square matrix N times N, and b must be a vector N times 1, with the coefficients of b. After the execution of the algorithm, the vector b will contain the solution.

Returns true if the linear system of euqations was successfully solved.

Referenced by Matrix< ElementType >::isNullMatrix().

◆ swapColumns()

template<typename ElementType >
Matrix& Matrix< ElementType >::swapColumns ( size_t  columnOne,
size_t  columnTwo 
)
noexcept

Swaps the contents of two columns in the matrix and returns a reference to itself.

Referenced by Matrix< ElementType >::clear().

◆ swapRows()

template<typename ElementType >
Matrix& Matrix< ElementType >::swapRows ( size_t  rowOne,
size_t  rowTwo 
)
noexcept

Swaps the contents of two rows in the matrix and returns a reference to itself.

Referenced by Matrix< ElementType >::clear().

◆ toeplitz()

template<typename ElementType >
static Matrix Matrix< ElementType >::toeplitz ( const Matrix< ElementType > &  vector,
size_t  size 
)
static

Creates a Toeplitz Matrix from a vector with a given squared size.

Referenced by Matrix< ElementType >::Matrix().

◆ toString()

template<typename ElementType >
String Matrix< ElementType >::toString ( ) const

Returns a String displaying in a convenient way the matrix contents.

Referenced by Matrix< ElementType >::isNullMatrix().

Member Data Documentation

◆ columns

◆ data

◆ dataAcceleration

template<typename ElementType >
Array<size_t> Matrix< ElementType >::dataAcceleration
private

◆ rows


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