numo-linalg-alt 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/ext/numo/linalg/blas/dot.c +61 -61
- data/ext/numo/linalg/blas/dot_sub.c +60 -60
- data/ext/numo/linalg/blas/gemm.c +161 -152
- data/ext/numo/linalg/blas/gemv.c +135 -131
- data/ext/numo/linalg/blas/nrm2.c +54 -54
- data/ext/numo/linalg/lapack/gebal.c +87 -0
- data/ext/numo/linalg/lapack/gebal.h +15 -0
- data/ext/numo/linalg/lapack/gees.c +243 -224
- data/ext/numo/linalg/lapack/geev.c +131 -114
- data/ext/numo/linalg/lapack/gelsd.c +85 -74
- data/ext/numo/linalg/lapack/geqrf.c +56 -55
- data/ext/numo/linalg/lapack/gerqf.c +70 -0
- data/ext/numo/linalg/lapack/gerqf.h +15 -0
- data/ext/numo/linalg/lapack/gesdd.c +100 -90
- data/ext/numo/linalg/lapack/gesv.c +84 -82
- data/ext/numo/linalg/lapack/gesvd.c +144 -133
- data/ext/numo/linalg/lapack/getrf.c +55 -54
- data/ext/numo/linalg/lapack/getri.c +68 -67
- data/ext/numo/linalg/lapack/getrs.c +96 -92
- data/ext/numo/linalg/lapack/gges.c +214 -0
- data/ext/numo/linalg/lapack/gges.h +15 -0
- data/ext/numo/linalg/lapack/heev.c +56 -54
- data/ext/numo/linalg/lapack/heevd.c +56 -54
- data/ext/numo/linalg/lapack/heevr.c +111 -100
- data/ext/numo/linalg/lapack/hegv.c +79 -76
- data/ext/numo/linalg/lapack/hegvd.c +79 -76
- data/ext/numo/linalg/lapack/hegvx.c +134 -122
- data/ext/numo/linalg/lapack/hetrf.c +56 -52
- data/ext/numo/linalg/lapack/lange.c +49 -48
- data/ext/numo/linalg/lapack/orgqr.c +65 -64
- data/ext/numo/linalg/lapack/orgrq.c +78 -0
- data/ext/numo/linalg/lapack/orgrq.h +15 -0
- data/ext/numo/linalg/lapack/potrf.c +53 -52
- data/ext/numo/linalg/lapack/potri.c +53 -52
- data/ext/numo/linalg/lapack/potrs.c +78 -76
- data/ext/numo/linalg/lapack/syev.c +56 -54
- data/ext/numo/linalg/lapack/syevd.c +56 -54
- data/ext/numo/linalg/lapack/syevr.c +109 -100
- data/ext/numo/linalg/lapack/sygv.c +79 -75
- data/ext/numo/linalg/lapack/sygvd.c +79 -75
- data/ext/numo/linalg/lapack/sygvx.c +134 -122
- data/ext/numo/linalg/lapack/sytrf.c +58 -54
- data/ext/numo/linalg/lapack/trtrs.c +83 -79
- data/ext/numo/linalg/lapack/ungqr.c +65 -64
- data/ext/numo/linalg/lapack/ungrq.c +78 -0
- data/ext/numo/linalg/lapack/ungrq.h +15 -0
- data/ext/numo/linalg/linalg.c +24 -13
- data/ext/numo/linalg/linalg.h +5 -0
- data/ext/numo/linalg/util.c +8 -0
- data/ext/numo/linalg/util.h +1 -0
- data/lib/numo/linalg/version.rb +1 -1
- data/lib/numo/linalg.rb +235 -3
- metadata +12 -2
|
@@ -6,58 +6,60 @@ struct _syevd_option {
|
|
|
6
6
|
char uplo;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc)
|
|
10
|
-
static void _iter_##fLapackFunc(na_loop_t* const lp) {
|
|
11
|
-
tDType* a = (tDType*)NDL_PTR(lp, 0);
|
|
12
|
-
tDType* w = (tDType*)NDL_PTR(lp, 1);
|
|
13
|
-
int* info = (int*)NDL_PTR(lp, 2);
|
|
14
|
-
struct _syevd_option* opt = (struct _syevd_option*)(lp->opt_ptr);
|
|
15
|
-
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1];
|
|
16
|
-
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0];
|
|
17
|
-
const lapack_int i =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
VALUE
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const char
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
9
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc) \
|
|
10
|
+
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
11
|
+
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
12
|
+
tDType* w = (tDType*)NDL_PTR(lp, 1); \
|
|
13
|
+
int* info = (int*)NDL_PTR(lp, 2); \
|
|
14
|
+
struct _syevd_option* opt = (struct _syevd_option*)(lp->opt_ptr); \
|
|
15
|
+
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1]; \
|
|
16
|
+
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0]; \
|
|
17
|
+
const lapack_int i = \
|
|
18
|
+
LAPACKE_##fLapackFunc(opt->matrix_layout, opt->jobz, opt->uplo, n, a, lda, w); \
|
|
19
|
+
*info = (int)i; \
|
|
20
|
+
} \
|
|
21
|
+
\
|
|
22
|
+
static VALUE _linalg_lapack_##fLapackFunc(int argc, VALUE* argv, VALUE self) { \
|
|
23
|
+
VALUE a_vnary = Qnil; \
|
|
24
|
+
VALUE kw_args = Qnil; \
|
|
25
|
+
rb_scan_args(argc, argv, "1:", &a_vnary, &kw_args); \
|
|
26
|
+
ID kw_table[3] = { rb_intern("jobz"), rb_intern("uplo"), rb_intern("order") }; \
|
|
27
|
+
VALUE kw_values[3] = { Qundef, Qundef, Qundef }; \
|
|
28
|
+
rb_get_kwargs(kw_args, kw_table, 0, 3, kw_values); \
|
|
29
|
+
const char jobz = kw_values[0] != Qundef ? get_jobz(kw_values[0]) : 'V'; \
|
|
30
|
+
const char uplo = kw_values[1] != Qundef ? get_uplo(kw_values[1]) : 'U'; \
|
|
31
|
+
const int matrix_layout = \
|
|
32
|
+
kw_values[2] != Qundef ? get_matrix_layout(kw_values[2]) : LAPACK_ROW_MAJOR; \
|
|
33
|
+
\
|
|
34
|
+
if (CLASS_OF(a_vnary) != tNAryClass) { \
|
|
35
|
+
a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
|
|
36
|
+
} \
|
|
37
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) { \
|
|
38
|
+
a_vnary = nary_dup(a_vnary); \
|
|
39
|
+
} \
|
|
40
|
+
\
|
|
41
|
+
narray_t* a_nary = NULL; \
|
|
42
|
+
GetNArray(a_vnary, a_nary); \
|
|
43
|
+
if (NA_NDIM(a_nary) != 2) { \
|
|
44
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
|
|
45
|
+
return Qnil; \
|
|
46
|
+
} \
|
|
47
|
+
if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) { \
|
|
48
|
+
rb_raise(rb_eArgError, "input array a must be square"); \
|
|
49
|
+
return Qnil; \
|
|
50
|
+
} \
|
|
51
|
+
\
|
|
52
|
+
const size_t n = NA_SHAPE(a_nary)[1]; \
|
|
53
|
+
size_t shape[1] = { n }; \
|
|
54
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } }; \
|
|
55
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 1, shape }, { numo_cInt32, 0 } }; \
|
|
56
|
+
ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 1, 2, ain, aout }; \
|
|
57
|
+
struct _syevd_option opt = { matrix_layout, jobz, uplo }; \
|
|
58
|
+
VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary); \
|
|
59
|
+
VALUE ret = rb_ary_new3(3, a_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1)); \
|
|
60
|
+
\
|
|
61
|
+
RB_GC_GUARD(a_vnary); \
|
|
62
|
+
return ret; \
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
DEF_LINALG_FUNC(double, numo_cDFloat, dsyevd)
|
|
@@ -66,6 +68,6 @@ DEF_LINALG_FUNC(float, numo_cSFloat, ssyevd)
|
|
|
66
68
|
#undef DEF_LINALG_FUNC
|
|
67
69
|
|
|
68
70
|
void define_linalg_lapack_syevd(VALUE mLapack) {
|
|
69
|
-
rb_define_module_function(mLapack, "dsyevd",
|
|
70
|
-
rb_define_module_function(mLapack, "ssyevd",
|
|
71
|
+
rb_define_module_function(mLapack, "dsyevd", _linalg_lapack_dsyevd, -1);
|
|
72
|
+
rb_define_module_function(mLapack, "ssyevd", _linalg_lapack_ssyevd, -1);
|
|
71
73
|
}
|
|
@@ -1,103 +1,112 @@
|
|
|
1
1
|
#include "syevr.h"
|
|
2
2
|
|
|
3
|
-
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc)
|
|
4
|
-
struct _syevr_option_##tDType {
|
|
5
|
-
int matrix_layout;
|
|
6
|
-
char jobz;
|
|
7
|
-
char range;
|
|
8
|
-
char uplo;
|
|
9
|
-
tDType vl;
|
|
10
|
-
tDType vu;
|
|
11
|
-
lapack_int il;
|
|
12
|
-
lapack_int iu;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
static void _iter_##fLapackFunc(na_loop_t* const lp) {
|
|
16
|
-
tDType* a = (tDType*)NDL_PTR(lp, 0);
|
|
17
|
-
int* m = (int*)NDL_PTR(lp, 1);
|
|
18
|
-
tDType* w = (tDType*)NDL_PTR(lp, 2);
|
|
19
|
-
tDType* z = (tDType*)NDL_PTR(lp, 3);
|
|
20
|
-
int* isuppz = (int*)NDL_PTR(lp, 4);
|
|
21
|
-
int* info = (int*)NDL_PTR(lp, 5);
|
|
22
|
-
struct _syevr_option_##tDType* opt = (struct _syevr_option_##tDType*)(lp->opt_ptr);
|
|
23
|
-
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1];
|
|
24
|
-
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0];
|
|
25
|
-
const lapack_int ldz = opt->range != 'I' ? n : opt->iu - opt->il + 1;
|
|
26
|
-
const tDType abstol = 0.0;
|
|
27
|
-
const lapack_int i = LAPACKE_##fLapackFunc(
|
|
28
|
-
opt->matrix_layout, opt->jobz, opt->range, opt->uplo, n, a, lda,
|
|
29
|
-
opt->
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
VALUE
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const char
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
a_vnary =
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
size_t
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
3
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc) \
|
|
4
|
+
struct _syevr_option_##tDType { \
|
|
5
|
+
int matrix_layout; \
|
|
6
|
+
char jobz; \
|
|
7
|
+
char range; \
|
|
8
|
+
char uplo; \
|
|
9
|
+
tDType vl; \
|
|
10
|
+
tDType vu; \
|
|
11
|
+
lapack_int il; \
|
|
12
|
+
lapack_int iu; \
|
|
13
|
+
}; \
|
|
14
|
+
\
|
|
15
|
+
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
16
|
+
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
17
|
+
int* m = (int*)NDL_PTR(lp, 1); \
|
|
18
|
+
tDType* w = (tDType*)NDL_PTR(lp, 2); \
|
|
19
|
+
tDType* z = (tDType*)NDL_PTR(lp, 3); \
|
|
20
|
+
int* isuppz = (int*)NDL_PTR(lp, 4); \
|
|
21
|
+
int* info = (int*)NDL_PTR(lp, 5); \
|
|
22
|
+
struct _syevr_option_##tDType* opt = (struct _syevr_option_##tDType*)(lp->opt_ptr); \
|
|
23
|
+
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1]; \
|
|
24
|
+
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0]; \
|
|
25
|
+
const lapack_int ldz = opt->range != 'I' ? n : opt->iu - opt->il + 1; \
|
|
26
|
+
const tDType abstol = 0.0; \
|
|
27
|
+
const lapack_int i = LAPACKE_##fLapackFunc( \
|
|
28
|
+
opt->matrix_layout, opt->jobz, opt->range, opt->uplo, n, a, lda, opt->vl, opt->vu, \
|
|
29
|
+
opt->il, opt->iu, abstol, m, w, z, ldz, isuppz \
|
|
30
|
+
); \
|
|
31
|
+
*info = (int)i; \
|
|
32
|
+
} \
|
|
33
|
+
\
|
|
34
|
+
static VALUE _linalg_lapack_##fLapackFunc(int argc, VALUE* argv, VALUE self) { \
|
|
35
|
+
VALUE a_vnary = Qnil; \
|
|
36
|
+
VALUE kw_args = Qnil; \
|
|
37
|
+
rb_scan_args(argc, argv, "1:", &a_vnary, &kw_args); \
|
|
38
|
+
ID kw_table[8] = { rb_intern("jobz"), rb_intern("range"), rb_intern("uplo"), \
|
|
39
|
+
rb_intern("vl"), rb_intern("vu"), rb_intern("il"), \
|
|
40
|
+
rb_intern("iu"), rb_intern("order") }; \
|
|
41
|
+
VALUE kw_values[8] = { Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef }; \
|
|
42
|
+
rb_get_kwargs(kw_args, kw_table, 0, 8, kw_values); \
|
|
43
|
+
const char jobz = kw_values[0] != Qundef ? get_jobz(kw_values[0]) : 'V'; \
|
|
44
|
+
const char range = kw_values[1] != Qundef ? get_range(kw_values[1]) : 'A'; \
|
|
45
|
+
const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
|
|
46
|
+
const tDType vl = kw_values[3] != Qundef ? NUM2DBL(kw_values[3]) : 0.0; \
|
|
47
|
+
const tDType vu = kw_values[4] != Qundef ? NUM2DBL(kw_values[4]) : 0.0; \
|
|
48
|
+
const lapack_int il = kw_values[5] != Qundef ? NUM2INT(kw_values[5]) : 0; \
|
|
49
|
+
const lapack_int iu = kw_values[6] != Qundef ? NUM2INT(kw_values[6]) : 0; \
|
|
50
|
+
const int matrix_layout = \
|
|
51
|
+
kw_values[7] != Qundef ? get_matrix_layout(kw_values[7]) : LAPACK_ROW_MAJOR; \
|
|
52
|
+
\
|
|
53
|
+
if (CLASS_OF(a_vnary) != tNAryClass) { \
|
|
54
|
+
a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
|
|
55
|
+
} \
|
|
56
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) { \
|
|
57
|
+
a_vnary = nary_dup(a_vnary); \
|
|
58
|
+
} \
|
|
59
|
+
\
|
|
60
|
+
narray_t* a_nary = NULL; \
|
|
61
|
+
GetNArray(a_vnary, a_nary); \
|
|
62
|
+
if (NA_NDIM(a_nary) != 2) { \
|
|
63
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
|
|
64
|
+
return Qnil; \
|
|
65
|
+
} \
|
|
66
|
+
if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) { \
|
|
67
|
+
rb_raise(rb_eArgError, "input array a must be square"); \
|
|
68
|
+
return Qnil; \
|
|
69
|
+
} \
|
|
70
|
+
\
|
|
71
|
+
if (range == 'V' && vu <= vl) { \
|
|
72
|
+
rb_raise(rb_eArgError, "vu must be greater than vl"); \
|
|
73
|
+
return Qnil; \
|
|
74
|
+
} \
|
|
75
|
+
\
|
|
76
|
+
const size_t n = NA_SHAPE(a_nary)[1]; \
|
|
77
|
+
if (range == 'I' && (il < 1 || il > (lapack_int)n)) { \
|
|
78
|
+
rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n"); \
|
|
79
|
+
return Qnil; \
|
|
80
|
+
} \
|
|
81
|
+
if (range == 'I' && (iu < 1 || iu > (lapack_int)n)) { \
|
|
82
|
+
rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n"); \
|
|
83
|
+
return Qnil; \
|
|
84
|
+
} \
|
|
85
|
+
if (range == 'I' && iu < il) { \
|
|
86
|
+
rb_raise(rb_eArgError, "iu must be greater than or equal to il"); \
|
|
87
|
+
return Qnil; \
|
|
88
|
+
} \
|
|
89
|
+
\
|
|
90
|
+
size_t m = range != 'I' ? n : (size_t)(iu - il + 1); \
|
|
91
|
+
size_t w_shape[1] = { m }; \
|
|
92
|
+
size_t z_shape[2] = { n, m }; \
|
|
93
|
+
size_t isuppz_shape[1] = { 2 * m }; \
|
|
94
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } }; \
|
|
95
|
+
ndfunc_arg_out_t aout[5] = { { numo_cInt32, 0 }, \
|
|
96
|
+
{ tNAryClass, 1, w_shape }, \
|
|
97
|
+
{ tNAryClass, 2, z_shape }, \
|
|
98
|
+
{ numo_cInt32, 1, isuppz_shape }, \
|
|
99
|
+
{ numo_cInt32, 0 } }; \
|
|
100
|
+
ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 1, 5, ain, aout }; \
|
|
101
|
+
struct _syevr_option_##tDType opt = { matrix_layout, jobz, range, uplo, vl, vu, il, iu }; \
|
|
102
|
+
VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary); \
|
|
103
|
+
VALUE ret = rb_ary_new3( \
|
|
104
|
+
6, a_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1), rb_ary_entry(res, 2), \
|
|
105
|
+
rb_ary_entry(res, 3), rb_ary_entry(res, 4) \
|
|
106
|
+
); \
|
|
107
|
+
\
|
|
108
|
+
RB_GC_GUARD(a_vnary); \
|
|
109
|
+
return ret; \
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
DEF_LINALG_FUNC(double, numo_cDFloat, dsyevr)
|
|
@@ -106,6 +115,6 @@ DEF_LINALG_FUNC(float, numo_cSFloat, ssyevr)
|
|
|
106
115
|
#undef DEF_LINALG_FUNC
|
|
107
116
|
|
|
108
117
|
void define_linalg_lapack_syevr(VALUE mLapack) {
|
|
109
|
-
rb_define_module_function(mLapack, "dsyevr",
|
|
110
|
-
rb_define_module_function(mLapack, "ssyevr",
|
|
118
|
+
rb_define_module_function(mLapack, "dsyevr", _linalg_lapack_dsyevr, -1);
|
|
119
|
+
rb_define_module_function(mLapack, "ssyevr", _linalg_lapack_ssyevr, -1);
|
|
111
120
|
}
|
|
@@ -7,79 +7,83 @@ struct _sygv_option {
|
|
|
7
7
|
char uplo;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc)
|
|
11
|
-
static void _iter_##fLapackFunc(na_loop_t* const lp) {
|
|
12
|
-
tDType* a = (tDType*)NDL_PTR(lp, 0);
|
|
13
|
-
tDType* b = (tDType*)NDL_PTR(lp, 1);
|
|
14
|
-
tDType* w = (tDType*)NDL_PTR(lp, 2);
|
|
15
|
-
int* info = (int*)NDL_PTR(lp, 3);
|
|
16
|
-
struct _sygv_option* opt = (struct _sygv_option*)(lp->opt_ptr);
|
|
17
|
-
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1];
|
|
18
|
-
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0];
|
|
19
|
-
const lapack_int ldb = (lapack_int)NDL_SHAPE(lp, 1)[0];
|
|
20
|
-
const lapack_int i = LAPACKE_##fLapackFunc(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
VALUE
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
rb_raise(rb_eArgError, "input array a must be
|
|
58
|
-
return Qnil;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
rb_raise(rb_eArgError, "input array b must be
|
|
68
|
-
return Qnil;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
10
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc) \
|
|
11
|
+
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
12
|
+
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
13
|
+
tDType* b = (tDType*)NDL_PTR(lp, 1); \
|
|
14
|
+
tDType* w = (tDType*)NDL_PTR(lp, 2); \
|
|
15
|
+
int* info = (int*)NDL_PTR(lp, 3); \
|
|
16
|
+
struct _sygv_option* opt = (struct _sygv_option*)(lp->opt_ptr); \
|
|
17
|
+
const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1]; \
|
|
18
|
+
const lapack_int lda = (lapack_int)NDL_SHAPE(lp, 0)[0]; \
|
|
19
|
+
const lapack_int ldb = (lapack_int)NDL_SHAPE(lp, 1)[0]; \
|
|
20
|
+
const lapack_int i = LAPACKE_##fLapackFunc( \
|
|
21
|
+
opt->matrix_layout, opt->itype, opt->jobz, opt->uplo, n, a, lda, b, ldb, w \
|
|
22
|
+
); \
|
|
23
|
+
*info = (int)i; \
|
|
24
|
+
} \
|
|
25
|
+
\
|
|
26
|
+
static VALUE _linalg_lapack_##fLapackFunc(int argc, VALUE* argv, VALUE self) { \
|
|
27
|
+
VALUE a_vnary = Qnil; \
|
|
28
|
+
VALUE b_vnary = Qnil; \
|
|
29
|
+
VALUE kw_args = Qnil; \
|
|
30
|
+
rb_scan_args(argc, argv, "2:", &a_vnary, &b_vnary, &kw_args); \
|
|
31
|
+
ID kw_table[4] = { rb_intern("itype"), rb_intern("jobz"), rb_intern("uplo"), \
|
|
32
|
+
rb_intern("order") }; \
|
|
33
|
+
VALUE kw_values[4] = { Qundef, Qundef, Qundef, Qundef }; \
|
|
34
|
+
rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
|
|
35
|
+
const lapack_int itype = kw_values[0] != Qundef ? get_itype(kw_values[0]) : 1; \
|
|
36
|
+
const char jobz = kw_values[1] != Qundef ? get_jobz(kw_values[1]) : 'V'; \
|
|
37
|
+
const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
|
|
38
|
+
const int matrix_layout = \
|
|
39
|
+
kw_values[3] != Qundef ? get_matrix_layout(kw_values[3]) : LAPACK_ROW_MAJOR; \
|
|
40
|
+
\
|
|
41
|
+
if (CLASS_OF(a_vnary) != tNAryClass) { \
|
|
42
|
+
a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
|
|
43
|
+
} \
|
|
44
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) { \
|
|
45
|
+
a_vnary = nary_dup(a_vnary); \
|
|
46
|
+
} \
|
|
47
|
+
if (CLASS_OF(b_vnary) != tNAryClass) { \
|
|
48
|
+
b_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, b_vnary); \
|
|
49
|
+
} \
|
|
50
|
+
if (!RTEST(nary_check_contiguous(b_vnary))) { \
|
|
51
|
+
b_vnary = nary_dup(b_vnary); \
|
|
52
|
+
} \
|
|
53
|
+
\
|
|
54
|
+
narray_t* a_nary = NULL; \
|
|
55
|
+
GetNArray(a_vnary, a_nary); \
|
|
56
|
+
if (NA_NDIM(a_nary) != 2) { \
|
|
57
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
|
|
58
|
+
return Qnil; \
|
|
59
|
+
} \
|
|
60
|
+
if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) { \
|
|
61
|
+
rb_raise(rb_eArgError, "input array a must be square"); \
|
|
62
|
+
return Qnil; \
|
|
63
|
+
} \
|
|
64
|
+
narray_t* b_nary = NULL; \
|
|
65
|
+
GetNArray(b_vnary, b_nary); \
|
|
66
|
+
if (NA_NDIM(b_nary) != 2) { \
|
|
67
|
+
rb_raise(rb_eArgError, "input array b must be 2-dimensional"); \
|
|
68
|
+
return Qnil; \
|
|
69
|
+
} \
|
|
70
|
+
if (NA_SHAPE(b_nary)[0] != NA_SHAPE(b_nary)[1]) { \
|
|
71
|
+
rb_raise(rb_eArgError, "input array b must be square"); \
|
|
72
|
+
return Qnil; \
|
|
73
|
+
} \
|
|
74
|
+
\
|
|
75
|
+
const size_t n = NA_SHAPE(a_nary)[1]; \
|
|
76
|
+
size_t shape[1] = { n }; \
|
|
77
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 2 }, { OVERWRITE, 2 } }; \
|
|
78
|
+
ndfunc_arg_out_t aout[2] = { { tNAryClass, 1, shape }, { numo_cInt32, 0 } }; \
|
|
79
|
+
ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 2, 2, ain, aout }; \
|
|
80
|
+
struct _sygv_option opt = { matrix_layout, itype, jobz, uplo }; \
|
|
81
|
+
VALUE res = na_ndloop3(&ndf, &opt, 2, a_vnary, b_vnary); \
|
|
82
|
+
VALUE ret = rb_ary_new3(4, a_vnary, b_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1)); \
|
|
83
|
+
\
|
|
84
|
+
RB_GC_GUARD(a_vnary); \
|
|
85
|
+
RB_GC_GUARD(b_vnary); \
|
|
86
|
+
return ret; \
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
DEF_LINALG_FUNC(double, numo_cDFloat, dsygv)
|
|
@@ -88,6 +92,6 @@ DEF_LINALG_FUNC(float, numo_cSFloat, ssygv)
|
|
|
88
92
|
#undef DEF_LINALG_FUNC
|
|
89
93
|
|
|
90
94
|
void define_linalg_lapack_sygv(VALUE mLapack) {
|
|
91
|
-
rb_define_module_function(mLapack, "dsygv",
|
|
92
|
-
rb_define_module_function(mLapack, "ssygv",
|
|
95
|
+
rb_define_module_function(mLapack, "dsygv", _linalg_lapack_dsygv, -1);
|
|
96
|
+
rb_define_module_function(mLapack, "ssygv", _linalg_lapack_ssygv, -1);
|
|
93
97
|
}
|