numo-linalg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +80 -0
  4. data/Rakefile +18 -0
  5. data/ext/numo/linalg/blas/blas.c +352 -0
  6. data/ext/numo/linalg/blas/cblas.h +575 -0
  7. data/ext/numo/linalg/blas/cblas_t.h +563 -0
  8. data/ext/numo/linalg/blas/depend.erb +23 -0
  9. data/ext/numo/linalg/blas/extconf.rb +67 -0
  10. data/ext/numo/linalg/blas/gen/cogen.rb +72 -0
  11. data/ext/numo/linalg/blas/gen/decl.rb +203 -0
  12. data/ext/numo/linalg/blas/gen/desc.rb +8138 -0
  13. data/ext/numo/linalg/blas/gen/erbpp2.rb +339 -0
  14. data/ext/numo/linalg/blas/gen/replace_cblas_h.rb +27 -0
  15. data/ext/numo/linalg/blas/gen/spec.rb +93 -0
  16. data/ext/numo/linalg/blas/numo_blas.h +41 -0
  17. data/ext/numo/linalg/blas/tmpl/axpy.c +75 -0
  18. data/ext/numo/linalg/blas/tmpl/copy.c +57 -0
  19. data/ext/numo/linalg/blas/tmpl/def_c.c +3 -0
  20. data/ext/numo/linalg/blas/tmpl/def_d.c +3 -0
  21. data/ext/numo/linalg/blas/tmpl/def_s.c +3 -0
  22. data/ext/numo/linalg/blas/tmpl/def_z.c +3 -0
  23. data/ext/numo/linalg/blas/tmpl/dot.c +68 -0
  24. data/ext/numo/linalg/blas/tmpl/ger.c +114 -0
  25. data/ext/numo/linalg/blas/tmpl/init_class.c +20 -0
  26. data/ext/numo/linalg/blas/tmpl/init_module.c +12 -0
  27. data/ext/numo/linalg/blas/tmpl/lib.c +40 -0
  28. data/ext/numo/linalg/blas/tmpl/mm.c +214 -0
  29. data/ext/numo/linalg/blas/tmpl/module.c +9 -0
  30. data/ext/numo/linalg/blas/tmpl/mv.c +194 -0
  31. data/ext/numo/linalg/blas/tmpl/nrm2.c +79 -0
  32. data/ext/numo/linalg/blas/tmpl/rot.c +65 -0
  33. data/ext/numo/linalg/blas/tmpl/rotm.c +82 -0
  34. data/ext/numo/linalg/blas/tmpl/scal.c +69 -0
  35. data/ext/numo/linalg/blas/tmpl/sdsdot.c +77 -0
  36. data/ext/numo/linalg/blas/tmpl/set_prefix.c +16 -0
  37. data/ext/numo/linalg/blas/tmpl/swap.c +57 -0
  38. data/ext/numo/linalg/blas/tmpl/syr.c +102 -0
  39. data/ext/numo/linalg/blas/tmpl/syr2.c +110 -0
  40. data/ext/numo/linalg/blas/tmpl/syr2k.c +129 -0
  41. data/ext/numo/linalg/blas/tmpl/syrk.c +132 -0
  42. data/ext/numo/linalg/lapack/depend.erb +23 -0
  43. data/ext/numo/linalg/lapack/extconf.rb +45 -0
  44. data/ext/numo/linalg/lapack/gen/cogen.rb +74 -0
  45. data/ext/numo/linalg/lapack/gen/desc.rb +151278 -0
  46. data/ext/numo/linalg/lapack/gen/replace_lapacke_h.rb +32 -0
  47. data/ext/numo/linalg/lapack/gen/spec.rb +104 -0
  48. data/ext/numo/linalg/lapack/lapack.c +387 -0
  49. data/ext/numo/linalg/lapack/lapacke.h +16425 -0
  50. data/ext/numo/linalg/lapack/lapacke_config.h +119 -0
  51. data/ext/numo/linalg/lapack/lapacke_mangling.h +17 -0
  52. data/ext/numo/linalg/lapack/lapacke_t.h +10550 -0
  53. data/ext/numo/linalg/lapack/numo_lapack.h +42 -0
  54. data/ext/numo/linalg/lapack/tmpl/def_c.c +3 -0
  55. data/ext/numo/linalg/lapack/tmpl/def_d.c +7 -0
  56. data/ext/numo/linalg/lapack/tmpl/def_s.c +7 -0
  57. data/ext/numo/linalg/lapack/tmpl/def_z.c +3 -0
  58. data/ext/numo/linalg/lapack/tmpl/fact.c +179 -0
  59. data/ext/numo/linalg/lapack/tmpl/geev.c +123 -0
  60. data/ext/numo/linalg/lapack/tmpl/gels.c +232 -0
  61. data/ext/numo/linalg/lapack/tmpl/gesv.c +149 -0
  62. data/ext/numo/linalg/lapack/tmpl/gesvd.c +189 -0
  63. data/ext/numo/linalg/lapack/tmpl/ggev.c +138 -0
  64. data/ext/numo/linalg/lapack/tmpl/gqr.c +121 -0
  65. data/ext/numo/linalg/lapack/tmpl/init_class.c +20 -0
  66. data/ext/numo/linalg/lapack/tmpl/init_module.c +12 -0
  67. data/ext/numo/linalg/lapack/tmpl/lange.c +79 -0
  68. data/ext/numo/linalg/lapack/tmpl/lib.c +40 -0
  69. data/ext/numo/linalg/lapack/tmpl/module.c +9 -0
  70. data/ext/numo/linalg/lapack/tmpl/syev.c +91 -0
  71. data/ext/numo/linalg/lapack/tmpl/sygv.c +104 -0
  72. data/ext/numo/linalg/lapack/tmpl/trf.c +276 -0
  73. data/ext/numo/linalg/numo_linalg.h +115 -0
  74. data/lib/numo/linalg.rb +3 -0
  75. data/lib/numo/linalg/function.rb +1008 -0
  76. data/lib/numo/linalg/linalg.rb +7 -0
  77. data/lib/numo/linalg/loader.rb +174 -0
  78. data/lib/numo/linalg/use/atlas.rb +3 -0
  79. data/lib/numo/linalg/use/lapack.rb +3 -0
  80. data/lib/numo/linalg/use/mkl.rb +3 -0
  81. data/lib/numo/linalg/use/openblas.rb +3 -0
  82. data/lib/numo/linalg/version.rb +5 -0
  83. data/numo-linalg.gemspec +26 -0
  84. data/spec/lapack_spec.rb +13 -0
  85. metadata +172 -0
