JUCE: dsp::Matrix< ElementType > Class Template Reference

JUCE

Public Member Functions | Static Public Member Functions | List of all members
dsp::Matrix< ElementType > Class Template Reference
juce_dsp » maths

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>`

## 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...
Matrix & | operator= (const Matrix &)=default
| Creates a copy of another matrix. More...
Matrix & | operator= (Matrix &&) noexcept=default
| Moves another matrix into this one. More...
size_t | getNumRows () const noexcept
| Returns the number of rows in the matrix. More...
size_t | getNumColumns () const noexcept
| Returns the number of columns in the matrix. More...
Array< size_t > | getSize () const noexcept
| Returns an Array of 2 integers with the number of rows and columns in the matrix. More...
void | clear () noexcept
| Fills the contents of the matrix with zeroes. More...
Matrix & | swapRows (size_t rowOne, size_t rowTwo) noexcept
| Swaps the contents of two rows in the matrix and returns a reference to itself. More...
Matrix & | swapColumns (size_t columnOne, size_t columnTwo) noexcept
| Swaps the contents of two columns in the matrix and returns a reference to itself. 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...
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...
Matrix & | operator+= (const Matrix &other) noexcept
| Addition of two matrices. More...
Matrix & | operator-= (const Matrix &other) noexcept
| Subtraction of two matrices. More...
Matrix & | operator*= (ElementType scalar) noexcept
| Scalar multiplication. More...
Matrix | operator+ (const Matrix &other) const
| Addition of two matrices. More...
Matrix | operator- (const Matrix &other) const
| Addition of two matrices. More...
Matrix | operator* (ElementType scalar) const
| Scalar multiplication. More...
Matrix | operator* (const Matrix &other) const
| Matrix multiplication. More...
Matrix & | hadarmard (const Matrix &other) noexcept
| Does a hadarmard product with the receiver and other and stores the result in the receiver. More...
bool | operator== (const Matrix &other) const noexcept
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...
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 | isNullMatrix () const noexcept
| Tells if the matrix is a null matrix. More...
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...
String | toString () const
| Returns a String displaying in a convenient way the matrix contents. More...
ElementType * | begin () noexcept
ElementType * | end () noexcept
const ElementType * | begin () const noexcept
const ElementType * | end () const noexcept

## Static Public Member Functions
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...
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 | hadarmard (const Matrix &a, const Matrix &b)
| Does a hadarmard product with a and b returns the result. More...
static bool | compare (const Matrix &a, const Matrix &b, ElementType tolerance=0) noexcept
| Compare to matrices with a given tolerance. More...

## Detailed Description

template<typename ElementType>
class dsp::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 >

dsp::Matrix< ElementType >::Matrix | ( | size_t | numRows,
|  | size_t | numColumns
| ) |  |

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

References dsp::Matrix< ElementType >::clear().

## ◆ Matrix() [2/4]

template<typename ElementType >

dsp::Matrix< ElementType >::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.

## ◆ Matrix() [3/4]

template<typename ElementType >

dsp::Matrix< ElementType >::Matrix | ( | const Matrix< ElementType > & |  | ) |
| default

Creates a copy of another matrix.

## ◆ Matrix() [4/4]

template<typename ElementType >

dsp::Matrix< ElementType >::Matrix | ( | Matrix< ElementType > && |  | ) |
| defaultnoexcept

Moves a copy of another matrix.

## Member Function Documentation

## ◆ operator=() [1/2]

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::operator= | ( | const Matrix< ElementType > & |  | ) |
| default

Creates a copy of another matrix.

## ◆ operator=() [2/2]

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::operator= | ( | Matrix< ElementType > && |  | ) |
| defaultnoexcept

Moves another matrix into this one.

## ◆ identity()

template<typename ElementType >

static Matrix dsp::Matrix< ElementType >::identity | ( | size_t | size | ) |
| static

Creates the identity matrix.

## ◆ toeplitz()

template<typename ElementType >

static Matrix dsp::Matrix< ElementType >::toeplitz | ( | const Matrix< ElementType > & | vector,
|  | size_t | size
| ) |  |
| static

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

## ◆ hankel()

template<typename ElementType >

static Matrix dsp::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

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

## ◆ getNumRows()

template<typename ElementType >

size_t dsp::Matrix< ElementType >::getNumRows | ( |  | ) | const
| noexcept

Returns the number of rows in the matrix.

## ◆ getNumColumns()

template<typename ElementType >

size_t dsp::Matrix< ElementType >::getNumColumns | ( |  | ) | const
| noexcept

Returns the number of columns in the matrix.

## ◆ getSize()

template<typename ElementType >

Array< size_t > dsp::Matrix< ElementType >::getSize | ( |  | ) | const
| noexcept

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

## ◆ clear()

template<typename ElementType >

void dsp::Matrix< ElementType >::clear | ( |  | ) |
| noexcept

Fills the contents of the matrix with zeroes.

References zeromem().

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

## ◆ swapRows()

template<typename ElementType >

Matrix & dsp::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.

## ◆ swapColumns()

template<typename ElementType >

Matrix & dsp::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.

## ◆ operator()() [1/2]

template<typename ElementType >

ElementType dsp::Matrix< ElementType >::operator() | ( | size_t | row,
|  | size_t | column
| ) |  | const
| noexcept

Returns the value of the matrix at a given row and column (for reading).

References Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getReference(), and jassert.

## ◆ operator()() [2/2]

template<typename ElementType >

ElementType & dsp::Matrix< ElementType >::operator() | ( | size_t | row,
|  | size_t | column
| ) |  |
| noexcept

Returns the value of the matrix at a given row and column (for modifying).

References Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getReference(), and jassert.

## ◆ getRawDataPointer() [1/2]

template<typename ElementType >

ElementType * dsp::Matrix< ElementType >::getRawDataPointer | ( |  | ) |
| noexcept

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

## ◆ getRawDataPointer() [2/2]

template<typename ElementType >

const ElementType * dsp::Matrix< ElementType >::getRawDataPointer | ( |  | ) | const
| noexcept

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

## ◆ operator+=()

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::operator+= | ( | const Matrix< ElementType > & | other | ) |
| noexcept

Addition of two matrices.

References gl::a, and gl::b.

## ◆ operator-=()

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::operator-= | ( | const Matrix< ElementType > & | other | ) |
| noexcept

Subtraction of two matrices.

References gl::a, and gl::b.

## ◆ operator*=()

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::operator*= | ( | ElementType | scalar | ) |
| noexcept

Scalar multiplication.

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

## ◆ operator+()

template<typename ElementType >

Matrix dsp::Matrix< ElementType >::operator+ | ( | const Matrix< ElementType > & | other | ) | const

Addition of two matrices.

References gl::result.

## ◆ operator-()

template<typename ElementType >

Matrix dsp::Matrix< ElementType >::operator- | ( | const Matrix< ElementType > & | other | ) | const

Addition of two matrices.

References gl::result.

## ◆ operator*() [1/2]

template<typename ElementType >

Matrix dsp::Matrix< ElementType >::operator* | ( | ElementType | scalar | ) | const

Scalar multiplication.

References gl::result.

## ◆ operator*() [2/2]

template<typename ElementType >

Matrix dsp::Matrix< ElementType >::operator* | ( | const Matrix< ElementType > & | other | ) | const

Matrix multiplication.

## ◆ hadarmard() [1/2]

template<typename ElementType >

Matrix & dsp::Matrix< ElementType >::hadarmard | ( | const Matrix< ElementType > & | other | ) |
| noexcept

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

References gl::a, and gl::b.

## ◆ hadarmard() [2/2]

template<typename ElementType >

static Matrix dsp::Matrix< ElementType >::hadarmard | ( | const Matrix< ElementType > & | a,
|  | const Matrix< ElementType > & | b
| ) |  |
| static

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

References gl::a, gl::b, and gl::result.

## ◆ compare()

template<typename ElementType >

static bool dsp::Matrix< ElementType >::compare | ( | const Matrix< ElementType > & | a,
|  | const Matrix< ElementType > & | b,
|  | ElementType | tolerance = `0`
| ) |  |
| staticnoexcept

Compare to matrices with a given tolerance.

Referenced by dsp::Matrix< ElementType >::operator==().

## ◆ operator==()

template<typename ElementType >

bool dsp::Matrix< ElementType >::operator== | ( | const Matrix< ElementType > & | other | ) | const
| noexcept

References dsp::Matrix< ElementType >::compare().

## ◆ isSquare()

template<typename ElementType >

bool dsp::Matrix< ElementType >::isSquare | ( |  | ) | const
| noexcept

Tells if the matrix is a square matrix.

## ◆ isVector()

template<typename ElementType >

bool dsp::Matrix< ElementType >::isVector | ( |  | ) | const
| noexcept

Tells if the matrix is a vector.

References dsp::Matrix< ElementType >::isOneColumnVector(), and dsp::Matrix< ElementType >::isOneRowVector().

## ◆ isOneColumnVector()

template<typename ElementType >

bool dsp::Matrix< ElementType >::isOneColumnVector | ( |  | ) | const
| noexcept

Tells if the matrix is a one column vector.

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

## ◆ isOneRowVector()

template<typename ElementType >

bool dsp::Matrix< ElementType >::isOneRowVector | ( |  | ) | const
| noexcept

Tells if the matrix is a one row vector.

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

## ◆ isNullMatrix()

template<typename ElementType >

bool dsp::Matrix< ElementType >::isNullMatrix | ( |  | ) | const
| noexcept

Tells if the matrix is a null matrix.

## ◆ solve()

template<typename ElementType >

bool dsp::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 equations was successfully solved.

## ◆ toString()

template<typename ElementType >

String dsp::Matrix< ElementType >::toString | ( |  | ) | const

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

## ◆ begin() [1/2]

template<typename ElementType >

ElementType * dsp::Matrix< ElementType >::begin | ( |  | ) |
| noexcept

Referenced by dsp::Matrix< ElementType >::end(), and dsp::Matrix< ElementType >::operator*=().

## ◆ end() [1/2]

template<typename ElementType >

ElementType * dsp::Matrix< ElementType >::end | ( |  | ) |
| noexcept

Referenced by dsp::Matrix< ElementType >::operator*=().

## ◆ begin() [2/2]

template<typename ElementType >

const ElementType * dsp::Matrix< ElementType >::begin | ( |  | ) | const
| noexcept

## ◆ end() [2/2]

template<typename ElementType >

const ElementType * dsp::Matrix< ElementType >::end | ( |  | ) | const
| noexcept

References dsp::Matrix< ElementType >::begin().

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

- juce_Matrix.h