numo-linalg-alt 0.4.1 → 0.6.0

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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/README.md +83 -5
  4. data/ext/numo/linalg/blas/blas_common.h +30 -0
  5. data/ext/numo/linalg/blas/blas_util.c +39 -0
  6. data/ext/numo/linalg/blas/blas_util.h +11 -0
  7. data/ext/numo/linalg/{converter.h → blas/converter.h} +0 -2
  8. data/ext/numo/linalg/blas/dot.c +1 -1
  9. data/ext/numo/linalg/blas/dot.h +1 -6
  10. data/ext/numo/linalg/blas/dot_sub.c +1 -1
  11. data/ext/numo/linalg/blas/dot_sub.h +1 -6
  12. data/ext/numo/linalg/blas/gemm.c +21 -21
  13. data/ext/numo/linalg/blas/gemm.h +3 -9
  14. data/ext/numo/linalg/blas/gemv.c +10 -10
  15. data/ext/numo/linalg/blas/gemv.h +3 -9
  16. data/ext/numo/linalg/blas/nrm2.c +1 -1
  17. data/ext/numo/linalg/blas/nrm2.h +1 -6
  18. data/ext/numo/linalg/extconf.rb +34 -6
  19. data/ext/numo/linalg/lapack/gebal.h +1 -1
  20. data/ext/numo/linalg/lapack/gees.c +4 -4
  21. data/ext/numo/linalg/lapack/gees.h +1 -1
  22. data/ext/numo/linalg/lapack/geev.c +8 -24
  23. data/ext/numo/linalg/lapack/geev.h +1 -1
  24. data/ext/numo/linalg/lapack/gehrd.c +77 -0
  25. data/ext/numo/linalg/lapack/gehrd.h +15 -0
  26. data/ext/numo/linalg/lapack/gelsd.h +1 -1
  27. data/ext/numo/linalg/lapack/geqrf.h +1 -1
  28. data/ext/numo/linalg/lapack/gerqf.h +1 -1
  29. data/ext/numo/linalg/lapack/gesdd.h +1 -1
  30. data/ext/numo/linalg/lapack/gesv.h +1 -1
  31. data/ext/numo/linalg/lapack/gesvd.h +1 -1
  32. data/ext/numo/linalg/lapack/getrf.h +1 -1
  33. data/ext/numo/linalg/lapack/getri.h +1 -1
  34. data/ext/numo/linalg/lapack/getrs.h +1 -1
  35. data/ext/numo/linalg/lapack/gges.c +4 -4
  36. data/ext/numo/linalg/lapack/gges.h +1 -1
  37. data/ext/numo/linalg/lapack/heev.c +1 -1
  38. data/ext/numo/linalg/lapack/heev.h +1 -1
  39. data/ext/numo/linalg/lapack/heevd.c +1 -1
  40. data/ext/numo/linalg/lapack/heevd.h +1 -1
  41. data/ext/numo/linalg/lapack/heevr.c +1 -1
  42. data/ext/numo/linalg/lapack/heevr.h +1 -1
  43. data/ext/numo/linalg/lapack/hegv.c +1 -1
  44. data/ext/numo/linalg/lapack/hegv.h +1 -1
  45. data/ext/numo/linalg/lapack/hegvd.c +1 -1
  46. data/ext/numo/linalg/lapack/hegvd.h +1 -1
  47. data/ext/numo/linalg/lapack/hegvx.c +1 -1
  48. data/ext/numo/linalg/lapack/hegvx.h +1 -1
  49. data/ext/numo/linalg/lapack/hetrf.h +1 -1
  50. data/ext/numo/linalg/lapack/lange.c +7 -8
  51. data/ext/numo/linalg/lapack/lange.h +1 -1
  52. data/ext/numo/linalg/lapack/lapack_util.c +57 -0
  53. data/ext/numo/linalg/lapack/lapack_util.h +27 -0
  54. data/ext/numo/linalg/lapack/orghr.c +82 -0
  55. data/ext/numo/linalg/lapack/orghr.h +15 -0
  56. data/ext/numo/linalg/lapack/orgqr.h +1 -1
  57. data/ext/numo/linalg/lapack/orgrq.h +1 -1
  58. data/ext/numo/linalg/lapack/potrf.h +1 -1
  59. data/ext/numo/linalg/lapack/potri.h +1 -1
  60. data/ext/numo/linalg/lapack/potrs.h +1 -1
  61. data/ext/numo/linalg/lapack/syev.c +1 -1
  62. data/ext/numo/linalg/lapack/syev.h +1 -1
  63. data/ext/numo/linalg/lapack/syevd.c +1 -1
  64. data/ext/numo/linalg/lapack/syevd.h +1 -1
  65. data/ext/numo/linalg/lapack/syevr.c +1 -1
  66. data/ext/numo/linalg/lapack/syevr.h +1 -1
  67. data/ext/numo/linalg/lapack/sygv.c +1 -1
  68. data/ext/numo/linalg/lapack/sygv.h +1 -1
  69. data/ext/numo/linalg/lapack/sygvd.c +1 -1
  70. data/ext/numo/linalg/lapack/sygvd.h +1 -1
  71. data/ext/numo/linalg/lapack/sygvx.c +1 -1
  72. data/ext/numo/linalg/lapack/sygvx.h +1 -1
  73. data/ext/numo/linalg/lapack/sytrf.h +1 -1
  74. data/ext/numo/linalg/lapack/trtrs.h +1 -1
  75. data/ext/numo/linalg/lapack/unghr.c +82 -0
  76. data/ext/numo/linalg/lapack/unghr.h +15 -0
  77. data/ext/numo/linalg/lapack/ungqr.h +1 -1
  78. data/ext/numo/linalg/lapack/ungrq.h +1 -1
  79. data/ext/numo/linalg/linalg.c +5 -0
  80. data/ext/numo/linalg/linalg.h +17 -6
  81. data/lib/numo/linalg/version.rb +1 -1
  82. data/lib/numo/linalg.rb +160 -20
  83. metadata +15 -6
  84. data/ext/numo/linalg/util.c +0 -103
  85. data/ext/numo/linalg/util.h +0 -18
  86. /data/ext/numo/linalg/{converter.c → blas/converter.c} +0 -0