@@ -0,0 +1,7 @@
1
+ require "numo/narray"
2
+ require "numo/linalg/blas"
3
+ require "numo/linalg/lapack"
4
+ require "numo/linalg/function"
5
+ require "numo/linalg/site_conf"
6
+ require "numo/linalg/loader"
7
+ require "numo/linalg/version"
@@ -0,0 +1,174 @@
1
+ require "fiddle"
2
+
3
+ module Numo
4
+ module Linalg
5
+ module Loader
6
+
7
+ @@libs = nil
8
+
9
+ module_function
10
+
11
+ def libs
12
+ @@libs
13
+ end
14
+
15
+ def load_mkl(path=nil,exc:true)
16
+ a = case path
17
+ when String; [path]
18
+ when Array ; path
19
+ when NilClass; [MKL_LIBPATH,""].compact
20
+ else raise ArgumentError,"invalid path"
21
+ end
22
+ a.each do |d|
23
+ if d.empty?
24
+ f_iomp5 = "libiomp5.so"
25
+ f_mkl_core = "libmkl_core.so"
26
+ f_intel_thread = "libmkl_intel_thread.so"
27
+ f_intel_lp64 = "libmkl_intel_lp64.so"
28
+ else
29
+ e = d.sub(/\/mkl\//, "/")
30
+ f_iomp5 = File.join(e,"libiomp5.so")
31
+ f_mkl_core = File.join(d,"libmkl_core.so")
32
+ f_intel_thread = File.join(d,"libmkl_intel_thread.so")
33
+ f_intel_lp64 = File.join(d,"libmkl_intel_lp64.so")
34
+ end
35
+ begin
36
+ Fiddle.dlopen(f_iomp5)
37
+ Fiddle.dlopen(f_mkl_core)
38
+ Fiddle.dlopen(f_intel_thread)
39
+ Blas.dlopen(f_intel_lp64)
40
+ Lapack.dlopen(f_intel_lp64)
41
+ @@libs = [ f_iomp5, f_mkl_core, f_intel_thread, f_intel_lp64 ]
42
+ if $DEBUG
43
+ $stderr.puts "Numo::Linalg: use #{f_intel_lp64}"
44
+ end
45
+ return true
46
+ rescue
47
+ end
48
+ end
49
+ if exc
50
+ raise RuntimeError, "cannot find MKL library"
51
+ end
52
+ false
53
+ end
54
+
55
+ def load_openblas(path=nil,exc:true)
56
+ a = case path
57
+ when String; [path]
58
+ when Array ; path
59
+ when NilClass; [OPENBLAS_LIBPATH,""].compact
60
+ else raise ArgumentError,"invalid path"
61
+ end
62
+ a.each do |d|
63
+ %w[libopenblaso.so libopenblasp.so libopenblas.so].each do |f|
64
+ f = File.join(d,f) if !d.empty?
65
+ begin
66
+ Blas.dlopen(f)
67
+ Lapack.dlopen(f)
68
+ @@libs = [ f ]
69
+ if $DEBUG
70
+ $stderr.puts "Numo::Linalg: use #{f}"
71
+ end
72
+ return true
73
+ rescue
74
+ end
75
+ end
76
+ end
77
+ if exc
78
+ raise RuntimeError, "cannot find OpenBLAS library"
79
+ end
80
+ false
81
+ end
82
+
83
+ def load_atlas(path=nil,exc:true)
84
+ a = case path
85
+ when String; [path]
86
+ when Array ; path
87
+ when NilClass; [ATLAS_LIBPATH,""].compact
88
+ else raise ArgumentError,"invalid path"
89
+ end
90
+ a.each do |d|
91
+ %w[libtatlas.so libatlas.so libsatlas.so].each do |f|
92
+ f = File.join(d,f) if !d.empty?
93
+ begin
94
+ Fiddle.dlopen(f)
95
+ Blas.dlopen(f)
96
+ l = LAPACK_LIBPATH
97
+ e = "liblapacke.so"
98
+ e = File.join(l,e) if l && !l.empty?
99
+ Lapack.dlopen(e)
100
+ @@libs = [ f, e ]
101
+ if $DEBUG
102
+ $stderr.puts "Numo::Linalg: use #{f}"
103
+ end
104
+ return true
105
+ rescue
106
+ end
107
+ end
108
+ end
109
+ if exc
110
+ raise RuntimeError, "cannot find ATLAS library"
111
+ end
112
+ false
113
+ end
114
+
115
+ def load_lapack(path=nil,exc:true)
116
+ a = case path
117
+ when String; [[path,path]]
118
+ when Array ; [path]
119
+ when NilClass
120
+ b = BLAS_LIBPATH || LAPACK_LIBPATH
121
+ l = LAPACK_LIBPATH || BLAS_LIBPATH
122
+ (b ? [[b,l]] : []) + ["",""]
123
+ else raise ArgumentError,"invalid path"
124
+ end
125
+ a.each do |arg|
126
+ b,l = *arg
127
+ if b.empty?
128
+ f_blas = "libblas.so"
129
+ f_cblas = "libcblas.so"
130
+ f_lapack = "liblapack.so"
131
+ f_lapacke = "liblapacke.so"
132
+ else
133
+ f_blas = File.join(b,"libblas.so")
134
+ f_cblas = File.join(b,"libcblas.so")
135
+ f_lapack = File.join(l,"liblapack.so")
136
+ f_lapacke = File.join(l,"liblapacke.so")
137
+ end
138
+ begin
139
+ Fiddle.dlopen(f_blas)
140
+ Fiddle.dlopen(f_lapack)
141
+ Blas.dlopen(f_cblas)
142
+ Lapack.dlopen(f_lapacke)
143
+ @@libs = [ f_blas, f_lapack, f_cblas, f_lapacke ]
144
+ if $DEBUG
145
+ $stderr.puts "Numo::Linalg: use #{f_blas} and #{f_lapack}"
146
+ end
147
+ return true
148
+ rescue
149
+ end
150
+ end
151
+ if exc
152
+ raise RuntimeError, "cannot find BLAS/LAPABK library"
153
+ end
154
+ false
155
+ end
156
+
157
+ def load_library
158
+ case BACKEND
159
+ when /mkl/i ; return if load_mkl(exc:false)
160
+ when /^openblas/i ; return if load_openblas(exc:false)
161
+ when /^atlas/i ; return if load_atlas(exc:false)
162
+ when /lapack|blas/i ; return if load_lapack(exc:false)
163
+ else
164
+ return if load_mkl(exc:false)
165
+ return if load_openblas(exc:false)
166
+ return if load_atlas(exc:false)
167
+ return if load_lapack(exc:false)
168
+ end
169
+ raise RuntimeError, "cannot find backend library for Numo::Linalg"
170
+ end
171
+
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,3 @@
1
+ require "numo/linalg/linalg"
2
+
3
+ Numo::Linalg::Loader.load_atlas
@@ -0,0 +1,3 @@
1
+ require "numo/linalg/linalg"
2
+
3
+ Numo::Linalg::Loader.load_lapack
@@ -0,0 +1,3 @@
1
+ require "numo/linalg/linalg"
2
+
3
+ Numo::Linalg::Loader.load_mkl
@@ -0,0 +1,3 @@
1
+ require "numo/linalg/linalg"
2
+
3
+ Numo::Linalg::Loader.load_openblas
@@ -0,0 +1,5 @@
1
+ module Numo
2
+ module Linalg
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require_relative "lib/numo/linalg/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "numo-linalg"
8
+ spec.version = Numo::Linalg::VERSION
9
+ spec.authors = ["Masahiro TANAKA"]
10
+ spec.email = ["masa16.tanaka@gmail.com"]
11
+ spec.description = %q{Linalg development version.}
12
+ spec.summary = %q{Linalg development version}
13
+ spec.homepage = "https://github.com/ruby-numo/numo-linalg"
14
+ spec.license = "BSD-3-Clause"
15
+
16
+ spec.files = `git ls-files Gemfile README.md Rakefile lib ext numo-linalg.gemspec spec`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.extensions = ["ext/numo/linalg/blas/extconf.rb",
21
+ "ext/numo/linalg/lapack/extconf.rb"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake", "~> 0"
25
+ spec.add_runtime_dependency "numo-narray", "~> 0.9.0.7"
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'numo/narray'
2
+ require File.join(File.dirname(__FILE__), "../ext/numo/lapack/lapack")
3
+ #Numo::NArray.debug = true
4
+
5
+ RSpec.configure do |config|
6
+ config.filter_run :focus
7
+ config.run_all_when_everything_filtered = true
8
+ end
9
+ #context :focus=>true do ... end
10
+
11
+ describe 'something' do
12
+ it{expect(Numo::LAPACK).to be_a(Module)}
13
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numo-linalg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro TANAKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: numo-narray
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0.7
55
+ description: Linalg development version.
56
+ email:
57
+ - masa16.tanaka@gmail.com
58
+ executables: []
59
+ extensions:
60
+ - ext/numo/linalg/blas/extconf.rb
61
+ - ext/numo/linalg/lapack/extconf.rb
62
+ extra_rdoc_files: []
63
+ files:
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - ext/numo/linalg/blas/blas.c
68
+ - ext/numo/linalg/blas/cblas.h
69
+ - ext/numo/linalg/blas/cblas_t.h
70
+ - ext/numo/linalg/blas/depend.erb
71
+ - ext/numo/linalg/blas/extconf.rb
72
+ - ext/numo/linalg/blas/gen/cogen.rb
73
+ - ext/numo/linalg/blas/gen/decl.rb
74
+ - ext/numo/linalg/blas/gen/desc.rb
75
+ - ext/numo/linalg/blas/gen/erbpp2.rb
76
+ - ext/numo/linalg/blas/gen/replace_cblas_h.rb
77
+ - ext/numo/linalg/blas/gen/spec.rb
78
+ - ext/numo/linalg/blas/numo_blas.h
79
+ - ext/numo/linalg/blas/tmpl/axpy.c
80
+ - ext/numo/linalg/blas/tmpl/copy.c
81
+ - ext/numo/linalg/blas/tmpl/def_c.c
82
+ - ext/numo/linalg/blas/tmpl/def_d.c
83
+ - ext/numo/linalg/blas/tmpl/def_s.c
84
+ - ext/numo/linalg/blas/tmpl/def_z.c
85
+ - ext/numo/linalg/blas/tmpl/dot.c
86
+ - ext/numo/linalg/blas/tmpl/ger.c
87
+ - ext/numo/linalg/blas/tmpl/init_class.c
88
+ - ext/numo/linalg/blas/tmpl/init_module.c
89
+ - ext/numo/linalg/blas/tmpl/lib.c
90
+ - ext/numo/linalg/blas/tmpl/mm.c
91
+ - ext/numo/linalg/blas/tmpl/module.c
92
+ - ext/numo/linalg/blas/tmpl/mv.c
93
+ - ext/numo/linalg/blas/tmpl/nrm2.c
94
+ - ext/numo/linalg/blas/tmpl/rot.c
95
+ - ext/numo/linalg/blas/tmpl/rotm.c
96
+ - ext/numo/linalg/blas/tmpl/scal.c
97
+ - ext/numo/linalg/blas/tmpl/sdsdot.c
98
+ - ext/numo/linalg/blas/tmpl/set_prefix.c
99
+ - ext/numo/linalg/blas/tmpl/swap.c
100
+ - ext/numo/linalg/blas/tmpl/syr.c
101
+ - ext/numo/linalg/blas/tmpl/syr2.c
102
+ - ext/numo/linalg/blas/tmpl/syr2k.c
103
+ - ext/numo/linalg/blas/tmpl/syrk.c
104
+ - ext/numo/linalg/lapack/depend.erb
105
+ - ext/numo/linalg/lapack/extconf.rb
106
+ - ext/numo/linalg/lapack/gen/cogen.rb
107
+ - ext/numo/linalg/lapack/gen/desc.rb
108
+ - ext/numo/linalg/lapack/gen/replace_lapacke_h.rb
109
+ - ext/numo/linalg/lapack/gen/spec.rb
110
+ - ext/numo/linalg/lapack/lapack.c
111
+ - ext/numo/linalg/lapack/lapacke.h
112
+ - ext/numo/linalg/lapack/lapacke_config.h
113
+ - ext/numo/linalg/lapack/lapacke_mangling.h
114
+ - ext/numo/linalg/lapack/lapacke_t.h
115
+ - ext/numo/linalg/lapack/numo_lapack.h
116
+ - ext/numo/linalg/lapack/tmpl/def_c.c
117
+ - ext/numo/linalg/lapack/tmpl/def_d.c
118
+ - ext/numo/linalg/lapack/tmpl/def_s.c
119
+ - ext/numo/linalg/lapack/tmpl/def_z.c
120
+ - ext/numo/linalg/lapack/tmpl/fact.c
121
+ - ext/numo/linalg/lapack/tmpl/geev.c
122
+ - ext/numo/linalg/lapack/tmpl/gels.c
123
+ - ext/numo/linalg/lapack/tmpl/gesv.c
124
+ - ext/numo/linalg/lapack/tmpl/gesvd.c
125
+ - ext/numo/linalg/lapack/tmpl/ggev.c
126
+ - ext/numo/linalg/lapack/tmpl/gqr.c
127
+ - ext/numo/linalg/lapack/tmpl/init_class.c
128
+ - ext/numo/linalg/lapack/tmpl/init_module.c
129
+ - ext/numo/linalg/lapack/tmpl/lange.c
130
+ - ext/numo/linalg/lapack/tmpl/lib.c
131
+ - ext/numo/linalg/lapack/tmpl/module.c
132
+ - ext/numo/linalg/lapack/tmpl/syev.c
133
+ - ext/numo/linalg/lapack/tmpl/sygv.c
134
+ - ext/numo/linalg/lapack/tmpl/trf.c
135
+ - ext/numo/linalg/numo_linalg.h
136
+ - lib/numo/linalg.rb
137
+ - lib/numo/linalg/function.rb
138
+ - lib/numo/linalg/linalg.rb
139
+ - lib/numo/linalg/loader.rb
140
+ - lib/numo/linalg/use/atlas.rb
141
+ - lib/numo/linalg/use/lapack.rb
142
+ - lib/numo/linalg/use/mkl.rb
143
+ - lib/numo/linalg/use/openblas.rb
144
+ - lib/numo/linalg/version.rb
145
+ - numo-linalg.gemspec
146
+ - spec/lapack_spec.rb
147
+ homepage: https://github.com/ruby-numo/numo-linalg
148
+ licenses:
149
+ - BSD-3-Clause
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.6.11
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Linalg development version
171
+ test_files:
172
+ - spec/lapack_spec.rb