numo-tiny_linalg 0.1.0 → 0.1.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 +3 -0
- data/lib/numo/tiny_linalg/version.rb +1 -1
- data/lib/numo/tiny_linalg.rb +16 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81e69278b32b0f565e3f5b5e1eae1738a57556773e9306bb3b0c8450c9fb75ea
|
4
|
+
data.tar.gz: de6daa349cd0d16b14f9c133ad451fac8bacbcd42cca682be68509bd5d8fc416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72894605f074e09f47a37834ba1c2b3a3e504e149742df3290fd4c4e8042b1ac0c70d11bd50e4ab83e19b07181d8a656ab57afcaa47de53794fc28a298e1e768
|
7
|
+
data.tar.gz: c896b561fcbeb0ff19196548a3a0f2f6a06098d706fbfe95b785ffd850b139e87ea5d62c1144cde4c456a7ef5bb2b79422b5c2e0ab909df76f5ea9fa4a4bd446
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [[0.1.1](https://github.com/yoshoku/numo-tiny_linalg/compare/v0.1.0...v0.1.1)] - 2023-08-07
|
4
|
+
- Fix method of getting start and end of eigenvalue range from vals_range arguement of TinyLinalg.eigh.
|
5
|
+
|
3
6
|
## [[0.1.0](https://github.com/yoshoku/numo-tiny_linalg/compare/v0.0.4...v0.1.0)] - 2023-08-06
|
4
7
|
- Refactor codes and update documentations.
|
5
8
|
|
data/lib/numo/tiny_linalg.rb
CHANGED
@@ -39,15 +39,15 @@ module Numo
|
|
39
39
|
# pp (x - vecs.dot(vals.diag).dot(vecs.transpose)).abs.max
|
40
40
|
# # => 3.3306690738754696e-16
|
41
41
|
#
|
42
|
-
# @param a [Numo::NArray] n-by-n symmetric / Hermitian matrix.
|
43
|
-
# @param b [Numo::NArray] n-by-n symmetric / Hermitian matrix. If nil, identity matrix is assumed.
|
42
|
+
# @param a [Numo::NArray] The n-by-n symmetric / Hermitian matrix.
|
43
|
+
# @param b [Numo::NArray] The n-by-n symmetric / Hermitian matrix. If nil, identity matrix is assumed.
|
44
44
|
# @param vals_only [Boolean] The flag indicating whether to return only eigenvalues.
|
45
45
|
# @param vals_range [Range/Array]
|
46
46
|
# The range of indices of the eigenvalues (in ascending order) and corresponding eigenvectors to be returned.
|
47
47
|
# If nil, all eigenvalues and eigenvectors are computed.
|
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
|
-
# @return [Array<Numo::NArray
|
50
|
+
# @return [Array<Numo::NArray>] The eigenvalues and eigenvectors.
|
51
51
|
def eigh(a, b = nil, vals_only: false, vals_range: nil, uplo: 'U', turbo: false) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists, 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]
|
@@ -70,8 +70,8 @@ module Numo
|
|
70
70
|
vecs, _b, vals, _info = Numo::TinyLinalg::Lapack.send(sy_he_gv.to_sym, a.dup, b.dup, jobz: jobz)
|
71
71
|
else
|
72
72
|
sy_he_gv << 'x'
|
73
|
-
il = vals_range.first + 1
|
74
|
-
iu = vals_range.last + 1
|
73
|
+
il = vals_range.first(1)[0] + 1
|
74
|
+
iu = vals_range.last(1)[0] + 1
|
75
75
|
_a, _b, _m, vals, vecs, _ifail, _info = Numo::TinyLinalg::Lapack.send(
|
76
76
|
sy_he_gv.to_sym, a.dup, b.dup, jobz: jobz, range: 'I', il: il, iu: iu
|
77
77
|
)
|
@@ -91,7 +91,7 @@ module Numo
|
|
91
91
|
# pp (3.0 - Numo::Linalg.det(a)).abs
|
92
92
|
# # => 1.3322676295501878e-15
|
93
93
|
#
|
94
|
-
# @param a [Numo::NArray] n-by-n square matrix.
|
94
|
+
# @param a [Numo::NArray] The n-by-n square matrix.
|
95
95
|
# @return [Float/Complex] The determinant of `a`.
|
96
96
|
def det(a)
|
97
97
|
raise ArgumentError, 'input array a must be 2-dimensional' if a.ndim != 2
|
@@ -132,7 +132,7 @@ module Numo
|
|
132
132
|
# pp inv_a.dot(a).sum
|
133
133
|
# # => 5.0
|
134
134
|
#
|
135
|
-
# @param a [Numo::NArray] n-by-n square matrix.
|
135
|
+
# @param a [Numo::NArray] The n-by-n square matrix.
|
136
136
|
# @param driver [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
137
137
|
# @param uplo [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
138
138
|
# @return [Numo::NArray] The inverse matrix of `a`.
|
@@ -156,7 +156,7 @@ module Numo
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
#
|
159
|
+
# Computes the (Moore-Penrose) pseudo-inverse of a matrix using singular value decomposition.
|
160
160
|
#
|
161
161
|
# @example
|
162
162
|
# require 'numo/tiny_linalg'
|
@@ -174,7 +174,7 @@ module Numo
|
|
174
174
|
# # => 3.0
|
175
175
|
#
|
176
176
|
# @param a [Numo::NArray] The m-by-n matrix to be pseudo-inverted.
|
177
|
-
# @param driver [String] LAPACK driver to be used ('svd' or 'sdd').
|
177
|
+
# @param driver [String] The LAPACK driver to be used ('svd' or 'sdd').
|
178
178
|
# @param rcond [Float] The threshold value for small singular values of `a`, default value is `a.shape.max * EPS`.
|
179
179
|
# @return [Numo::NArray] The pseudo-inverse of `a`.
|
180
180
|
def pinv(a, driver: 'svd', rcond: nil)
|
@@ -186,7 +186,7 @@ module Numo
|
|
186
186
|
u.dot(vh[0...rank, true]).conj.transpose
|
187
187
|
end
|
188
188
|
|
189
|
-
#
|
189
|
+
# Computes the QR decomposition of a matrix.
|
190
190
|
#
|
191
191
|
# @example
|
192
192
|
# require 'numo/tiny_linalg'
|
@@ -222,9 +222,8 @@ module Numo
|
|
222
222
|
# - "r" -- returns only R,
|
223
223
|
# - "economic" -- returns both Q [m, n] and R [n, n],
|
224
224
|
# - "raw" -- returns QR and TAU (LAPACK geqrf results).
|
225
|
-
# @return [Numo::NArray] if mode='r'
|
226
|
-
# @return [Array<Numo::NArray
|
227
|
-
# @return [Array<Numo::NArray,Numo::NArray>] if mode='raw' (LAPACK geqrf result)
|
225
|
+
# @return [Numo::NArray] if mode='r'.
|
226
|
+
# @return [Array<Numo::NArray>] if mode='reduce' or 'economic' or 'raw'.
|
228
227
|
def qr(a, mode: 'reduce')
|
229
228
|
raise ArgumentError, 'input array a must be 2-dimensional' if a.ndim != 2
|
230
229
|
raise ArgumentError, "invalid mode: #{mode}" unless %w[reduce r economic raw].include?(mode)
|
@@ -295,7 +294,7 @@ module Numo
|
|
295
294
|
Numo::TinyLinalg::Lapack.send(gesv, a.dup, b.dup)[1]
|
296
295
|
end
|
297
296
|
|
298
|
-
#
|
297
|
+
# Computes the Singular Value Decomposition (SVD) of a matrix: `A = U * S * V^T`
|
299
298
|
#
|
300
299
|
# @example
|
301
300
|
# require 'numo/tiny_linalg'
|
@@ -328,9 +327,9 @@ module Numo
|
|
328
327
|
# # => 4.440892098500626e-16
|
329
328
|
#
|
330
329
|
# @param a [Numo::NArray] Matrix to be decomposed.
|
331
|
-
# @param driver [String] LAPACK driver to be used ('svd' or 'sdd').
|
332
|
-
# @param job [String]
|
333
|
-
# @return [Array<Numo::NArray>]
|
330
|
+
# @param driver [String] The LAPACK driver to be used ('svd' or 'sdd').
|
331
|
+
# @param job [String] The job option ('A', 'S', or 'N').
|
332
|
+
# @return [Array<Numo::NArray>] The singular values and singular vectors ([s, u, vt]).
|
334
333
|
def svd(a, driver: 'svd', job: 'A')
|
335
334
|
raise ArgumentError, "invalid job: #{job}" unless /^[ASN]/i.match?(job.to_s)
|
336
335
|
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|