NTLib - Number Theory Library 0.9
Loading...
Searching...
No Matches
matrix.cpp File Reference
module matrix

Primary module interface unit for module matrix. More...

#include <cassert>
#include <concepts>
#include <cstddef>
#include <initializer_list>
#include <ostream>
#include <string>
import base;
Include dependency graph for matrix.cpp:

Classes

class  ntlib::matrix< ROWS, COLUMNS, T >
 Represents a matrix with a given number of rows and colums. More...
class  ntlib::algebra_traits< matrix< ROWS, COLUMNS, T > >
 Specialization of ntlib::algebra_traits for matrix. More...

Functions

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
std::string ntlib::to_string (matrix< ROWS, COLUMNS, T > mat)
 Converts a given matrix into a human readable string representation.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
std::ostream & ntlib::operator<< (std::ostream &os, const matrix< ROWS, COLUMNS, T > &m)
 Writes a string representation of a given matrix to a given output stream.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator+ (matrix< ROWS, COLUMNS, T > lhs, const matrix< ROWS, COLUMNS, T > &rhs)
 Plus operator for matrix addition.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator- (matrix< ROWS, COLUMNS, T > lhs, const matrix< ROWS, COLUMNS, T > &rhs)
 Minus operator for matrix subtraction.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator* (matrix< ROWS, COLUMNS, T > lhs, T rhs)
 Times operator for right scalar multiplication.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator* (T lhs, matrix< ROWS, COLUMNS, T > rhs)
 Times operator for left scalar multiplication.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator/ (matrix< ROWS, COLUMNS, T > lhs, T rhs)
 Divides operator for scalar division.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator% (matrix< ROWS, COLUMNS, T > lhs, T rhs)
 Modulo operator for elementwise modulo by a scalar.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator+ (const matrix< ROWS, COLUMNS, T > &rhs)
 Unary plus operator. Does nothing.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator- (const matrix< ROWS, COLUMNS, T > &rhs)
 Unary minus operator.
template<std::size_t ROWS_LHS, std::size_t COLUMNS_LHS, std::size_t ROWS_RHS, std::size_t COLUMNS_RHS, Ring T>
matrix< ROWS_LHS, COLUMNS_RHS, T > ntlib::operator* (const matrix< ROWS_LHS, COLUMNS_LHS, T > &lhs, const matrix< ROWS_RHS, COLUMNS_RHS, T > &rhs)
 Times operator for matrix multiplication.
template<std::size_t ROWS, std::size_t COLUMNS, Ring T, std::invocable< T > F>
matrix< ROWS, COLUMNS, T > ntlib::exec_each_element (const matrix< ROWS, COLUMNS, T > &m, const F &func)
 Executes a function an each element.

Detailed Description

Primary module interface unit for module matrix.

Function Documentation

◆ exec_each_element()

template<std::size_t ROWS, std::size_t COLUMNS, Ring T, std::invocable< T > F>
matrix< ROWS, COLUMNS, T > ntlib::exec_each_element ( const matrix< ROWS, COLUMNS, T > & m,
const F & func )
export

Executes a function an each element.

TODO (pjungeblut): Try to get rid of this function.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
FA function object.
Parameters
mThe matrix.
funcThe function to execute.
Returns
The new matrix.

◆ operator%()

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator% ( matrix< ROWS, COLUMNS, T > lhs,
T rhs )
export

Modulo operator for elementwise modulo by a scalar.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe dividend. A matrix.
rhsThe divisor. A scalar.
Returns
A matrix with every element being the remainder of the corresponding element in lhs after divison by rhs.

◆ operator*() [1/3]

template<std::size_t ROWS_LHS, std::size_t COLUMNS_LHS, std::size_t ROWS_RHS, std::size_t COLUMNS_RHS, Ring T>
matrix< ROWS_LHS, COLUMNS_RHS, T > ntlib::operator* ( const matrix< ROWS_LHS, COLUMNS_LHS, T > & lhs,
const matrix< ROWS_RHS, COLUMNS_RHS, T > & rhs )
export

Times operator for matrix multiplication.

Template Parameters
ROWS_LHSThe number of rows of the first factor.
COLUMNS_LHSThe number of columns of the first factor.
ROWS_RHSThe number of rows of the second factor.
COLUMNS_RHSThe number of columns of the second factor.
TThe element type.
Parameters
lhsThe first factor.
rhsThe second factor.
Returns
The matrix product of lhs and rhs.

◆ operator*() [2/3]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator* ( matrix< ROWS, COLUMNS, T > lhs,
T rhs )
export

Times operator for right scalar multiplication.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe first factor, a matrix.
rhsThe second factor, a scalar.
Returns
The product of lhs and rhs.

◆ operator*() [3/3]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator* ( T lhs,
matrix< ROWS, COLUMNS, T > rhs )
export

Times operator for left scalar multiplication.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe first factor, a scalar.
rhsThe second factor, a matrix.
Returns
The product of lhs and rhs.

◆ operator+() [1/2]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator+ ( const matrix< ROWS, COLUMNS, T > & rhs)
export

Unary plus operator. Does nothing.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
rhsThe matrix..
Returns
A copy of the old matrix.

◆ operator+() [2/2]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator+ ( matrix< ROWS, COLUMNS, T > lhs,
const matrix< ROWS, COLUMNS, T > & rhs )
nodiscardexport

Plus operator for matrix addition.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe first summand.
rhsThe second summand.
Returns
The sum of lhs and rhs.

◆ operator-() [1/2]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator- ( const matrix< ROWS, COLUMNS, T > & rhs)
export

Unary minus operator.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
rhsThe matrix.
Returns
A matrix with all elements negated.

◆ operator-() [2/2]

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator- ( matrix< ROWS, COLUMNS, T > lhs,
const matrix< ROWS, COLUMNS, T > & rhs )
export

Minus operator for matrix subtraction.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe minuend.
rhsThe subtrahend.
Returns
The difference of lhs and rhs.

◆ operator/()

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
matrix< ROWS, COLUMNS, T > ntlib::operator/ ( matrix< ROWS, COLUMNS, T > lhs,
T rhs )
export

Divides operator for scalar division.

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
lhsThe dividend. A matrix.
rhsThe divisor. A scalar.
Returns
The quotient matrix.

◆ operator<<()

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
std::ostream & ntlib::operator<< ( std::ostream & os,
const matrix< ROWS, COLUMNS, T > & m )
export

Writes a string representation of a given matrix to a given output stream.

Template Parameters
ROWSThe number of rows.
COLUMSThe number of colums.
TThe element type.
Parameters
osThe given output stream.
mThe given matrix.
Returns
Reference to the output stream.

◆ to_string()

template<std::size_t ROWS, std::size_t COLUMNS, Ring T>
std::string ntlib::to_string ( matrix< ROWS, COLUMNS, T > mat)
export

Converts a given matrix into a human readable string representation.

For example, the matrix

\[\begin{pmatrix} a & b \\ c & d \end{pmatrix} \]

will be converted into "{{a,b},{c,d}}".

Template Parameters
ROWSThe number of rows.
COLUMNSThe number of columns.
TThe element type.
Parameters
matThe given matrix.
Returns
A string representation of the given matrix.