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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf52b8241dd646725159141067e9e38948c95d89d459f81e8ec5b19a20ce7a69
4
- data.tar.gz: 286fb08653029ff6bfd745323fd7b8e1165a9d6027bbcf3871bb5333eae8eddd
3
+ metadata.gz: dc07e81b983e8ac3353509992185849f458f1559e6e484786c92f2a8d717de0e
4
+ data.tar.gz: 660ae0a6cc21ca8beec6858a2f7c1efeee990261fdc649710f080becbb3ccc50
5
5
  SHA512:
6
- metadata.gz: a7205197001dd99f404a39e63ac7caf6a88fa653ab9487756d3ef69b03c2c9abedc0c3900a1284ae70d41415ddc97f9180e1977d765e3b5f46578a72c67429cf
7
- data.tar.gz: 3b18b323a4d0873f19c5514ca3856de7651078ef227559f2c55ae9f82f6cb05b4a2bf28958a4c499d7909741e6ad0e58ae53b5821681d6d0f9a363b3719291da
6
+ metadata.gz: 674d3e13ce4ac8b340eb66a77d83d33420af54c8f5e7836c31d398d5e3a86d5811e89baa737cb29d00f4a770f0616b4c3ff3393e17692a4dbf2ac3c9dfccdf54
7
+ data.tar.gz: b6f0a374232dc259e0ea49e4e9d13c421aab685f38b0d01ef4d602f1e0f74a17835330e9864cfb335e9571fa246a80f015f29e904e2926646eb19680b176ba5d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [[0.4.1](https://github.com/yoshoku/numo-linalg-alt/compare/v0.3.0...v0.4.0)] - 2025-10-19
2
+
3
+ - FIX: remove incorrect usage of RUBY_METHOD_FUNC macro: [#2](https://github.com/yoshoku/numo-linalg-alt/pull/2)
4
+ - add `matrix_balance` moudle function to Numo::Linalg.
5
+
6
+ ## [[0.4.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.3.0...v0.4.0)] - 2025-10-16
7
+
8
+ - add `rq`, `qz`, and `tanm` module functions to Numo::Linalg.
9
+
1
10
  ## [[0.3.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.2.0...v0.3.0)] - 2025-10-06
2
11
 
3
12
  - add `schur`, `cosm`, `sinm`, `orthogonal_procrustes`, and `polar` module functions to Numo::Linalg.
@@ -1,64 +1,64 @@
1
1
  #include "dot.h"
2
2
 
3
- #define DEF_LINALG_FUNC(tDType, tNAryClass, fBlasFunc) \
4
- static void _iter_##fBlasFunc(na_loop_t* const lp) { \
5
- tDType* x = (tDType*)NDL_PTR(lp, 0); \
6
- tDType* y = (tDType*)NDL_PTR(lp, 1); \
7
- tDType* d = (tDType*)NDL_PTR(lp, 2); \
8
- const blasint n = (blasint)NDL_SHAPE(lp, 0)[0]; \
9
- tDType ret = cblas_##fBlasFunc(n, x, 1, y, 1); \
10
- *d = ret; \
11
- } \
12
- \
13
- static VALUE _linalg_blas_##fBlasFunc(VALUE self, VALUE x, VALUE y) { \
14
- if (CLASS_OF(x) != tNAryClass) { \
15
- x = rb_funcall(tNAryClass, rb_intern("cast"), 1, x); \
16
- } \
17
- if (!RTEST(nary_check_contiguous(x))) { \
18
- x = nary_dup(x); \
19
- } \
20
- if (CLASS_OF(y) != tNAryClass) { \
21
- y = rb_funcall(tNAryClass, rb_intern("cast"), 1, y); \
22
- } \
23
- if (!RTEST(nary_check_contiguous(y))) { \
24
- y = nary_dup(y); \
25
- } \
26
- \
27
- narray_t* x_nary = NULL; \
28
- GetNArray(x, x_nary); \
29
- narray_t* y_nary = NULL; \
30
- GetNArray(y, y_nary); \
31
- \
32
- if (NA_NDIM(x_nary) != 1) { \
33
- rb_raise(rb_eArgError, "x must be 1-dimensional"); \
34
- return Qnil; \
35
- } \
36
- if (NA_NDIM(y_nary) != 1) { \
37
- rb_raise(rb_eArgError, "y must be 1-dimensional"); \
38
- return Qnil; \
39
- } \
40
- if (NA_SIZE(x_nary) == 0) { \
41
- rb_raise(rb_eArgError, "x must not be empty"); \
42
- return Qnil; \
43
- } \
44
- if (NA_SIZE(y_nary) == 0) { \
45
- rb_raise(rb_eArgError, "x must not be empty"); \
46
- return Qnil; \
47
- } \
48
- if (NA_SIZE(x_nary) != NA_SIZE(y_nary)) { \
49
- rb_raise(rb_eArgError, "x and y must have same size"); \
50
- return Qnil; \
51
- } \
52
- \
53
- ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { tNAryClass, 1 } }; \
54
- size_t shape_out[1] = { 1 }; \
55
- ndfunc_arg_out_t aout[1] = { { tNAryClass, 0, shape_out } }; \
56
- ndfunc_t ndf = { _iter_##fBlasFunc, NO_LOOP | NDF_EXTRACT, 2, 1, ain, aout }; \
57
- VALUE ret = na_ndloop(&ndf, 2, x, y); \
58
- \
59
- RB_GC_GUARD(x); \
60
- RB_GC_GUARD(y); \
61
- return ret; \
3
+ #define DEF_LINALG_FUNC(tDType, tNAryClass, fBlasFunc) \
4
+ static void _iter_##fBlasFunc(na_loop_t* const lp) { \
5
+ tDType* x = (tDType*)NDL_PTR(lp, 0); \
6
+ tDType* y = (tDType*)NDL_PTR(lp, 1); \
7
+ tDType* d = (tDType*)NDL_PTR(lp, 2); \
8
+ const blasint n = (blasint)NDL_SHAPE(lp, 0)[0]; \
9
+ tDType ret = cblas_##fBlasFunc(n, x, 1, y, 1); \
10
+ *d = ret; \
11
+ } \
12
+ \
13
+ static VALUE _linalg_blas_##fBlasFunc(VALUE self, VALUE x, VALUE y) { \
14
+ if (CLASS_OF(x) != tNAryClass) { \
15
+ x = rb_funcall(tNAryClass, rb_intern("cast"), 1, x); \
16
+ } \
17
+ if (!RTEST(nary_check_contiguous(x))) { \
18
+ x = nary_dup(x); \
19
+ } \
20
+ if (CLASS_OF(y) != tNAryClass) { \
21
+ y = rb_funcall(tNAryClass, rb_intern("cast"), 1, y); \
22
+ } \
23
+ if (!RTEST(nary_check_contiguous(y))) { \
24
+ y = nary_dup(y); \
25
+ } \
26
+ \
27
+ narray_t* x_nary = NULL; \
28
+ GetNArray(x, x_nary); \
29
+ narray_t* y_nary = NULL; \
30
+ GetNArray(y, y_nary); \
31
+ \
32
+ if (NA_NDIM(x_nary) != 1) { \
33
+ rb_raise(rb_eArgError, "x must be 1-dimensional"); \
34
+ return Qnil; \
35
+ } \
36
+ if (NA_NDIM(y_nary) != 1) { \
37
+ rb_raise(rb_eArgError, "y must be 1-dimensional"); \
38
+ return Qnil; \
39
+ } \
40
+ if (NA_SIZE(x_nary) == 0) { \
41
+ rb_raise(rb_eArgError, "x must not be empty"); \
42
+ return Qnil; \
43
+ } \
44
+ if (NA_SIZE(y_nary) == 0) { \
45
+ rb_raise(rb_eArgError, "x must not be empty"); \
46
+ return Qnil; \
47
+ } \
48
+ if (NA_SIZE(x_nary) != NA_SIZE(y_nary)) { \
49
+ rb_raise(rb_eArgError, "x and y must have same size"); \
50
+ return Qnil; \
51
+ } \
52
+ \
53
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { tNAryClass, 1 } }; \
54
+ size_t shape_out[1] = { 1 }; \
55
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0, shape_out } }; \
56
+ ndfunc_t ndf = { _iter_##fBlasFunc, NO_LOOP | NDF_EXTRACT, 2, 1, ain, aout }; \
57
+ VALUE ret = na_ndloop(&ndf, 2, x, y); \
58
+ \
59
+ RB_GC_GUARD(x); \
60
+ RB_GC_GUARD(y); \
61
+ return ret; \
62
62
  }