@@ -6,22 +6,6 @@ struct _geev_option {
6
6
  char jobvr;
7
7
  };
8
8
 
9
- char _get_jobvl(VALUE val) {
10
- const char jobvl = NUM2CHR(val);
11
- if (jobvl != 'N' && jobvl != 'V') {
12
- rb_raise(rb_eArgError, "jobvl must be 'N' or 'V'");
13
- }
14
- return jobvl;
15
- }
16
-
17
- char _get_jobvr(VALUE val) {
18
- const char jobvr = NUM2CHR(val);
19
- if (jobvr != 'N' && jobvr != 'V') {
20
- rb_raise(rb_eArgError, "jobvr must be 'N' or 'V'");
21
- }
22
- return jobvr;
23
- }
24
-
25
9
  #define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc) \
26
10
  static void _iter_##fLapackFunc(na_loop_t* const lp) { \
27
11
  tDType* a = (tDType*)NDL_PTR(lp, 0); \
@@ -35,8 +19,8 @@ char _get_jobvr(VALUE val) {
35
19
  (lapack_int)(opt->matrix_layout == LAPACK_ROW_MAJOR ? NDL_SHAPE(lp, 0)[0] \
36
20
  : NDL_SHAPE(lp, 0)[1]); \
37
21
  const lapack_int lda = n; \
38
- const lapack_int ldvl = (opt->jobvl == 'N') ? 1 : n; \
39
- const lapack_int ldvr = (opt->jobvr == 'N') ? 1 : n; \
22
+ const lapack_int ldvl = n; \
23
+ const lapack_int ldvr = n; \
40
24
  lapack_int i = LAPACKE_##fLapackFunc( \
41
25
  opt->matrix_layout, opt->jobvl, opt->jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr \
42
26
  ); \
