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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/ext/numo/linalg/blas/dot.c +61 -61
  4. data/ext/numo/linalg/blas/dot_sub.c +60 -60
  5. data/ext/numo/linalg/blas/gemm.c +161 -152
  6. data/ext/numo/linalg/blas/gemv.c +135 -131
  7. data/ext/numo/linalg/blas/nrm2.c +54 -54
  8. data/ext/numo/linalg/lapack/gebal.c +87 -0
  9. data/ext/numo/linalg/lapack/gebal.h +15 -0
  10. data/ext/numo/linalg/lapack/gees.c +243 -224
  11. data/ext/numo/linalg/lapack/geev.c +131 -114
  12. data/ext/numo/linalg/lapack/gelsd.c +85 -74
  13. data/ext/numo/linalg/lapack/geqrf.c +56 -55
  14. data/ext/numo/linalg/lapack/gerqf.c +70 -0
  15. data/ext/numo/linalg/lapack/gerqf.h +15 -0
  16. data/ext/numo/linalg/lapack/gesdd.c +100 -90
  17. data/ext/numo/linalg/lapack/gesv.c +84 -82
  18. data/ext/numo/linalg/lapack/gesvd.c +144 -133
  19. data/ext/numo/linalg/lapack/getrf.c +55 -54
  20. data/ext/numo/linalg/lapack/getri.c +68 -67
  21. data/ext/numo/linalg/lapack/getrs.c +96 -92
  22. data/ext/numo/linalg/lapack/gges.c +214 -0
  23. data/ext/numo/linalg/lapack/gges.h +15 -0
  24. data/ext/numo/linalg/lapack/heev.c +56 -54
  25. data/ext/numo/linalg/lapack/heevd.c +56 -54
  26. data/ext/numo/linalg/lapack/heevr.c +111 -100
  27. data/ext/numo/linalg/lapack/hegv.c +79 -76
  28. data/ext/numo/linalg/lapack/hegvd.c +79 -76
  29. data/ext/numo/linalg/lapack/hegvx.c +134 -122
  30. data/ext/numo/linalg/lapack/hetrf.c +56 -52
  31. data/ext/numo/linalg/lapack/lange.c +49 -48
  32. data/ext/numo/linalg/lapack/orgqr.c +65 -64
  33. data/ext/numo/linalg/lapack/orgrq.c +78 -0
  34. data/ext/numo/linalg/lapack/orgrq.h +15 -0
  35. data/ext/numo/linalg/lapack/potrf.c +53 -52
  36. data/ext/numo/linalg/lapack/potri.c +53 -52
  37. data/ext/numo/linalg/lapack/potrs.c +78 -76
  38. data/ext/numo/linalg/lapack/syev.c +56 -54
  39. data/ext/numo/linalg/lapack/syevd.c +56 -54
  40. data/ext/numo/linalg/lapack/syevr.c +109 -100
  41. data/ext/numo/linalg/lapack/sygv.c +79 -75
  42. data/ext/numo/linalg/lapack/sygvd.c +79 -75
  43. data/ext/numo/linalg/lapack/sygvx.c +134 -122
  44. data/ext/numo/linalg/lapack/sytrf.c +58 -54
  45. data/ext/numo/linalg/lapack/trtrs.c +83 -79
  46. data/ext/numo/linalg/lapack/ungqr.c +65 -64
  47. data/ext/numo/linalg/lapack/ungrq.c +78 -0
  48. data/ext/numo/linalg/lapack/ungrq.h +15 -0
  49. data/ext/numo/linalg/linalg.c +24 -13
  50. data/ext/numo/linalg/linalg.h +5 -0
  51. data/ext/numo/linalg/util.c +8 -0
  52. data/ext/numo/linalg/util.h +1 -0
  53. data/lib/numo/linalg/version.rb +1 -1
  54. data/lib/numo/linalg.rb +235 -3
  55. metadata +12 -2
@@ -1,103 +1,114 @@
1
1
  #include "heevr.h"
2
2
 
