|
LMMC
Lamina Mathematic core
|
稀疏矩阵增量构造器与 COO 条目累积。 更多...
#include <string.h>#include "memory_bridge.h"#include "internal.h"#include "sparse_internal.h"#include "lmmc/sparse.h"结构体 | |
| struct | lmmc_sparse_builder_t |
| 增量构造稀疏矩阵的辅助对象(不透明类型)。 更多... | |
函数 | |
| lmmc_status_t | lmmc_sparse_builder_create (size_t rows, size_t cols, size_t initial_capacity, lmmc_sparse_builder_t **out_builder) |
| 创建稀疏矩阵增量构造器。 | |
| lmmc_status_t | lmmc_sparse_builder_add (lmmc_sparse_builder_t *b, size_t row, size_t col, lmmc_real_t val) |
| 向构造器追加一项非零元。 | |
| void | lmmc_sparse_builder_destroy (lmmc_sparse_builder_t *b) |
| 销毁稀疏构造器,释放动态数组与句柄。 | |
| lmmc_status_t | lmmc_sparse_builder_build (lmmc_sparse_builder_t *b, lmmc_sparse_format_t format, lmmc_sparse_mat_t *out) |
| 将构造器条目转换为指定压缩格式的稀疏矩阵。 | |
| lmmc_status_t | lmmc_sparse_coo_create (size_t rows, size_t cols, size_t capacity, lmmc_sparse_coo_t *out_coo) |
创建容量为 capacity 的空 COO 矩阵。 | |
| lmmc_status_t | lmmc_sparse_coo_add_entry (lmmc_sparse_coo_t *coo, size_t row, size_t col, lmmc_real_t value) |
| 向 COO 追加一项非零元,达到容量时返回错误。 | |
稀疏矩阵增量构造器与 COO 条目累积。
在文件 sparse_builder.c 中定义.
| struct lmmc_sparse_builder_t |
增量构造稀疏矩阵的辅助对象(不透明类型)。
适合 nnz 未知或乱序插入的场景.最终调用 lmmc_sparse_builder_build 得到 lmmc_sparse_mat_t 。
在文件 sparse_builder.c 第 12 行定义.
| 成员变量 | ||
|---|---|---|
| size_t | rows | |
| size_t | cols | |
| size_t | nnz | |
| size_t | capacity | |
| size_t * | r_idx | |
| size_t * | c_idx | |
| lmmc_real_t * | vals | |
| lmmc_status_t lmmc_sparse_builder_create | ( | size_t | rows, |
| size_t | cols, | ||
| size_t | initial_capacity, | ||
| lmmc_sparse_builder_t ** | out_builder ) |
创建稀疏矩阵增量构造器。
支持未知条目数和乱序插入,动态数组容量不足时翻倍扩容。 用 lmmc_sparse_builder_build 生成压缩格式矩阵。
| [in] | rows | 矩阵行数,须 > 0。 |
| [in] | cols | 矩阵列数,须 > 0。 |
| [in] | initial_capacity | 初始容量,0 时采用默认值 16。 |
| [out] | out_builder | 输出构造器句柄。 |
在文件 sparse_builder.c 第 83 行定义.
引用了 lmmc_sparse_builder_t::c_idx, lmmc_sparse_builder_t::capacity, lmmc_sparse_builder_t::cols, lmmc_memory_alloc(), lmmc_memory_free(), LMMC_REAL_INIT, lmmc_sparse_builder_create(), lmmc_sparse_builder_destroy(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_builder_t::nnz, lmmc_sparse_builder_t::r_idx, lmmc_sparse_builder_t::rows , 以及 lmmc_sparse_builder_t::vals.
被这些函数引用 lmmc_sparse_builder_create().
| lmmc_status_t lmmc_sparse_builder_add | ( | lmmc_sparse_builder_t * | builder, |
| size_t | row, | ||
| size_t | col, | ||
| lmmc_real_t | value ) |
向构造器追加一项非零元。
重复坐标在 build 时累加合并;nnz 递增,容量不足时通过 realloc 翻倍扩容。
| [in,out] | builder | 构造器句柄。 |
| [in] | row | 行下标,须 < rows。 |
| [in] | col | 列下标,须 < cols。 |
| [in] | value | 非零元数值。 |
在文件 sparse_builder.c 第 124 行定义.
引用了 lmmc_sparse_builder_t::c_idx, lmmc_sparse_builder_t::capacity, lmmc_sparse_builder_t::cols, LMMC_REAL_SET, lmmc_sparse_builder_add(), LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_builder_t::nnz, lmmc_sparse_builder_t::r_idx, lmmc_sparse_builder_t::rows , 以及 lmmc_sparse_builder_t::vals.
被这些函数引用 lmmc_sparse_builder_add().
| void lmmc_sparse_builder_destroy | ( | lmmc_sparse_builder_t * | builder | ) |
销毁稀疏构造器,释放动态数组与句柄。
| [in] | builder | 构造器句柄,接受 NULL,销毁后失效。 |
在文件 sparse_builder.c 第 144 行定义.
引用了 lmmc_sparse_builder_t::c_idx, lmmc_sparse_builder_t::capacity, lmmc_memory_free(), LMMC_REAL_CLEAR, lmmc_sparse_builder_destroy(), lmmc_sparse_builder_t::r_idx , 以及 lmmc_sparse_builder_t::vals.
被这些函数引用 lmmc_sparse_builder_create() , 以及 lmmc_sparse_builder_destroy().
| lmmc_status_t lmmc_sparse_builder_build | ( | lmmc_sparse_builder_t * | builder, |
| lmmc_sparse_format_t | format, | ||
| lmmc_sparse_mat_t * | out_sparse ) |
将构造器条目转换为指定压缩格式的稀疏矩阵。
按坐标排序,重复 (row,col) 按插入顺序累加,保留相消后的显式零。 每段索引严格递增;构造器保持不变,可继续追加或再次 build。
| [in] | builder | 构造器句柄。 |
| [in] | format | 目标格式,CSR 或 CSC。 |
| [out] | out_sparse | 输出稀疏矩阵,调用方须用 lmmc_sparse_destroy 释放。 |
在文件 sparse_builder.c 第 162 行定义.
引用了 lmmc_sparse_builder_t::c_idx, lmmc_sparse_builder_t::capacity, lmmc_sparse_coo_t::capacity, lmmc_sparse_coo_t::col_idx, lmmc_sparse_builder_t::cols, lmmc_sparse_coo_t::cols, lmmc_sparse_builder_build(), lmmc_sparse_coo_to_csc(), lmmc_sparse_coo_to_csr(), LMMC_SPARSE_CSC, LMMC_SPARSE_CSR, LMMC_STATUS_INVALID_ARGUMENT, lmmc_sparse_builder_t::nnz, lmmc_sparse_coo_t::nnz, lmmc_sparse_builder_t::r_idx, lmmc_sparse_coo_t::row_idx, lmmc_sparse_builder_t::rows, lmmc_sparse_coo_t::rows, lmmc_sparse_builder_t::vals , 以及 lmmc_sparse_coo_t::values.
被这些函数引用 lmmc_sparse_builder_build().
| lmmc_status_t lmmc_sparse_coo_create | ( | size_t | rows, |
| size_t | cols, | ||
| size_t | capacity, | ||
| lmmc_sparse_coo_t * | out_coo ) |
创建容量为 capacity 的空 COO 矩阵。
在文件 sparse_builder.c 第 181 行定义.
引用了 lmmc_sparse_coo_t::capacity, lmmc_sparse_coo_t::col_idx, lmmc_sparse_coo_t::cols, lmmc_memory_alloc(), lmmc_memory_free(), LMMC_REAL_INIT, lmmc_sparse_coo_create(), LMMC_STATUS_ALLOCATION_FAILED, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_coo_t::nnz, lmmc_sparse_coo_t::row_idx, lmmc_sparse_coo_t::rows , 以及 lmmc_sparse_coo_t::values.
被这些函数引用 lmmc_sparse_coo_create().
| lmmc_status_t lmmc_sparse_coo_add_entry | ( | lmmc_sparse_coo_t * | coo, |
| size_t | row, | ||
| size_t | col, | ||
| lmmc_real_t | value ) |
向 COO 追加一项非零元,达到容量时返回错误。
在文件 sparse_builder.c 第 231 行定义.
引用了 lmmc_sparse_coo_t::capacity, lmmc_sparse_coo_t::col_idx, lmmc_sparse_coo_t::cols, LMMC_REAL_SET, lmmc_sparse_coo_add_entry(), LMMC_STATUS_INDEX_OUT_OF_BOUNDS, LMMC_STATUS_INVALID_ARGUMENT, LMMC_STATUS_OK, lmmc_sparse_coo_t::nnz, lmmc_sparse_coo_t::row_idx, lmmc_sparse_coo_t::rows , 以及 lmmc_sparse_coo_t::values.
被这些函数引用 lmmc_sparse_coo_add_entry().