OpenWareLaboratory
FloatMatrix Class Reference

This class contains useful methods for manipulating NxN dimensioned matrices of floats. More...

Public Member Functions

void add (float scalar)
 Matrix-scalar sum. More...
 
void add (FloatMatrix operand2)
 Element-wise sum between arrays. More...
 
void add (FloatMatrix operand2, FloatMatrix destination)
 Element-wise sum between matrices. More...
 
void clear ()
 Clear the array. More...
 
void copyFrom (FloatMatrix source)
 Copies the content of another matrix into this matrix. More...
 
void copyTo (FloatMatrix destination)
 Copies the content of this matrix to another matrix. More...
 
 FloatMatrix ()
 
 FloatMatrix (const float *data, size_t rows, size_t columns)
 
 FloatMatrix (float *data, size_t rows, size_t columns)
 
size_t getColumns () const
 
float * getData ()
 Get the data stored in the FloatMatrix. More...
 
float getElement (int row, int col)
 Get a single float stored in the FloatMatrix. More...
 
size_t getRows () const
 
size_t getSize () const
 Get the number of elements in this matrix. More...
 
void multiply (float scalar)
 Matrix scalar multiplication. More...
 
void multiply (FloatMatrix operand2)
 Element-wise multiplication between arrays. More...
 
void multiply (FloatMatrix operand2, FloatMatrix destination)
 Element-wise multiplication between arrays. More...
 
 operator float * ()
 Casting operator to float*. More...
 
float * operator[] (const int index)
 
void setAll (float value)
 Set all the values in the array. More...
 
void setElement (int row, int col, float value)
 Set a single float in the FloatMatrix. More...
 
void sigmoid ()
 
void sigmoid (FloatMatrix destination)
 
void softmax ()
 
void softmax (FloatMatrix destination)
 

Static Public Member Functions

static FloatMatrix create (size_t rows, size_t columns)
 Creates a new FloatMatrix. More...
 
static void destroy (FloatMatrix array)
 Destroys a FloatMatrix created with the create() method. More...
 

Detailed Description

This class contains useful methods for manipulating NxN dimensioned matrices of floats.

Definition at line 10 of file FloatMatrix.h.

Constructor & Destructor Documentation

◆ FloatMatrix() [1/3]

FloatMatrix::FloatMatrix ( )

Definition at line 19 of file FloatMatrix.cpp.

◆ FloatMatrix() [2/3]

FloatMatrix::FloatMatrix ( float *  data,
size_t  rows,
size_t  columns 
)

Definition at line 21 of file FloatMatrix.cpp.

◆ FloatMatrix() [3/3]

FloatMatrix::FloatMatrix ( const float *  data,
size_t  rows,
size_t  columns 
)

Definition at line 23 of file FloatMatrix.cpp.

Member Function Documentation

◆ add() [1/3]

void FloatMatrix::add ( float  scalar)

Matrix-scalar sum.

Adds scalar to the values in the array.

Parameters
scalarvalue to be added to the array

Definition at line 47 of file FloatMatrix.cpp.

References getData(), and getSize().

◆ add() [2/3]

void FloatMatrix::add ( FloatMatrix  operand2)

Element-wise sum between arrays.

Adds each element of operand2 to the corresponding element in the array.

Parameters
operand2second operand for the sum

Definition at line 43 of file FloatMatrix.cpp.

References add().

◆ add() [3/3]

void FloatMatrix::add ( FloatMatrix  operand2,
FloatMatrix  destination 
)

Element-wise sum between matrices.

Parameters
[in]operand2second operand for the sum
[out]destinationthe destination array

Definition at line 27 of file FloatMatrix.cpp.

References ASSERT, and getSize().

Referenced by add(), and InterpolatedCompositeTransform< matrix_order >::process().

◆ clear()

void FloatMatrix::clear ( )
inline

Clear the array.

Set all the values in the array to 0.

Definition at line 49 of file FloatMatrix.h.

References setAll().

Referenced by create(), and AbstractMatrix< matrix_order >::resetMatrix().

◆ copyFrom()

void FloatMatrix::copyFrom ( FloatMatrix  source)

Copies the content of another matrix into this matrix.

This matrix needs to be at least as big as the other matrix.

Parameters
[in]sourcethe source matrix

Definition at line 133 of file FloatMatrix.cpp.

References ASSERT, getData(), and getSize().

Referenced by CompositeTransform< matrix_order >::computeMatrix(), InterpolatedCompositeTransform< matrix_order >::computeMatrix(), and InterpolatedCompositeTransform< matrix_order >::process().

◆ copyTo()

void FloatMatrix::copyTo ( FloatMatrix  destination)

Copies the content of this matrix to another matrix.

The other matrix needs to be at least as big as this matrix.

Parameters
[out]destinationthe destination matrix

Definition at line 128 of file FloatMatrix.cpp.

References ASSERT, getData(), and getSize().

◆ create()

FloatMatrix FloatMatrix::create ( size_t  rows,
size_t  columns 
)
static

Creates a new FloatMatrix.

Allocates rows*columns*sizeof(float) bytes of memory and returns a FloatMatrix that points to it.

Parameters
rowsthe number of rows of the new FloatMatrix.
columnsthe number of columns of the new FloatMatrix.
Returns
a FloatMatrix which data point to the newly allocated memory and rows and columns initialized to the proper values.
Remarks
a FloatMatrix created with this method should be destroyed invoking the FloatMatrix::destroy() method.

Definition at line 138 of file FloatMatrix.cpp.

References clear().

Referenced by TransformationMatrix< matrix_order, Operation >::create(), CompositeTransform< matrix_order >::create(), and InterpolatedCompositeTransform< matrix_order >::create().

◆ destroy()

void FloatMatrix::destroy ( FloatMatrix  array)
static

Destroys a FloatMatrix created with the create() method.

Parameters
arraythe FloatMatrix to be destroyed.
Remarks
the FloatMatrix object passed as an argument should not be used again after invoking this method.
a FloatMatrix object that has not been created by the FloatMatrix::create() method might cause an exception if passed as an argument to this method.

Definition at line 144 of file FloatMatrix.cpp.

Referenced by CompositeTransform< matrix_order >::destroy(), InterpolatedCompositeTransform< matrix_order >::destroy(), and TransformationMatrix< matrix_order, Operation >::destroy().

◆ getColumns()

size_t FloatMatrix::getColumns ( ) const
inline

Definition at line 37 of file FloatMatrix.h.

Referenced by getElement(), getSize(), multiply(), operator[](), and setElement().

◆ getData()

float* FloatMatrix::getData ( )
inline

Get the data stored in the FloatMatrix.

Returns
a float* pointer to the data stored in the FloatMatrix

Definition at line 135 of file FloatMatrix.h.

Referenced by add(), copyFrom(), copyTo(), getElement(), multiply(), operator float *(), operator[](), setAll(), setElement(), sigmoid(), and softmax().

◆ getElement()

float FloatMatrix::getElement ( int  row,
int  col 
)
inline

Get a single float stored in the FloatMatrix.

Returns
the float stored at index row and col

Definition at line 147 of file FloatMatrix.h.

References getColumns(), and getData().

Referenced by multiply().

◆ getRows()

size_t FloatMatrix::getRows ( ) const
inline

Definition at line 29 of file FloatMatrix.h.

Referenced by getSize(), and multiply().

◆ getSize()

size_t FloatMatrix::getSize ( ) const
inline

Get the number of elements in this matrix.

Definition at line 25 of file FloatMatrix.h.

References getColumns(), and getRows().

Referenced by add(), copyFrom(), copyTo(), multiply(), setAll(), sigmoid(), and softmax().

◆ multiply() [1/3]

void FloatMatrix::multiply ( float  scalar)

Matrix scalar multiplication.

Multiplies each value in the matrix by scalar.

Parameters
scalarto be subtracted from the array

Definition at line 86 of file FloatMatrix.cpp.

References getData(), and getSize().

◆ multiply() [2/3]

void FloatMatrix::multiply ( FloatMatrix  operand2)

Element-wise multiplication between arrays.

Multiplies each element in the array by the corresponding element in operand2.

Parameters
operand2second operand for the sum

Definition at line 82 of file FloatMatrix.cpp.

References multiply().

◆ multiply() [3/3]

void FloatMatrix::multiply ( FloatMatrix  operand2,
FloatMatrix  destination 
)

Element-wise multiplication between arrays.

Sets each element in destination to the product of the corresponding element of the array and operand2 Multiplying an M x N matrix with an N x P matrix results in an M x P matrix.

Parameters
[in]operand2second operand for the product
[out]destinationthe destination array

Definition at line 54 of file FloatMatrix.cpp.

References ASSERT, getColumns(), getElement(), getRows(), and setElement().

Referenced by CompositeTransform< matrix_order >::computeMatrix(), InterpolatedCompositeTransform< matrix_order >::computeMatrix(), and multiply().

◆ operator float *()

FloatMatrix::operator float * ( )
inline

Casting operator to float*.

Returns
a float* pointer to the data stored in the FloatMatrix

Definition at line 123 of file FloatMatrix.h.

References getData().

◆ operator[]()

float* FloatMatrix::operator[] ( const int  index)
inline

Definition at line 127 of file FloatMatrix.h.

References getColumns(), and getData().

◆ setAll()

void FloatMatrix::setAll ( float  value)

Set all the values in the array.

Sets all the elements of the array to value.

Parameters
[in]valueall the elements are set to this value.

Definition at line 93 of file FloatMatrix.cpp.

References getData(), and getSize().

Referenced by clear().

◆ setElement()

void FloatMatrix::setElement ( int  row,
int  col,
float  value 
)
inline

Set a single float in the FloatMatrix.

Definition at line 154 of file FloatMatrix.h.

References getColumns(), and getData().

Referenced by multiply().

◆ sigmoid() [1/2]

void FloatMatrix::sigmoid ( )
inline

Definition at line 166 of file FloatMatrix.h.

◆ sigmoid() [2/2]

void FloatMatrix::sigmoid ( FloatMatrix  destination)

Definition at line 119 of file FloatMatrix.cpp.

References ASSERT, getData(), and getSize().

◆ softmax() [1/2]

void FloatMatrix::softmax ( )
inline

Definition at line 160 of file FloatMatrix.h.

◆ softmax() [2/2]

void FloatMatrix::softmax ( FloatMatrix  destination)

Definition at line 100 of file FloatMatrix.cpp.

References ASSERT, getData(), and getSize().


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