numo-linalg-alt 0.6.0 → 0.7.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 +37 -0
- data/ext/numo/linalg/blas/nrm2.c +5 -5
- data/ext/numo/linalg/extconf.rb +3 -3
- data/ext/numo/linalg/lapack/gebal.c +5 -5
- data/ext/numo/linalg/lapack/gelsd.c +5 -5
- data/ext/numo/linalg/lapack/gesdd.c +5 -5
- data/ext/numo/linalg/lapack/gesvd.c +5 -5
- data/ext/numo/linalg/lapack/heev.c +3 -3
- data/ext/numo/linalg/lapack/heevd.c +3 -3
- data/ext/numo/linalg/lapack/heevr.c +3 -3
- data/ext/numo/linalg/lapack/hegv.c +3 -3
- data/ext/numo/linalg/lapack/hegvd.c +3 -3
- data/ext/numo/linalg/lapack/hegvx.c +3 -3
- data/ext/numo/linalg/lapack/lange.c +5 -5
- data/lib/numo/linalg/version.rb +1 -1
- data/lib/numo/linalg.rb +94 -47
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7eeac3bb724777fb9b247445c0519c21d95744c9e07fbfd6ab0af51d490b6232
|
|
4
|
+
data.tar.gz: 05ae98f73325fa3328217bcc17231d92e465d37f3b766fd609b18e2c752a8649
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61e88804d88190e1e01307cec2ffb7f6cbaaa799b760fa56cf77778d697b83ccb143f802f46a58fcbe4ed984caa6cc9b8b27f66ea4ef78989e781af81c7a5aab
|
|
7
|
+
data.tar.gz: 1a618efe98fc6d464d4924402c37ab133085edfa7b0faf420f3c4c4c913d838396dd27fe1f0080e754dbbe85685760b63c83938cc53fc499302063e217376b6d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
## [[0.7.1](https://github.com/yoshoku/numo-linalg-alt/compare/v0.7.0...v0.7.1)] - 2025-11-19
|
|
2
|
+
|
|
3
|
+
- set the required version of numo-narray-alt to 0.9.10 or higher.
|
|
4
|
+
- change require statement to explicitly load numo/narray/alt.
|
|
5
|
+
- fix to use require for compatibility with distributions installing extensions separately.
|
|
6
|
+
|
|
7
|
+
## [[0.7.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.6.0...v0.7.0)] - 2025-11-11
|
|
8
|
+
|
|
9
|
+
**Breaking changes**
|
|
10
|
+
|
|
11
|
+
improve error handling for LAPACK functions:
|
|
12
|
+
|
|
13
|
+
- add `LapackError` class under `Numo::Linalg` module.
|
|
14
|
+
- This exception class is raised when invalid arguments are passed to a LAPACK function or
|
|
15
|
+
when the algorithm does not execute successfully. In previous versions, `StandardError`
|
|
16
|
+
was raised in these cases.
|
|
17
|
+
```ruby
|
|
18
|
+
> Numo::Linalg.inv(Numo::DFloat[[3, 1], [9, 3]])
|
|
19
|
+
/numo-linalg-alt/lib/numo/linalg.rb:418:in 'Numo::Linalg.inv': The matrix is singular, and
|
|
20
|
+
the inverse matrix could not be computed. (Numo::Linalg::LapackError)
|
|
21
|
+
```
|
|
22
|
+
- change `solve`, `lu_fact`, `ldl`, and `qz` methods to issue a warning instead of raising an
|
|
23
|
+
error when the algorithm completes but produces a result that may affect further computations,
|
|
24
|
+
such as when the resulting matrix is sigular.
|
|
25
|
+
```ruby
|
|
26
|
+
> Numo::Linalg.solve(Numo::DFloat.zeros(2, 2), Numo::DFloat.ones(2))
|
|
27
|
+
the factorization has been completed, but the factor is singular, so the solution could not be computed.
|
|
28
|
+
=>
|
|
29
|
+
Numo::DFloat#shape=[2]
|
|
30
|
+
[1, 1]
|
|
31
|
+
```
|
|
32
|
+
- change `det` method to return zero instead of raising an error when the input matrix is singular.
|
|
33
|
+
```ruby
|
|
34
|
+
Numo::Linalg.det(Numo::DFloat[[1, 2], [2, 4]])
|
|
35
|
+
=> -0.0
|
|
36
|
+
```
|
|
37
|
+
|
|
1
38
|
## [[0.6.0](https://github.com/yoshoku/numo-linalg-alt/compare/v0.5.0...v0.6.0)] - 2025-11-02
|
|
2
39
|
|
|
3
40
|
- add `--with-blas` and `--with-lapacke` options for selecting backend libraries.
|
data/ext/numo/linalg/blas/nrm2.c
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#include "nrm2.h"
|
|
2
2
|
|
|
3
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
3
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fBlasFunc) \
|
|
4
4
|
static void _iter_##fBlasFunc(na_loop_t* const lp) { \
|
|
5
5
|
tDType* x = (tDType*)NDL_PTR(lp, 0); \
|
|
6
6
|
tRtDType* d = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
return ret; \
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
DEF_LINALG_FUNC(double,
|
|
56
|
-
DEF_LINALG_FUNC(float,
|
|
57
|
-
DEF_LINALG_FUNC(dcomplex,
|
|
58
|
-
DEF_LINALG_FUNC(scomplex,
|
|
55
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dnrm2)
|
|
56
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, snrm2)
|
|
57
|
+
DEF_LINALG_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat, dznrm2)
|
|
58
|
+
DEF_LINALG_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat, scnrm2)
|
|
59
59
|
|
|
60
60
|
#undef DEF_LINALG_FUNC
|
|
61
61
|
|
data/ext/numo/linalg/extconf.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'mkmf'
|
|
4
|
-
require 'numo/narray'
|
|
4
|
+
require 'numo/narray/alt'
|
|
5
5
|
require 'open-uri'
|
|
6
6
|
require 'etc'
|
|
7
7
|
require 'fileutils'
|
|
@@ -22,8 +22,8 @@ on_windows = RUBY_PLATFORM.match?(/mswin|cygwin|mingw/)
|
|
|
22
22
|
|
|
23
23
|
if on_windows
|
|
24
24
|
$LOAD_PATH.each do |lp|
|
|
25
|
-
if File.exist?(File.join(lp, 'numo/libnarray.a'))
|
|
26
|
-
$LDFLAGS = "-L#{lp}/numo #{$LDFLAGS}"
|
|
25
|
+
if File.exist?(File.join(lp, 'numo/narray/libnarray.a'))
|
|
26
|
+
$LDFLAGS = "-L#{lp}/numo/narray #{$LDFLAGS}"
|
|
27
27
|
break
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -13,7 +13,7 @@ char _get_job(VALUE val) {
|
|
|
13
13
|
return job;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
16
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
17
17
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
18
18
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
19
19
|
int* ilo = (int*)NDL_PTR(lp, 1); \
|
|
@@ -72,10 +72,10 @@ char _get_job(VALUE val) {
|
|
|
72
72
|
return ret; \
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
DEF_LINALG_FUNC(double,
|
|
76
|
-
DEF_LINALG_FUNC(float,
|
|
77
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
78
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
75
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dgebal)
|
|
76
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, sgebal)
|
|
77
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zgebal)
|
|
78
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cgebal)
|
|
79
79
|
|
|
80
80
|
#undef DEF_LINALG_FUNC
|
|
81
81
|
|
|
@@ -5,7 +5,7 @@ struct _gelsd_option {
|
|
|
5
5
|
double rcond;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
8
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
9
9
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
10
10
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
11
11
|
tDType* b = (tDType*)NDL_PTR(lp, 1); \
|
|
@@ -88,10 +88,10 @@ struct _gelsd_option {
|
|
|
88
88
|
return ret; \
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
DEF_LINALG_FUNC(double,
|
|
92
|
-
DEF_LINALG_FUNC(float,
|
|
93
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
94
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
91
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dgelsd)
|
|
92
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, sgelsd)
|
|
93
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zgelsd)
|
|
94
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cgelsd)
|
|
95
95
|
|
|
96
96
|
#undef DEF_LINALG_FUNC
|
|
97
97
|
|
|
@@ -5,7 +5,7 @@ struct _gesdd_option {
|
|
|
5
5
|
char jobz;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
8
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
9
9
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
10
10
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
11
11
|
tRtDType* s = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -103,10 +103,10 @@ struct _gesdd_option {
|
|
|
103
103
|
return ret; \
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
DEF_LINALG_FUNC(double,
|
|
107
|
-
DEF_LINALG_FUNC(float,
|
|
108
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
109
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
106
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dgesdd)
|
|
107
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, sgesdd)
|
|
108
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zgesdd)
|
|
109
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cgesdd)
|
|
110
110
|
|
|
111
111
|
#undef DEF_LINALG_FUNC
|
|
112
112
|
|
|
@@ -6,7 +6,7 @@ struct _gesvd_option {
|
|
|
6
6
|
char jobvt;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
9
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
10
10
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
11
11
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
12
12
|
tRtDType* s = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -148,10 +148,10 @@ struct _gesvd_option {
|
|
|
148
148
|
return ret; \
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
DEF_LINALG_FUNC(double,
|
|
152
|
-
DEF_LINALG_FUNC(float,
|
|
153
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
154
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
151
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dgesvd)
|
|
152
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, sgesvd)
|
|
153
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zgesvd)
|
|
154
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cgesvd)
|
|
155
155
|
|
|
156
156
|
#undef DEF_LINALG_FUNC
|
|
157
157
|
|
|
@@ -6,7 +6,7 @@ struct _heev_option {
|
|
|
6
6
|
char uplo;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
9
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
10
10
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
11
11
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
12
12
|
tRtDType* w = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -62,8 +62,8 @@ struct _heev_option {
|
|
|
62
62
|
return ret; \
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
66
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
65
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zheev)
|
|
66
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cheev)
|
|
67
67
|
|
|
68
68
|
#undef DEF_LINALG_FUNC
|
|
69
69
|
|
|
@@ -6,7 +6,7 @@ struct _heevd_option {
|
|
|
6
6
|
char uplo;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
9
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
10
10
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
11
11
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
12
12
|
tRtDType* w = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -62,8 +62,8 @@ struct _heevd_option {
|
|
|
62
62
|
return ret; \
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
66
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
65
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zheevd)
|
|
66
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cheevd)
|
|
67
67
|
|
|
68
68
|
#undef DEF_LINALG_FUNC
|
|
69
69
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#include "heevr.h"
|
|
2
2
|
|
|
3
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
3
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
4
4
|
struct _heevr_option_##tRtDType { \
|
|
5
5
|
int matrix_layout; \
|
|
6
6
|
char jobz; \
|
|
@@ -111,8 +111,8 @@
|
|
|
111
111
|
return ret; \
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
115
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
114
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zheevr)
|
|
115
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, cheevr)
|
|
116
116
|
|
|
117
117
|
#undef DEF_LINALG_FUNC
|
|
118
118
|
|
|
@@ -7,7 +7,7 @@ struct _hegv_option {
|
|
|
7
7
|
char uplo;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
10
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
11
11
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
12
12
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
13
13
|
tDType* b = (tDType*)NDL_PTR(lp, 1); \
|
|
@@ -86,8 +86,8 @@ struct _hegv_option {
|
|
|
86
86
|
return ret; \
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
90
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
89
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zhegv)
|
|
90
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, chegv)
|
|
91
91
|
|
|
92
92
|
#undef DEF_LINALG_FUNC
|
|
93
93
|
|
|
@@ -7,7 +7,7 @@ struct _hegvd_option {
|
|
|
7
7
|
char uplo;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
10
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
11
11
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
12
12
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
13
13
|
tDType* b = (tDType*)NDL_PTR(lp, 1); \
|
|
@@ -86,8 +86,8 @@ struct _hegvd_option {
|
|
|
86
86
|
return ret; \
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
90
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
89
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zhegvd)
|
|
90
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, chegvd)
|
|
91
91
|
|
|
92
92
|
#undef DEF_LINALG_FUNC
|
|
93
93
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#include "hegvx.h"
|
|
2
2
|
|
|
3
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
3
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
4
4
|
struct _hegvx_option_##tRtDType { \
|
|
5
5
|
int matrix_layout; \
|
|
6
6
|
lapack_int itype; \
|
|
@@ -134,8 +134,8 @@
|
|
|
134
134
|
return ret; \
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
138
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
137
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zhegvx)
|
|
138
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, chegvx)
|
|
139
139
|
|
|
140
140
|
#undef DEF_LINALG_FUNC
|
|
141
141
|
|
|
@@ -5,7 +5,7 @@ struct _lange_option {
|
|
|
5
5
|
char norm;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
#define DEF_LINALG_FUNC(tDType,
|
|
8
|
+
#define DEF_LINALG_FUNC(tDType, tNAryClass, tRtDType, tRtNAryClass, fLapackFunc) \
|
|
9
9
|
static void _iter_##fLapackFunc(na_loop_t* const lp) { \
|
|
10
10
|
tDType* a = (tDType*)NDL_PTR(lp, 0); \
|
|
11
11
|
tRtDType* d = (tRtDType*)NDL_PTR(lp, 1); \
|
|
@@ -51,10 +51,10 @@ struct _lange_option {
|
|
|
51
51
|
return ret; \
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
DEF_LINALG_FUNC(double,
|
|
55
|
-
DEF_LINALG_FUNC(float,
|
|
56
|
-
DEF_LINALG_FUNC(lapack_complex_double,
|
|
57
|
-
DEF_LINALG_FUNC(lapack_complex_float,
|
|
54
|
+
DEF_LINALG_FUNC(double, numo_cDFloat, double, numo_cDFloat, dlange)
|
|
55
|
+
DEF_LINALG_FUNC(float, numo_cSFloat, float, numo_cSFloat, slange)
|
|
56
|
+
DEF_LINALG_FUNC(lapack_complex_double, numo_cDComplex, double, numo_cDFloat, zlange)
|
|
57
|
+
DEF_LINALG_FUNC(lapack_complex_float, numo_cSComplex, float, numo_cSFloat, clange)
|
|
58
58
|
|
|
59
59
|
#undef DEF_LINALG_FUNC
|
|
60
60
|
|
data/lib/numo/linalg/version.rb
CHANGED
data/lib/numo/linalg.rb
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'numo/narray'
|
|
3
|
+
require 'numo/narray/alt'
|
|
4
|
+
|
|
5
|
+
# On distributions like Rocky Linux, native extensions are installed in a separate
|
|
6
|
+
# directory from Ruby code, so use require to load them.
|
|
7
|
+
require 'numo/linalg/linalg'
|
|
4
8
|
require_relative 'linalg/version'
|
|
5
|
-
require_relative 'linalg/linalg'
|
|
6
9
|
|
|
7
10
|
# Ruby/Numo (NUmerical MOdules)
|
|
8
11
|
module Numo
|
|
9
12
|
# Numo::Linalg Alternative (numo-linalg-alt) is an alternative to Numo::Linalg.
|
|
10
13
|
module Linalg # rubocop:disable Metrics/ModuleLength
|
|
14
|
+
# Exception class for errors occurred in LAPACK functions.
|
|
15
|
+
class LapackError < StandardError; end
|
|
16
|
+
|
|
11
17
|
module_function
|
|
12
18
|
|
|
13
19
|
# Computes the eigenvalues and eigenvectors of a symmetric / Hermitian matrix
|
|
@@ -341,7 +347,7 @@ module Numo
|
|
|
341
347
|
|
|
342
348
|
fnc = :"#{bchr}potrs"
|
|
343
349
|
x, info = Numo::Linalg::Lapack.send(fnc, a, b.dup, uplo: uplo)
|
|
344
|
-
raise "the #{-info}-th argument of potrs had illegal value" if info.negative?
|
|
350
|
+
raise LapackError, "the #{-info}-th argument of potrs had illegal value" if info.negative?
|
|
345
351
|
|
|
346
352
|
x
|
|
347
353
|
end
|
|
@@ -366,8 +372,12 @@ module Numo
|
|
|
366
372
|
|
|
367
373
|
getrf = :"#{bchr}getrf"
|
|
368
374
|
lu, piv, info = Numo::Linalg::Lapack.send(getrf, a.dup)
|
|
369
|
-
raise "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
370
|
-
|
|
375
|
+
raise LapackError, "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
376
|
+
|
|
377
|
+
# info > 0 means the factor U has a zero diagonal element and is singular.
|
|
378
|
+
# In this case, the determinant is zero. The method should simply return 0.0.
|
|
379
|
+
# Therefore, the error is not raised here.
|
|
380
|
+
# raise 'the factor U is singular, ...' if info.positive?
|
|
371
381
|
|
|
372
382
|
det_l = 1
|
|
373
383
|
det_u = lu.diagonal.prod
|
|
@@ -405,12 +415,11 @@ module Numo
|
|
|
405
415
|
getri = :"#{bchr}getri"
|
|
406
416
|
|
|
407
417
|
lu, piv, info = Numo::Linalg::Lapack.send(getrf, a.dup)
|
|
408
|
-
raise "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
409
|
-
raise 'the factor U is singular, and the inverse matrix could not be computed.' if info.positive?
|
|
418
|
+
raise LapackError, "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
410
419
|
|
|
411
420
|
a_inv, info = Numo::Linalg::Lapack.send(getri, lu, piv)
|
|
412
|
-
raise "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
413
|
-
raise '
|
|
421
|
+
raise LapackError, "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
422
|
+
raise LapackError, 'The matrix is singular, and the inverse matrix could not be computed.' if info.positive?
|
|
414
423
|
|
|
415
424
|
a_inv
|
|
416
425
|
end
|
|
@@ -611,7 +620,7 @@ module Numo
|
|
|
611
620
|
|
|
612
621
|
fnc = :"#{bchr}gerqf"
|
|
613
622
|
rq, tau, info = Numo::Linalg::Lapack.send(fnc, a.dup)
|
|
614
|
-
raise "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
623
|
+
raise LapackError, "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
615
624
|
|
|
616
625
|
m, n = rq.shape
|
|
617
626
|
r = rq.triu(n - m).dup
|
|
@@ -629,7 +638,7 @@ module Numo
|
|
|
629
638
|
end
|
|
630
639
|
|
|
631
640
|
q, info = Numo::Linalg::Lapack.send(fnc, tmp, tau)
|
|
632
|
-
raise "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
641
|
+
raise LapackError, "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
633
642
|
|
|
634
643
|
[r, q]
|
|
635
644
|
end
|
|
@@ -674,8 +683,21 @@ module Numo
|
|
|
674
683
|
aa, bb, _alpha, _beta, q, z, _sdim, info = Numo::Linalg::Lapack.send(fnc, a.dup, b.dup)
|
|
675
684
|
end
|
|
676
685
|
|
|
677
|
-
|
|
678
|
-
raise
|
|
686
|
+
n = a.shape[0]
|
|
687
|
+
raise LapackError, "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
688
|
+
raise LapackError, 'something other than QZ iteration failed.' if info == n + 1
|
|
689
|
+
raise LapackError, "reordering failed in #{bchr}tgsen" if info == n + 3
|
|
690
|
+
|
|
691
|
+
if info == n + 2
|
|
692
|
+
raise LapackError, 'after reordering, roundoff changed values of some eigenvalues ' \
|
|
693
|
+
'so that leading eigenvalues in the Generalized Schur form no ' \
|
|
694
|
+
'longer satisfy the sorting condition.'
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
if info.positive? && info <= n
|
|
698
|
+
warn('the QZ iteration failed. (a, b) are not in Schur form, ' \
|
|
699
|
+
"but alpha[i] and beta[i] for i = #{info},...,n are correct.")
|
|
700
|
+
end
|
|
679
701
|
|
|
680
702
|
[aa, bb, q, z]
|
|
681
703
|
end
|
|
@@ -731,10 +753,15 @@ module Numo
|
|
|
731
753
|
end
|
|
732
754
|
|
|
733
755
|
n = a.shape[0]
|
|
734
|
-
raise "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
735
|
-
raise 'the QR algorithm failed to compute all the eigenvalues.' if info.positive? && info <= n
|
|
736
|
-
raise 'the eigenvalues could not be reordered.' if info == n + 1
|
|
737
|
-
|
|
756
|
+
raise LapackError, "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
757
|
+
raise LapackError, 'the QR algorithm failed to compute all the eigenvalues.' if info.positive? && info <= n
|
|
758
|
+
raise LapackError, 'the eigenvalues could not be reordered.' if info == n + 1
|
|
759
|
+
|
|
760
|
+
if info == n + 2
|
|
761
|
+
raise LapackError, 'after reordering, roundoff changed values of some eigenvalues ' \
|
|
762
|
+
'so that leading eigenvalues in the Schur form no longer satisfy ' \
|
|
763
|
+
'the sorting condition.'
|
|
764
|
+
end
|
|
738
765
|
|
|
739
766
|
[b, v, sdim]
|
|
740
767
|
end
|
|
@@ -778,12 +805,12 @@ module Numo
|
|
|
778
805
|
func = :"#{bchr}gebal"
|
|
779
806
|
b, ilo, ihi, _, info = Numo::Linalg::Lapack.send(func, a.dup)
|
|
780
807
|
|
|
781
|
-
raise "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
808
|
+
raise LapackError, "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
782
809
|
|
|
783
810
|
func = :"#{bchr}gehrd"
|
|
784
811
|
hq, tau, info = Numo::Linalg::Lapack.send(func, b, ilo: ilo, ihi: ihi)
|
|
785
812
|
|
|
786
|
-
raise "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
813
|
+
raise LapackError, "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
787
814
|
|
|
788
815
|
h = hq.triu(-1)
|
|
789
816
|
return h unless calc_q
|
|
@@ -791,7 +818,7 @@ module Numo
|
|
|
791
818
|
func = %w[d s].include?(bchr) ? :"#{bchr}orghr" : :"#{bchr}unghr"
|
|
792
819
|
q, info = Numo::Linalg::Lapack.send(func, hq, tau, ilo: ilo, ihi: ihi)
|
|
793
820
|
|
|
794
|
-
raise "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
821
|
+
raise LapackError, "the #{-info}-th argument of #{func} had illegal value" if info.negative?
|
|
795
822
|
|
|
796
823
|
[h, q]
|
|
797
824
|
end
|
|
@@ -830,8 +857,12 @@ module Numo
|
|
|
830
857
|
|
|
831
858
|
gesv = :"#{bchr}gesv"
|
|
832
859
|
_lu, x, _ipiv, info = Numo::Linalg::Lapack.send(gesv, a.dup, b.dup)
|
|
833
|
-
raise "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
834
|
-
|
|
860
|
+
raise LapackError, "the #{-info}-th argument of getrf had illegal value" if info.negative?
|
|
861
|
+
|
|
862
|
+
if info.positive?
|
|
863
|
+
warn('the factorization has been completed, but the factor is singular, ' \
|
|
864
|
+
'so the solution could not be computed.')
|
|
865
|
+
end
|
|
835
866
|
|
|
836
867
|
x
|
|
837
868
|
end
|
|
@@ -870,7 +901,7 @@ module Numo
|
|
|
870
901
|
trtrs = :"#{bchr}trtrs"
|
|
871
902
|
uplo = lower ? 'L' : 'U'
|
|
872
903
|
x, info = Numo::Linalg::Lapack.send(trtrs, a, b.dup, uplo: uplo)
|
|
873
|
-
raise "wrong value is given to the #{info}-th argument of #{trtrs} used internally" if info.negative?
|
|
904
|
+
raise LapackError, "wrong value is given to the #{info}-th argument of #{trtrs} used internally" if info.negative?
|
|
874
905
|
|
|
875
906
|
x
|
|
876
907
|
end
|
|
@@ -926,9 +957,9 @@ module Numo
|
|
|
926
957
|
raise ArgumentError, "invalid driver: #{driver}"
|
|
927
958
|
end
|
|
928
959
|
|
|
929
|
-
raise "the #{info.abs}-th argument had illegal value" if info.negative?
|
|
930
|
-
raise 'input array has a NAN entry' if info == -4
|
|
931
|
-
raise '
|
|
960
|
+
raise LapackError, "the #{info.abs}-th argument had illegal value" if info.negative?
|
|
961
|
+
raise LapackError, 'the input array has a NAN entry' if info == -4
|
|
962
|
+
raise LapackError, 'the did not converge' if info.positive?
|
|
932
963
|
|
|
933
964
|
[s, u, vt]
|
|
934
965
|
end
|
|
@@ -1015,9 +1046,9 @@ module Numo
|
|
|
1015
1046
|
raise ArgumentError, "invalid driver: #{driver}"
|
|
1016
1047
|
end
|
|
1017
1048
|
|
|
1018
|
-
raise "the #{info.abs}-th argument had illegal value" if info.negative?
|
|
1019
|
-
raise 'input array has a NAN entry' if info == -4
|
|
1020
|
-
raise '
|
|
1049
|
+
raise LapackError, "the #{info.abs}-th argument had illegal value" if info.negative?
|
|
1050
|
+
raise LapackError, 'the input array has a NAN entry' if info == -4
|
|
1051
|
+
raise LapackError, 'the decomposition did not converge' if info.positive?
|
|
1021
1052
|
|
|
1022
1053
|
s
|
|
1023
1054
|
end
|
|
@@ -1143,8 +1174,12 @@ module Numo
|
|
|
1143
1174
|
getrf = :"#{bchr}getrf"
|
|
1144
1175
|
lu, piv, info = Numo::Linalg::Lapack.send(getrf, a.dup)
|
|
1145
1176
|
|
|
1146
|
-
raise "the #{info.abs}-th argument of getrf had illegal value" if info.negative?
|
|
1147
|
-
|
|
1177
|
+
raise LapackError, "the #{info.abs}-th argument of getrf had illegal value" if info.negative?
|
|
1178
|
+
|
|
1179
|
+
if info.positive?
|
|
1180
|
+
warn("the factorization has been completed, but the factor U[#{info - 1}, #{info - 1}] is " \
|
|
1181
|
+
'exactly zero, indicating that the matrix is singular.')
|
|
1182
|
+
end
|
|
1148
1183
|
|
|
1149
1184
|
[lu, piv]
|
|
1150
1185
|
end
|
|
@@ -1182,7 +1217,7 @@ module Numo
|
|
|
1182
1217
|
getrs = :"#{bchr}getrs"
|
|
1183
1218
|
x, info = Numo::Linalg::Lapack.send(getrs, lu, ipiv, b.dup)
|
|
1184
1219
|
|
|
1185
|
-
raise "the #{info.abs}-th argument of getrs had illegal value" if info.negative?
|
|
1220
|
+
raise LapackError, "the #{info.abs}-th argument of getrs had illegal value" if info.negative?
|
|
1186
1221
|
|
|
1187
1222
|
x
|
|
1188
1223
|
end
|
|
@@ -1203,8 +1238,12 @@ module Numo
|
|
|
1203
1238
|
fnc = :"#{bchr}potrf"
|
|
1204
1239
|
c, info = Numo::Linalg::Lapack.send(fnc, a.dup, uplo: uplo)
|
|
1205
1240
|
|
|
1206
|
-
raise "the #{info}-th
|
|
1207
|
-
|
|
1241
|
+
raise LapackError, "the #{-info}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1242
|
+
|
|
1243
|
+
if info.positive?
|
|
1244
|
+
raise LapackError, "the leading principal minor of order #{info} is not positive, " \
|
|
1245
|
+
'and the factorization could not be completed.'
|
|
1246
|
+
end
|
|
1208
1247
|
|
|
1209
1248
|
c
|
|
1210
1249
|
end
|
|
@@ -1300,7 +1339,7 @@ module Numo
|
|
|
1300
1339
|
fnc = :"#{bchr}gebal"
|
|
1301
1340
|
b, lo, hi, prm_scl, info = Numo::Linalg::Lapack.send(fnc, a.dup, job: job)
|
|
1302
1341
|
|
|
1303
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1342
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1304
1343
|
|
|
1305
1344
|
# convert from Fortran style index to Ruby style index.
|
|
1306
1345
|
lo -= 1
|
|
@@ -1377,8 +1416,8 @@ module Numo
|
|
|
1377
1416
|
wr, wi, vl, vr, info = Numo::Linalg::Lapack.send(fnc, a.dup, jobvl: jobvl, jobvr: jobvr)
|
|
1378
1417
|
end
|
|
1379
1418
|
|
|
1380
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1381
|
-
raise 'the QR algorithm failed to compute all the eigenvalues.' if info.positive?
|
|
1419
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1420
|
+
raise LapackError, 'the QR algorithm failed to compute all the eigenvalues.' if info.positive?
|
|
1382
1421
|
|
|
1383
1422
|
if %w[d s].include?(bchr)
|
|
1384
1423
|
w = wr + (wi * 1.0i)
|
|
@@ -1422,8 +1461,8 @@ module Numo
|
|
|
1422
1461
|
w = wr + (wi * 1.0i)
|
|
1423
1462
|
end
|
|
1424
1463
|
|
|
1425
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1426
|
-
raise 'the QR algorithm failed to compute all the eigenvalues.' if info.positive?
|
|
1464
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1465
|
+
raise LapackError, 'the QR algorithm failed to compute all the eigenvalues.' if info.positive?
|
|
1427
1466
|
|
|
1428
1467
|
w
|
|
1429
1468
|
end
|
|
@@ -1473,8 +1512,12 @@ module Numo
|
|
|
1473
1512
|
lud = a.dup
|
|
1474
1513
|
ipiv, info = Numo::Linalg::Lapack.send(fnc, lud, uplo: uplo)
|
|
1475
1514
|
|
|
1476
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1477
|
-
|
|
1515
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1516
|
+
|
|
1517
|
+
if info.positive?
|
|
1518
|
+
warn("the factorization has been completed, but the D[#{info - 1}, #{info - 1}] is " \
|
|
1519
|
+
'exactly zero, indicating that the block diagonal matrix is singular.')
|
|
1520
|
+
end
|
|
1478
1521
|
|
|
1479
1522
|
_lud_permutation(lud, ipiv, uplo: uplo, hermitian: hermitian)
|
|
1480
1523
|
end
|
|
@@ -1562,8 +1605,8 @@ module Numo
|
|
|
1562
1605
|
fnc = :"#{bchr}gelsd"
|
|
1563
1606
|
s, rank, info = Numo::Linalg::Lapack.send(fnc, a.dup, x, rcond: rcond)
|
|
1564
1607
|
|
|
1565
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1566
|
-
raise 'the algorithm for computing the SVD failed to converge' if info.positive?
|
|
1608
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1609
|
+
raise LapackError, 'the algorithm for computing the SVD failed to converge' if info.positive?
|
|
1567
1610
|
|
|
1568
1611
|
resids = x.class[]
|
|
1569
1612
|
if m > n
|
|
@@ -1765,8 +1808,8 @@ module Numo
|
|
|
1765
1808
|
fnc = :"#{bchr}getri"
|
|
1766
1809
|
inv, info = Numo::Linalg::Lapack.send(fnc, lu.dup, ipiv)
|
|
1767
1810
|
|
|
1768
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1769
|
-
raise 'the matrix is singular and its inverse could not be computed' if info.positive?
|
|
1811
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1812
|
+
raise LapackError, 'the matrix is singular and its inverse could not be computed' if info.positive?
|
|
1770
1813
|
|
|
1771
1814
|
inv
|
|
1772
1815
|
end
|
|
@@ -1796,8 +1839,12 @@ module Numo
|
|
|
1796
1839
|
fnc = :"#{bchr}potri"
|
|
1797
1840
|
inv, info = Numo::Linalg::Lapack.send(fnc, a.dup, uplo: uplo)
|
|
1798
1841
|
|
|
1799
|
-
raise "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1800
|
-
|
|
1842
|
+
raise LapackError, "the #{info.abs}-th argument of #{fnc} had illegal value" if info.negative?
|
|
1843
|
+
|
|
1844
|
+
if info.positive?
|
|
1845
|
+
raise LapackError, "the (#{info - 1}, #{info - 1})-th element of the factor U or L is zero, " \
|
|
1846
|
+
'and the inverse could not be computed.'
|
|
1847
|
+
end
|
|
1801
1848
|
|
|
1802
1849
|
inv
|
|
1803
1850
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: numo-linalg-alt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yoshoku
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.9.
|
|
18
|
+
version: 0.9.10
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.9.
|
|
25
|
+
version: 0.9.10
|
|
26
26
|
description: |
|
|
27
27
|
Numo::Linalg Alternative (numo-linalg-alt) is an alternative to Numo::Linalg.
|
|
28
28
|
Unlike Numo::Linalg, numo-linalg-alt depends on Numo::NArray Alternative (numo-narray-alt).
|
|
@@ -145,7 +145,7 @@ metadata:
|
|
|
145
145
|
homepage_uri: https://github.com/yoshoku/numo-linalg-alt
|
|
146
146
|
source_code_uri: https://github.com/yoshoku/numo-linalg-alt
|
|
147
147
|
changelog_uri: https://github.com/yoshoku/numo-linalg-alt/blob/main/CHANGELOG.md
|
|
148
|
-
documentation_uri: https://gemdocs.org/gems/numo-linalg-alt/0.
|
|
148
|
+
documentation_uri: https://gemdocs.org/gems/numo-linalg-alt/0.7.1/
|
|
149
149
|
rubygems_mfa_required: 'true'
|
|
150
150
|
rdoc_options: []
|
|
151
151
|
require_paths:
|
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
161
161
|
- !ruby/object:Gem::Version
|
|
162
162
|
version: '0'
|
|
163
163
|
requirements: []
|
|
164
|
-
rubygems_version: 3.
|
|
164
|
+
rubygems_version: 3.7.2
|
|
165
165
|
specification_version: 4
|
|
166
166
|
summary: Numo::Linalg Alternative (numo-linalg-alt) is an alternative to Numo::Linalg.
|
|
167
167
|
test_files: []
|