CppMatrix
Loading...
Searching...
No Matches
cpp_matrix::Matrix< M > Class Template Reference
module cpp_matrix

Public Types

using ElementType = M::ElementType
 

Public Member Functions

 Matrix (size_t row, size_t column)
 
 Matrix (size_t row, size_t column, ElementType v)
 Create a row x column matrix. All elements are v.
 
 Matrix (size_t row, size_t column, std::span< ElementType > initData)
 
 Matrix (std::initializer_list< std::initializer_list< ElementType > > initData)
 
 Matrix (std::initializer_list< Matrix > matrixs)
 Stack matrixs in sequence horizontally (column wise).
 
 Matrix (const Matrix &m)
 
 Matrix (Matrix &&m)
 
template<size_t N>
void Write (std::span< ElementType, N > data)
 
std::vector< ElementType > Read () const
 
Matrix operator- () const
 
Matrix operator+ (const Matrix &other) const
 
Matrixoperator+= (const Matrix &other)
 
Matrix operator- (const Matrix &other) const
 
Matrix operator+ (ElementType v) const
 
Matrix operator/ (ElementType v) const
 
Matrix operator- (ElementType v) const
 
Matrix operator* (ElementType v) const
 
Matrix operator* (const Matrix &other) const
 
size_t Row () const
 
size_t Column () const
 
Matrixoperator= (std::vector< ElementType > data)
 
Matrixoperator= (ElementType f)
 
Matrixoperator= (std::span< ElementType > data)
 
Matrixoperator= (Matrix &&m)
 
Matrix Transpose () const
 
Matrix ElementProduct (const Matrix &other) const
 
Matrix Relu () const
 
Matrix Exp () const
 Caculate exp() element-wise.
 
Matrix Pow (ElementType e) const
 
float operator[] (size_t row, size_t column) const
 
Matrix AddToRow (const Matrix &m) const
 Add value each row. The input should be a 1xC matrix.
 
Matrix Sum () const
 Returns the sum of all elements in the matrix. The value will be a 1 x 1 matrix.
 
Matrix SumByRow () const
 Returns the sum of all elements in the same row. If this is a R x C matrix, the result will be a R x 1 matrix.
 
Matrix SumByColumn () const
 Returns the sum of all elements in the same column. If this is a R x C matrix, the result will be a 1 x C matrix.
 

Static Public Member Functions

static Matrix Random (size_t row, size_t column)
 Create a matrix with random value (value will be between 0 and 1).
 
static bool IsAvaliable ()
 

Friends

Matrix operator+ (ElementType v, const Matrix &m)
 
Matrix operator- (ElementType v, const Matrix &m)
 
Matrix operator* (ElementType v, const Matrix &m)
 
Matrix operator/ (ElementType v, const Matrix &m)
 

Constructor & Destructor Documentation

◆ Matrix()

template<MatrixBackend M>
cpp_matrix::Matrix< M >::Matrix ( std::initializer_list< Matrix< M > > matrixs)
inline

Stack matrixs in sequence horizontally (column wise).

Exceptions
std::runtime_errorIf matrix has different number of rows.

This constructor will create a matrix by stack other matrixs in sequence horizontally.

For example, there are two matrixs:

auto a = Matrix {
{1.0, 1.1},
{2.0, 2.1}
};
auto b = Matrix {
{1.2, 1.3, 1.4},
{2.2, 2.3, 2.4}
};

Now, you can create the third matrix like this:

auto c = Matrix { a, b };

The matrix c will be:

c = {
    {1.0, 1.1, 1.2, 1.3, 1.4},
    {2.0, 2.1, 2.2, 2.3, 2.4}
};

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