@@ -52,8 +36,8 @@ char _get_jobvr(VALUE val) {
52
36
  rb_get_kwargs(kw_args, kw_table, 0, 3, kw_values); \
53
37
  const int matrix_layout = \
54
38
  kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR; \
55
- const char jobvl = kw_values[1] != Qundef ? _get_jobvl(kw_values[1]) : 'V'; \
56
- const char jobvr = kw_values[2] != Qundef ? _get_jobvr(kw_values[2]) : 'V'; \
39
+ const char jobvl = kw_values[1] != Qundef ? get_job(kw_values[1], "jobvl") : 'V'; \
40
+ const char jobvr = kw_values[2] != Qundef ? get_job(kw_values[2], "jobvr") : 'V'; \
57
41
  \
58
42
  if (CLASS_OF(a_vnary) != tNAryClass) { \
59
43
  a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
@@ -101,8 +85,8 @@ char _get_jobvr(VALUE val) {
101
85
  (lapack_int)(opt->matrix_layout == LAPACK_ROW_MAJOR ? NDL_SHAPE(lp, 0)[0] \
102
86
  : NDL_SHAPE(lp, 0)[1]); \
103
87
  const lapack_int lda = n; \
104
- const lapack_int ldvl = (opt->jobvl == 'N') ? 1 : n; \
105
- const lapack_int ldvr = (opt->jobvr == 'N') ? 1 : n; \
88
+ const lapack_int ldvl = n; \
89
+ const lapack_int ldvr = n; \
106
90
  lapack_int i = LAPACKE_##fLapackFunc( \
107
91
  opt->matrix_layout, opt->jobvl, opt->jobvr, n, a, lda, w, vl, ldvl, vr, ldvr \
108
92
  ); \
@@ -118,8 +102,8 @@ char _get_jobvr(VALUE val) {
118
102
  rb_get_kwargs(kw_args, kw_table, 0, 3, kw_values); \
119
103
  const int matrix_layout = \
120
104
  kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR; \
121
- const char jobvl = kw_values[1] != Qundef ? _get_jobvl(kw_values[1]) : 'V'; \
122
- const char jobvr = kw_values[2] != Qundef ? _get_jobvr(kw_values[2]) : 'V'; \
105
+ const char jobvl = kw_values[1] != Qundef ? get_job(kw_values[1], "jobvl") : 'V'; \
106
+ const char jobvr = kw_values[2] != Qundef ? get_job(kw_values[2], "jobvr") : 'V'; \
123
107
  \
124
108
  if (CLASS_OF(a_vnary) != tNAryClass) { \
125
109
  a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_geev(VALUE mLapack);
14
14
 
@@ -0,0 +1,77 @@
1
+ #include "gehrd.h"
2
+
3
+ struct _gehrd_option {
4
+ int matrix_layout;
5
+ int ilo;
6
+ int ihi;
7
+ };
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* tau = (tDType*)NDL_PTR(lp, 1); \
13
+ int* info = (int*)NDL_PTR(lp, 2); \
14
+ struct _gehrd_option* opt = (struct _gehrd_option*)(lp->opt_ptr); \
15
+ const lapack_int ilo = opt->ilo; \
16
+ const lapack_int ihi = opt->ihi; \
17
+ const lapack_int n = \
18
+ (lapack_int)(opt->matrix_layout == LAPACK_ROW_MAJOR ? NDL_SHAPE(lp, 0)[0] \
19
+ : NDL_SHAPE(lp, 0)[1]); \
20
+ const lapack_int lda = n; \
21
+ lapack_int i = LAPACKE_##fLapackFunc(opt->matrix_layout, n, ilo, ihi, a, lda, tau); \
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 kw_args = Qnil; \
28
+ rb_scan_args(argc, argv, "1:", &a_vnary, &kw_args); \
29
+ ID kw_table[3] = { rb_intern("ilo"), rb_intern("ihi"), rb_intern("order") }; \
30
+ VALUE kw_values[3] = { Qundef, Qundef, Qundef }; \
31
+ rb_get_kwargs(kw_args, kw_table, 2, 1, kw_values); \
32
+ const int ilo = NUM2INT(kw_values[0]); \
33
+ const int ihi = NUM2INT(kw_values[1]); \
34
+ const int matrix_layout = \
35
+ kw_values[2] != Qundef ? get_matrix_layout(kw_values[2]) : LAPACK_ROW_MAJOR; \
36
+ \
37
+ if (CLASS_OF(a_vnary) != tNAryClass) { \
38
+ a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
39
+ } \
40
+ if (!RTEST(nary_check_contiguous(a_vnary))) { \
41
+ a_vnary = nary_dup(a_vnary); \
42
+ } \
43
+ \
44
+ narray_t* a_nary = NULL; \
45
+ GetNArray(a_vnary, a_nary); \
46
+ const int n_dims = NA_NDIM(a_nary); \
47
+ if (n_dims != 2) { \
48
+ rb_raise(rb_eArgError, "input array a must be 2-dimensional"); \
49
+ return Qnil; \
50
+ } \
51
+ \
52
+ size_t n = matrix_layout == LAPACK_ROW_MAJOR ? NA_SHAPE(a_nary)[0] : NA_SHAPE(a_nary)[1]; \
53
+ size_t shape_tau[1] = { n - 1 }; \
54
+ ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } }; \
55
+ ndfunc_arg_out_t aout[2] = { { tNAryClass, 1, shape_tau }, { numo_cInt32, 0 } }; \
56
+ ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 1, 2, ain, aout }; \
57
+ struct _gehrd_option opt = { matrix_layout, ilo, ihi }; \
58
+ VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary); \
59
+ VALUE ret = rb_ary_concat(rb_ary_new3(1, a_vnary), res); \
60
+ \
61
+ RB_GC_GUARD(a_vnary); \
62
+ return ret; \
63
+ }
64
+
65
+ DEF_LINALG_FUNC(double, numo_cDFloat, dgehrd)
66
+ DEF_LINALG_FUNC(float, numo_cSFloat, sgehrd)
67
+ DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, zgehrd)
68
+ DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, cgehrd)
69
+
70
+ #undef DEF_LINALG_FUNC
71
+
72
+ void define_linalg_lapack_gehrd(VALUE mLapack) {
73
+ rb_define_module_function(mLapack, "dgehrd", _linalg_lapack_dgehrd, -1);
74
+ rb_define_module_function(mLapack, "sgehrd", _linalg_lapack_sgehrd, -1);
75
+ rb_define_module_function(mLapack, "zgehrd", _linalg_lapack_zgehrd, -1);
76
+ rb_define_module_function(mLapack, "cgehrd", _linalg_lapack_cgehrd, -1);
77
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef NUMO_LINALG_ALT_LAPACK_GEHRD_H
2
+ #define NUMO_LINALG_ALT_LAPACK_GEHRD_H 1
3
+
4
+ #include <lapacke.h>
5
+
6
+ #include <ruby.h>
7
+
8
+ #include <numo/narray.h>
9
+ #include <numo/template.h>
10
+
11
+ #include "lapack_util.h"
12
+
13
+ void define_linalg_lapack_gehrd(VALUE mLapack);
14
+
15
+ #endif // NUMO_LINALG_ALT_LAPACK_GEHRD_H
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gelsd(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_geqrf(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gerqf(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gesdd(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gesv(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gesvd(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_getrf(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_getri(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_getrs(VALUE mLapack);
14
14
 
@@ -49,8 +49,8 @@
49
49
  rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
50
50
  const int matrix_layout = \
51
51
  kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR; \
52
- const char jobvsl = kw_values[1] != Qundef ? get_jobvs(kw_values[1]) : 'V'; \
53
- const char jobvsr = kw_values[2] != Qundef ? get_jobvs(kw_values[2]) : 'V'; \
52
+ const char jobvsl = kw_values[1] != Qundef ? get_job(kw_values[1], "jobvsl") : 'V'; \
53
+ const char jobvsr = kw_values[2] != Qundef ? get_job(kw_values[2], "jobvsr") : 'V'; \
54
54
  \
55
55
  if (CLASS_OF(a_vnary) != tNAryClass) { \
56
56
  a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
@@ -141,8 +141,8 @@
141
141
  rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
142
142
  const int matrix_layout = \
143
143
  kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR; \
144
- const char jobvsl = kw_values[1] != Qundef ? get_jobvs(kw_values[1]) : 'V'; \
145
- const char jobvsr = kw_values[2] != Qundef ? get_jobvs(kw_values[1]) : 'V'; \
144
+ const char jobvsl = kw_values[1] != Qundef ? get_job(kw_values[1], "jobvsl") : 'V'; \
145
+ const char jobvsr = kw_values[2] != Qundef ? get_job(kw_values[2], "jobvsr") : 'V'; \
146
146
  \
147
147
  if (CLASS_OF(a_vnary) != tNAryClass) { \
148
148
  a_vnary = rb_funcall(tNAryClass, rb_intern("cast"), 1, a_vnary); \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_gges(VALUE mLapack);
14
14
 
@@ -26,7 +26,7 @@ struct _heev_option {
26
26
  ID kw_table[3] = { rb_intern("jobz"), rb_intern("uplo"), rb_intern("order") }; \
27
27
  VALUE kw_values[3] = { Qundef, Qundef, Qundef }; \
28
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'; \
29
+ const char jobz = kw_values[0] != Qundef ? get_job(kw_values[0], "jobz") : 'V'; \
30
30
  const char uplo = kw_values[1] != Qundef ? get_uplo(kw_values[1]) : 'U'; \
31
31
  const int matrix_layout = \
32
32
  kw_values[2] != Qundef ? get_matrix_layout(kw_values[2]) : LAPACK_ROW_MAJOR; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_heev(VALUE mLapack);
14
14
 
@@ -26,7 +26,7 @@ struct _heevd_option {
26
26
  ID kw_table[3] = { rb_intern("jobz"), rb_intern("uplo"), rb_intern("order") }; \
27
27
  VALUE kw_values[3] = { Qundef, Qundef, Qundef }; \
28
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'; \
29
+ const char jobz = kw_values[0] != Qundef ? get_job(kw_values[0], "jobz") : 'V'; \
30
30
  const char uplo = kw_values[1] != Qundef ? get_uplo(kw_values[1]) : 'U'; \
31
31
  const int matrix_layout = \
32
32
  kw_values[2] != Qundef ? get_matrix_layout(kw_values[2]) : LAPACK_ROW_MAJOR; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_heevd(VALUE mLapack);
14
14
 
@@ -40,7 +40,7 @@
40
40
  rb_intern("iu"), rb_intern("order") }; \
41
41
  VALUE kw_values[8] = { Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef, Qundef }; \
42
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'; \
43
+ const char jobz = kw_values[0] != Qundef ? get_job(kw_values[0], "jobz") : 'V'; \
44
44
  const char range = kw_values[1] != Qundef ? get_range(kw_values[1]) : 'A'; \
45
45
  const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
46
46
  const tRtDType vl = kw_values[3] != Qundef ? NUM2DBL(kw_values[3]) : 0.0; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_heevr(VALUE mLapack);
14
14
 
@@ -33,7 +33,7 @@ struct _hegv_option {
33
33
  VALUE kw_values[4] = { Qundef, Qundef, Qundef, Qundef }; \
34
34
  rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
35
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'; \
36
+ const char jobz = kw_values[1] != Qundef ? get_job(kw_values[1], "jobz") : 'V'; \
37
37
  const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
38
38
  const int matrix_layout = \
39
39
  kw_values[3] != Qundef ? get_matrix_layout(kw_values[3]) : LAPACK_ROW_MAJOR; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_hegv(VALUE mLapack);
14
14
 
@@ -33,7 +33,7 @@ struct _hegvd_option {
33
33
  VALUE kw_values[4] = { Qundef, Qundef, Qundef, Qundef }; \
34
34
  rb_get_kwargs(kw_args, kw_table, 0, 4, kw_values); \
35
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'; \
36
+ const char jobz = kw_values[1] != Qundef ? get_job(kw_values[1], "jobz") : 'V'; \
37
37
  const char uplo = kw_values[2] != Qundef ? get_uplo(kw_values[2]) : 'U'; \
38
38
  const int matrix_layout = \
39
39
  kw_values[3] != Qundef ? get_matrix_layout(kw_values[3]) : LAPACK_ROW_MAJOR; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_hegvd(VALUE mLapack);
14
14
 
@@ -46,7 +46,7 @@
46
46
  Qundef, Qundef, Qundef, Qundef }; \
47
47
  rb_get_kwargs(kw_args, kw_table, 0, 9, kw_values); \
48
48
  const lapack_int itype = kw_values[0] != Qundef ? get_itype(kw_values[0]) : 1; \
49
- const char jobz = kw_values[1] != Qundef ? get_jobz(kw_values[1]) : 'V'; \
49
+ const char jobz = kw_values[1] != Qundef ? get_job(kw_values[1], "jobz") : 'V'; \
50
50
  const char range = kw_values[2] != Qundef ? get_range(kw_values[2]) : 'A'; \
51
51
  const char uplo = kw_values[3] != Qundef ? get_uplo(kw_values[3]) : 'U'; \
52
52
  const tRtDType vl = kw_values[4] != Qundef ? NUM2DBL(kw_values[4]) : 0.0; \
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_hegvx(VALUE mLapack);
14
14
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_hetrf(VALUE mLapack);
14
14
 
@@ -5,10 +5,10 @@ struct _lange_option {
5
5
  char norm;
6
6
  };
7
7
 
8
- #define DEF_LINALG_FUNC(tDType, tNAryClass, fLapackFunc) \
8
+ #define DEF_LINALG_FUNC(tDType, tRtDType, tNAryClass, tRtNAryClass, fLapackFunc) \
9
9
  static void _iter_##fLapackFunc(na_loop_t* const lp) { \
10
10
  tDType* a = (tDType*)NDL_PTR(lp, 0); \
11
- tDType* d = (tDType*)NDL_PTR(lp, 1); \
11
+ tRtDType* d = (tRtDType*)NDL_PTR(lp, 1); \
12
12
  struct _lange_option* opt = (struct _lange_option*)(lp->opt_ptr); \
13
13
  const lapack_int m = (lapack_int)NDL_SHAPE(lp, 0)[0]; \
14
14
  const lapack_int n = (lapack_int)NDL_SHAPE(lp, 0)[1]; \
@@ -42,8 +42,7 @@ struct _lange_option {
42
42
  } \
43
43
  \
44
44
  ndfunc_arg_in_t ain[1] = { { tNAryClass, 2 } }; \
45
- size_t shape_out[1] = { 1 }; \
46
- ndfunc_arg_out_t aout[1] = { { tNAryClass, 0, shape_out } }; \
45
+ ndfunc_arg_out_t aout[1] = { { tRtNAryClass, 0 } }; \
47
46
  ndfunc_t ndf = { _iter_##fLapackFunc, NO_LOOP | NDF_EXTRACT, 1, 1, ain, aout }; \
48
47
  struct _lange_option opt = { matrix_layout, norm }; \
49
48
  VALUE ret = na_ndloop3(&ndf, &opt, 1, a_vnary); \
@@ -52,10 +51,10 @@ struct _lange_option {
52
51
  return ret; \
53
52
  }
54
53
 
55
- DEF_LINALG_FUNC(double, numo_cDFloat, dlange)
56
- DEF_LINALG_FUNC(float, numo_cSFloat, slange)
57
- DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, zlange)
58
- DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, clange)
54
+ DEF_LINALG_FUNC(double, double, numo_cDFloat, numo_cDFloat, dlange)
55
+ DEF_LINALG_FUNC(float, float, numo_cSFloat, numo_cSFloat, slange)
56
+ DEF_LINALG_FUNC(lapack_complex_double, double, numo_cDComplex, numo_cDFloat, zlange)
57
+ DEF_LINALG_FUNC(lapack_complex_float, float, numo_cSComplex, numo_cSFloat, clange)
59
58
 
60
59
  #undef DEF_LINALG_FUNC
61
60
 
@@ -8,7 +8,7 @@
8
8
  #include <numo/narray.h>
9
9
  #include <numo/template.h>
10
10
 
11
- #include "../util.h"
11
+ #include "lapack_util.h"
12
12
 
13
13
  void define_linalg_lapack_lange(VALUE mLapack);
14
14
 
@@ -0,0 +1,57 @@
1
+ #include "lapack_util.h"
2
+
3
+ lapack_int get_itype(VALUE val) {
4
+ const lapack_int itype = NUM2INT(val);
5
+
6
+ if (itype != 1 && itype != 2 && itype != 3) {
7
+ rb_raise(rb_eArgError, "itype must be 1, 2 or 3");
8
+ }
9
+
10
+ return itype;
11
+ }
12
+
13
+ char get_job(VALUE val, const char* param_name) {
14
+ const char job = NUM2CHR(val);
15
+
16
+ if (job != 'N' && job != 'V') {
17
+ rb_raise(rb_eArgError, "%s must be 'N' or 'V'", param_name);
18
+ }
19
+
20
+ return job;
21
+ }
22
+
23
+ char get_range(VALUE val) {
24
+ const char range = NUM2CHR(val);
25
+
26
+ if (range != 'A' && range != 'V' && range != 'I') {
27
+ rb_raise(rb_eArgError, "range must be 'A', 'V' or 'I'");
28
+ }
29
+
30
+ return range;
31
+ }
32
+
33
+ char get_uplo(VALUE val) {
34
+ const char uplo = NUM2CHR(val);
35
+
36
+ if (uplo != 'U' && uplo != 'L') {
37
+ rb_raise(rb_eArgError, "uplo must be 'U' or 'L'");
38
+ }
39
+
40
+ return uplo;
41
+ }
42
+
43
+ int get_matrix_layout(VALUE val) {
44
+ const char option = NUM2CHR(val);
45
+
46
+ switch (option) {
47
+ case 'r':
48
+ case 'R':
49
+ break;
50
+ case 'c':
51
+ case 'C':
52
+ rb_warn("Numo::Linalg does not support column major.");
53
+ break;
54
+ }
55
+
56
+ return LAPACK_ROW_MAJOR;
57
+ }
@@ -0,0 +1,27 @@
1
+ #ifndef NUMO_LINALG_ALT_LAPACK_UTIL_H
2
+ #define NUMO_LINALG_ALT_LAPACK_UTIL_H 1
3
+
4
+ #include <ruby.h>
5
+
6
+ #include <lapacke.h>
7
+
8
+ #ifndef lapack_complex_float_real
9
+ #define lapack_complex_float_real(z) ((z).real)
10
+ #endif
11
+ #ifndef lapack_complex_float_imag
12
+ #define lapack_complex_float_imag(z) ((z).imag)
13
+ #endif
14
+ #ifndef lapack_complex_double_real
15
+ #define lapack_complex_double_real(z) ((z).real)
16
+ #endif
17
+ #ifndef lapack_complex_double_imag
18
+ #define lapack_complex_double_imag(z) ((z).imag)
19
+ #endif
20
+
21
+ lapack_int get_itype(VALUE val);
22
+ char get_job(VALUE val, const char* param_name);
23
+ char get_range(VALUE val);
24
+ char get_uplo(VALUE val);
25
+ int get_matrix_layout(VALUE val);
26
+
27
+ #endif // NUMO_LINALG_ALT_LAPACK_UTIL_H