3
- #define DEF_LINALG_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass, fLapackFunc) \
4
- struct _heevr_option_##tRtDType { \
5
- int matrix_layout; \
6
- char jobz; \
7
- char range; \
8
- char uplo; \
9
- tRtDType vl; \
10
- tRtDType 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
- tRtDType* w = (tRtDType*)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 _heevr_option_##tRtDType* opt = (struct _heevr_option_##tRtDType*)(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 tRtDType 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->vl, opt->vu, opt->il, opt->iu, abstol, m, w, z, ldz, isuppz); \
30
- *info = (int)i; \
31
- } \
32
- \
33
- static VALUE _linalg_lapack_##fLapackFunc(int argc, VALUE* argv, VALUE self) { \
34
- VALUE a_vnary = Qnil; \
35
- VALUE kw_args = Qnil; \
36
- rb_scan_args(argc, argv, "1:", &a_vnary, &kw_args); \
37
- ID kw_table[8] = { rb_intern("jobz"), rb_intern("range"), rb_intern("uplo"), \
38
- rb_intern("vl"), rb_intern("vu"), rb_intern("il"), rb_intern("iu"), rb_intern("order") }; \
39
- VALUE kw_values[8] = { Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef }; \
40
- rb_get_kwargs(kw_args, kw_table, 0, 8, kw_values); \
41
- const char jobz = kw_values[0] != Qundef ? get_jobz(kw_values[0]) : 'V'; \
42
- const char range = kw_values[1] != Qundef ? get_range(kw_values[1]) : 'A'; \
43
- const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
44
- const tRtDType vl = kw_values[3] != Qundef ? NUM2DBL(kw_values[3]) : 0.0; \
45
- const tRtDType vu = kw_values[4] != Qundef ? NUM2DBL(kw_values[4]) : 0.0; \
46
- const lapack_int il = kw_values[5] != Qundef ? NUM2INT(kw_values[5]) : 0; \
47
- const lapack_int iu = kw_values[6] != Qundef ? NUM2INT(kw_values[6]) : 0; \
48
- const int matrix_layout = kw_values[7] != Qundef ? get_matrix_layout(kw_values[7]) : LAPACK_ROW_MAJOR; \
49
- \
50
- if (CLASS_OF(a_vnary) != tNAryClass) { \
51
- a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
52
- } \
53
- if (!RTEST(nary_check_contiguous(a_vnary))) { \
54
- a_vnary = nary_dup(a_vnary); \
55
- } \
56
- \
57
- narray_t* a_nary = NULL; \
58
- GetNArray(a_vnary, a_nary); \
59
- if (NA_NDIM(a_nary) != 2) { \
60
- rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
61
- return Qnil; \
62
- } \
63
- if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) { \
64
- rb_raise(rb_eArgError, "input array a must be square"); \
65
- return Qnil; \
66
- } \
67
- \
68
- if (range == 'V' && vu <= vl) { \
69
- rb_raise(rb_eArgError, "vu must be greater than vl"); \
70
- return Qnil; \
71
- } \
72
- \
73
- const size_t n = NA_SHAPE(a_nary)[1]; \
74
- if (range == 'I' && (il < 1 || il > (lapack_int)n)) { \
75
- rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n"); \
76
- return Qnil; \
77
- } \
78
- if (range == 'I' && (iu < 1 || iu > (lapack_int)n)) { \
79
- rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n"); \
80
- return Qnil; \
81
- } \
82
- if (range == 'I' && iu < il) { \
83
- rb_raise(rb_eArgError, "iu must be greater than or equal to il"); \
84
- return Qnil; \
85
- } \
86
- \
87
- size_t m = range != 'I' ? n : (size_t)(iu - il + 1); \
88
- size_t w_shape[1] = { m }; \
89
- size_t z_shape[2] = { n, m }; \
90
- size_t isuppz_shape[1] = { 2 * m }; \
91
- ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } }; \
92
- ndfunc_arg_out_t aout[5] = { { numo_cInt32, 0 }, { tRtNAryClass, 1, w_shape }, { tNAryClass, 2, z_shape }, { numo_cInt32, 1, isuppz_shape }, { numo_cInt32, 0 } }; \
93
- ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 1, 5, ain, aout }; \
94
- struct _heevr_option_##tRtDType opt = { matrix_layout, jobz, range, uplo, vl, vu, il, iu }; \
95
- VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary); \
96
- VALUE ret = rb_ary_new3(6, a_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1), rb_ary_entry(res, 2), \
97
- rb_ary_entry(res, 3), rb_ary_entry(res, 4)); \
98
- \
99
- RB_GC_GUARD(a_vnary); \
100
- return ret; \
3
+ #define DEF_LINALG_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass, fLapackFunc) \
4
+ struct _heevr_option_##tRtDType { \
5
+ int matrix_layout; \
6
+ char jobz; \
7
+ char range; \
8
+ char uplo; \
9
+ tRtDType vl; \
10
+ tRtDType 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
+ tRtDType* w = (tRtDType*)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 _heevr_option_##tRtDType* opt = (struct _heevr_option_##tRtDType*)(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 tRtDType 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 tRtDType vl = kw_values[3] != Qundef ? NUM2DBL(kw_values[3]) : 0.0; \
47
+ const tRtDType 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
+ { tRtNAryClass, 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 _heevr_option_##tRtDType opt = { \
102
+ matrix_layout, jobz, range, uplo, vl, vu, il, iu \
103
+ }; \
104
+ VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary); \
105
+ VALUE ret = rb_ary_new3( \
106
+ 6, a_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1), rb_ary_entry(res, 2), \
107
+ rb_ary_entry(res, 3), rb_ary_entry(res, 4) \
108
+ ); \
109
+ \
110
+ RB_GC_GUARD(a_vnary); \
111
+ return ret; \
101
112
  }
