|
CNum 0.2.1
CPU-optimized ML library for C++
|
2d array abstraction More...
#include <Matrix.h>
Public Member Functions | |
| Matrix (size_t rows=0, size_t cols=0, ::std::unique_ptr< T[]> ptr=nullptr) | |
| Default Overloaded Constructor. | |
| Matrix (const Matrix &other) noexcept | |
| Copy Constructor. | |
| Matrix< T > & | operator= (const Matrix &other) noexcept |
| Copy Logic. | |
| Matrix (Matrix &&other) noexcept | |
| Move Constructor. | |
| Matrix< T > & | operator= (Matrix &&other) noexcept |
| Move Assignment. | |
| ~Matrix () | |
| Destructor. | |
| Matrix< T > | operator* (const Matrix &other) const |
| Dot Product. | |
| Matrix< T > | operator* (T scale_factor) const noexcept |
| Scale a matrix. | |
| T | dot (const Matrix< T > &other) const |
| Vector dot product (1d). | |
| Matrix< T > | operator+ (const Matrix &other) const |
| Add two matrices element wise. | |
| Matrix< T > | operator+ (T a) const noexcept |
| Add a value to every element in a matrix. | |
| Matrix< T > | operator- (const Matrix &other) const |
| Subtract two matrices element wise. | |
| Matrix< T > | operator- (T a) const noexcept |
| Subtract a value to every element in a matrix. | |
| Matrix< T > | abs () const |
| Take the absolute value of all elements in a matrix. | |
| Matrix< T > | squared () const |
| Square all elements in a matrix. | |
| Matrix< T > | standardize () const |
| Standardize Matrix. | |
| T | sum () const |
| Get the sum of all elements in a matrix. | |
| T | mean () const |
| Get the mean of all values in a matrix. | |
| T | std () const |
| Get the standard deviation of all elements in a matrix. | |
| T | get (size_t row, size_t col) const |
| Get value of a matrix. | |
| Matrix< T > | get (Dim d, size_t idx) const |
| Get a copy of a Row/Col (prefer views for memory effeciency). | |
| CNum::DataStructs::Views::StrideView< T > | get_col_view (size_t idx) const |
| Get a column view. | |
| ::std::span< T > | get_row_view (size_t idx) const |
| Get a row view. | |
| T | operator[] (size_t idx) const |
| Get the value at index idx of a Matrix with shape=(n,1). | |
| Matrix< T > | operator[] (const BinaryMask &bin_mask) const |
| Apply a binary mask. | |
| Matrix< T > | operator[] (const IndexMask &idx_mask) const noexcept |
| Apply index mask. | |
| Matrix< T > | col_wise_mask_application (const IndexMask &idx_mask) const noexcept |
| Apply IndexMask column wise. | |
| BinaryMask | operator< (T val) const |
| Create a binary mask of values less than another. | |
| BinaryMask | operator<= (T val) const |
| Create a binary mask of values less than or equal to another. | |
| BinaryMask | operator> (T val) const |
| Create a binary mask of values greater than another. | |
| BinaryMask | operator>= (T val) const |
| Create a binary mask of values greater than or equal to another. | |
| BinaryMask | operator== (T val) const |
| Create a binary mask of values equal to another. | |
| BinaryMask | operator!= (T val) const |
| Create a binary mask of values not equal to another. | |
| IndexMask | argsort (bool descending=false) const |
| Argsort. | |
| Matrix< T > | transpose () const noexcept |
| Transpose a matrix. | |
| size_t | get_rows () const |
| Get the number of rows in a matrix. | |
| size_t | get_cols () const |
| Get the number of rows in a matrix. | |
| const T * | begin () const |
| Get an iterator (pointer) to the beginning of a matrix. | |
| const T * | end () const |
| Get a const iterator (pointer) to the end of a matrix. | |
| T * | begin () |
| Get an iterator (pointer) to the beginning of a matrix. | |
| T * | end () |
| Get an iterator (pointer) to the end of a matrix. | |
| size_t | size () const |
| Get the number of rows in a Matrix (helpful for stl algorithms). | |
| ::std::unique_ptr< T[]> && | move_ptr () |
| Relinquish ownership of the unique pointer with the matrix data. | |
| void | print_matrix () const |
| Print a matrix. | |
Static Public Member Functions | |
| static Matrix< T > | init_const (size_t rows, size_t cols, T val) |
| Initialize a matrix with a constant value in each element. | |
| static Matrix< T > | identity (size_t dim) |
| Get an identity matrix. | |
| static Matrix< T > | join_cols (::std::vector< Matrix< T > > &cols) |
| Join a list of column matrices. | |
| static Matrix< T > | combine_vertically (::std::vector< Matrix< T > > &matrices, size_t total_rows) |
| Combine a list of row matrices. | |
2d array abstraction
Used for storing 2d, tabular data. Used in conjuction with CNum ML models and linear algebra operations
| T | The type of the data stored |
| CNum::DataStructs::Matrix< T >::Matrix | ( | size_t | rows = 0, |
| size_t | cols = 0, | ||
| ::std::unique_ptr< T[]> | ptr = nullptr ) |
Default Overloaded Constructor.
| rows | Number of rows in the matrix |
| cols | Number of columns in the matrix |
| ptr | The unique pointer containing the matrix data |
|
noexcept |
Copy Constructor.
|
noexcept |
Move Constructor.
| CNum::DataStructs::Matrix< T >::~Matrix | ( | ) |
Destructor.
| Matrix< T > CNum::DataStructs::Matrix< T >::abs | ( | ) | const |
Take the absolute value of all elements in a matrix.
| IndexMask CNum::DataStructs::Matrix< T >::argsort | ( | bool | descending = false | ) | const |
Argsort.
| descending | Whether or not to sort in descending order |
| T * CNum::DataStructs::Matrix< T >::begin | ( | ) |
Get an iterator (pointer) to the beginning of a matrix.
| const T * CNum::DataStructs::Matrix< T >::begin | ( | ) | const |
Get an iterator (pointer) to the beginning of a matrix.
|
noexcept |
Apply IndexMask column wise.
| idx_mask | The mask containing the column indeces to preserve |
|
static |
Combine a list of row matrices.
| The | list of row matrices |
| T CNum::DataStructs::Matrix< T >::dot | ( | const Matrix< T > & | other | ) | const |
Vector dot product (1d).
| other | The other vector with which to perform the dot product (shape=(n, 1)) |
| T * CNum::DataStructs::Matrix< T >::end | ( | ) |
Get an iterator (pointer) to the end of a matrix.
| const T * CNum::DataStructs::Matrix< T >::end | ( | ) | const |
Get a const iterator (pointer) to the end of a matrix.
| Matrix< T > CNum::DataStructs::Matrix< T >::get | ( | Dim | d, |
| size_t | idx ) const |
Get a copy of a Row/Col (prefer views for memory effeciency).
| d | either ROW or COL |
| idx | the index of the row/col |
| T CNum::DataStructs::Matrix< T >::get | ( | size_t | row, |
| size_t | col ) const |
Get value of a matrix.
| row | The row of the value |
| col | The column of the value |
| CNum::DataStructs::Views::StrideView< T > CNum::DataStructs::Matrix< T >::get_col_view | ( | size_t | idx | ) | const |
Get a column view.
| idx | The index of the column |
| size_t CNum::DataStructs::Matrix< T >::get_cols | ( | ) | const |
Get the number of rows in a matrix.
| std::span< T > CNum::DataStructs::Matrix< T >::get_row_view | ( | size_t | idx | ) | const |
Get a row view.
| idx | The index of the row |
| size_t CNum::DataStructs::Matrix< T >::get_rows | ( | ) | const |
Get the number of rows in a matrix.
|
static |
Get an identity matrix.
| dim | The dimensionality of the identity matrix |
|
static |
Initialize a matrix with a constant value in each element.
| rows | Amount of rows in the matrix |
| cols | Amount of columns in the matrix |
|
static |
Join a list of column matrices.
| cols | The list of column matrices |
| T CNum::DataStructs::Matrix< T >::mean | ( | ) | const |
Get the mean of all values in a matrix.
| std::unique_ptr< T[]> && CNum::DataStructs::Matrix< T >::move_ptr | ( | ) |
Relinquish ownership of the unique pointer with the matrix data.
| BinaryMask CNum::DataStructs::Matrix< T >::operator!= | ( | T | val | ) | const |
Create a binary mask of values not equal to another.
| val | The value with which to compare the elements of the Matrix to |
| Matrix< T > CNum::DataStructs::Matrix< T >::operator* | ( | const Matrix< T > & | other | ) | const |
Dot Product.
| other | Another matrix with which to perform a dot product |
|
noexcept |
Scale a matrix.
| scale_factor | The factor with which to scale the matrix |
| Matrix< T > CNum::DataStructs::Matrix< T >::operator+ | ( | const Matrix< T > & | other | ) | const |
Add two matrices element wise.
| other | The matrix to add |
|
noexcept |
Add a value to every element in a matrix.
| a | The value to add |
| Matrix< T > CNum::DataStructs::Matrix< T >::operator- | ( | const Matrix< T > & | other | ) | const |
Subtract two matrices element wise.
| other | The matrix to subtract |
|
noexcept |
Subtract a value to every element in a matrix.
| a | The element to subtract |
| BinaryMask CNum::DataStructs::Matrix< T >::operator< | ( | T | val | ) | const |
Create a binary mask of values less than another.
| val | The value with which to compare the elements of the Matrix to |
| BinaryMask CNum::DataStructs::Matrix< T >::operator<= | ( | T | val | ) | const |
Create a binary mask of values less than or equal to another.
| val | The value with which to compare the elements of the Matrix to |
|
noexcept |
Copy Logic.
|
noexcept |
Move Assignment.
| BinaryMask CNum::DataStructs::Matrix< T >::operator== | ( | T | val | ) | const |
Create a binary mask of values equal to another.
| val | The value with which to compare the elements of the Matrix to |
| BinaryMask CNum::DataStructs::Matrix< T >::operator> | ( | T | val | ) | const |
Create a binary mask of values greater than another.
| val | The value with which to compare the elements of the Matrix to |
| BinaryMask CNum::DataStructs::Matrix< T >::operator>= | ( | T | val | ) | const |
Create a binary mask of values greater than or equal to another.
| val | The value with which to compare the elements of the Matrix to |
| Matrix< T > CNum::DataStructs::Matrix< T >::operator[] | ( | const BinaryMask & | bin_mask | ) | const |
Apply a binary mask.
| m | The mask to apply |
|
noexcept |
Apply index mask.
| idx_mask | The index mask to apply |
| T CNum::DataStructs::Matrix< T >::operator[] | ( | size_t | idx | ) | const |
Get the value at index idx of a Matrix with shape=(n,1).
| idx | The index of the value |
| void CNum::DataStructs::Matrix< T >::print_matrix | ( | ) | const |
Print a matrix.
| size_t CNum::DataStructs::Matrix< T >::size | ( | ) | const |
| Matrix< T > CNum::DataStructs::Matrix< T >::squared | ( | ) | const |
Square all elements in a matrix.
| Matrix< T > CNum::DataStructs::Matrix< T >::standardize | ( | ) | const |
Standardize Matrix.
| T CNum::DataStructs::Matrix< T >::std | ( | ) | const |
Get the standard deviation of all elements in a matrix.
| T CNum::DataStructs::Matrix< T >::sum | ( | ) | const |
Get the sum of all elements in a matrix.
|
noexcept |
Transpose a matrix.