numo-tiny_linalg 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0aeb68c259f8d4c4dcd44c15caef6926cbe3f26f9dd99e9229721d02a939d7c1
4
- data.tar.gz: 5465aebebc07612812b861932fcabf14b66ee0ec389603c9ffcf06694eb69ce4
3
+ metadata.gz: 911223ba40879d779bcc9bc77b840fb7b5e41ed68d6ccf7d26816913c42aed73
4
+ data.tar.gz: 9dce9c353da5466e1104c604c2749369131cb6640e14ddd33c697cee5d973563
5
5
  SHA512:
6
- metadata.gz: 3e1ddd9a4f43d89635d0fc4e07fc3eab0e302b108648e00506deaec106f147f10132b6c28818f6ef054d5fa0ef52bb2c33287dcdeb413fc12268fb35edfde859
7
- data.tar.gz: 78903f772d37936f73a69624b3241d43703632f08542a2f57e38a619b6dc1ac012d8885c79056459ef4fd50102d416f996ea54269b64b919ac91a3db46330d8c
6
+ metadata.gz: 9d666bdd04f48132005a9aee455047c80d83184815fac5c688ec593412ff8e670f1f31ba3376b1ee2985b8e829680590c1dad6a0ec3bf5366e584a82b523d8e4
7
+ data.tar.gz: 22027c54b56bad7214060ba7d5939b986be660a75afd65d74de7fdae095a6699ceea35422eee56831b621f2132e5bce921cb6b70bc9709e77e3efdf6cfc8a098
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [[0.2.0](https://github.com/yoshoku/numo-tiny_linalg/compare/v0.1.2...v0.2.0)] - 2023-08-11
4
+ **Breaking change**
5
+ - Change LAPACK function to call when array b is not given to TinyLinalg.eigh method.
6
+
3
7
  ## [[0.1.2](https://github.com/yoshoku/numo-tiny_linalg/compare/v0.1.1...v0.1.2)] - 2023-08-09
4
8
  - Add dsyev, ssyev, zheev, and cheev module functions to TinyLinalg::Lapack.
5
9
  - Add dsyevd, ssyevd, zheevd, and cheevd module functions to TinyLinalg::Lapack.
data/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
  Numo::TinyLinalg is a subset library from [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) consisting only of methods used in Machine Learning algorithms.
9
9
  The functions Numo::TinyLinalg supports are dot, det, eigh, inv, pinv, qr, solve, and svd.
10
10
 
11
+ Note that the version numbering rule of Numo::TinyLinalg is not compatible with that of Numo::Linalg.
12
+
11
13
  ## Installation
12
14
  Unlike Numo::Linalg, Numo::TinyLinalg only supports OpenBLAS as a backend library for BLAS and LAPACK.
13
15
 
@@ -93,7 +93,25 @@ private:
93
93
  return Qnil;
94
94
  }
95
95
 
96
+ if (range == 'V' && vu <= vl) {
97
+ rb_raise(rb_eArgError, "vu must be greater than vl");
98
+ return Qnil;
99
+ }
100
+
96
101
  const size_t n = NA_SHAPE(a_nary)[1];
102
+ if (range == 'I' && (il < 1 || il > n)) {
103
+ rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n");
104
+ return Qnil;
105
+ }
106
+ if (range == 'I' && (iu < 1 || iu > n)) {
107
+ rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n");
108
+ return Qnil;
109
+ }
110
+ if (range == 'I' && iu < il) {
111
+ rb_raise(rb_eArgError, "iu must be greater than or equal to il");
112
+ return Qnil;
113
+ }
114
+
97
115
  size_t m = range != 'I' ? n : iu - il + 1;
98
116
  size_t w_shape[1] = { m };
99
117
  size_t z_shape[2] = { n, m };
@@ -114,7 +114,25 @@ private:
114
114
  return Qnil;
115
115
  }
116
116
 
