numo-tiny_linalg 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -0
- data/ext/numo/tiny_linalg/extconf.rb +64 -16
- data/ext/numo/tiny_linalg/lapack/gesv.hpp +148 -0
- data/ext/numo/tiny_linalg/lapack/getrf.hpp +118 -0
- data/ext/numo/tiny_linalg/lapack/getri.hpp +127 -0
- data/ext/numo/tiny_linalg/tiny_linalg.cpp +22 -7
- data/lib/numo/tiny_linalg/version.rb +1 -1
- data/lib/numo/tiny_linalg.rb +46 -0
- data/vendor/tmp/.gitkeep +0 -0
- metadata +14 -17
- data/.clang-format +0 -149
- data/.husky/commit-msg +0 -4
- data/.rubocop.yml +0 -47
- data/Gemfile +0 -15
- data/Rakefile +0 -30
- data/commitlint.config.js +0 -1
- data/numo-tiny_linalg.gemspec +0 -42
- data/package.json +0 -15
- /data/ext/numo/tiny_linalg/{dot.hpp → blas/dot.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{dot_sub.hpp → blas/dot_sub.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{gemm.hpp → blas/gemm.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{gemv.hpp → blas/gemv.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{nrm2.hpp → blas/nrm2.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{gesdd.hpp → lapack/gesdd.hpp} +0 -0
- /data/ext/numo/tiny_linalg/{gesvd.hpp → lapack/gesvd.hpp} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06379198010df5ee43b42c8d6776e551ac7870e0a81bb43ecfd776868464edf9'
|
4
|
+
data.tar.gz: e0e38cd51c48332a496e8b9405e219cdcd9f7dcebd83e53d977daa6b82a5b1fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5288ec9be4365280fc177d4d57523e7187360e8d298bb5d60819a2776274f03979a2e0319aee1081532f0abfcc23e0c3a897dbca47d1cd1bde36df5ac87db011
|
7
|
+
data.tar.gz: 4f03737044a25e81aab2fda5ce2bb555c8565a092bb6edc52776c54b758c1d76147ccdea845ea3e834f510b79a6254e8e9379f264e88421a1e446057f8bac058
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [[0.0.2](https://github.com/yoshoku/numo-tiny_linalg/compare/v0.0.1...v0.0.2)] - 2023-07-26
|
4
|
+
- Add automatic build of OpenBLAS if it is not found.
|
5
|
+
- Add dgesv, sgesv, zgesv, and cgesv module functions to TinyLinalg::Lapack.
|
6
|
+
- Add dgetrf, sgetrf, zgetrf, and cgetrf module functions to TinyLinalg::Lapack.
|
7
|
+
- Add dgetri, sgetri, zgetri, and cgetri module functions to TinyLinalg::Lapack.
|
8
|
+
- Add solve module function to TinyLinalg.
|
9
|
+
- Add inv module function to TinyLinalg.
|
10
|
+
|
3
11
|
## [0.0.1] - 2023-07-14
|
4
12
|
|
5
13
|
- Initial release
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Numo::TinyLinalg
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/numo-tiny_linalg.svg)](https://badge.fury.io/rb/numo-tiny_linalg)
|
3
4
|
[![Build Status](https://github.com/yoshoku/numo-tiny_linalg/actions/workflows/main.yml/badge.svg)](https://github.com/yoshoku/numo-tiny_linalg/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-tiny_linalg/blob/main/LICENSE.txt)
|
6
|
+
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/numo-tiny_linalg/doc/)
|
5
7
|
|
6
8
|
Numo::TinyLinalg is a subset library from Numo::Linalg consisting only of methods used in Machine Learning algorithms.
|
7
9
|
|
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'mkmf'
|
4
4
|
require 'numo/narray'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'etc'
|
7
|
+
require 'fileutils'
|
8
|
+
require 'open3'
|
9
|
+
require 'digest/md5'
|
10
|
+
require 'rubygems/package'
|
5
11
|
|
6
12
|
$LOAD_PATH.each do |lp|
|
7
13
|
if File.exist?(File.join(lp, 'numo/numo/narray.h'))
|
@@ -22,33 +28,75 @@ if RUBY_PLATFORM.match?(/mswin|cygwin|mingw/)
|
|
22
28
|
abort 'libnarray.a is not found' unless have_library('narray', 'nary_new')
|
23
29
|
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
$LDFLAGS << ' -Wl,-undefined,dynamic_lookup'
|
28
|
-
end
|
31
|
+
abort 'libstdc++ is not found.' unless have_library('stdc++')
|
32
|
+
$CXXFLAGS << ' -std=c++11'
|
29
33
|
|
30
|
-
use_accelerate = false
|
31
34
|
# NOTE: Accelerate framework does not support LAPACKE.
|
35
|
+
# use_accelerate = false
|
32
36
|
# if RUBY_PLATFORM.include?('darwin') && have_framework('Accelerate')
|
33
37
|
# $CFLAGS << ' -DTINYLINALG_USE_ACCELERATE'
|
34
38
|
# use_accelerate = true
|
35
39
|
# end
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
build_openblas = false
|
42
|
+
unless find_library('openblas', 'LAPACKE_dsyevr')
|
43
|
+
build_openblas = true unless have_library('openblas')
|
44
|
+
build_openblas = true unless have_library('lapacke')
|
45
|
+
end
|
46
|
+
build_openblas = true unless have_header('cblas.h')
|
47
|
+
build_openblas = true unless have_header('lapacke.h')
|
48
|
+
build_openblas = true unless have_header('openblas_config.h')
|
49
|
+
|
50
|
+
if build_openblas
|
51
|
+
warn 'BLAS and LAPACKE APIs are not found. Downloading and Building OpenBLAS...'
|
52
|
+
|
53
|
+
VENDOR_DIR = File.expand_path("#{__dir__}/../../../vendor")
|
54
|
+
OPENBLAS_VER = '0.3.23'
|
55
|
+
OPENBLAS_KEY = '115634b39007de71eb7e75cf7591dfb2'
|
56
|
+
OPENBLAS_URI = "https://github.com/xianyi/OpenBLAS/archive/v#{OPENBLAS_VER}.tar.gz"
|
57
|
+
OPENBLAS_TGZ = "#{VENDOR_DIR}/tmp/openblas.tgz"
|
58
|
+
|
59
|
+
unless File.exist?("#{VENDOR_DIR}/installed_#{OPENBLAS_VER}")
|
60
|
+
URI.parse(OPENBLAS_URI).open { |f| File.binwrite(OPENBLAS_TGZ, f.read) }
|
61
|
+
abort('MD5 digest of downloaded OpenBLAS does not match.') if Digest::MD5.file(OPENBLAS_TGZ).to_s != OPENBLAS_KEY
|
62
|
+
|
63
|
+
Gem::Package::TarReader.new(Zlib::GzipReader.open(OPENBLAS_TGZ)) do |tar|
|
64
|
+
tar.each do |entry|
|
65
|
+
next unless entry.file?
|
66
|
+
|
67
|
+
filename = "#{VENDOR_DIR}/tmp/#{entry.full_name}"
|
68
|
+
next if filename == File.dirname(filename)
|
69
|
+
|
70
|
+
FileUtils.mkdir_p("#{VENDOR_DIR}/tmp/#{File.dirname(entry.full_name)}")
|
71
|
+
File.binwrite(filename, entry.read)
|
72
|
+
File.chmod(entry.header.mode, filename)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Dir.chdir("#{VENDOR_DIR}/tmp/OpenBLAS-#{OPENBLAS_VER}") do
|
77
|
+
mkstdout, _mkstderr, mkstatus = Open3.capture3("make -j#{Etc.nprocessors}")
|
78
|
+
File.open("#{VENDOR_DIR}/tmp/openblas.log", 'w') { |f| f.puts(mkstdout) }
|
79
|
+
abort("Failed to build OpenBLAS. Check the openblas.log file for more details: #{VENDOR_DIR}/tmp/openblas.log") unless mkstatus.success?
|
80
|
+
|
81
|
+
insstdout, _insstderr, insstatus = Open3.capture3("make install PREFIX=#{VENDOR_DIR}")
|
82
|
+
File.open("#{VENDOR_DIR}/tmp/openblas.log", 'a') { |f| f.puts(insstdout) }
|
83
|
+
abort("Failed to install OpenBLAS. Check the openblas.log file for more details: #{VENDOR_DIR}/tmp/openblas.log") unless insstatus.success?
|
84
|
+
|
85
|
+
FileUtils.touch("#{VENDOR_DIR}/installed_#{OPENBLAS_VER}")
|
86
|
+
end
|
43
87
|
end
|
44
88
|
|
45
|
-
abort
|
46
|
-
abort
|
47
|
-
abort
|
89
|
+
abort('libopenblas is not found.') unless find_library('openblas', nil, "#{VENDOR_DIR}/lib")
|
90
|
+
abort('openblas_config.h is not found.') unless find_header('openblas_config.h', nil, "#{VENDOR_DIR}/include")
|
91
|
+
abort('cblas.h is not found.') unless find_header('cblas.h', nil, "#{VENDOR_DIR}/include")
|
92
|
+
abort('lapacke.h is not found.') unless find_header('lapacke.h', nil, "#{VENDOR_DIR}/include")
|
48
93
|
end
|
49
94
|
|
50
|
-
|
95
|
+
$CFLAGS << ' -DNUMO_TINY_LINALG_USE_OPENBLAS'
|
51
96
|
|
52
|
-
|
97
|
+
if RUBY_PLATFORM.include?('darwin') && Gem::Version.new('3.1.0') <= Gem::Version.new(RUBY_VERSION) &&
|
98
|
+
try_link('int main(void){return 0;}', '-Wl,-undefined,dynamic_lookup')
|
99
|
+
$LDFLAGS << ' -Wl,-undefined,dynamic_lookup'
|
100
|
+
end
|
53
101
|
|
54
102
|
create_makefile('numo/tiny_linalg/tiny_linalg')
|
@@ -0,0 +1,148 @@
|
|
1
|
+
namespace TinyLinalg {
|
2
|
+
|
3
|
+
struct DGESV {
|
4
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_int nrhs,
|
5
|
+
double* a, lapack_int lda, lapack_int* ipiv,
|
6
|
+
double* b, lapack_int ldb) {
|
7
|
+
return LAPACKE_dgesv(matrix_layout, n, nrhs, a, lda, ipiv, b, ldb);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
|
11
|
+
struct SGESV {
|
12
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_int nrhs,
|
13
|
+
float* a, lapack_int lda, lapack_int* ipiv,
|
14
|
+
float* b, lapack_int ldb) {
|
15
|
+
return LAPACKE_sgesv(matrix_layout, n, nrhs, a, lda, ipiv, b, ldb);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
|
19
|
+
struct ZGESV {
|
20
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_int nrhs,
|
21
|
+
lapack_complex_double* a, lapack_int lda, lapack_int* ipiv,
|
22
|
+
lapack_complex_double* b, lapack_int ldb) {
|
23
|
+
return LAPACKE_zgesv(matrix_layout, n, nrhs, a, lda, ipiv, b, ldb);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
struct CGESV {
|
28
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_int nrhs,
|
29
|
+
lapack_complex_float* a, lapack_int lda, lapack_int* ipiv,
|
30
|
+
lapack_complex_float* b, lapack_int ldb) {
|
31
|
+
return LAPACKE_cgesv(matrix_layout, n, nrhs, a, lda, ipiv, b, ldb);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
template <int nary_dtype_id, typename DType, typename FncType>
|
36
|
+
class GESV {
|
37
|
+
public:
|
38
|
+
static void define_module_function(VALUE mLapack, const char* fnc_name) {
|
39
|
+
rb_define_module_function(mLapack, fnc_name, RUBY_METHOD_FUNC(tiny_linalg_gesv), -1);
|
40
|
+
}
|
41
|
+
|
42
|
+
private:
|
43
|
+
struct gesv_opt {
|
44
|
+
int matrix_layout;
|
45
|
+
};
|
46
|
+
|
47
|
+
static void iter_gesv(na_loop_t* const lp) {
|
48
|
+
DType* a = (DType*)NDL_PTR(lp, 0);
|
49
|
+
DType* b = (DType*)NDL_PTR(lp, 1);
|
50
|
+
int* ipiv = (int*)NDL_PTR(lp, 2);
|
51
|
+
int* info = (int*)NDL_PTR(lp, 3);
|
52
|
+
gesv_opt* opt = (gesv_opt*)(lp->opt_ptr);
|
53
|
+
const lapack_int n = NDL_SHAPE(lp, 0)[0];
|
54
|
+
const lapack_int nhrs = lp->args[1].ndim == 1 ? 1 : NDL_SHAPE(lp, 1)[1];
|
55
|
+
const lapack_int lda = n;
|
56
|
+
const lapack_int ldb = nhrs;
|
57
|
+
const lapack_int i = FncType().call(opt->matrix_layout, n, nhrs, a, lda, ipiv, b, ldb);
|
58
|
+
*info = static_cast<int>(i);
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE tiny_linalg_gesv(int argc, VALUE* argv, VALUE self) {
|
62
|
+
VALUE nary_dtype = NaryTypes[nary_dtype_id];
|
63
|
+
VALUE a_vnary = Qnil;
|
64
|
+
VALUE b_vnary = Qnil;
|
65
|
+
VALUE kw_args = Qnil;
|
66
|
+
|
67
|
+
rb_scan_args(argc, argv, "2:", &a_vnary, &b_vnary, &kw_args);
|
68
|
+
|
69
|
+
ID kw_table[1] = { rb_intern("order") };
|
70
|
+
VALUE kw_values[1] = { Qundef };
|
71
|
+
|
72
|
+
rb_get_kwargs(kw_args, kw_table, 0, 1, kw_values);
|
73
|
+
|
74
|
+
const int matrix_layout = kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR;
|
75
|
+
|
76
|
+
if (CLASS_OF(a_vnary) != nary_dtype) {
|
77
|
+
a_vnary = rb_funcall(nary_dtype, rb_intern("cast"), 1, a_vnary);
|
78
|
+
}
|
79
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) {
|
80
|
+
a_vnary = nary_dup(a_vnary);
|
81
|
+
}
|
82
|
+
if (CLASS_OF(b_vnary) != nary_dtype) {
|
83
|
+
b_vnary = rb_funcall(nary_dtype, rb_intern("cast"), 1, b_vnary);
|
84
|
+
}
|
85
|
+
if (!RTEST(nary_check_contiguous(b_vnary))) {
|
86
|
+
b_vnary = nary_dup(b_vnary);
|
87
|
+
}
|
88
|
+
|
89
|
+
narray_t* a_nary = NULL;
|
90
|
+
narray_t* b_nary = NULL;
|
91
|
+
GetNArray(a_vnary, a_nary);
|
92
|
+
GetNArray(b_vnary, b_nary);
|
93
|
+
const int a_n_dims = NA_NDIM(a_nary);
|
94
|
+
const int b_n_dims = NA_NDIM(b_nary);
|
95
|
+
if (a_n_dims != 2) {
|
96
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional");
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
if (b_n_dims != 1 && b_n_dims != 2) {
|
100
|
+
rb_raise(rb_eArgError, "input array b must be 1- or 2-dimensional");
|
101
|
+
return Qnil;
|
102
|
+
}
|
103
|
+
|
104
|
+
lapack_int n = NA_SHAPE(a_nary)[0];
|
105
|
+
lapack_int nb = b_n_dims == 1 ? NA_SHAPE(b_nary)[0] : NA_SHAPE(b_nary)[0];
|
106
|
+
if (n != nb) {
|
107
|
+
rb_raise(nary_eShapeError, "shape1[1](=%d) != shape2[0](=%d)", n, nb);
|
108
|
+
}
|
109
|
+
|
110
|
+
lapack_int nhrs = b_n_dims == 1 ? 1 : NA_SHAPE(b_nary)[1];
|
111
|
+
size_t shape[2] = { static_cast<size_t>(n), static_cast<size_t>(nhrs) };
|
112
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 2 }, { OVERWRITE, b_n_dims } };
|
113
|
+
ndfunc_arg_out_t aout[2] = { { numo_cInt32, 1, shape }, { numo_cInt32, 0 } };
|
114
|
+
|
115
|
+
ndfunc_t ndf = { iter_gesv, NO_LOOP | NDF_EXTRACT, 2, 2, ain, aout };
|
116
|
+
gesv_opt opt = { matrix_layout };
|
117
|
+
VALUE res = na_ndloop3(&ndf, &opt, 2, a_vnary, b_vnary);
|
118
|
+
|
119
|
+
VALUE ret = rb_ary_concat(rb_assoc_new(a_vnary, b_vnary), res);
|
120
|
+
|
121
|
+
RB_GC_GUARD(a_vnary);
|
122
|
+
RB_GC_GUARD(b_vnary);
|
123
|
+
|
124
|
+
return ret;
|
125
|
+
}
|
126
|
+
|
127
|
+
static int get_matrix_layout(VALUE val) {
|
128
|
+
const char* option_str = StringValueCStr(val);
|
129
|
+
|
130
|
+
if (std::strlen(option_str) > 0) {
|
131
|
+
switch (option_str[0]) {
|
132
|
+
case 'r':
|
133
|
+
case 'R':
|
134
|
+
break;
|
135
|
+
case 'c':
|
136
|
+
case 'C':
|
137
|
+
rb_warn("Numo::TinyLinalg::Lapack.gesv does not support column major.");
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
RB_GC_GUARD(val);
|
143
|
+
|
144
|
+
return LAPACK_ROW_MAJOR;
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
} // namespace TinyLinalg
|
@@ -0,0 +1,118 @@
|
|
1
|
+
namespace TinyLinalg {
|
2
|
+
|
3
|
+
struct DGETRF {
|
4
|
+
lapack_int call(int matrix_layout, lapack_int m, lapack_int n,
|
5
|
+
double* a, lapack_int lda, lapack_int* ipiv) {
|
6
|
+
return LAPACKE_dgetrf(matrix_layout, m, n, a, lda, ipiv);
|
7
|
+
}
|
8
|
+
};
|
9
|
+
|
10
|
+
struct SGETRF {
|
11
|
+
lapack_int call(int matrix_layout, lapack_int m, lapack_int n,
|
12
|
+
float* a, lapack_int lda, lapack_int* ipiv) {
|
13
|
+
return LAPACKE_sgetrf(matrix_layout, m, n, a, lda, ipiv);
|
14
|
+
}
|
15
|
+
};
|
16
|
+
|
17
|
+
struct ZGETRF {
|
18
|
+
lapack_int call(int matrix_layout, lapack_int m, lapack_int n,
|
19
|
+
lapack_complex_double* a, lapack_int lda, lapack_int* ipiv) {
|
20
|
+
return LAPACKE_zgetrf(matrix_layout, m, n, a, lda, ipiv);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
struct CGETRF {
|
25
|
+
lapack_int call(int matrix_layout, lapack_int m, lapack_int n,
|
26
|
+
lapack_complex_float* a, lapack_int lda, lapack_int* ipiv) {
|
27
|
+
return LAPACKE_cgetrf(matrix_layout, m, n, a, lda, ipiv);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
template <int nary_dtype_id, typename DType, typename FncType>
|
32
|
+
class GETRF {
|
33
|
+
public:
|
34
|
+
static void define_module_function(VALUE mLapack, const char* fnc_name) {
|
35
|
+
rb_define_module_function(mLapack, fnc_name, RUBY_METHOD_FUNC(tiny_linalg_getrf), -1);
|
36
|
+
}
|
37
|
+
|
38
|
+
private:
|
39
|
+
struct getrf_opt {
|
40
|
+
int matrix_layout;
|
41
|
+
};
|
42
|
+
|
43
|
+
static void iter_getrf(na_loop_t* const lp) {
|
44
|
+
DType* a = (DType*)NDL_PTR(lp, 0);
|
45
|
+
int* ipiv = (int*)NDL_PTR(lp, 1);
|
46
|
+
int* info = (int*)NDL_PTR(lp, 2);
|
47
|
+
getrf_opt* opt = (getrf_opt*)(lp->opt_ptr);
|
48
|
+
const lapack_int m = NDL_SHAPE(lp, 0)[0];
|
49
|
+
const lapack_int n = NDL_SHAPE(lp, 0)[1];
|
50
|
+
const lapack_int lda = n;
|
51
|
+
const lapack_int i = FncType().call(opt->matrix_layout, m, n, a, lda, ipiv);
|
52
|
+
*info = static_cast<int>(i);
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE tiny_linalg_getrf(int argc, VALUE* argv, VALUE self) {
|
56
|
+
VALUE nary_dtype = NaryTypes[nary_dtype_id];
|
57
|
+
|
58
|
+
VALUE a_vnary = Qnil;
|
59
|
+
VALUE kw_args = Qnil;
|
60
|
+
rb_scan_args(argc, argv, "1:", &a_vnary, &kw_args);
|
61
|
+
ID kw_table[1] = { rb_intern("order") };
|
62
|
+
VALUE kw_values[1] = { Qundef };
|
63
|
+
rb_get_kwargs(kw_args, kw_table, 0, 1, kw_values);
|
64
|
+
const int matrix_layout = kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR;
|
65
|
+
|
66
|
+
if (CLASS_OF(a_vnary) != nary_dtype) {
|
67
|
+
a_vnary = rb_funcall(nary_dtype, rb_intern("cast"), 1, a_vnary);
|
68
|
+
}
|
69
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) {
|
70
|
+
a_vnary = nary_dup(a_vnary);
|
71
|
+
}
|
72
|
+
|
73
|
+
narray_t* a_nary = NULL;
|
74
|
+
GetNArray(a_vnary, a_nary);
|
75
|
+
const int n_dims = NA_NDIM(a_nary);
|
76
|
+
if (n_dims != 2) {
|
77
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional");
|
78
|
+
return Qnil;
|
79
|
+
}
|
80
|
+
|
81
|
+
size_t m = NA_SHAPE(a_nary)[0];
|
82
|
+
size_t n = NA_SHAPE(a_nary)[1];
|
83
|
+
size_t shape[1] = { m < n ? m : n };
|
84
|
+
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } };
|
85
|
+
ndfunc_arg_out_t aout[2] = { { numo_cInt32, 1, shape }, { numo_cInt32, 0 } };
|
86
|
+
ndfunc_t ndf = { iter_getrf, NO_LOOP | NDF_EXTRACT, 1, 2, ain, aout };
|
87
|
+
getrf_opt opt = { matrix_layout };
|
88
|
+
VALUE res = na_ndloop3(&ndf, &opt, 1, a_vnary);
|
89
|
+
|
90
|
+
VALUE ret = rb_ary_concat(rb_ary_new3(1, a_vnary), res);
|
91
|
+
|
92
|
+
RB_GC_GUARD(a_vnary);
|
93
|
+
|
94
|
+
return ret;
|
95
|
+
}
|
96
|
+
|
97
|
+
static int get_matrix_layout(VALUE val) {
|
98
|
+
const char* option_str = StringValueCStr(val);
|
99
|
+
|
100
|
+
if (std::strlen(option_str) > 0) {
|
101
|
+
switch (option_str[0]) {
|
102
|
+
case 'r':
|
103
|
+
case 'R':
|
104
|
+
break;
|
105
|
+
case 'c':
|
106
|
+
case 'C':
|
107
|
+
rb_warn("Numo::TinyLinalg::Lapack.getrf does not support column major.");
|
108
|
+
break;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
RB_GC_GUARD(val);
|
113
|
+
|
114
|
+
return LAPACK_ROW_MAJOR;
|
115
|
+
}
|
116
|
+
};
|
117
|
+
|
118
|
+
} // namespace TinyLinalg
|
@@ -0,0 +1,127 @@
|
|
1
|
+
namespace TinyLinalg {
|
2
|
+
|
3
|
+
struct DGETRI {
|
4
|
+
lapack_int call(int matrix_layout, lapack_int n, double* a, lapack_int lda, const lapack_int* ipiv) {
|
5
|
+
return LAPACKE_dgetri(matrix_layout, n, a, lda, ipiv);
|
6
|
+
}
|
7
|
+
};
|
8
|
+
|
9
|
+
struct SGETRI {
|
10
|
+
lapack_int call(int matrix_layout, lapack_int n, float* a, lapack_int lda, const lapack_int* ipiv) {
|
11
|
+
return LAPACKE_sgetri(matrix_layout, n, a, lda, ipiv);
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
struct ZGETRI {
|
16
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_complex_double* a, lapack_int lda, const lapack_int* ipiv) {
|
17
|
+
return LAPACKE_zgetri(matrix_layout, n, a, lda, ipiv);
|
18
|
+
}
|
19
|
+
};
|
20
|
+
|
21
|
+
struct CGETRI {
|
22
|
+
lapack_int call(int matrix_layout, lapack_int n, lapack_complex_float* a, lapack_int lda, const lapack_int* ipiv) {
|
23
|
+
return LAPACKE_cgetri(matrix_layout, n, a, lda, ipiv);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
template <int nary_dtype_id, typename DType, typename FncType>
|
28
|
+
class GETRI {
|
29
|
+
public:
|
30
|
+
static void define_module_function(VALUE mLapack, const char* fnc_name) {
|
31
|
+
rb_define_module_function(mLapack, fnc_name, RUBY_METHOD_FUNC(tiny_linalg_getri), -1);
|
32
|
+
}
|
33
|
+
|
34
|
+
private:
|
35
|
+
struct getri_opt {
|
36
|
+
int matrix_layout;
|
37
|
+
};
|
38
|
+
|
39
|
+
static void iter_getri(na_loop_t* const lp) {
|
40
|
+
DType* a = (DType*)NDL_PTR(lp, 0);
|
41
|
+
lapack_int* ipiv = (lapack_int*)NDL_PTR(lp, 1);
|
42
|
+
int* info = (int*)NDL_PTR(lp, 2);
|
43
|
+
getri_opt* opt = (getri_opt*)(lp->opt_ptr);
|
44
|
+
const lapack_int n = NDL_SHAPE(lp, 0)[0];
|
45
|
+
const lapack_int lda = n;
|
46
|
+
const lapack_int i = FncType().call(opt->matrix_layout, n, a, lda, ipiv);
|
47
|
+
*info = static_cast<int>(i);
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE tiny_linalg_getri(int argc, VALUE* argv, VALUE self) {
|
51
|
+
VALUE nary_dtype = NaryTypes[nary_dtype_id];
|
52
|
+
|
53
|
+
VALUE a_vnary = Qnil;
|
54
|
+
VALUE ipiv_vnary = Qnil;
|
55
|
+
VALUE kw_args = Qnil;
|
56
|
+
rb_scan_args(argc, argv, "2:", &a_vnary, &ipiv_vnary, &kw_args);
|
57
|
+
ID kw_table[1] = { rb_intern("order") };
|
58
|
+
VALUE kw_values[1] = { Qundef };
|
59
|
+
rb_get_kwargs(kw_args, kw_table, 0, 1, kw_values);
|
60
|
+
const int matrix_layout = kw_values[0] != Qundef ? get_matrix_layout(kw_values[0]) : LAPACK_ROW_MAJOR;
|
61
|
+
|
62
|
+
if (CLASS_OF(a_vnary) != nary_dtype) {
|
63
|
+
a_vnary = rb_funcall(nary_dtype, rb_intern("cast"), 1, a_vnary);
|
64
|
+
}
|
65
|
+
if (!RTEST(nary_check_contiguous(a_vnary))) {
|
66
|
+
a_vnary = nary_dup(a_vnary);
|
67
|
+
}
|
68
|
+
if (CLASS_OF(ipiv_vnary) != numo_cInt32) {
|
69
|
+
ipiv_vnary = rb_funcall(numo_cInt32, rb_intern("cast"), 1, ipiv_vnary);
|
70
|
+
}
|
71
|
+
if (!RTEST(nary_check_contiguous(ipiv_vnary))) {
|
72
|
+
ipiv_vnary = nary_dup(ipiv_vnary);
|
73
|
+
}
|
74
|
+
|
75
|
+
narray_t* a_nary = NULL;
|
76
|
+
GetNArray(a_vnary, a_nary);
|
77
|
+
if (NA_NDIM(a_nary) != 2) {
|
78
|
+
rb_raise(rb_eArgError, "input array a must be 2-dimensional");
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
if (NA_SHAPE(a_nary)[0] != NA_SHAPE(a_nary)[1]) {
|
82
|
+
rb_raise(rb_eArgError, "input array a must be square");
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
narray_t* ipiv_nary = NULL;
|
86
|
+
GetNArray(ipiv_vnary, ipiv_nary);
|
87
|
+
if (NA_NDIM(ipiv_nary) != 1) {
|
88
|
+
rb_raise(rb_eArgError, "input array ipiv must be 1-dimensional");
|
89
|
+
return Qnil;
|
90
|
+
}
|
91
|
+
|
92
|
+
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 2 }, { numo_cInt32, 1 } };
|
93
|
+
ndfunc_arg_out_t aout[1] = { { numo_cInt32, 0 } };
|
94
|
+
ndfunc_t ndf = { iter_getri, NO_LOOP | NDF_EXTRACT, 2, 1, ain, aout };
|
95
|
+
getri_opt opt = { matrix_layout };
|
96
|
+
VALUE res = na_ndloop3(&ndf, &opt, 2, a_vnary, ipiv_vnary);
|
97
|
+
|
98
|
+
VALUE ret = rb_ary_new3(2, a_vnary, res);
|
99
|
+
|
100
|
+
RB_GC_GUARD(a_vnary);
|
101
|
+
RB_GC_GUARD(ipiv_vnary);
|
102
|
+
|
103
|
+
return ret;
|
104
|
+
}
|
105
|
+
|
106
|
+
static int get_matrix_layout(VALUE val) {
|
107
|
+
const char* option_str = StringValueCStr(val);
|
108
|
+
|
109
|
+
if (std::strlen(option_str) > 0) {
|
110
|
+
switch (option_str[0]) {
|
111
|
+
case 'r':
|
112
|
+
case 'R':
|
113
|
+
break;
|
114
|
+
case 'c':
|
115
|
+
case 'C':
|
116
|
+
rb_warn("Numo::TinyLinalg::Lapack.getri does not support column major.");
|
117
|
+
break;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
RB_GC_GUARD(val);
|
122
|
+
|
123
|
+
return LAPACK_ROW_MAJOR;
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
} // namespace TinyLinalg
|
@@ -1,12 +1,15 @@
|
|
1
1
|
#include "tiny_linalg.hpp"
|
2
|
+
#include "blas/dot.hpp"
|
3
|
+
#include "blas/dot_sub.hpp"
|
4
|
+
#include "blas/gemm.hpp"
|
5
|
+
#include "blas/gemv.hpp"
|
6
|
+
#include "blas/nrm2.hpp"
|
2
7
|
#include "converter.hpp"
|
3
|
-
#include "
|
4
|
-
#include "
|
5
|
-
#include "
|
6
|
-
#include "
|
7
|
-
#include "
|
8
|
-
#include "gesvd.hpp"
|
9
|
-
#include "nrm2.hpp"
|
8
|
+
#include "lapack/gesdd.hpp"
|
9
|
+
#include "lapack/gesv.hpp"
|
10
|
+
#include "lapack/gesvd.hpp"
|
11
|
+
#include "lapack/getrf.hpp"
|
12
|
+
#include "lapack/getri.hpp"
|
10
13
|
|
11
14
|
VALUE rb_mTinyLinalg;
|
12
15
|
VALUE rb_mTinyLinalgBlas;
|
@@ -237,6 +240,10 @@ extern "C" void Init_tiny_linalg(void) {
|
|
237
240
|
TinyLinalg::Nrm2<TinyLinalg::numo_cSFloatId, float, TinyLinalg::SNrm2>::define_module_function(rb_mTinyLinalgBlas, "snrm2");
|
238
241
|
TinyLinalg::Nrm2<TinyLinalg::numo_cDComplexId, double, TinyLinalg::DZNrm2>::define_module_function(rb_mTinyLinalgBlas, "dznrm2");
|
239
242
|
TinyLinalg::Nrm2<TinyLinalg::numo_cSComplexId, float, TinyLinalg::SCNrm2>::define_module_function(rb_mTinyLinalgBlas, "scnrm2");
|
243
|
+
TinyLinalg::GESV<TinyLinalg::numo_cDFloatId, double, TinyLinalg::DGESV>::define_module_function(rb_mTinyLinalgLapack, "dgesv");
|
244
|
+
TinyLinalg::GESV<TinyLinalg::numo_cSFloatId, float, TinyLinalg::SGESV>::define_module_function(rb_mTinyLinalgLapack, "sgesv");
|
245
|
+
TinyLinalg::GESV<TinyLinalg::numo_cDComplexId, lapack_complex_double, TinyLinalg::ZGESV>::define_module_function(rb_mTinyLinalgLapack, "zgesv");
|
246
|
+
TinyLinalg::GESV<TinyLinalg::numo_cSComplexId, lapack_complex_float, TinyLinalg::CGESV>::define_module_function(rb_mTinyLinalgLapack, "cgesv");
|
240
247
|
TinyLinalg::GESVD<TinyLinalg::numo_cDFloatId, TinyLinalg::numo_cDFloatId, double, double, TinyLinalg::DGESVD>::define_module_function(rb_mTinyLinalgLapack, "dgesvd");
|
241
248
|
TinyLinalg::GESVD<TinyLinalg::numo_cSFloatId, TinyLinalg::numo_cSFloatId, float, float, TinyLinalg::SGESVD>::define_module_function(rb_mTinyLinalgLapack, "sgesvd");
|
242
249
|
TinyLinalg::GESVD<TinyLinalg::numo_cDComplexId, TinyLinalg::numo_cDFloatId, lapack_complex_double, double, TinyLinalg::ZGESVD>::define_module_function(rb_mTinyLinalgLapack, "zgesvd");
|
@@ -245,6 +252,14 @@ extern "C" void Init_tiny_linalg(void) {
|
|
245
252
|
TinyLinalg::GESDD<TinyLinalg::numo_cSFloatId, TinyLinalg::numo_cSFloatId, float, float, TinyLinalg::SGESDD>::define_module_function(rb_mTinyLinalgLapack, "sgesdd");
|
246
253
|
TinyLinalg::GESDD<TinyLinalg::numo_cDComplexId, TinyLinalg::numo_cDFloatId, lapack_complex_double, double, TinyLinalg::ZGESDD>::define_module_function(rb_mTinyLinalgLapack, "zgesdd");
|
247
254
|
TinyLinalg::GESDD<TinyLinalg::numo_cSComplexId, TinyLinalg::numo_cSFloatId, lapack_complex_float, float, TinyLinalg::CGESDD>::define_module_function(rb_mTinyLinalgLapack, "cgesdd");
|
255
|
+
TinyLinalg::GETRF<TinyLinalg::numo_cDFloatId, double, TinyLinalg::DGETRF>::define_module_function(rb_mTinyLinalgLapack, "dgetrf");
|
256
|
+
TinyLinalg::GETRF<TinyLinalg::numo_cSFloatId, float, TinyLinalg::SGETRF>::define_module_function(rb_mTinyLinalgLapack, "sgetrf");
|
257
|
+
TinyLinalg::GETRF<TinyLinalg::numo_cDComplexId, lapack_complex_double, TinyLinalg::ZGETRF>::define_module_function(rb_mTinyLinalgLapack, "zgetrf");
|
258
|
+
TinyLinalg::GETRF<TinyLinalg::numo_cSComplexId, lapack_complex_float, TinyLinalg::CGETRF>::define_module_function(rb_mTinyLinalgLapack, "cgetrf");
|
259
|
+
TinyLinalg::GETRI<TinyLinalg::numo_cDFloatId, double, TinyLinalg::DGETRI>::define_module_function(rb_mTinyLinalgLapack, "dgetri");
|
260
|
+
TinyLinalg::GETRI<TinyLinalg::numo_cSFloatId, float, TinyLinalg::SGETRI>::define_module_function(rb_mTinyLinalgLapack, "sgetri");
|
261
|
+
TinyLinalg::GETRI<TinyLinalg::numo_cDComplexId, lapack_complex_double, TinyLinalg::ZGETRI>::define_module_function(rb_mTinyLinalgLapack, "zgetri");
|
262
|
+
TinyLinalg::GETRI<TinyLinalg::numo_cSComplexId, lapack_complex_float, TinyLinalg::CGETRI>::define_module_function(rb_mTinyLinalgLapack, "cgetri");
|
248
263
|
|
249
264
|
rb_define_alias(rb_singleton_class(rb_mTinyLinalgBlas), "znrm2", "dznrm2");
|
250
265
|
rb_define_alias(rb_singleton_class(rb_mTinyLinalgBlas), "cnrm2", "scnrm2");
|
data/lib/numo/tiny_linalg.rb
CHANGED
@@ -10,6 +10,52 @@ module Numo
|
|
10
10
|
module TinyLinalg
|
11
11
|
module_function
|
12
12
|
|
13
|
+
# Computes the inverse matrix of a square matrix.
|
14
|
+
#
|
15
|
+
# @param a [Numo::NArray] n-by-n square matrix.
|
16
|
+
# @param driver [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
17
|
+
# @param uplo [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
18
|
+
# @return [Numo::NArray] The inverse matrix of `a`.
|
19
|
+
def inv(a, driver: 'getrf', uplo: 'U') # rubocop:disable Lint/UnusedMethodArgument
|
20
|
+
raise ArgumentError, 'input array a must be 2-dimensional' if a.ndim != 2
|
21
|
+
raise ArgumentError, 'input array a must be square' if a.shape[0] != a.shape[1]
|
22
|
+
|
23
|
+
bchr = blas_char(a)
|
24
|
+
raise ArgumentError, "invalid array type: #{a.class}" if bchr == 'n'
|
25
|
+
|
26
|
+
getrf = "#{bchr}getrf".to_sym
|
27
|
+
getri = "#{bchr}getri".to_sym
|
28
|
+
|
29
|
+
lu, piv, info = Numo::TinyLinalg::Lapack.send(getrf, a.dup)
|
30
|
+
if info.zero?
|
31
|
+
Numo::TinyLinalg::Lapack.send(getri, lu, piv)[0]
|
32
|
+
elsif info.positive?
|
33
|
+
raise 'the factor U is singular, and the inverse matrix could not be computed.'
|
34
|
+
else
|
35
|
+
raise "the #{-info}-th argument of getrf had illegal value"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Solves linear equation `A * x = b` or `A * X = B` for `x` from square matrix `a`.
|
40
|
+
#
|
41
|
+
# @param a [Numo::NArray] The n-by-n square matrix (>= 2-dimensinal NArray).
|
42
|
+
# @param b [Numo::NArray] The n right-hand side vector, or n-by-nrhs right-hand side matrix (>= 1-dimensinal NArray).
|
43
|
+
# @param driver [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
44
|
+
# @param uplo [String] This argument is for compatibility with Numo::Linalg.solver, and is not used.
|
45
|
+
# @return [Numo::NArray] The solusion vector / matrix `x`.
|
46
|
+
def solve(a, b, driver: 'gen', uplo: 'U') # rubocop:disable Lint/UnusedMethodArgument
|
47
|
+
case blas_char(a, b)
|
48
|
+
when 'd'
|
49
|
+
Lapack.dgesv(a.dup, b.dup)[1]
|
50
|
+
when 's'
|
51
|
+
Lapack.sgesv(a.dup, b.dup)[1]
|
52
|
+
when 'z'
|
53
|
+
Lapack.zgesv(a.dup, b.dup)[1]
|
54
|
+
when 'c'
|
55
|
+
Lapack.cgesv(a.dup, b.dup)[1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
13
59
|
# Calculates the Singular Value Decomposition (SVD) of a matrix: `A = U * S * V^T`
|
14
60
|
#
|
15
61
|
# @param a [Numo::NArray] Matrix to be decomposed.
|
data/vendor/tmp/.gitkeep
ADDED
File without changes
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -35,31 +35,27 @@ extensions:
|
|
35
35
|
- ext/numo/tiny_linalg/extconf.rb
|
36
36
|
extra_rdoc_files: []
|
37
37
|
files:
|
38
|
-
- ".clang-format"
|
39
|
-
- ".husky/commit-msg"
|
40
|
-
- ".rubocop.yml"
|
41
38
|
- CHANGELOG.md
|
42
39
|
- CODE_OF_CONDUCT.md
|
43
|
-
- Gemfile
|
44
40
|
- LICENSE.txt
|
45
41
|
- README.md
|
46
|
-
-
|
47
|
-
-
|
42
|
+
- ext/numo/tiny_linalg/blas/dot.hpp
|
43
|
+
- ext/numo/tiny_linalg/blas/dot_sub.hpp
|
44
|
+
- ext/numo/tiny_linalg/blas/gemm.hpp
|
45
|
+
- ext/numo/tiny_linalg/blas/gemv.hpp
|
46
|
+
- ext/numo/tiny_linalg/blas/nrm2.hpp
|
48
47
|
- ext/numo/tiny_linalg/converter.hpp
|
49
|
-
- ext/numo/tiny_linalg/dot.hpp
|
50
|
-
- ext/numo/tiny_linalg/dot_sub.hpp
|
51
48
|
- ext/numo/tiny_linalg/extconf.rb
|
52
|
-
- ext/numo/tiny_linalg/
|
53
|
-
- ext/numo/tiny_linalg/
|
54
|
-
- ext/numo/tiny_linalg/
|
55
|
-
- ext/numo/tiny_linalg/
|
56
|
-
- ext/numo/tiny_linalg/
|
49
|
+
- ext/numo/tiny_linalg/lapack/gesdd.hpp
|
50
|
+
- ext/numo/tiny_linalg/lapack/gesv.hpp
|
51
|
+
- ext/numo/tiny_linalg/lapack/gesvd.hpp
|
52
|
+
- ext/numo/tiny_linalg/lapack/getrf.hpp
|
53
|
+
- ext/numo/tiny_linalg/lapack/getri.hpp
|
57
54
|
- ext/numo/tiny_linalg/tiny_linalg.cpp
|
58
55
|
- ext/numo/tiny_linalg/tiny_linalg.hpp
|
59
56
|
- lib/numo/tiny_linalg.rb
|
60
57
|
- lib/numo/tiny_linalg/version.rb
|
61
|
-
-
|
62
|
-
- package.json
|
58
|
+
- vendor/tmp/.gitkeep
|
63
59
|
homepage: https://github.com/yoshoku/numo-tiny_linalg
|
64
60
|
licenses:
|
65
61
|
- BSD-3-Clause
|
@@ -67,6 +63,7 @@ metadata:
|
|
67
63
|
homepage_uri: https://github.com/yoshoku/numo-tiny_linalg
|
68
64
|
source_code_uri: https://github.com/yoshoku/numo-tiny_linalg
|
69
65
|
changelog_uri: https://github.com/yoshoku/numo-tiny_linalg/blob/main/CHANGELOG.md
|
66
|
+
documentation_uri: https://yoshoku.github.io/numo-tiny_linalg/doc/
|
70
67
|
rubygems_mfa_required: 'true'
|
71
68
|
post_install_message:
|
72
69
|
rdoc_options: []
|
data/.clang-format
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
---
|
2
|
-
Language: Cpp
|
3
|
-
# BasedOnStyle: LLVM
|
4
|
-
AccessModifierOffset: -2
|
5
|
-
AlignAfterOpenBracket: Align
|
6
|
-
AlignConsecutiveMacros: false
|
7
|
-
AlignConsecutiveAssignments: false
|
8
|
-
AlignConsecutiveBitFields: false
|
9
|
-
AlignConsecutiveDeclarations: false
|
10
|
-
AlignEscapedNewlines: Right
|
11
|
-
AlignOperands: Align
|
12
|
-
AlignTrailingComments: true
|
13
|
-
AllowAllArgumentsOnNextLine: true
|
14
|
-
AllowAllConstructorInitializersOnNextLine: true
|
15
|
-
AllowAllParametersOfDeclarationOnNextLine: true
|
16
|
-
AllowShortEnumsOnASingleLine: true
|
17
|
-
AllowShortBlocksOnASingleLine: Never
|
18
|
-
AllowShortCaseLabelsOnASingleLine: false
|
19
|
-
AllowShortFunctionsOnASingleLine: All
|
20
|
-
AllowShortLambdasOnASingleLine: All
|
21
|
-
AllowShortIfStatementsOnASingleLine: true
|
22
|
-
AllowShortLoopsOnASingleLine: true
|
23
|
-
AlwaysBreakAfterDefinitionReturnType: None
|
24
|
-
AlwaysBreakAfterReturnType: None
|
25
|
-
AlwaysBreakBeforeMultilineStrings: false
|
26
|
-
AlwaysBreakTemplateDeclarations: MultiLine
|
27
|
-
BinPackArguments: true
|
28
|
-
BinPackParameters: true
|
29
|
-
BraceWrapping:
|
30
|
-
AfterCaseLabel: false
|
31
|
-
AfterClass: false
|
32
|
-
AfterControlStatement: Never
|
33
|
-
AfterEnum: false
|
34
|
-
AfterFunction: false
|
35
|
-
AfterNamespace: false
|
36
|
-
AfterObjCDeclaration: false
|
37
|
-
AfterStruct: false
|
38
|
-
AfterUnion: false
|
39
|
-
AfterExternBlock: false
|
40
|
-
BeforeCatch: false
|
41
|
-
BeforeElse: false
|
42
|
-
BeforeLambdaBody: false
|
43
|
-
BeforeWhile: false
|
44
|
-
IndentBraces: false
|
45
|
-
SplitEmptyFunction: true
|
46
|
-
SplitEmptyRecord: true
|
47
|
-
SplitEmptyNamespace: true
|
48
|
-
BreakBeforeBinaryOperators: None
|
49
|
-
BreakBeforeBraces: Attach
|
50
|
-
BreakBeforeInheritanceComma: false
|
51
|
-
BreakInheritanceList: BeforeColon
|
52
|
-
BreakBeforeTernaryOperators: true
|
53
|
-
BreakConstructorInitializersBeforeComma: false
|
54
|
-
BreakConstructorInitializers: BeforeColon
|
55
|
-
BreakAfterJavaFieldAnnotations: false
|
56
|
-
BreakStringLiterals: true
|
57
|
-
ColumnLimit: 0
|
58
|
-
CommentPragmas: '^ IWYU pragma:'
|
59
|
-
CompactNamespaces: false
|
60
|
-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
61
|
-
ConstructorInitializerIndentWidth: 4
|
62
|
-
ContinuationIndentWidth: 2
|
63
|
-
Cpp11BracedListStyle: false
|
64
|
-
DeriveLineEnding: true
|
65
|
-
DerivePointerAlignment: false
|
66
|
-
DisableFormat: false
|
67
|
-
ExperimentalAutoDetectBinPacking: false
|
68
|
-
FixNamespaceComments: true
|
69
|
-
ForEachMacros:
|
70
|
-
- foreach
|
71
|
-
- Q_FOREACH
|
72
|
-
- BOOST_FOREACH
|
73
|
-
IncludeBlocks: Preserve
|
74
|
-
IncludeCategories:
|
75
|
-
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
76
|
-
Priority: 2
|
77
|
-
SortPriority: 0
|
78
|
-
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
79
|
-
Priority: 3
|
80
|
-
SortPriority: 0
|
81
|
-
- Regex: '.*'
|
82
|
-
Priority: 1
|
83
|
-
SortPriority: 0
|
84
|
-
IncludeIsMainRegex: '(Test)?$'
|
85
|
-
IncludeIsMainSourceRegex: ''
|
86
|
-
IndentCaseLabels: false
|
87
|
-
IndentCaseBlocks: false
|
88
|
-
IndentGotoLabels: true
|
89
|
-
IndentPPDirectives: None
|
90
|
-
IndentExternBlock: AfterExternBlock
|
91
|
-
IndentWidth: 2
|
92
|
-
IndentWrappedFunctionNames: false
|
93
|
-
InsertTrailingCommas: None
|
94
|
-
JavaScriptQuotes: Leave
|
95
|
-
JavaScriptWrapImports: true
|
96
|
-
KeepEmptyLinesAtTheStartOfBlocks: true
|
97
|
-
MacroBlockBegin: ''
|
98
|
-
MacroBlockEnd: ''
|
99
|
-
MaxEmptyLinesToKeep: 1
|
100
|
-
NamespaceIndentation: None
|
101
|
-
ObjCBinPackProtocolList: Auto
|
102
|
-
ObjCBlockIndentWidth: 2
|
103
|
-
ObjCBreakBeforeNestedBlockParam: true
|
104
|
-
ObjCSpaceAfterProperty: false
|
105
|
-
ObjCSpaceBeforeProtocolList: true
|
106
|
-
PenaltyBreakAssignment: 2
|
107
|
-
PenaltyBreakBeforeFirstCallParameter: 19
|
108
|
-
PenaltyBreakComment: 300
|
109
|
-
PenaltyBreakFirstLessLess: 120
|
110
|
-
PenaltyBreakString: 1000
|
111
|
-
PenaltyBreakTemplateDeclaration: 10
|
112
|
-
PenaltyExcessCharacter: 1000000
|
113
|
-
PenaltyReturnTypeOnItsOwnLine: 60
|
114
|
-
PointerAlignment: Left
|
115
|
-
ReflowComments: true
|
116
|
-
SortIncludes: true
|
117
|
-
SortUsingDeclarations: true
|
118
|
-
SpaceAfterCStyleCast: false
|
119
|
-
SpaceAfterLogicalNot: false
|
120
|
-
SpaceAfterTemplateKeyword: true
|
121
|
-
SpaceBeforeAssignmentOperators: true
|
122
|
-
SpaceBeforeCpp11BracedList: false
|
123
|
-
SpaceBeforeCtorInitializerColon: true
|
124
|
-
SpaceBeforeInheritanceColon: true
|
125
|
-
SpaceBeforeParens: ControlStatements
|
126
|
-
SpaceBeforeRangeBasedForLoopColon: true
|
127
|
-
SpaceInEmptyBlock: false
|
128
|
-
SpaceInEmptyParentheses: false
|
129
|
-
SpacesBeforeTrailingComments: 1
|
130
|
-
SpacesInAngles: false
|
131
|
-
SpacesInConditionalStatement: false
|
132
|
-
SpacesInContainerLiterals: true
|
133
|
-
SpacesInCStyleCastParentheses: false
|
134
|
-
SpacesInParentheses: false
|
135
|
-
SpacesInSquareBrackets: false
|
136
|
-
SpaceBeforeSquareBrackets: false
|
137
|
-
Standard: Latest
|
138
|
-
StatementMacros:
|
139
|
-
- Q_UNUSED
|
140
|
-
- QT_REQUIRE_VERSION
|
141
|
-
TabWidth: 8
|
142
|
-
UseCRLF: false
|
143
|
-
UseTab: Never
|
144
|
-
WhitespaceSensitiveMacros:
|
145
|
-
- STRINGIZE
|
146
|
-
- PP_STRINGIZE
|
147
|
-
- BOOST_PP_STRINGIZE
|
148
|
-
...
|
149
|
-
|
data/.husky/commit-msg
DELETED
data/.rubocop.yml
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-rake
|
3
|
-
- rubocop-minitest
|
4
|
-
- rubocop-performance
|
5
|
-
|
6
|
-
AllCops:
|
7
|
-
TargetRubyVersion: 2.7
|
8
|
-
NewCops: enable
|
9
|
-
DisplayCopNames: true
|
10
|
-
DisplayStyleGuide: true
|
11
|
-
Exclude:
|
12
|
-
- 'tmp/**/*'
|
13
|
-
- 'vendor/**/*'
|
14
|
-
|
15
|
-
Gemspec/RequiredRubyVersion:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Layout/LineLength:
|
19
|
-
AllowedPatterns: ['(\A|\s)#']
|
20
|
-
|
21
|
-
Metrics/AbcSize:
|
22
|
-
Max: 40
|
23
|
-
Exclude:
|
24
|
-
- 'test/**/*'
|
25
|
-
|
26
|
-
Metrics/BlockLength:
|
27
|
-
Exclude:
|
28
|
-
- 'test/**/*'
|
29
|
-
- '*.gemspec'
|
30
|
-
|
31
|
-
Metrics/CyclomaticComplexity:
|
32
|
-
Max: 16
|
33
|
-
|
34
|
-
Metrics/MethodLength:
|
35
|
-
Max: 40
|
36
|
-
Exclude:
|
37
|
-
- 'test/**/*'
|
38
|
-
|
39
|
-
Metrics/PerceivedComplexity:
|
40
|
-
Max: 16
|
41
|
-
|
42
|
-
Naming/MethodParameterName:
|
43
|
-
Enabled: false
|
44
|
-
|
45
|
-
Style/GlobalVars:
|
46
|
-
Exclude:
|
47
|
-
- 'ext/**/*'
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in tiny_linalg.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem 'minitest', '~> 5.0'
|
9
|
-
gem 'rake', '~> 13.0'
|
10
|
-
gem 'rake-compiler'
|
11
|
-
gem 'rubocop', '~> 1.21'
|
12
|
-
gem 'rubocop-minitest', '~> 0.30.0'
|
13
|
-
gem 'rubocop-performance', '~> 1.17'
|
14
|
-
gem 'rubocop-rake', '~> 0.6.0'
|
15
|
-
gem 'yard', github: '/yoshoku/yard', branch: 'jquery-3.6.0'
|
data/Rakefile
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'rake/testtask'
|
5
|
-
|
6
|
-
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs << 'test'
|
8
|
-
t.libs << 'lib'
|
9
|
-
t.test_files = FileList['test/**/test_*.rb']
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'rubocop/rake_task'
|
13
|
-
|
14
|
-
RuboCop::RakeTask.new
|
15
|
-
|
16
|
-
require 'rake/extensiontask'
|
17
|
-
|
18
|
-
task build: :compile # rubocop:disable Rake/Desc
|
19
|
-
|
20
|
-
desc 'Run clang-format'
|
21
|
-
task :'clang-format' do
|
22
|
-
sh 'clang-format -style=file -Werror --dry-run ext/numo/tiny_linalg/*.cpp ext/numo/tiny_linalg/*.hpp'
|
23
|
-
end
|
24
|
-
|
25
|
-
Rake::ExtensionTask.new('tiny_linalg') do |ext|
|
26
|
-
ext.ext_dir = 'ext/numo/tiny_linalg'
|
27
|
-
ext.lib_dir = 'lib/numo/tiny_linalg'
|
28
|
-
end
|
29
|
-
|
30
|
-
task default: %i[clobber compile test rubocop]
|
data/commitlint.config.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
module.exports = { extends: ['@commitlint/config-conventional'] };
|
data/numo-tiny_linalg.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/numo/tiny_linalg/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'numo-tiny_linalg'
|
7
|
-
spec.version = Numo::TinyLinalg::VERSION
|
8
|
-
spec.authors = ['yoshoku']
|
9
|
-
spec.email = ['yoshoku@outlook.com']
|
10
|
-
|
11
|
-
spec.summary = <<~MSG
|
12
|
-
Numo::TinyLinalg is a subset library from Numo::Linalg consisting only of methods used in Machine Learning algorithms.
|
13
|
-
MSG
|
14
|
-
spec.description = <<~MSG
|
15
|
-
Numo::TinyLinalg is a subset library from Numo::Linalg consisting only of methods used in Machine Learning algorithms.
|
16
|
-
MSG
|
17
|
-
spec.homepage = 'https://github.com/yoshoku/numo-tiny_linalg'
|
18
|
-
spec.license = 'BSD-3-Clause'
|
19
|
-
|
20
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
21
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
22
|
-
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
23
|
-
|
24
|
-
# Specify which files should be added to the gem when it is released.
|
25
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(__dir__) do
|
27
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
29
|
-
end
|
30
|
-
end
|
31
|
-
spec.bindir = 'exe'
|
32
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
-
spec.require_paths = ['lib']
|
34
|
-
spec.extensions = ['ext/numo/tiny_linalg/extconf.rb']
|
35
|
-
|
36
|
-
# Uncomment to register a new dependency of your gem
|
37
|
-
spec.add_dependency 'numo-narray', '>= 0.9.1'
|
38
|
-
|
39
|
-
# For more information and examples about making a new gem, check out our
|
40
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
42
|
-
end
|
data/package.json
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "numo-tiny_linalg",
|
3
|
-
"repository": "git@github.com:yoshoku/numo-tiny_linalg.git",
|
4
|
-
"author": "Atsushi Tatsuma <yoshoku@outlook.com>",
|
5
|
-
"license": "BSD-3-Clause",
|
6
|
-
"private": true,
|
7
|
-
"scripts": {
|
8
|
-
"prepare": "husky install"
|
9
|
-
},
|
10
|
-
"devDependencies": {
|
11
|
-
"@commitlint/cli": "^17.6.1",
|
12
|
-
"@commitlint/config-conventional": "^17.6.1",
|
13
|
-
"husky": "^8.0.3"
|
14
|
-
}
|
15
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|