LMMC
Lamina Mathematic core
载入中...
搜索中...
未找到
sparse_direct.c
浏览该文件的文档.
1#include <string.h>
2#include <math.h>
3#include "memory_bridge.h"
4#include "internal.h"
5#include "lmmc/sparse.h"
7#include "sparse_internal.h"
8
10 lmmc_sparse_mat_t* csc_out,
11 int* needs_free)
12{
13 if (csc_out == NULL || needs_free == NULL ||
14 lmmc_sparse_validate(a) != LMMC_STATUS_OK) {
16 }
17 *needs_free = 0;
18 if (a->format == LMMC_SPARSE_CSC) {
19 *csc_out = *a;
20 return LMMC_STATUS_OK;
21 }
22 *needs_free = 1;
23 return lmmc_sparse_to_csc(a, csc_out);
24}
25
27 size_t* capacity, size_t needed)
28{
29 size_t new_cap;
30 size_t idx_bytes;
31 size_t value_bytes;
32
33 if (needed < *capacity) {
34 return LMMC_STATUS_OK;
35 }
36 if (!lmmc_safe_mul_size(*capacity, 2, &new_cap) || new_cap <= needed) {
37 if (!lmmc_safe_add_size(needed, 1, &new_cap)) {
39 }
40 }
41 if (!lmmc_safe_mul_size(new_cap, sizeof(size_t), &idx_bytes) ||
42 !lmmc_safe_mul_size(new_cap, sizeof(lmmc_real_t), &value_bytes)) {
44 }
45 size_t* new_idx = (size_t*)lmmc_memory_realloc(*idx, idx_bytes);
46 if (new_idx == NULL) {
48 }
49 *idx = new_idx;
50 lmmc_real_t* new_vals = (lmmc_real_t*)lmmc_memory_realloc(*vals, value_bytes);
51 if (new_vals == NULL) {
53 }
54 *vals = new_vals;
55 *capacity = new_cap;
56 return LMMC_STATUS_OK;
57}
double lmmc_real_t
Public and internal LMMC real type.
LMMC 内部使用的公共工具(仅源文件可见).
void * lmmc_memory_realloc(void *pointer, size_t size)
Private recoverable allocator for persistent LMMC ownership.
lmmc_status_t lmmc_sparse_factor_capacity(size_t **idx, lmmc_real_t **vals, size_t *capacity, size_t needed)
lmmc_status_t lmmc_sparse_direct_csc(const lmmc_sparse_mat_t *a, lmmc_sparse_mat_t *csc_out, int *needs_free)
稀疏矩阵模块内部共享辅助函数(仅源文件可见)。
lmmc_status_t lmmc_sparse_to_csc(const lmmc_sparse_mat_t *src, lmmc_sparse_mat_t *dst)
转换为 CSC,src 已为 CSC 时执行深拷贝。
@ LMMC_SPARSE_CSC
lmmc_sparse_format_t format
通用稀疏矩阵(CSR / CSC 共用同一结构)。
lmmc_status_t
LMMC 库统一返回的状态码.
@ LMMC_STATUS_OK
@ LMMC_STATUS_ALLOCATION_FAILED
@ LMMC_STATUS_INVALID_ARGUMENT