var::matrix
Class for 2d matrix of objects. More...
#include "matrix.hpp"
Public Classes
Name | |
---|---|
struct | LU Struct for PLU decomposition. |
Protected Classes
Name | |
---|---|
class | Col Col class for another operator[]. |
Protected Types
Name | |
---|---|
template <typename T > using std::vector< std::vector< T > > |
table 2D vector definition |
Public Functions
Name | |
---|---|
matrix(int r, int c) Construct a new matrix object. |
|
matrix() Default construct a new matrix object. |
|
matrix(std::initializer_list< std::initializer_list< D >> a) Construct a new matrix object. |
|
int | row() Returns the number of rows. |
int | col() Returns the number of columns. |
int | size() Returns total number of elements. |
auto | begin() Mainly invoked for the ranged for loop. |
auto | end() Returns end of data. |
auto | begin() const Returns const begin. |
auto | end() const Returns const end. |
D | get_element(int i, int j) Get the element object. |
std::vector< D > | get_row(int i) Returns the row at an index. |
std::vector< D > | get_col(int j) Returns the column at an index. |
void | resize(int r, int c) Resizes the matrix. |
void | push_row(std::vector< D > a) Inserts row at the end or the matrix. |
void | push_col(std::vector< D > a) Inserts column at the end of the matrix. |
void | insert_row(int i, std::vector< D > a) Inserts row at specefic index. |
void | insert_col(int j, std::vector< D > a) Inserts column at specefic index. |
void | pop_row() Removes last row. |
void | pop_col() removes last column |
void | erase_row(int i) Erase row at index. |
void | erase_col(int j) Erases column at index. |
void | row_swap(int i1, int i2) Swaps row of matrix. |
void | col_swap(int j1, int j2) Colum swap. |
void | replace_row(int i, std::vector< D > a) Replaces certain row. |
void | replace_col(int j, std::vector< D > a) Replaces certain colum. |
void | sort_rows(int d =1) Sorts all rows. |
void | sort_cols(int d =1) Sorts all columns. |
void | sort_row(int i, int d =1) Sorts rows at specefic index. |
void | sort_col(int j, int d =1) Sorts column at specefic index. |
template <typename LAMBDA > void |
row_op(int i, LAMBDA f) Does operations on specefic rows. |
template <typename LAMBDA > void |
col_op(int j, LAMBDA f) Does operations on a specefic column. |
template <typename LAMBDA > void |
mat_op(LAMBDA f) Function operation on all of the matrix. |
void | join_row(matrix other) Combines the rows of another matrix. |
void | join_col(matrix other) Combines the columns of another matrix. |
void | turn_to(D n) Converts all elements to n. |
D | sum() Sum of all elements. |
D | tr() Trace of a matrix. |
D | det() Returns the determinant. |
matrix | T() Transpose of a matrix. |
matrix | cofactor() Returns cofactor matrix. |
matrix | M(int i, int j) Minor of a matrix. |
matrix | adj() Adjugate of a matrix. |
matrix | inv() Returns inverse of a matrix. |
matrix | rref() Reduced row echolon form. |
matrix | ref() Row echolon form. |
LU | plu() PLU decomposition. |
bool | is_square() Checks if matrix is square. |
bool | is_empty() Returns if the matrix is empty or not. |
bool | is_identity() Checks if matrix is an identity matrix. |
Col | operator[](int i) [][] operator for matrix |
matrix | operator+(const matrix & other) Matrix addition. |
matrix | operator+(D n)matrix+var as var as added to all elements |
void | operator+=(matrix a) Increments current matrix by matrix a |
void | operator+=(D a) Specific variable increment. |
void | operator++(int a) Increment operator. |
matrix | operator-() Negative of a matrix. |
matrix | operator-(const matrix & other) Matrix subtraction. |
matrix | operator-(D n)matrix-var |
void | operator-=(matrix a) Decrement current matrix by matrix a |
void | operator-=(D a) Decrement current matrix by value a |
void | operator--(int a) Decrement operator. |
matrix | operator*(const matrix & other) Matrix multiplication. |
matrix | operator*(D n)matrix*var |
matrix | mathmul(const matrix & other) Normal multiplicatoin. |
matrix | operator/(matrix & other) Matrix division using inverse. |
matrix | operator/(D n)matrix/var |
matrix | mathdiv(const matrix & other) Normal math division. |
matrix | operator()(int i1, int i2) Returns a sliced matrix. |
std::vector< D > | operator()(int i, int j1, int j2) Column per row slicing. |
matrix | operator()(int i1, int i2, int j1, int j2) Row and column slice. |
Protected Functions
Name | |
---|---|
void | check_col(int j) checks index for columns |
void | check_row(int i) checks index for rows |
table< D > | TT() Returns transpose for data. |
void | check_size(int r, int c) Checks other matrix size for operators. |
matrix | MM(int i, int j, matrix & other) Protected minor (used in DET ) |
D | DET(matrix a) Recursive determinant. |
void | square() throws exception if matrix is not a square |
Friends
Name | |
---|---|
matrix | operator+(D n, matrix & other) var+matrix |
matrix | operator-(D n, matrix & other) var-matrix |
matrix | operator*(D n, matrix & other) var*matrix |
matrix | operator/(D n, matrix & other) var/matrix |
Detailed Description
template <typename D >
class var::matrix;
Class for 2d matrix of objects.
Template Parameters:
- D can be of any type
Protected Types Documentation
using table
template <typename T >
using var::matrix< D >::table = std::vector<std::vector<T> >;
2D vector definition
Template Parameters:
- T
Public Functions Documentation
function matrix
inline matrix(
int r,
int c
)
Construct a new matrix object.
Parameters:
- r number of rows
- c number of colums
Usage:
var::matrix<int> m(2, 3); // 2 rows, 3 colums
function matrix
inline matrix()
Default construct a new matrix object.
Usage:
var::matrix<int> m;
function matrix
inline matrix(
std::initializer_list< std::initializer_list< D >> a
)
Construct a new matrix object.
Usage:
var::matrix<int> m = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
Getters
ainitializer list
function row
inline int row()
Returns the number of rows.
Return: int
Usage:
var::matrix<int> m(2, 3);
int r = m.row();
function col
inline int col()
Returns the number of columns.
Return: int
function size
inline int size()
Returns total number of elements.
Return: int
function begin
inline auto begin()
Mainly invoked for the ranged for loop.
Return: std::vector<D>