|
LMMC
Lamina Mathematic core
|
稀疏矩阵格式转换:稠密互转、转置与 CSR/CSC/COO 转换。 更多...
#include <stdlib.h>#include <string.h>#include "memory_bridge.h"#include "internal.h"#include "sparse_internal.h"#include "lmmc/sparse.h"结构体 | |
| struct | lmmc_coo_sort_entry_t |
稀疏矩阵格式转换:稠密互转、转置与 CSR/CSC/COO 转换。
在文件 sparse_conversion.c 中定义.
| struct lmmc_coo_sort_entry_t |
在文件 sparse_conversion.c 第 257 行定义.
| 成员变量 | ||
|---|---|---|
| size_t | row | |
| size_t | col | |
| size_t | orig_idx | |
| lmmc_status_t lmmc_sparse_from_dense | ( | const lmmc_mat_t * | dense, |
| lmmc_real_t | eps, | ||
| lmmc_sparse_mat_t * | out_sparse ) |
由稠密矩阵生成 CSR,丢弃绝对值 <= eps 的元素。
| [in] | dense | 输入稠密矩阵,保持不变。 |
| [in] | eps | 非负丢弃阈值。 |
| [out] | out_sparse | 输出 CSR,调用方须用 lmmc_sparse_destroy 释放。 |
在文件 sparse_conversion.c 第 13 行定义.
引用了 lmmc_sparse_mat_t::col_idx, lmmc_mat_t::cols, lmmc_mat_t::data, LMMC_REAL_ABS, LMMC_REAL_CLEAR, LMMC_REAL_CMP, LMMC_REAL_INIT, LMMC_REAL_SET, LMMC_REAL_SET_D, lmmc_sparse_create_csr(), lmmc_sparse_from_dense(), LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_mat_t::row_ptr, lmmc_mat_t::rows, lmmc_mat_t::stride , 以及 lmmc_sparse_mat_t::values.
被这些函数引用 lmmc_sparse_from_dense().
| lmmc_status_t lmmc_sparse_to_dense | ( | const lmmc_sparse_mat_t * | sparse, |
| lmmc_mat_t * | out_dense ) |
将稀疏矩阵展开为稠密矩阵,缺失项填零。
| [in] | sparse | 输入稀疏矩阵,保持不变。 |
| [out] | out_dense | 已创建且与 sparse 同维的稠密矩阵,内容被完全覆写。 |
在文件 sparse_conversion.c 第 64 行定义.
引用了 lmmc_sparse_mat_t::col_idx, lmmc_mat_t::cols, lmmc_sparse_mat_t::cols, lmmc_mat_t::data, lmmc_sparse_mat_t::format, lmmc_mat_fill(), LMMC_REAL_CLEAR, LMMC_REAL_INIT, LMMC_REAL_SET, LMMC_REAL_SET_D, LMMC_SPARSE_CSR, lmmc_sparse_to_dense(), LMMC_STATUS_DIMENSION_MISMATCH, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_mat_t::row_ptr, lmmc_mat_t::rows, lmmc_sparse_mat_t::rows, lmmc_mat_t::stride , 以及 lmmc_sparse_mat_t::values.
被这些函数引用 lmmc_sparse_to_dense().
| lmmc_status_t lmmc_sparse_transpose | ( | const lmmc_sparse_mat_t * | sparse, |
| lmmc_sparse_mat_t * | out_transposed ) |
计算稀疏矩阵转置,保持原存储格式。
| [in] | sparse | 输入稀疏矩阵,保持不变。 |
| [out] | out_transposed | 输出转置矩阵,调用方须用 lmmc_sparse_destroy 释放。 |
在文件 sparse_conversion.c 第 100 行定义.
引用了 lmmc_sparse_mat_t::col_idx, lmmc_sparse_mat_t::cols, lmmc_sparse_mat_t::format, lmmc_memory_alloc_array(), lmmc_memory_free(), LMMC_REAL_SET, LMMC_SPARSE_CSR, lmmc_sparse_destroy(), lmmc_sparse_transpose(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_mat_t::nnz, lmmc_sparse_mat_t::row_ptr, lmmc_sparse_mat_t::rows , 以及 lmmc_sparse_mat_t::values.
被这些函数引用 lmmc_sparse_transpose().
| lmmc_status_t lmmc_sparse_to_csc | ( | const lmmc_sparse_mat_t * | src, |
| lmmc_sparse_mat_t * | dst ) |
转换为 CSC,src 已为 CSC 时执行深拷贝。
| [in] | src | 输入稀疏矩阵,保持不变。 |
| [out] | dst | 输出 CSC,调用方须用 lmmc_sparse_destroy 释放。 |
在文件 sparse_conversion.c 第 148 行定义.
引用了 lmmc_sparse_mat_t::col_idx, lmmc_sparse_mat_t::cols, lmmc_sparse_mat_t::format, lmmc_memory_alloc_array(), lmmc_memory_free(), LMMC_REAL_SET, lmmc_sparse_create_csc(), LMMC_SPARSE_CSC, lmmc_sparse_destroy(), lmmc_sparse_to_csc(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_mat_t::nnz, lmmc_sparse_mat_t::row_ptr, lmmc_sparse_mat_t::rows , 以及 lmmc_sparse_mat_t::values.
被这些函数引用 lmmc_sparse_direct_csc() , 以及 lmmc_sparse_to_csc().
| lmmc_status_t lmmc_sparse_to_csr | ( | const lmmc_sparse_mat_t * | src, |
| lmmc_sparse_mat_t * | dst ) |
转换为 CSR,src 已为 CSR 时执行深拷贝。
| [in] | src | 输入稀疏矩阵,保持不变。 |
| [out] | dst | 输出 CSR,调用方须用 lmmc_sparse_destroy 释放。 |
在文件 sparse_conversion.c 第 203 行定义.
引用了 lmmc_sparse_mat_t::col_idx, lmmc_sparse_mat_t::cols, lmmc_sparse_mat_t::format, lmmc_memory_alloc_array(), lmmc_memory_free(), LMMC_REAL_SET, lmmc_sparse_create_csr(), LMMC_SPARSE_CSR, lmmc_sparse_destroy(), lmmc_sparse_to_csr(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_mat_t::nnz, lmmc_sparse_mat_t::row_ptr, lmmc_sparse_mat_t::rows , 以及 lmmc_sparse_mat_t::values.
被这些函数引用 lmmc_sparse_add(), lmmc_sparse_diag(), lmmc_sparse_mat_mat_mul_sparse() , 以及 lmmc_sparse_to_csr().
| lmmc_status_t lmmc_sparse_coo_to_csr | ( | const lmmc_sparse_coo_t * | coo, |
| lmmc_sparse_mat_t * | out_csr ) |
将 COO 排序为 CSR,重复坐标按插入顺序累加,保留显式零。 要求非零维度、nnz<=capacity、有效条目数组和范围内坐标。 输入保持不变;非法描述符返回 INVALID_ARGUMENT,输出保持不变。
在文件 sparse_conversion.c 第 349 行定义.
引用了 lmmc_coo_sort_entry_t::col, lmmc_sparse_coo_t::col_idx, lmmc_sparse_coo_t::cols, lmmc_memory_alloc_array(), lmmc_memory_free(), LMMC_REAL_CLEAR, LMMC_REAL_INIT, lmmc_sparse_coo_to_csr(), lmmc_sparse_create_csr(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_coo_t::nnz, lmmc_coo_sort_entry_t::orig_idx, lmmc_coo_sort_entry_t::row, lmmc_sparse_coo_t::row_idx, lmmc_sparse_mat_t::row_ptr , 以及 lmmc_sparse_coo_t::rows.
被这些函数引用 lmmc_sparse_builder_build() , 以及 lmmc_sparse_coo_to_csr().
| lmmc_status_t lmmc_sparse_coo_to_csc | ( | const lmmc_sparse_coo_t * | coo, |
| lmmc_sparse_mat_t * | out_csc ) |
将 COO 转换为 CSC,校验、稳定合并与显式零语义同 COO→CSR。
在文件 sparse_conversion.c 第 414 行定义.
引用了 lmmc_coo_sort_entry_t::col, lmmc_sparse_coo_t::col_idx, lmmc_sparse_coo_t::cols, lmmc_memory_alloc_array(), lmmc_memory_free(), LMMC_REAL_CLEAR, LMMC_REAL_INIT, lmmc_sparse_coo_to_csc(), lmmc_sparse_create_csc(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_coo_t::nnz, lmmc_coo_sort_entry_t::orig_idx, lmmc_coo_sort_entry_t::row, lmmc_sparse_coo_t::row_idx, lmmc_sparse_mat_t::row_ptr , 以及 lmmc_sparse_coo_t::rows.
被这些函数引用 lmmc_sparse_builder_build() , 以及 lmmc_sparse_coo_to_csc().
| void lmmc_sparse_coo_destroy | ( | lmmc_sparse_coo_t * | coo | ) |
销毁 COO 矩阵并释放缓冲区。
在文件 sparse_conversion.c 第 478 行定义.
引用了 lmmc_sparse_coo_t::capacity, lmmc_sparse_coo_t::col_idx, lmmc_sparse_coo_t::cols, lmmc_memory_free(), LMMC_REAL_CLEAR, lmmc_sparse_coo_destroy(), lmmc_sparse_coo_t::nnz, lmmc_sparse_coo_t::row_idx, lmmc_sparse_coo_t::rows , 以及 lmmc_sparse_coo_t::values.
被这些函数引用 lmmc_sparse_coo_destroy().