LMMC
Lamina Mathematic core
Toggle main menu visibility
载入中...
搜索中...
未找到
eigen_general_vectors.c
浏览该文件的文档.
1
#include <math.h>
2
#include <string.h>
3
#include "
memory_bridge.h
"
4
#include "
internal.h
"
5
#include "
eigen_internal.h
"
6
#include "
lmmc/config.h
"
7
#include "
lmmc/dense.h
"
8
#include "
lmmc/eigen.h
"
9
#include "
lmmc/linear_algebra.h
"
10
#include "
eigen_general_internal.h
"
11
13
14
void
lmmc_eigen_gen_full_result_destroy
(
lmmc_eigen_gen_full_result_t
*result) {
15
if
(!result) {
16
return
;
17
}
18
lmmc_vec_destroy
(&result->
real_parts
);
19
lmmc_vec_destroy
(&result->
imag_parts
);
20
lmmc_mat_destroy
(&result->
vectors_real
);
21
lmmc_mat_destroy
(&result->
vectors_imag
);
22
}
23
24
static
lmmc_status_t
create_full_result(
size_t
n,
lmmc_eigen_gen_full_result_t
* result)
25
{
26
memset(result, 0,
sizeof
(*result));
27
lmmc_status_t
status =
lmmc_vec_create
(n, &result->
real_parts
);
28
if
(status !=
LMMC_STATUS_OK
) {
29
return
status;
30
}
31
status =
lmmc_vec_create
(n, &result->
imag_parts
);
32
if
(status !=
LMMC_STATUS_OK
) {
33
return
status;
34
}
35
status =
lmmc_mat_create
(n, n, &result->
vectors_real
);
36
if
(status !=
LMMC_STATUS_OK
) {
37
return
status;
38
}
39
return
lmmc_mat_create
(n, n, &result->
vectors_imag
);
40
}
41
42
static
lmmc_status_t
eigenvectors_large(
const
lmmc_mat_t
* a,
lmmc_real_t
matrix_scale,
43
lmmc_eigen_gen_full_result_t
* out_result)
44
{
45
size_t
n = a->
rows
;
46
lmmc_mat_t
scaled_a = {0};
47
lmmc_eigen_gen_result_t
eigenvalues = {0};
48
lmmc_status_t
status =
lmmc_mat_create
(n, n, &scaled_a);
49
if
(status !=
LMMC_STATUS_OK
) {
50
return
status;
51
}
52
lmmc_eigen_copy_scaled
(a, matrix_scale, &scaled_a);
53
status =
lmmc_eigen_general
(&scaled_a, &eigenvalues);
54
if
(status !=
LMMC_STATUS_OK
) {
55
goto
cleanup;
56
}
57
for
(
size_t
i = 0; i < n; ++i) {
58
out_result->
real_parts
.
data
[i] = eigenvalues.
real_parts
.
data
[i];
59
out_result->
imag_parts
.
data
[i] = eigenvalues.
imag_parts
.
data
[i];
60
}
61
lmmc_eigen_gen_result_destroy
(&eigenvalues);
62
for
(
size_t
i = 0; i < n; i++) {
63
for
(
size_t
j = 0; j < n; j++) {
64
MAT_ELEM
(&out_result->
vectors_imag
, i, j) = 0.0;
65
}
66
}
67
status =
lmmc_eigen_inverse_vectors
(&scaled_a, out_result);
68
if
(status ==
LMMC_STATUS_OK
) {
69
status =
lmmc_eigen_restore_scale
(&out_result->
real_parts
,
70
&out_result->
imag_parts
, matrix_scale);
71
}
72
cleanup:
73
lmmc_mat_destroy
(&scaled_a);
74
return
status;
75
}
76
77
lmmc_status_t
lmmc_eigen_general_full
(
const
lmmc_mat_t
* a,
78
lmmc_eigen_gen_full_result_t
* out_result)
79
{
80
lmmc_real_t
matrix_scale;
81
if
(!lmmc_mat_descriptor_is_valid(a) || !out_result) {
82
return
LMMC_STATUS_INVALID_ARGUMENT
;
83
}
84
if
(a->
rows
!= a->
cols
) {
85
return
LMMC_STATUS_INVALID_ARGUMENT
;
86
}
87
lmmc_status_t
status =
lmmc_eigen_matrix_scale
(a, &matrix_scale);
88
if
(status !=
LMMC_STATUS_OK
) {
89
return
status;
90
}
91
size_t
n = a->
rows
;
92
status = create_full_result(n, out_result);
93
if
(status !=
LMMC_STATUS_OK
) {
94
goto
fail;
95
}
96
if
(n == 1) {
97
out_result->
real_parts
.
data
[0] =
MAT_ELEM
(a, 0, 0);
98
out_result->
imag_parts
.
data
[0] = 0.0;
99
MAT_ELEM
(&out_result->
vectors_real
, 0, 0) = 1.0;
100
MAT_ELEM
(&out_result->
vectors_imag
, 0, 0) = 0.0;
101
return
LMMC_STATUS_OK
;
102
}
103
if
(n == 2) {
104
lmmc_eigen_vectors_2x2
(a, matrix_scale, out_result);
105
return
LMMC_STATUS_OK
;
106
}
107
status = eigenvectors_large(a, matrix_scale, out_result);
108
if
(status ==
LMMC_STATUS_OK
) {
109
return
status;
110
}
111
fail:
112
lmmc_eigen_gen_full_result_destroy
(out_result);
113
memset(out_result, 0,
sizeof
(*out_result));
114
return
status;
115
}
config.h
LMMC binary real type and arithmetic spelling.
lmmc_real_t
double lmmc_real_t
Public and internal LMMC real type.
定义
config.h:28
dense.h
lmmc_mat_create
lmmc_status_t lmmc_mat_create(size_t rows, size_t cols, lmmc_mat_t *out_mat)
创建 rows x cols 的零矩阵。
定义
dense_storage.c:14
lmmc_vec_create
lmmc_status_t lmmc_vec_create(size_t size, lmmc_vec_t *out_vec)
创建长度为 size 的零向量。
定义
dense_storage.c:144
lmmc_mat_destroy
void lmmc_mat_destroy(lmmc_mat_t *mat)
销毁矩阵,释放其拥有的缓冲区并清零结构体字段。
定义
dense_storage.c:62
lmmc_vec_destroy
void lmmc_vec_destroy(lmmc_vec_t *vec)
销毁向量,释放其拥有的缓冲区并清零字段。
定义
dense_storage.c:184
lmmc_mat_t::cols
size_t cols
定义
dense_types.h:20
lmmc_mat_t::rows
size_t rows
定义
dense_types.h:19
lmmc_vec_t::data
lmmc_real_t * data
定义
dense_types.h:33
lmmc_mat_t
行优先存储的稠密矩阵。
定义
dense_types.h:18
eigen.h
特征值 / 奇异值分解,伪逆与条件数接口.
lmmc_eigen_gen_full_result_t::imag_parts
lmmc_vec_t imag_parts
定义
eigen.h:44
lmmc_eigen_general
lmmc_status_t lmmc_eigen_general(const lmmc_mat_t *a, lmmc_eigen_gen_result_t *out_result)
计算一般实矩阵的特征值(不输出特征向量).
定义
eigen_general.c:138
lmmc_eigen_gen_full_result_t::vectors_real
lmmc_mat_t vectors_real
定义
eigen.h:45
lmmc_eigen_gen_result_t::imag_parts
lmmc_vec_t imag_parts
定义
eigen.h:30
lmmc_eigen_gen_full_result_t::real_parts
lmmc_vec_t real_parts
定义
eigen.h:43
lmmc_eigen_gen_full_result_t::vectors_imag
lmmc_mat_t vectors_imag
定义
eigen.h:46
lmmc_eigen_gen_result_t::real_parts
lmmc_vec_t real_parts
定义
eigen.h:29
lmmc_eigen_general_full
lmmc_status_t lmmc_eigen_general_full(const lmmc_mat_t *a, lmmc_eigen_gen_full_result_t *out_result)
计算一般实矩阵的特征值与特征向量.
定义
eigen_general_vectors.c:77
lmmc_eigen_gen_result_destroy
void lmmc_eigen_gen_result_destroy(lmmc_eigen_gen_result_t *result)
释放 lmmc_eigen_general 输出结果.
定义
eigen_general.c:172
lmmc_eigen_gen_full_result_destroy
void lmmc_eigen_gen_full_result_destroy(lmmc_eigen_gen_full_result_t *result)
释放 lmmc_eigen_general_full 输出结果.
定义
eigen_general_vectors.c:14
lmmc_eigen_gen_full_result_t
一般实矩阵完整特征分解结果(特征值 + 特征向量).
定义
eigen.h:42
lmmc_eigen_gen_result_t
一般实矩阵特征分解结果(仅特征值,使用实部 / 虚部分别存储).
定义
eigen.h:28
lmmc_eigen_restore_scale
lmmc_status_t lmmc_eigen_restore_scale(lmmc_vec_t *real, lmmc_vec_t *imag, lmmc_real_t scale)
定义
eigen_general.c:21
lmmc_eigen_copy_scaled
void lmmc_eigen_copy_scaled(const lmmc_mat_t *a, lmmc_real_t scale, lmmc_mat_t *result)
定义
eigen_general.c:12
eigen_general_internal.h
lmmc_eigen_vectors_2x2
void lmmc_eigen_vectors_2x2(const lmmc_mat_t *a, lmmc_real_t scale, lmmc_eigen_gen_full_result_t *result)
定义
eigen_general_small.c:115
lmmc_eigen_inverse_vectors
lmmc_status_t lmmc_eigen_inverse_vectors(const lmmc_mat_t *a, lmmc_eigen_gen_full_result_t *result)
定义
eigen_inverse_iteration.c:227
lmmc_eigen_matrix_scale
lmmc_status_t lmmc_eigen_matrix_scale(const lmmc_mat_t *a, lmmc_real_t *scale)
定义
eigen_internal.c:16
eigen_internal.h
特征值 / SVD 模块内部共享的缩放、Householder 与 Givens 辅助接口(仅源文件可见)。
MAT_ELEM
#define MAT_ELEM(mat, i, j)
定义
eigen_internal.h:15
internal.h
LMMC 内部使用的公共工具(仅源文件可见).
linear_algebra.h
稠密矩阵直接分解接口(LU、Cholesky、QR)。
memory_bridge.h
Private recoverable allocator for persistent LMMC ownership.
lmmc_status_t
lmmc_status_t
LMMC 库统一返回的状态码.
定义
status.h:22
LMMC_STATUS_OK
@ LMMC_STATUS_OK
定义
status.h:23
LMMC_STATUS_INVALID_ARGUMENT
@ LMMC_STATUS_INVALID_ARGUMENT
定义
status.h:24
src
eigen_general_vectors.c
生成于
, 为 LMMC使用
1.18.0