102
113
 
103
114
  DEF_LINALG_FUNC(lapack_complex_double, double, numo_cDComplex, numo_cDFloat, zheevr)
@@ -106,6 +117,6 @@ DEF_LINALG_FUNC(lapack_complex_float, float, numo_cSComplex, numo_cSFloat, cheev
106
117
  #undef DEF_LINALG_FUNC
107
118
 
108
119
  void define_linalg_lapack_heevr(VALUE mLapack) {
109
- rb_define_module_function(mLapack, "zheevr", RUBY_METHOD_FUNC(_linalg_lapack_zheevr), -1);
110
- rb_define_module_function(mLapack, "cheevr", RUBY_METHOD_FUNC(_linalg_lapack_cheevr), -1);
120
+ rb_define_module_function(mLapack, "zheevr", _linalg_lapack_zheevr, -1);
121
+ rb_define_module_function(mLapack, "cheevr", _linalg_lapack_cheevr, -1);
111
122
  }
@@ -7,80 +7,83 @@ struct _hegv_option {
7
7
  char uplo;
8
8
  };
9
9
 
10
- #define DEF_LINALG_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass, 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
- tRtDType* w = (tRtDType*)NDL_PTR(lp, 2); \
15
- int* info = (int*)NDL_PTR(lp, 3); \
16
- struct _hegv_option* opt = (struct _hegv_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
- *info = (int)i; \
23
- } \
24
- \
25
- static VALUE _linalg_lapack_##fLapackFunc(int argc, VALUE* argv, VALUE self) { \
26
- VALUE a_vnary = Qnil; \
27
- VALUE b_vnary = Qnil; \
28
- VALUE kw_args = Qnil; \
29
- rb_scan_args(argc, argv, "2:", &a_vnary, &b_vnary, &kw_args); \
30
- ID kw_table[4] = { rb_intern("itype"), rb_intern("jobz"), rb_intern("uplo"), rb_intern("order") }; \
31
- VALUE kw_values[4] = { Qundef, Qundef, Qundef, Qundef }; \
32
- rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
33
- const lapack_int itype = kw_values[0] != Qundef ? get_itype(kw_values[0]) : 1; \
34
- const char jobz = kw_values[1] != Qundef ? get_jobz(kw_values[1]) : 'V'; \
35
- const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
36
- const int matrix_layout = kw_values[3] != Qundef ? get_matrix_layout(kw_values[3]) : LAPACK_ROW_MAJOR; \
37
- \
38
- if (CLASS_OF(a_vnary) != tNAryClass) { \
39
- a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
40
- } \
41
- if (!RTEST(nary_check_contiguous(a_vnary))) { \
42
- a_vnary = nary_dup(a_vnary); \
43
- } \
44
- if (CLASS_OF(b_vnary) != tNAryClass) { \
45
- b_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, b_vnary); \
46
- } \
47
- if (!RTEST(nary_check_contiguous(b_vnary))) { \
48
- b_vnary = nary_dup(b_vnary); \
49
- } \
50
- \
51
- narray_t* a_nary = NULL; \
52
- GetNArray(a_vnary, a_nary); \
53
- if (NA_NDIM(a_nary) != 2) { \
54
- rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
55
- return Qnil; \
56
- } \
57
- if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) { \
58
- rb_raise(rb_eArgError, "input array a must be square"); \
59
- return Qnil; \
60
- } \
61
- narray_t* b_nary = NULL; \
62
- GetNArray(b_vnary, b_nary); \
63
- if (NA_NDIM(b_nary) != 2) { \
64
- rb_raise(rb_eArgError, "input array b must be 2-dimensional"); \
65
- return Qnil; \
66
- } \
67
- if (NA_SHAPE(b_nary)[0] != NA_SHAPE(b_nary)[1]) { \
68
- rb_raise(rb_eArgError, "input array b must be square"); \
69
- return Qnil; \
70
- } \
71
- \
72
- const size_t n = NA_SHAPE(a_nary)[1]; \
73
- size_t shape[1] = { n }; \
74
- ndfunc_arg_in_t ain[2] = { { OVERWRITE, 2 }, { OVERWRITE, 2 } }; \
75
- ndfunc_arg_out_t aout[2] = { { tRtNAryClass, 1, shape }, { numo_cInt32, 0 } }; \
76
- ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 2, 2, ain, aout }; \
77
- struct _hegv_option opt = { matrix_layout, itype, jobz, uplo }; \
78
- VALUE res = na_ndloop3(&ndf, &opt, 2, a_vnary, b_vnary); \
79
- VALUE ret = rb_ary_new3(4, a_vnary, b_vnary, rb_ary_entry(res, 0), rb_ary_entry(res, 1)); \
80
- \
81
- RB_GC_GUARD(a_vnary); \
82
- RB_GC_GUARD(b_vnary); \
83
- return ret; \
10
+ #define DEF_LINALG_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass, 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
+ tRtDType* w = (tRtDType*)NDL_PTR(lp, 2); \
15
+ int* info = (int*)NDL_PTR(lp, 3); \
16
+ struct _hegv_option* opt = (struct _hegv_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] = { { tRtNAryClass, 1, shape }, { numo_cInt32, 0 } }; \
79
+ ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 2, 2, ain, aout }; \
80
+ struct _hegv_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; \
84
87
  }
85
88
 
86
89
  DEF_LINALG_FUNC(lapack_complex_double, double, numo_cDComplex, numo_cDFloat, zhegv)
@@ -89,6 +92,6 @@ DEF_LINALG_FUNC(lapack_complex_float, float, numo_cSComplex, numo_cSFloat, chegv
89
92
  #undef DEF_LINALG_FUNC
90
93
 
91
94
  void define_linalg_lapack_hegv(VALUE mLapack) {
92
- rb_define_module_function(mLapack, "zhegv", RUBY_METHOD_FUNC(_linalg_lapack_zhegv), -1);
93
- rb_define_module_function(mLapack, "chegv", RUBY_METHOD_FUNC(_linalg_lapack_chegv), -1);
95
+ rb_define_module_function(mLapack, "zhegv", _linalg_lapack_zhegv, -1);
96
+ rb_define_module_function(mLapack, "chegv", _linalg_lapack_chegv, -1);
94
97
  }