117
+ if (range == 'V' && vu <= vl) {
118
+ rb_raise(rb_eArgError, "vu must be greater than vl");
119
+ return Qnil;
120
+ }
121
+
117
122
  const size_t n = NA_SHAPE(a_nary)[1];
123
+ if (range == 'I' && (il < 1 || il > n)) {
124
+ rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n");
125
+ return Qnil;
126
+ }
127
+ if (range == 'I' && (iu < 1 || iu > n)) {
128
+ rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n");
129
+ return Qnil;
130
+ }
131
+ if (range == 'I' && iu < il) {
132
+ rb_raise(rb_eArgError, "il must be less than or equal to iu");
133
+ return Qnil;
134
+ }
135
+
118
136
  size_t m = range != 'I' ? n : iu - il + 1;
119
137
  size_t w_shape[1] = { m };
120
138
  size_t z_shape[2] = { n, m };
@@ -90,7 +90,25 @@ private:
90
90
  return Qnil;
91
91
  }
92
92
 
93
+ if (range == 'V' && vu <= vl) {
94
+ rb_raise(rb_eArgError, "vu must be greater than vl");
95
+ return Qnil;
96
+ }
97
+
93
98
  const size_t n = NA_SHAPE(a_nary)[1];
99
+ if (range == 'I' && (il < 1 || il > n)) {
100
+ rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n");
101
+ return Qnil;
102
+ }
103
+ if (range == 'I' && (iu < 1 || iu > n)) {
104
+ rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n");
105
+ return Qnil;
106
+ }
107
+ if (range == 'I' && iu < il) {
108
+ rb_raise(rb_eArgError, "iu must be greater than or equal to il");
109
+ return Qnil;
110
+ }
111
+
94
112
  size_t m = range != 'I' ? n : iu - il + 1;
95
113
  size_t w_shape[1] = { m };
96
114
  size_t z_shape[2] = { n, m };
@@ -113,7 +113,25 @@ private:
113
113
  return Qnil;
114
114
  }
115
115
 
116
+ if (range == 'V' && vu <= vl) {
117
+ rb_raise(rb_eArgError, "vu must be greater than vl");
118
+ return Qnil;
119
+ }
120
+
116
121
  const size_t n = NA_SHAPE(a_nary)[1];
122
+ if (range == 'I' && (il < 1 || il > n)) {
123
+ rb_raise(rb_eArgError, "il must satisfy 1 <= il <= n");
124
+ return Qnil;
125
+ }
126
+ if (range == 'I' && (iu < 1 || iu > n)) {
127
+ rb_raise(rb_eArgError, "iu must satisfy 1 <= iu <= n");
128
+ return Qnil;
129
+ }
130
+ if (range == 'I' && iu < il) {
131
+ rb_raise(rb_eArgError, "iu must be greater than or equal to il");
132
+ return Qnil;
133
+ }
134
+
117
135
  size_t m = range != 'I' ? n : iu - il + 1;
118
136
  size_t w_shape[1] = { m };
119
137
  size_t z_shape[2] = { n, m };
@@ -5,6 +5,6 @@ module Numo
5
5
  # Numo::TinyLinalg is a subset library from Numo::Linalg consisting only of methods used in Machine Learning algorithms.
6
6
  module TinyLinalg
7
7
  # The version of Numo::TinyLinalg you install.
8
- VERSION = '0.1.2'
8
+ VERSION = '0.2.0'
9
9
  end
10
10
  end
@@ -48,35 +48,50 @@ module Numo
48
48
  # @param uplo [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
49
49
  # @param turbo [Bool] The flag indicating whether to use a divide and conquer algorithm. If vals_range is given, this flag is ignored.
50
50
  # @return [Array<Numo::NArray>] The eigenvalues and eigenvectors.
