CUDA Networks
|
Represents a matrix with GPU-accelerated operations. More...
#include <matrix.h>
Public Member Functions | |
Matrix (int rows, int cols) | |
Construct a new Matrix object. More... | |
Matrix (const Matrix &other) | |
Copy constructor. More... | |
Matrix (Matrix &&other) noexcept | |
Move constructor. More... | |
Matrix & | operator= (const Matrix &other) |
Copy assignment operator. More... | |
Matrix & | operator= (Matrix &&other) noexcept |
Move assignment operator. More... | |
~Matrix () | |
Destroy the Matrix object. More... | |
void | initialize () |
Initialize the matrix (typically sets all elements to zero) More... | |
void | randomize () |
Randomize the matrix elements with values between -0.5 and 0.5. More... | |
void | print (int decimals) |
Print the matrix contents. More... | |
int | get_rows () const |
Get the number of rows in the matrix. More... | |
int | get_cols () const |
Get the number of columns in the matrix. More... | |
double * | get_data () const |
Get the raw data pointer of the matrix. More... | |
void | read_csv (const char *filename) |
Read data from a CSV file into the matrix. More... | |
void | read_csv_limited (const char *filename, int startRow, int endRow, int fileRows, int fileCols) |
Read a subset of data from a CSV file into the matrix. More... | |
void | preview_image (int row_index, int image_size_x, int image_size_y) const |
Preview a single image from the matrix. More... | |
Matrix | relu () const |
Applies the ReLU activation function to the matrix. More... | |
Matrix | relu_derivative () const |
Applies the derivative of the ReLU activation function to the matrix. More... | |
Matrix | sigmoid () const |
Applies the sigmoid activation function to the matrix. More... | |
Matrix | sigmoid_derivative () const |
Applies the derivative of the sigmoid activation function to the matrix. More... | |
Matrix | softmax () const |
Applies the softmax function to the matrix column-wise. More... | |
Matrix | copy () const |
Creates a deep copy of the matrix. More... | |
Matrix | multiply (const Matrix &other) const |
Multiplies this matrix with another matrix. More... | |
Matrix | multiply_elementwise (const Matrix &other) const |
Performs element-wise multiplication with another matrix. More... | |
void | add_vector (const Vector &v) |
Adds a vector to each column of the matrix. More... | |
Matrix | subtract (const Matrix &other) const |
Subtracts another matrix from this matrix. More... | |
double | sum () const |
Sums all elements in the matrix. More... | |
void | divide_scalar (double scalar) |
Divides all elements in the matrix by a scalar. More... | |
void | multiply_scalar (double scalar) |
Multiplies all elements in the matrix by a scalar. More... | |
Vector | argmax () const |
Computes the argmax of each column in the matrix. More... | |
Matrix | transpose () const |
Transposes the matrix and returns a new Matrix object. More... | |
Matrix | select_batch (int start_row, int end_row, int start_col, int end_col) const |
Selects a subset of the matrix based on specified row and column ranges. More... | |
Matrix::Matrix | ( | int | rows, |
int | cols | ||
) |
Construct a new Matrix object.
rows | Number of rows in the matrix |
cols | Number of columns in the matrix |
Definition at line 8 of file matrix_constructor.cu.
Matrix::Matrix | ( | const Matrix & | other | ) |
Copy constructor.
other | The matrix to copy from |
Definition at line 9 of file matrix_copy.cu.
|
noexcept |
Move constructor.
other | The matrix to move from |
Definition at line 33 of file matrix_copy.cu.
Matrix::~Matrix | ( | ) |
Destroy the Matrix object.
Definition at line 8 of file matrix_destructor.cu.
void Matrix::add_vector | ( | const Vector & | v | ) |
Adds a vector to each column of the matrix.
v | The vector to add. |
std::invalid_argument | if vector dimension doesn't match matrix rows. |
Definition at line 39 of file matrix_add_vector.cu.
Vector Matrix::argmax | ( | ) | const |
Computes the argmax of each column in the matrix.
Launches the argmax_GPU kernel to perform column-wise argmax on the matrix.
Definition at line 44 of file matrix_argmax.cu.
Matrix Matrix::copy | ( | ) | const |
Creates a deep copy of the matrix.
Definition at line 59 of file matrix_copy.cu.
void Matrix::divide_scalar | ( | double | scalar | ) |
Divides all elements in the matrix by a scalar.
scalar | The scalar to divide by. |
std::invalid_argument | if scalar is zero. |
scalar | The scalar to divide by. |
std::invalid_argument | if scalar is exactly zero. |
Definition at line 47 of file matrix_divide_scalar.cu.
int Matrix::get_cols | ( | ) | const |
Get the number of columns in the matrix.
Definition at line 7 of file matrix_get_cols.cu.
double * Matrix::get_data | ( | ) | const |
Get the raw data pointer of the matrix.
Definition at line 7 of file matrix_get_data.cu.
int Matrix::get_rows | ( | ) | const |
Get the number of rows in the matrix.
Definition at line 7 of file matrix_get_rows.cu.
void Matrix::initialize | ( | ) |
Initialize the matrix (typically sets all elements to zero)
Definition at line 8 of file matrix_initialize.cu.
Multiplies this matrix with another matrix.
other | The matrix to multiply with. |
std::invalid_argument | if matrix dimensions are incompatible for multiplication. |
Definition at line 51 of file matrix_multiply.cu.
Performs element-wise multiplication with another matrix.
other | The matrix to multiply element-wise with. |
std::invalid_argument | if matrix dimensions are not identical. |
Definition at line 40 of file matrix_multiply_elementwise.cu.
void Matrix::multiply_scalar | ( | double | scalar | ) |
Multiplies all elements in the matrix by a scalar.
scalar | The scalar to multiply by. |
Definition at line 41 of file matrix_multiply_scalar.cu.
Copy assignment operator.
other | The matrix to copy from |
Definition at line 16 of file matrix_copy.cu.
Move assignment operator.
other | The matrix to move from |
Definition at line 41 of file matrix_copy.cu.
void Matrix::preview_image | ( | int | row_index, |
int | image_size_x, | ||
int | image_size_y | ||
) | const |
Preview a single image from the matrix.
row_index | Index of the row containing the image data |
image_size_x | Number of rows in the image |
image_size_y | Number of columns in the image |
Definition at line 11 of file matrix_preview_image.cu.
void Matrix::print | ( | int | decimals | ) |
Print the matrix contents.
decimals | Number of decimal places to display |
Definition at line 11 of file matrix_print.cu.
void Matrix::randomize | ( | ) |
Randomize the matrix elements with values between -0.5 and 0.5.
Fills the matrix with random values between -0.5 and 0.5.
Definition at line 43 of file matrix_randomize.cu.
void Matrix::read_csv | ( | const char * | filename | ) |
Read data from a CSV file into the matrix.
filename | Path to the CSV file |
Definition at line 12 of file matrix_read_csv.cu.
void Matrix::read_csv_limited | ( | const char * | filename, |
int | startRow, | ||
int | endRow, | ||
int | fileRows, | ||
int | fileCols | ||
) |
Read a subset of data from a CSV file into the matrix.
filename | Path to the CSV file |
startRow | Starting row to read from the CSV file (0-based index) |
endRow | Ending row to read from the CSV file (exclusive) |
fileRows | Total number of rows in the CSV file |
fileCols | Total number of columns in the CSV file |
Definition at line 12 of file matrix_read_csv_limited.cu.
Matrix Matrix::relu | ( | ) | const |
Applies the ReLU activation function to the matrix.
Definition at line 30 of file matrix_relu.cu.
Matrix Matrix::relu_derivative | ( | ) | const |
Applies the derivative of the ReLU activation function to the matrix.
Applies the ReLU derivative function to the matrix.
Definition at line 30 of file matrix_relu_derivative.cu.
Matrix Matrix::select_batch | ( | int | start_row, |
int | end_row, | ||
int | start_col, | ||
int | end_col | ||
) | const |
Selects a subset of the matrix based on specified row and column ranges.
start_row | Starting row index (inclusive). |
end_row | Ending row index (exclusive). |
start_col | Starting column index (inclusive). |
end_col | Ending column index (exclusive). |
std::out_of_range | if the specified ranges are invalid. |
Definition at line 38 of file matrix_select_batch.cu.
Matrix Matrix::sigmoid | ( | ) | const |
Applies the sigmoid activation function to the matrix.
Definition at line 31 of file matrix_sigmoid.cu.
Matrix Matrix::sigmoid_derivative | ( | ) | const |
Applies the derivative of the sigmoid activation function to the matrix.
Applies the sigmoid derivative function to the matrix.
Definition at line 33 of file matrix_sigmoid_derivative.cu.
Matrix Matrix::softmax | ( | ) | const |
Applies the softmax function to the matrix column-wise.
Definition at line 53 of file matrix_softmax.cu.
Subtracts another matrix from this matrix.
other | The matrix to subtract. |
std::invalid_argument | if matrix dimensions are not identical. |
Definition at line 40 of file matrix_subtract.cu.
double Matrix::sum | ( | ) | const |
Sums all elements in the matrix.
Definition at line 15 of file matrix_sum.cu.
Matrix Matrix::transpose | ( | ) | const |
Transposes the matrix and returns a new Matrix object.
Transposes the matrix and returns a new Matrix object containing the transposed data.
Definition at line 36 of file matrix_transpose.cu.