numo-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d78b166ec210437736f2153cbee645d9cb1fe43c99ebfdc8831e15b1fa46249f
4
- data.tar.gz: ce602ae09a67e518a5e7bc539256b2e35ebc342c528860eb9a527d7446d4c871
3
+ metadata.gz: 8a9f783654dbe1c2f8ca4dbeef4030053d8e8c92a99f1ccf0fa0ecd551c90f90
4
+ data.tar.gz: 46f3558e6bd86db15fb0d3ab9558e1f4e565ca844db500684b9eaac0e6ec57c7
5
5
  SHA512:
6
- metadata.gz: 79a092556b215e5a3667aab25ba97dc752fe3223dcca95d0a4018c71dd934d0eddad7816a94f87eb230e55cac5397ff430bdfb3d4ba8178eb443cf9f9dbd82da
7
- data.tar.gz: 13774cf94a8b2724217bb3f00e6ed24337ad5c64db83f873bb5dfb7e6bf9b606311013d7eaeca8fcf99c4a2d98837cc2259d5389f5a9da1a784bb3d1d2c18176
6
+ metadata.gz: f1c478c9f017babd63b40dcea4eeb6ca9222226f680cc6870b01c1f305f54080ab7c035ead34c39d9f70aa431c6b2d9c9ec1be0642f7bab66eea32ee97c39363
7
+ data.tar.gz: d55a4aa11afffbb51486007df3c80b221a3e90e990e86b76eadc996d560abf8d3e16df62aa25e3f65f050175dca8d45d5b791c1dc4b2b2c3ac66031da0c70c7b
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Numo::Linalg : Linear Algebra library with BLAS/LAPACK binding to Numo::NArray
2
2
 
