矩阵类模板 更多...
#include <Matrix.hpp>
Public 成员函数 | |
| constexpr | Matrix (const Matrix &other) |
| constexpr | Matrix (const T(&arr)[M][N]) |
| 构造函数 | |
| constexpr | Matrix (Matrix &&other) |
| constexpr | Matrix (T val=0) |
| 构造函数 | |
| constexpr Matrix | adjugate () const |
| 求矩阵的伴随矩阵 | |
| consteval size | cols () const |
| 获取矩阵的列数 | |
| const Matrix & | correct (T eis=static_cast< T >(1e-6)) |
| 执行矩阵误差修正操作 | |
| consteval size | count () const |
| 获取矩阵的元素个数 | |
| constexpr T | det () const |
| 求矩阵的行列式值 | |
| constexpr Matrix | inverse () const |
| 求矩阵的逆矩阵 | |
| constexpr | operator bool () const |
| 将矩阵转换到 bool 值 | |
| template<typename U > requires std::is_arithmetic_v<U> | |
| constexpr | operator Matrix< M, N, U > () const |
| 矩阵类型转换函数 | |
| constexpr bool | operator! () const |
| 逻辑非运算符重载 | |
| constexpr bool | operator!= (const Matrix &other) const |
| 不等于比较运算符重载 | |
| constexpr T & | operator() (size i, size j) |
| 以 Matrix(M,N) 的形式访问矩阵数据 | |
| constexpr const T & | operator() (size i, size j) const |
| 以 Matrix(M,N) 的形式访问矩阵数据的 const 版本 | |
| template<size P> requires (P > 0) | |
| constexpr Matrix< M, P, T > | operator* (const Matrix< N, P, T > &other) const |
| 矩阵乘法运算符重载 | |
| constexpr Matrix | operator* (T scalar) const |
| 矩阵数乘运算符重载 | |
| constexpr Matrix & | operator*= (T scalar) |
| 矩阵数乘且赋值运算符重载 | |
| constexpr Matrix | operator+ () const |
| 矩阵加号运算符重载 | |
| constexpr Matrix | operator+ (const Matrix &other) const |
| 矩阵加法运算符重载 | |
| constexpr Matrix & | operator+= (const Matrix &other) |
| 矩阵加且赋值运算符重载 | |
| constexpr Matrix | operator- () const |
| 矩阵负号运算符重载 | |
| constexpr Matrix | operator- (const Matrix &other) const |
| 矩阵减法运算符重载 | |
| constexpr Matrix & | operator-= (const Matrix &other) |
| 矩阵减且赋值运算符重载 | |
| constexpr Matrix | operator/ (T scalar) const |
| 矩阵数乘(1/scalar)运算符重载 | |
| constexpr Matrix & | operator/= (T scalar) |
| 矩阵数乘(1/scalar)且赋值运算符重载 | |
| constexpr Matrix & | operator= (const Matrix &other) |
| constexpr Matrix & | operator= (Matrix &&other) |
| constexpr bool | operator== (const Matrix &other) const |
| 等于比较运算符重载 | |
| constexpr T * | operator[] (size i) |
| 以 Matrix[M][N] 的形式访问矩阵数据 | |
| constexpr const T * | operator[] (size i) const |
| 以 Matrix[M][N] 的形式访问矩阵数据的 const 版本 | |
| consteval size | rows () const |
| 获取矩阵的行数 | |
| constexpr Matrix< N, M, T > | transpose () const |
| 求矩阵的转置矩阵 | |
静态 Public 成员函数 | |
| static constexpr Matrix< M, N, T > | I () |
友元 | |
| constexpr Matrix | operator* (T scalar, const Matrix &mat) |
| 矩阵数乘运算符重载 | |
矩阵类模板
此处采用行主序矩阵,即 data[i][j] 表示第 i 行第 j 列元素
| M | 行数 |
| N | 列数 |
| T | 数据类型 |
构造函数
此构造函数将以指定值初始化矩阵,默认初始化为零矩阵
| val | 初始值 |
|
inlineconstexpr |
构造函数
此构造函数将以给定数组初始化矩阵
| arr | 数组 |
|
inlineconstexpr |
求矩阵的伴随矩阵
采用伴随矩阵定义式求伴随矩阵
获取矩阵的列数
执行矩阵误差修正操作
此操作为将矩阵元素与最近邻整数差值小于 eis 的元素都置为最近邻整数
对于非浮点数矩阵,此操作无效
| eis | 误差范围 |
获取矩阵的元素个数
求矩阵的行列式值
采用定义式求行列式值
若矩阵不是方阵,则返回零值
|
inlineconstexpr |
求矩阵的逆矩阵
采用伴随矩阵法求逆矩阵
若矩阵不可逆,则返回零矩阵
|
inlineexplicitconstexpr |
将矩阵转换到 bool 值
若矩阵为零矩阵,则返回 false;否则返回 true
矩阵类型转换函数
矩阵类型转换函数,将矩阵的元素类型转换为 U 类型
| U | 目标类型 |
|
inlineconstexpr |
逻辑非运算符重载
相当于 !static_cast<bool>(*this)
|
inlineconstexpr |
不等于比较运算符重载
相当于 !(*this == other)
| other | 另一个矩阵 |
以 Matrix(M,N) 的形式访问矩阵数据
以 Matrix(M,N) 的形式访问矩阵数据的 const 版本
|
inlineconstexpr |
矩阵乘法运算符重载
执行矩阵乘法时要确保左操作数的列数等于右操作数的行数
| P | 另一个矩阵的列数 |
| other | 另一个矩阵 |
矩阵数乘运算符重载
矩阵数乘运算,返回矩阵与标量相乘结果
| scalar | 标量 |
矩阵数乘且赋值运算符重载
相当于 this = this * scalar
| scalar | 标量 |
|
inlineconstexpr |
矩阵加号运算符重载
矩阵加法运算符重载
矩阵加法运算,返回矩阵相加结果
| other | 另一个矩阵 |
矩阵加且赋值运算符重载
相当于 this = this + other
| other | 另一个矩阵 |
|
inlineconstexpr |
矩阵负号运算符重载
相当于 0 - this
矩阵减法运算符重载
矩阵减法运算,返回矩阵相减结果
| other | 另一个矩阵 |
矩阵减且赋值运算符重载
相当于 this = this - other
| other | 另一个矩阵 |
矩阵数乘(1/scalar)运算符重载
矩阵数乘(1/scalar)运算,返回矩阵与标量相乘结果
| scalar | 标量 |
矩阵数乘(1/scalar)且赋值运算符重载
相当于 this = this / scalar
| scalar | 标量 |
等于比较运算符重载
矩阵相等比较,若所有元素都相等则返回 true,否则返回 false
此函数对于浮点数比较是安全的
| other | 另一个矩阵 |
以 Matrix[M][N] 的形式访问矩阵数据
以 Matrix[M][N] 的形式访问矩阵数据的 const 版本
获取矩阵的行数