LMMC
Lamina Mathematic core
Toggle main menu visibility
载入中...
搜索中...
未找到
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
"
6
#include "
sparse_direct_internal.h
"
7
#include "
sparse_internal.h
"
8
9
lmmc_status_t
lmmc_sparse_direct_csc
(
const
lmmc_sparse_mat_t
* a,
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
) {
15
return
LMMC_STATUS_INVALID_ARGUMENT
;
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
26
lmmc_status_t
lmmc_sparse_factor_capacity
(
size_t
** idx,
lmmc_real_t
** vals,
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)) {
38
return
LMMC_STATUS_ALLOCATION_FAILED
;
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)) {
43
return
LMMC_STATUS_ALLOCATION_FAILED
;
44
}
45
size_t
* new_idx = (
size_t
*)
lmmc_memory_realloc
(*idx, idx_bytes);
46
if
(new_idx == NULL) {
47
return
LMMC_STATUS_ALLOCATION_FAILED
;
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) {
52
return
LMMC_STATUS_ALLOCATION_FAILED
;
53
}
54
*vals = new_vals;
55
*capacity = new_cap;
56
return
LMMC_STATUS_OK
;
57
}
lmmc_real_t
double lmmc_real_t
Public and internal LMMC real type.
定义
config.h:28
internal.h
LMMC 内部使用的公共工具(仅源文件可见).
lmmc_memory_realloc
void * lmmc_memory_realloc(void *pointer, size_t size)
定义
memory_bridge.c:82
memory_bridge.h
Private recoverable allocator for persistent LMMC ownership.
sparse.h
lmmc_sparse_factor_capacity
lmmc_status_t lmmc_sparse_factor_capacity(size_t **idx, lmmc_real_t **vals, size_t *capacity, size_t needed)
定义
sparse_direct.c:26
lmmc_sparse_direct_csc
lmmc_status_t lmmc_sparse_direct_csc(const lmmc_sparse_mat_t *a, lmmc_sparse_mat_t *csc_out, int *needs_free)
定义
sparse_direct.c:9
sparse_direct_internal.h
sparse_internal.h
稀疏矩阵模块内部共享辅助函数(仅源文件可见)。
lmmc_sparse_to_csc
lmmc_status_t lmmc_sparse_to_csc(const lmmc_sparse_mat_t *src, lmmc_sparse_mat_t *dst)
转换为 CSC,src 已为 CSC 时执行深拷贝。
定义
sparse_conversion.c:148
LMMC_SPARSE_CSC
@ LMMC_SPARSE_CSC
定义
sparse_types.h:15
lmmc_sparse_mat_t::format
lmmc_sparse_format_t format
定义
sparse_types.h:41
lmmc_sparse_mat_t
通用稀疏矩阵(CSR / CSC 共用同一结构)。
定义
sparse_types.h:34
lmmc_status_t
lmmc_status_t
LMMC 库统一返回的状态码.
定义
status.h:22
LMMC_STATUS_OK
@ LMMC_STATUS_OK
定义
status.h:23
LMMC_STATUS_ALLOCATION_FAILED
@ LMMC_STATUS_ALLOCATION_FAILED
定义
status.h:26
LMMC_STATUS_INVALID_ARGUMENT
@ LMMC_STATUS_INVALID_ARGUMENT
定义
status.h:24
src
sparse_direct.c
生成于
, 为 LMMC使用
1.18.0