3
- [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/ruby-numo/linalg)
4
- [![Build Status](https://travis-ci.org/ruby-numo/linalg.svg?branch=master)](https://travis-ci.org/ruby-numo/linalg)
3
+ [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/ruby-numo/numo-linalg)
4
+ [![Build Status](https://travis-ci.org/ruby-numo/numo-linalg.svg?branch=master)](https://travis-ci.org/ruby-numo/numo-linalg)
5
5
 
6
- [GitHub](https://github.com/ruby-numo/linalg) |
7
- [RubyGems](https://github.com/ruby-numo/linalg)
6
+ [GitHub](https://github.com/ruby-numo/numo-linalg) |
7
+ [RubyGems](https://rubygems.org/gems/numo-linalg)
8
8
 
9
9
  Under development!
10
10
 
@@ -49,7 +49,7 @@ This desgin allows you to change backend libraries without re-compiling.
49
49
  * [Intel MKL](https://software.intel.com/intel-mkl)
50
50
 
51
51
  * Note that the performance depends on the backend library as shown in
52
- [benchmark](https://github.com/ruby-numo/linalg/tree/master/bench).
52
+ [benchmark](https://github.com/ruby-numo/numo-linalg/tree/master/bench).
53
53
 
54
54
  * Install Numo::Linalg
55
55
 
@@ -60,7 +60,7 @@ $ gem install numo-linalg
60
60
  or
61
61
 
62
62
  ```shell
63
- $ git clone https://github.com/ruby-numo/linalg.git
63
+ $ git clone https://github.com/ruby-numo/numo-linalg.git
64
64
  $ cd linalg
65
65
  $ rake build
66
66
  $ gem install pkg/numo-linalg-*.gem
@@ -74,7 +74,7 @@ $ gem install pkg/numo-linalg-*.gem
74
74
  require "numo/linalg"
75
75
  ```
76
76
 
77
- * Read also instruction for [Selecting Backend Library](https://github.com/ruby-numo/linalg/tree/master/doc/select-backend.md).
77
+ * Read also instruction for [Selecting Backend Library](https://github.com/ruby-numo/numo-linalg/tree/master/doc/select-backend.md).
78
78
 
79
79
  ## Authors
80
80
 
@@ -1,14 +1,12 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  pwd = File.dirname(__FILE__)
4
- #libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
5
- #$LOAD_PATH.unshift libpath
6
4
 
7
5
  require_relative "./decl"
8
6
 
9
7
  while true
10
8
  if ARGV[0] == "-l"
11
- require "erbpp/line_number"
9
+ $line_number = true
12
10
  ARGV.shift
13
11
  elsif ARGV[0] == "-o"
14
12
  ARGV.shift
@@ -31,12 +29,12 @@ erb_dir = ["../tmpl"]
31
29
  erb_dir.map!{|d| File.join(pwd,d)}
32
30
 
33
31
  code = DefLib.new do
32
+ set line_number: $line_number
34
33
  set erb_dir: erb_dir
35
34
  set erb_suffix: ".c"
36
35
  set ns_var: "mN"
37
36
 
38
37
  set file_name: $output || ""
39
- #set include_files: ["numo/types/#{type_name}.h"]
40
38
  set lib_name: "numo_linalg_blas_"+blas_char
41
39
 
42
40
  def_module do
@@ -1,4 +1,4 @@
1
- require_relative './erbpp2'
1
+ require_relative 'erbpp2'
2
2
 
3
3
  module Decl
4
4
 
@@ -0,0 +1,132 @@
1
+ require 'erb'
2
+
3
+ class ErbPP
4
+
5
+ class CountLnString < String
6
+
7
+ def initialize(filename)
8
+ @filename = filename
9
+ @lnchar = "\n"
10
+ @buf = ""
11
+ @str = ""
12
+ @countln = 1
13
+ @current = 1
14
+ super("\n"+report_line)
15
+ end
16
+
17
+ def report_line
18
+ "#line #{@current} \"#{@filename}\"\n"
19
+ end
20
+
21
+ def concat0(s)
22
+ ln(caller[0])
23
+ @buf.concat(s)
24
+ @str.concat(s)
25
+ end
26
+
27
+ def concat1(s)
28
+ ln(caller[0])
29
+ @buf.concat(s)
30
+ end
31
+
32
+ def ln(status=nil)
33
+ case status
34
+ when /:(\d+):/
35
+ n = $1.to_i
36
+ else
37
+ n = status.to_i
38
+ end
39
+ return if n == @current
40
+ if @current != @countln || @postpone
41
+ if /\A\s*\z/ =~ @str || /\A#line / =~ @buf
42
+ @postpone = true
43
+ elsif @in_comment
44
+ @postpone = false
45
+ else
46
+ if self[-1] != "\n"
47
+ concat("\n")
48
+ end
49
+ concat(report_line)
50
+ @postpone = false
51
+ end
52
+ end
53
+ concat(@buf)
54
+
55
+ b = @buf.gsub(/".*?(?<!\\)"/,'""')
56
+ /^.*(\/\*)(.*?)$/ =~ b
57
+ x = $2
58
+ /^.*(\*\/)(.*?)$/ =~ b
59
+ y = $2
60
+ if x
61
+ if y
62
+ if x.size < y.size
63
+ #:in_comment
64
+ @in_comment = true
65
+ else
66
+ #:out_comment
67
+ @in_comment = false
68
+ end
69
+ else
70
+ #:in_comment
71
+ @in_comment = true
72
+ end
73
+ else
74
+ if y
75
+ #:out_comment
76
+ @in_comment = false
77
+ else
78
+ #:keep
79
+ end
80
+ end
81
+
82
+ @countln = @current + @buf.count(@lnchar)
83
+ @current = n
84
+ @buf = ""
85
+ @str = ""
86
+ end
87
+
88
+ def d(s)
89
+ p [s, [x,y], r]
90
+ r
91
+ end
92
+
93
+ def final
94
+ ln(caller[0])
95
+ concat(@buf)
96
+ end
97
+
98
+ end
99
+
100
+ class ERBLN
101
+
102
+ def initialize(str, filename, trim_mode=nil, eoutvar='_erbout')
103
+ @filename = filename
104
+ compiler = ERB::Compiler.new(trim_mode)
105
+ set_eoutvar(compiler, eoutvar)
106
+ @src, @enc = *compiler.compile(str)
107
+ end
108
+
109
+ def set_eoutvar(compiler, eoutvar = '_erbout')
110
+ compiler.put_cmd = "#{eoutvar}.concat0"
111
+ compiler.insert_cmd = "#{eoutvar}.concat1"
112
+ compiler.pre_cmd = ["#{eoutvar} = CountLnString.new(#{@filename.inspect})"]
113
+ compiler.post_cmd = ["#{eoutvar}.final"]
114
+ end
115
+
116
+ def run(b)
117
+ print self.result(b)
118
+ end
119
+
120
+ def result(b)
121
+ #open("tmpout","a") do |f|
122
+ # f.puts "\n#file:#{@filename}"
123
+ # f.puts @src
124
+ #end
125
+ eval(@src, b, (@filename || '(erb)'), 0)
126
+ end
127
+
128
+ #require "fileutils"
129
+ #FileUtils.rm_f("tmpout")
130
+ end
131
+
132
+ end
@@ -1,4 +1,5 @@
1
1
  require "erb"
2
+ require_relative "erbln"
2
3
 
3
4
  class ErbPP
4
5
 
@@ -66,8 +67,12 @@ class ErbPP
66
67
  Dir.glob(x).each do |dir|
67
68
  path = File.join(dir,file)
68
69
  if File.exist?(path)
69
- erb = ERB.new(File.read(path), safe_level, trim_mode)
70
- erb.filename = path
70
+ if get(:line_number)
71
+ erb = ERBLN.new(File.read(path), path, trim_mode)
72
+ else
73
+ erb = ERB.new(File.read(path), safe_level, trim_mode)
74
+ erb.filename = path
75
+ end
71
76
  return erb
72
77
  end
73
78
  end
@@ -1,14 +1,12 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  pwd = File.dirname(__FILE__)
4
- #libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
5
- #$LOAD_PATH.unshift libpath
6
4
 
7
5
  require_relative "../../blas/gen/decl"
8
6
 
9
7
  while true
10
8
  if ARGV[0] == "-l"
11
- require "erbpp/line_number"
9
+ $line_number = true
12
10
  ARGV.shift
13
11
  elsif ARGV[0] == "-o"
14
12
  ARGV.shift
@@ -31,6 +29,7 @@ erb_dir = ["../tmpl"]
31
29
  erb_dir.map!{|d| File.join(pwd,d)}
32
30
 
33
31
  code = DefLib.new do
32
+ set line_number: $line_number
34
33
  set erb_dir: erb_dir
35
34
  set erb_suffix: ".c"
36
35
  set ns_var: "mN"
@@ -0,0 +1,142 @@
1
+ require 'fiddle'
2
+ require 'rbconfig'
3
+ require 'numo/linalg/linalg'
4
+
5
+ module Numo
6
+ module Linalg
7
+ module Autoloader
8
+
9
+ @@libs = nil
10
+
11
+ module_function
12
+
13
+ def libs
14
+ @@libs
15
+ end
16
+
17
+ # Load backend libraries for Numo::Linalg automatically.
18
+ #
19
+ # @return [String] name of loaded backend library (mkl/openblas/lapack)
20
+ def load_library
21
+ mkl_dirs = ['/opt/intel/lib', '/opt/intel/lib64', '/opt/intel/mkl/lib', '/opt/intel/mkl/lib64']
22
+ openblas_dirs = ['/opt/openblas/lib', '/opt/openblas/lib64', '/usr/local/opt/openblas/lib']
23
+ atlas_dirs = ['/opt/atlas/lib', '/opt/atlas/lib64',
24
+ '/usr/lib/atlas', '/usr/lib64/atlas', '/usr/local/opt/atlas/lib']
25
+ lapacke_dirs = ['/opt/lapack/lib', '/opt/lapack/lib64', '/opt/local/lib/lapack',
26
+ '/usr/local/opt/lapack/lib']
27
+ opt_dirs = ['/opt/local/lib', '/opt/local/lib64', '/opt/lib', '/opt/lib64']
28
+ base_dirs = ['/usr/local/lib', '/usr/local/lib64', '/usr/lib', '/usr/lib64']
29
+ base_dirs.unshift(*ENV['LD_LIBRARY_PATH'].split(':')) unless ENV['LD_LIBRARY_PATH'].nil?
30
+
31
+ mkl_libs = find_mkl_libs([*base_dirs, *opt_dirs, *mkl_dirs])
32
+ openblas_libs = find_openblas_libs([*base_dirs, *opt_dirs, *openblas_dirs])
33
+ atlas_libs = find_atlas_libs([*base_dirs, *opt_dirs, *atlas_dirs, *lapacke_dirs])
34
+ lapack_libs = find_lapack_libs([*base_dirs, *opt_dirs, *lapacke_dirs])
35
+
36
+ @@libs = nil
37
+ if !mkl_libs.value?(nil)
38
+ open_mkl_libs(mkl_libs)
39
+ @@libs = mkl_libs.values
40
+ 'mkl'
41
+ elsif !openblas_libs.value?(nil)
42
+ open_openblas_libs(openblas_libs)
43
+ @@libs = openblas_libs.values.uniq
44
+ 'openblas'
45
+ elsif !atlas_libs.value?(nil)
46
+ open_atlas_libs(atlas_libs)
47
+ @@libs = atlas_libs.values.uniq
48
+ 'atlas'
49
+ elsif !lapack_libs.value?(nil)
50
+ open_lapack_libs(lapack_libs)
51
+ @@libs = lapack_libs.values.uniq
52
+ 'lapack'
53
+ else
54
+ raise 'cannot find MKL/OpenBLAS/ATLAS/BLAS-LAPACK library'
55
+ end
56
+ end
57
+
58
+ def detect_library_extension
59
+ case RbConfig::CONFIG['host_os']
60
+ when /mswin|msys|mingw|cygwin/
61
+ 'dll'
62
+ when /darwin|mac os/
63
+ 'dylib'
64
+ else
65
+ 'so'
66
+ end
67
+ end
68
+
69
+ def find_libs(lib_names, lib_dirs)
70
+ lib_ext = detect_library_extension
71
+ lib_arr = lib_names.map do |l|
72
+ [l.to_sym, lib_dirs.map { |d| "#{d}/lib#{l}.#{lib_ext}" }
73
+ .keep_if { |f| File.exist?(f) }.first]
74
+ end
75
+ Hash[*lib_arr.flatten]
76
+ end
77
+
78
+ def find_mkl_libs(lib_dirs)
79
+ lib_names = %w[iomp5 mkl_core mkl_intel_thread mkl_intel_lp64]
80
+ find_libs(lib_names, lib_dirs)
81
+ end
82
+
83
+ def find_openblas_libs(lib_dirs)
84
+ lib_names = %w[openblas lapacke]
85
+ openblas_libs = find_libs(lib_names, lib_dirs)
86
+ openblas_libs[:lapacke] = openblas_libs[:openblas] if openblas_libs[:lapacke].nil?
87
+ openblas_libs
88
+ end
89
+
90
+ def find_atlas_libs(lib_dirs)
91
+ lib_names = %w[tatlas atlas satlas cblas lapacke]
92
+ atlas_libs = find_libs(lib_names, lib_dirs)
93
+ atlas_libs[:atlas] = atlas_libs[:tatlas] unless atlas_libs[:tatlas].nil?
94
+ atlas_libs[:atlas] = atlas_libs[:satlas] if atlas_libs[:atlas].nil?
95
+ atlas_libs[:cblas] = atlas_libs[:atlas] if atlas_libs[:cblas].nil?
96
+ atlas_libs.delete(:tatlas)
97
+ atlas_libs.delete(:satlas)
98
+ atlas_libs
99
+ end
100
+
101
+ def find_lapack_libs(lib_dirs)
102
+ lib_names = %w[blas cblas lapack lapacke]
103
+ lapack_libs = find_libs(lib_names, lib_dirs)
104
+ lapack_libs[:cblas] = lapack_libs[:blas] if lapack_libs[:cblas].nil?
105
+ lapack_libs
106
+ end
107
+
108
+ def open_mkl_libs(mkl_libs)
109
+ Fiddle.dlopen(mkl_libs[:iomp5])
110
+ Fiddle.dlopen(mkl_libs[:mkl_core])
111
+ Fiddle.dlopen(mkl_libs[:mkl_intel_thread])
112
+ Fiddle.dlopen(mkl_libs[:mkl_intel_lp64])
113
+ Numo::Linalg::Blas.dlopen(mkl_libs[:mkl_intel_lp64])
114
+ Numo::Linalg::Lapack.dlopen(mkl_libs[:mkl_intel_lp64])
115
+ end
116
+
117
+ def open_openblas_libs(openblas_libs)
118
+ Numo::Linalg::Blas.dlopen(openblas_libs[:openblas])
119
+ Numo::Linalg::Lapack.dlopen(openblas_libs[:lapacke])
120
+ end
121
+
122
+ def open_atlas_libs(atlas_libs)
123
+ Fiddle.dlopen(atlas_libs[:atlas])
124
+ Numo::Linalg::Blas.dlopen(atlas_libs[:cblas])
125
+ Numo::Linalg::Lapack.dlopen(atlas_libs[:lapacke])
126
+ end
127
+
128
+ def open_lapack_libs(lapack_libs)
129
+ Fiddle.dlopen(lapack_libs[:blas])
130
+ Fiddle.dlopen(lapack_libs[:lapack])
131
+ Numo::Linalg::Blas.dlopen(lapack_libs[:cblas])
132
+ Numo::Linalg::Lapack.dlopen(lapack_libs[:lapacke])
133
+ end
134
+
135
+ private_class_method :detect_library_extension,
136
+ :find_libs, :find_mkl_libs, :find_openblas_libs, :find_atlas_libs, :find_lapack_libs,
137
+ :open_mkl_libs, :open_openblas_libs, :open_atlas_libs, :open_lapack_libs
138
+ end
139
+ end
140
+ end
141
+
142
+ Numo::Linalg::Autoloader.load_library
@@ -992,17 +992,17 @@ module Numo; module Linalg
992
992
  end
993
993
  end
994
994
 
995
- private
996
-
997
995
  # @!visibility private
998
996
  def _make_complex_eigvecs(w, vin) # :nodoc:
999
997
  v = w.class.cast(vin)
1000
998
  # broadcast to vin.shape
1001
- m = (w.imag > 0 | Bit.zeros(*vin.shape)).where
999
+ m = ((w.imag > 0) | Bit.zeros(*vin.shape)).where
1002
1000
  v[m].imag = vin[m+1]
1003
1001
  v[m+1] = v[m].conj
1004
1002
  v
1005
1003
  end
1006
1004
 
1005
+ private_class_method :_make_complex_eigvecs
1006
+
1007
1007
  end
1008
1008
  end
@@ -1,5 +1,5 @@
1
1
  module Numo
2
2
  module Linalg
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake", "~> 0"
25
- spec.add_runtime_dependency "numo-narray", "~> 0.9.0"
25
+ spec.add_runtime_dependency "numo-narray", ">= 0.9.0.7"
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-linalg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-28 00:00:00.000000000 Z
12
+ date: 2018-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,16 +43,16 @@ dependencies:
43
43
  name: numo-narray
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 0.9.0
48
+ version: 0.9.0.7
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.9.0
55
+ version: 0.9.0.7
56
56
  description: Ruby/Numo Linear Algebra library with interface to BLAS/LAPACK.
57
57
  email:
58
58
  - masa16.tanaka@gmail.com
@@ -73,6 +73,7 @@ files:
73
73
  - ext/numo/linalg/blas/gen/cogen.rb
74
74
  - ext/numo/linalg/blas/gen/decl.rb
75
75
  - ext/numo/linalg/blas/gen/desc.rb
76
+ - ext/numo/linalg/blas/gen/erbln.rb
76
77
  - ext/numo/linalg/blas/gen/erbpp2.rb
77
78
  - ext/numo/linalg/blas/gen/replace_cblas_h.rb
78
79
  - ext/numo/linalg/blas/gen/spec.rb
@@ -135,6 +136,7 @@ files:
135
136
  - ext/numo/linalg/lapack/tmpl/trf.c
136
137
  - ext/numo/linalg/numo_linalg.h
137
138
  - lib/numo/linalg.rb
139
+ - lib/numo/linalg/autoloader.rb
138
140
  - lib/numo/linalg/function.rb
139
141
  - lib/numo/linalg/linalg.rb
140
142
  - lib/numo/linalg/loader.rb