63
63
 
64
64
  DEF_LINALG_FUNC(double, numo_cDFloat, ddot)
@@ -67,6 +67,6 @@ DEF_LINALG_FUNC(float, numo_cSFloat, sdot)
67
67
  #undef DEF_LINALG_FUNC
68
68
 
69
69
  void define_linalg_blas_dot(VALUE mBlas) {
70
- rb_define_module_function(mBlas, "ddot", RUBY_METHOD_FUNC(_linalg_blas_ddot), 2);
71
- rb_define_module_function(mBlas, "sdot", RUBY_METHOD_FUNC(_linalg_blas_sdot), 2);
70
+ rb_define_module_function(mBlas, "ddot", _linalg_blas_ddot, 2);
71
+ rb_define_module_function(mBlas, "sdot", _linalg_blas_sdot, 2);
72
72
  }
@@ -1,63 +1,63 @@
1
1
  #include "dot_sub.h"
2
2
 
3
- #define DEF_LINALG_FUNC(tDType, tNAryClass, fBlasFunc) \
4
- static void _iter_##fBlasFunc(na_loop_t* const lp) { \
5
- tDType* x = (tDType*)NDL_PTR(lp, 0); \
6
- tDType* y = (tDType*)NDL_PTR(lp, 1); \
7
- tDType* d = (tDType*)NDL_PTR(lp, 2); \
8
- const blasint n = (blasint)NDL_SHAPE(lp, 0)[0]; \
9
- cblas_##fBlasFunc(n, x, 1, y, 1, d); \
10
- } \
11
- \
12
- static VALUE _linalg_blas_##fBlasFunc(VALUE self, VALUE x, VALUE y) { \
13
- if (CLASS_OF(x) != tNAryClass) { \
14
- x = rb_funcall(tNAryClass, rb_intern("cast"), 1, x); \
15
- } \
16
- if (!RTEST(nary_check_contiguous(x))) { \
17
- x = nary_dup(x); \
18
- } \
19
- if (CLASS_OF(y) != tNAryClass) { \
20
- y = rb_funcall(tNAryClass, rb_intern("cast"), 1, y); \
21
- } \
22
- if (!RTEST(nary_check_contiguous(y))) { \
23
- y = nary_dup(y); \
24
- } \
25
- \
26
- narray_t* x_nary = NULL; \
27
- GetNArray(x, x_nary); \
28
- narray_t* y_nary = NULL; \
29
- GetNArray(y, y_nary); \
30
- \
31
- if (NA_NDIM(x_nary) != 1) { \
32
- rb_raise(rb_eArgError, "x must be 1-dimensional"); \
33
- return Qnil; \
34
- } \
35
- if (NA_NDIM(y_nary) != 1) { \
36
- rb_raise(rb_eArgError, "y must be 1-dimensional"); \
37
- return Qnil; \
38
- } \
39
- if (NA_SIZE(x_nary) == 0) { \
40
- rb_raise(rb_eArgError, "x must not be empty"); \
41
- return Qnil; \
42
- } \
43
- if (NA_SIZE(y_nary) == 0) { \
44
- rb_raise(rb_eArgError, "x must not be empty"); \
45
- return Qnil; \
46
- } \
47
- if (NA_SIZE(x_nary) != NA_SIZE(y_nary)) { \
48
- rb_raise(rb_eArgError, "x and y must have same size"); \
49
- return Qnil; \
50
- } \
51
- \
52
- ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { tNAryClass, 1 } }; \
53
- size_t shape_out[1] = { 1 }; \
54
- ndfunc_arg_out_t aout[1] = { { tNAryClass, 0, shape_out } }; \
55
- ndfunc_t ndf = { _iter_##fBlasFunc, NO_LOOP | NDF_EXTRACT, 2, 1, ain, aout }; \
56
- VALUE ret = na_ndloop(&ndf, 2, x, y); \
57
- \
58
- RB_GC_GUARD(x); \
59
- RB_GC_GUARD(y); \
60
- return ret; \
3
+ #define DEF_LINALG_FUNC(tDType, tNAryClass, fBlasFunc) \
4
+ static void _iter_##fBlasFunc(na_loop_t* const lp) { \
5
+ tDType* x = (tDType*)NDL_PTR(lp, 0); \
6
+ tDType* y = (tDType*)NDL_PTR(lp, 1); \
7
+ tDType* d = (tDType*)NDL_PTR(lp, 2); \
8
+ const blasint n = (blasint)NDL_SHAPE(lp, 0)[0]; \
9
+ cblas_##fBlasFunc(n, x, 1, y, 1, d); \
10
+ } \
11
+ \
12
+ static VALUE _linalg_blas_##fBlasFunc(VALUE self, VALUE x, VALUE y) { \
13
+ if (CLASS_OF(x) != tNAryClass) { \
14
+ x = rb_funcall(tNAryClass, rb_intern("cast"), 1, x); \
15
+ } \
16
+ if (!RTEST(nary_check_contiguous(x))) { \
17
+ x = nary_dup(x); \
18
+ } \
19
+ if (CLASS_OF(y) != tNAryClass) { \
20
+ y = rb_funcall(tNAryClass, rb_intern("cast"), 1, y); \
21
+ } \
22
+ if (!RTEST(nary_check_contiguous(y))) { \
23
+ y = nary_dup(y); \
24
+ } \
25
+ \
26
+ narray_t* x_nary = NULL; \
27
+ GetNArray(x, x_nary); \
28
+ narray_t* y_nary = NULL; \
29
+ GetNArray(y, y_nary); \
30
+ \
31
+ if (NA_NDIM(x_nary) != 1) { \
32
+ rb_raise(rb_eArgError, "x must be 1-dimensional"); \
33
+ return Qnil; \
34
+ } \
35
+ if (NA_NDIM(y_nary) != 1) { \
36
+ rb_raise(rb_eArgError, "y must be 1-dimensional"); \
37
+ return Qnil; \
38
+ } \
39
+ if (NA_SIZE(x_nary) == 0) { \
40
+ rb_raise(rb_eArgError, "x must not be empty"); \
41
+ return Qnil; \
42
+ } \
43
+ if (NA_SIZE(y_nary) == 0) { \
44
+ rb_raise(rb_eArgError, "x must not be empty"); \
45
+ return Qnil; \
46
+ } \
47
+ if (NA_SIZE(x_nary) != NA_SIZE(y_nary)) { \
48
+ rb_raise(rb_eArgError, "x and y must have same size"); \
49
+ return Qnil; \
50
+ } \
51
+ \
52
+ ndfunc_arg_in_t ain[2] = { { tNAryClass, 1 }, { tNAryClass, 1 } }; \
53
+ size_t shape_out[1] = { 1 }; \
54
+ ndfunc_arg_out_t aout[1] = { { tNAryClass, 0, shape_out } }; \
55
+ ndfunc_t ndf = { _iter_##fBlasFunc, NO_LOOP | NDF_EXTRACT, 2, 1, ain, aout }; \
56
+ VALUE ret = na_ndloop(&ndf, 2, x, y); \
57
+ \
58
+ RB_GC_GUARD(x); \
59
+ RB_GC_GUARD(y); \
60
+ return ret; \
61
61
  }
62
62
 
63
63
  DEF_LINALG_FUNC(double, numo_cDComplex, zdotu_sub)
@@ -66,6 +66,6 @@ DEF_LINALG_FUNC(float, numo_cSComplex, cdotu_sub)
66
66
  #undef DEF_LINALG_FUNC
67
67
 
68
68
  void define_linalg_blas_dot_sub(VALUE mBlas) {
69
- rb_define_module_function(mBlas, "zdotu", RUBY_METHOD_FUNC(_linalg_blas_zdotu_sub), 2);
70
- rb_define_module_function(mBlas, "cdotu", RUBY_METHOD_FUNC(_linalg_blas_cdotu_sub), 2);
69
+ rb_define_module_function(mBlas, "zdotu", _linalg_blas_zdotu_sub, 2);
70
+ rb_define_module_function(mBlas, "cdotu", _linalg_blas_cdotu_sub, 2);
71
71
  }