# MatPly **Repository Path**: PythonnotJava/MatPly ## Basic Information - **Project Name**: MatPly - **Description**: MatPly based on C language is used to build Matrix. Additionally, it provides Dart and Python versions - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-30 - **Last Updated**: 2023-12-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MatPly #### 介绍 MatPly based on C language is used to build Matrix. Additionally, it provides Dart and Python versions # 基于C语言的矩阵的实现 # 数据结构与算法说明 ## Auxiliary.h - Auxiliary文件主要存放基本数据类型的辅助功能,或者函数一些辅助功能 ### 数据结构 | 名称 | 实质类型 | 作用 | |-------------|---------|-------------------------------------------------------------------------| | NumberType | enum | 用于记录数据类型,比如说是int8、int16还是其他 | | Number | struct | Number类型表明了数据类型,另外还记录着矩阵的全部数据 | | SpecialType | struct | 为了便于一些特殊矩阵计算,当用户传入或者经过相关计算时,对于已经确定的一些性质(比如说对称性),算法为了节省时间复杂度,会特地选择相关算法模块 | | Datas | union | Datas类型配合数据类型,进行相关值操作 | | DatasWT | struct | 即Datas with type,带有数据类型的Datas类型 | ### 算法 | 名称 | 参数 | 返回类型 | 作用 | |----------------------|--------------------------------------------------------------------------------------------|-------|----------------------------------------------------------------------| | _COPY_NUMBER | Number * p, Number * c, int row, int col | void | 把c的数据内容复制给p,p的数据类型取决于c的,但是请请提前开辟好row行数组所占用的内存 | | _COPY_SPECIAL | SpecialType * p, SpecialType * c | void | 把c的特殊性质复制给c | | _INIT_SPECIAL | SpecialType * stype | void | 对指向的stype各种属性初始化为false | | _THROW_ERROR | int type | void | 各种的报错类型 | | _ASSERT_IN_RANGE | int i, int j, int row, int col | void | 判断索引\[i\]\[j\]是否在row * col的矩阵内 | | _COPY_PARTIAL_NUMBER | Number * p, Number * c, int i, int j, int p_row, int p_col, int c_row, int c_col, double k | void | 将c的数据从\[i\]\[j\]索引作为左上角开始截取(前提是该索引必须在c范围内)片段复制到p数组,若片段无法布满p,则使用数据k填充 | | _PRINT_DATAS | DatasWT | void | 打印DatasWT类型的数据 | | _ASSERT_RESHAPE | int r1, int c1, int r2, int c2 | void | 重塑尺寸之前判断原来的row * col是否还等于新的row * col | | | | | | | | | | | ## MatBox.h - MatBox是矩阵操作的核心实现 - 考虑到矩阵的行向量和列向量 - 默认行向量为主方向 ### 数据结构 | 名称 | 实质类型 | 作用 | |--------------------|--------|-----------------------------| | _Matrix | struct | 矩阵的本体,除了相关数据,特殊性,还记录着矩阵的行列数 | | Matrix(*MatrixOpt) | struct | 把矩阵本体作为属性,还记录着相关操作 | ### 算法 | 名称 | 参数 | 返回类型 | 作用 | |---------------------|---------------------------------------------------------------------------|----------|-------------------------------------------------------------------| | __new__ | int row, int col, NumberType dtype | Matrix * | 创建一个特殊性和数据域空的矩阵,会开辟data每行指针的内存空间,但是不开辟每一行的数据域的空间,另外,特殊性初始化全为false | | __init__ | int row, int col, Number * datas | Matrix * | 根据传入的数据,决定数据类型,并创建row * low形状的矩阵 | | __delete__ | Matrix * matrix | void | 删除并且释放一个矩阵所占的内存空间 | | getCopiedMatrix | Matrix matrix | Matrix * | 深拷贝一个矩阵 | | VisibleMatrix | Matrix matrix, NumberType dtype | void | 可视化打印一个矩阵并使用dtype类型展示 | | isSquare | Matrix matrix | bool | 判断矩阵是否是一个方阵 | | getMatrixByShape | Matrix matrix, int i, int j, int row, int col, double k, NumberType dtype | Matrix * | 获取从matrix内\[i\]\[j\]索引点开始截取的矩阵,其形状为row * col,缺失部分使用k填充 | | getTrace | Matrix matrix | void * | 获取矩阵的迹,计算不判断方阵,取决于min(row, col)方阵的主对角线值,返回类型是DatasWT | | Reshape | Matrix * matrix, int row, int col, NumberType dtype | void | 重塑形状至row * col,先调用ASSERT_RESHAPE判断;另外,数据类型也会被重置 | | Resize | Matrix * matrix, int row, int col, NumberType dtype, double k | void | 不同于形状变化,不做原大小检测,被覆盖数据保留,多余部分使用数据k代替 | | Redtype | Matrix * matrix, NumberType dtype | void | 对数据进行类型修改。由于矩阵存储采用类型与数据独立存储,所以仅对数据类型进行修改即可,待到数据真正被用到,才会被附上指定类型 | | getChildMatrix | Matrix matrix, int i, int j | Matrix * | 去掉第i行和第j列的数据,获取余子矩阵;行数或者列数等于1的时候,不支持,会报错 | | TransformExchange | Matrix * matrix, int i, int j, bool row | void | 矩阵的初等变换——i、j行(列)对换;对于传入两行(列)值相等或者行数为1时,交换行无效、列数为1时,交换列无效 | | TransformMultiply | Matrix * matrix, int i, double k, bool row | void | 矩阵的初等变换——某行(列)倍乘一个浮点数,可以为0 | | TransformAM | Matrix * matrix, int i, int j, double k, bool row | void | 矩阵的初等变换——把第j行(列)的k倍加到第i行(列);对于传入两行(列)值相等或者行数为1时或者列为1以及k为0,不做任何 | | getIdentityMatrix | int n, NumberType dtype | Matrix * | 获取n阶的单位矩阵 | | getTransposeMatrix | Matrix matrix | Matrix * | 获取转置矩阵 | | __delete_new__ | Matrix * matrix | void | 当一个矩阵的初始化未成功,便会调用此方法销毁 |