51
- def eigh(a, b = nil, vals_only: false, vals_range: nil, uplo: 'U', turbo: false) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists, Lint/UnusedMethodArgument
51
+ def eigh(a, b = nil, vals_only: false, vals_range: nil, uplo: 'U', turbo: false) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/ParameterLists, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument
52
52
  raise ArgumentError, 'input array a must be 2-dimensional' if a.ndim != 2
53
53
  raise ArgumentError, 'input array a must be square' if a.shape[0] != a.shape[1]
54
54
 
55
+ b_given = !b.nil?
56
+ raise ArgumentError, 'input array b must be 2-dimensional' if b_given && b.ndim != 2
57
+ raise ArgumentError, 'input array b must be square' if b_given && b.shape[0] != b.shape[1]
58
+ raise ArgumentError, "invalid array type: #{b.class}" if b_given && blas_char(b) == 'n'
59
+
55
60
  bchr = blas_char(a)
56
61
  raise ArgumentError, "invalid array type: #{a.class}" if bchr == 'n'
57
62
 
58
- unless b.nil?
59
- raise ArgumentError, 'input array b must be 2-dimensional' if b.ndim != 2
60
- raise ArgumentError, 'input array b must be square' if b.shape[0] != b.shape[1]
61
- raise ArgumentError, "invalid array type: #{b.class}" if blas_char(b) == 'n'
62
- end
63
-
64
63
  jobz = vals_only ? 'N' : 'V'
65
- b = a.class.eye(a.shape[0]) if b.nil?
66
- sy_he_gv = %w[d s].include?(bchr) ? "#{bchr}sygv" : "#{bchr}hegv"
67
64
 
68
- if vals_range.nil?
69
- sy_he_gv << 'd' if turbo
70
- vecs, _b, vals, _info = Numo::TinyLinalg::Lapack.send(sy_he_gv.to_sym, a.dup, b.dup, jobz: jobz)
65
+ if b_given
66
+ fnc = %w[d s].include?(bchr) ? "#{bchr}sygv" : "#{bchr}hegv"
67
+ if vals_range.nil?
68
+ fnc << 'd' if turbo
69
+ vecs, _b, vals, _info = Numo::TinyLinalg::Lapack.send(fnc.to_sym, a.dup, b.dup, jobz: jobz)
70
+ else
71
+ fnc << 'x'
72
+ il = vals_range.first(1)[0] + 1
73
+ iu = vals_range.last(1)[0] + 1
74
+ _a, _b, _m, vals, vecs, _ifail, _info = Numo::TinyLinalg::Lapack.send(
75
+ fnc.to_sym, a.dup, b.dup, jobz: jobz, range: 'I', il: il, iu: iu
76
+ )
77
+ end
71
78
  else
72
- sy_he_gv << 'x'
73
- il = vals_range.first(1)[0] + 1
74
- iu = vals_range.last(1)[0] + 1
75
- _a, _b, _m, vals, vecs, _ifail, _info = Numo::TinyLinalg::Lapack.send(
76
- sy_he_gv.to_sym, a.dup, b.dup, jobz: jobz, range: 'I', il: il, iu: iu
77
- )
79
+ fnc = %w[d s].include?(bchr) ? "#{bchr}syev" : "#{bchr}heev"
80
+ if vals_range.nil?
81
+ fnc << 'd' if turbo
82
+ vecs, vals, _info = Numo::TinyLinalg::Lapack.send(fnc.to_sym, a.dup, jobz: jobz)
83
+ else
84
+ fnc << 'r'
85
+ il = vals_range.first(1)[0] + 1
86
+ iu = vals_range.last(1)[0] + 1
87
+ _a, _m, vals, vecs, _isuppz, _info = Numo::TinyLinalg::Lapack.send(
88
+ fnc.to_sym, a.dup, jobz: jobz, range: 'I', il: il, iu: iu
89
+ )
90
+ end
78
91
  end
92
+
79
93
  vecs = nil if vals_only
94
+
80
95
  [vals, vecs]
81
96
  end
82
97
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-tiny_linalg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2023-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray