OpenWareLaboratory
FloatMatrix Class Reference

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

Public Member Functions

void add (FloatMatrix operand2, FloatMatrix destination)
 Element-wise sum between matrices. More...
 
void add (FloatMatrix operand2)
 Element-wise sum between arrays. More...
 
void add (float scalar)
 Matrix-scalar sum. More...
 
void clear ()
 Clear the array. More...
 
 FloatMatrix ()
 
 FloatMatrix (float *data, size_t rows, size_t columns)
 
 FloatMatrix (const 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 (FloatMatrix operand2, FloatMatrix destination)
 Element-wise multiplication between arrays. More...
 
void multiply (FloatMatrix operand2)
 Element-wise multiplication between arrays. More...
 
void multiply (float scalar)
 Matrix scalar multiplication. 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 (FloatMatrix destination)
 
void sigmoid ()
 
void softmax (FloatMatrix destination)
 
void softmax ()
 

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::FloatMatrix ( )

Definition at line 18 of file FloatMatrix.cpp.

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

Definition at line 20 of file FloatMatrix.cpp.

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

Definition at line 22 of file FloatMatrix.cpp.

Member Function Documentation

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 26 of file FloatMatrix.cpp.

References ASSERT, and getSize().

Referenced by add().

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 42 of file FloatMatrix.cpp.

References add().

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 46 of file FloatMatrix.cpp.

References getData(), and getSize().

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().

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 127 of file FloatMatrix.cpp.

References clear().

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 133 of file FloatMatrix.cpp.

size_t FloatMatrix::getColumns ( ) const
inline

Definition at line 37 of file FloatMatrix.h.

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

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(), getElement(), multiply(), operator float *(), operator[](), setAll(), setElement(), sigmoid(), and softmax().

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

Get a single float stored in the FloatMatrix.

Returns
the float stored at index
Parameters
index

Definition at line 147 of file FloatMatrix.h.

References getColumns(), and getData().

Referenced by multiply().

size_t FloatMatrix::getRows ( ) const
inline

Definition at line 29 of file FloatMatrix.h.

Referenced by getSize(), and multiply().

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(), multiply(), setAll(), sigmoid(), and softmax().

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 53 of file FloatMatrix.cpp.

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

Referenced by multiply().

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 81 of file FloatMatrix.cpp.

References multiply().

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 85 of file FloatMatrix.cpp.

References getData(), and getSize().

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().

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

Definition at line 127 of file FloatMatrix.h.

References getColumns(), and getData().

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 92 of file FloatMatrix.cpp.

References getData(), and getSize().

Referenced by clear().

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().

void FloatMatrix::sigmoid ( FloatMatrix  destination)

Definition at line 118 of file FloatMatrix.cpp.

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

void FloatMatrix::sigmoid ( )
inline

Definition at line 166 of file FloatMatrix.h.

void FloatMatrix::softmax ( FloatMatrix  destination)

Definition at line 99 of file FloatMatrix.cpp.

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

void FloatMatrix::softmax ( )
inline

Definition at line 160 of file FloatMatrix.h.


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