numo-linalg-alt 0.2.0 → 0.4.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -1
  3. data/README.md +3 -1
  4. data/ext/numo/linalg/blas/dot.c +59 -59
  5. data/ext/numo/linalg/blas/dot_sub.c +58 -58
  6. data/ext/numo/linalg/blas/gemm.c +157 -148
  7. data/ext/numo/linalg/blas/gemv.c +131 -127
  8. data/ext/numo/linalg/blas/nrm2.c +50 -50
  9. data/ext/numo/linalg/lapack/gees.c +276 -0
  10. data/ext/numo/linalg/lapack/gees.h +15 -0
  11. data/ext/numo/linalg/lapack/geev.c +127 -110
  12. data/ext/numo/linalg/lapack/gelsd.c +81 -70
  13. data/ext/numo/linalg/lapack/geqrf.c +52 -51
  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 +96 -86
  17. data/ext/numo/linalg/lapack/gesv.c +80 -78
  18. data/ext/numo/linalg/lapack/gesvd.c +140 -129
  19. data/ext/numo/linalg/lapack/getrf.c +51 -50
  20. data/ext/numo/linalg/lapack/getri.c +64 -63
  21. data/ext/numo/linalg/lapack/getrs.c +92 -88
  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 +54 -52
  25. data/ext/numo/linalg/lapack/heevd.c +54 -52
  26. data/ext/numo/linalg/lapack/heevr.c +109 -98
  27. data/ext/numo/linalg/lapack/hegv.c +77 -74
  28. data/ext/numo/linalg/lapack/hegvd.c +77 -74
  29. data/ext/numo/linalg/lapack/hegvx.c +132 -120
  30. data/ext/numo/linalg/lapack/hetrf.c +54 -50
  31. data/ext/numo/linalg/lapack/lange.c +45 -44
  32. data/ext/numo/linalg/lapack/orgqr.c +63 -62
  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 +49 -48
  36. data/ext/numo/linalg/lapack/potri.c +49 -48
  37. data/ext/numo/linalg/lapack/potrs.c +74 -72
  38. data/ext/numo/linalg/lapack/syev.c +54 -52
  39. data/ext/numo/linalg/lapack/syevd.c +54 -52
  40. data/ext/numo/linalg/lapack/syevr.c +107 -98
  41. data/ext/numo/linalg/lapack/sygv.c +77 -73
  42. data/ext/numo/linalg/lapack/sygvd.c +77 -73
  43. data/ext/numo/linalg/lapack/sygvx.c +132 -120
  44. data/ext/numo/linalg/lapack/sytrf.c +54 -50
  45. data/ext/numo/linalg/lapack/trtrs.c +79 -75
  46. data/ext/numo/linalg/lapack/ungqr.c +63 -62
  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 +21 -10
  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 +322 -0
  55. metadata +14 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a27ac7b0136649ad3cb4f65ecaa88eb56327aee77ce92ec189ae51209937dfd
4
- data.tar.gz: d646eb637c82f3602741c6e31a9d18a6b69298c260a5837bfe5cf7c3089fd064
3
+ metadata.gz: 38d36b0f9d79ba30d90825df434ff9b7c4bdd44d71a120e65a75b7474017c04d
4
+ data.tar.gz: ea9c959067a82b0acf3c1990317657dfea6b055a2c4244d7cdfb7fa76b1d298b
5
5
  SHA512:
6
- metadata.gz: c89a302f9855730a25ce18fc1b7e81346aecdc6bb22ec4036a1b43dc8981a2e3cb1cfb70249aaee2f2ed3cb641b27058210c5eb6c0e3aef0fc706183d154e7e8
7
- data.tar.gz: 475964589987be96c4a258f4fe01ee63101b5d936e2d6f0e4a198357ccd54361c2d162f87d41c0fe8faaba0badb741f620cb44f9d260c84d33663dd5e27a13f2
6
+ metadata.gz: 71004a21081aec907f9142dfbbed991d662c11639450d691f3c4322bfe5a68d66279c48259c9cb1a8a33704d08c9033cc675a7370a00c402c31b68cf6848fea5
7
+ data.tar.gz: 667a1f392aa95e2681b40575ea53c18669596ee62d77f1e01a470b25691963111b8632a967acf6eef42be0544d99206bcf0fa1407de093a2d225a0aeaf21afe3
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## [[0.2.0](https://github.com/yoshoku/numo-linalg-alt/compare/d010476...ea50089)]
1
+ ## [[0.4.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.3.0...v0.4.0)] - 2025-10-16
2
+
3
+ - add `rq`, `qz`, and `tanm` module functions to Numo::Linalg.
4
+
5
+ ## [[0.3.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.2.0...v0.3.0)] - 2025-10-06
6
+
7
+ - add `schur`, `cosm`, `sinm`, `orthogonal_procrustes`, and `polar` module functions to Numo::Linalg.
8
+ - fix version specifier for numo-narray-alt.
9
+
10
+ ## [[0.2.0](https://github.com/yoshoku/numo-linalg-alt/compare/d010476...ea50089)] - 2025-09-29
2
11
 
3
12
  - fork from [Numo::TinyLinalg main branch](https://github.com/yoshoku/numo-tiny_linalg/tree/d0104765c560e9664a868b7a3e2f3144bd32c428)
4
13
  - rewrite native extensions with C programming language.
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Numo::Linalg Alternative
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/numo-linalg-alt.svg)](https://badge.fury.io/rb/numo-linalg-alt)
3
4
  [![Build Status](https://github.com/yoshoku/numo-linalg-alt/actions/workflows/main.yml/badge.svg)](https://github.com/yoshoku/numo-linalg-alt/actions/workflows/main.yml)
4
5
  [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-linalg-alt/blob/main/LICENSE.txt)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://gemdocs.org/gems/numo-linalg-alt/)
5
7
 
6
8
  Numo::Linalg Alternative (numo-linalg-alt) is an alternative to [Numo::Linalg](https://github.com/ruby-numo/numo-linalg).
7
9
  Unlike Numo::Linalg, numo-linalg-alt depends on [Numo::NArray Alterntive](https://github.com/yoshoku/numo-narray-alt).
@@ -99,7 +101,7 @@ This project is intended to be a safe, welcoming space for collaboration, and co
99
101
 
100
102
  ## Code of Conduct
101
103
 
102
- Everyone interacting in the Numo::TinyLinalg project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-linalg-alt/blob/main/CODE_OF_CONDUCT.md).
104
+ Everyone interacting in the Numo::Linalg Alternative project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-linalg-alt/blob/main/CODE_OF_CONDUCT.md).
103
105
 
104
106
  ## License
105
107
 
@@ -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)
@@ -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)