[DRE-commits] [ruby-lapack] 01/04: Imported Upstream version 1.6
Youhei SASAKI
uwabami-guest at moszumanska.debian.org
Sun Mar 23 12:53:02 UTC 2014
This is an automated email from the git hooks/post-receive script.
uwabami-guest pushed a commit to branch master
in repository ruby-lapack.
commit c6d799500f30f5195d831dc1c7beba970ff673e3
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date: Sun Mar 23 16:55:20 2014 +0900
Imported Upstream version 1.6
---
Rakefile | 38 ++++++++++++++--------------
ext/extconf.rb | 2 +-
lib/numru/lapack.rb | 4 +++
samples/dpotrf.rb | 26 +++++++++++++++++++
tests/lin/sy/test_sysv.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 114 insertions(+), 19 deletions(-)
diff --git a/Rakefile b/Rakefile
index 9bfc3c5..d0d2205 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,21 +1,28 @@
require "rubygems"
+require "rubygems/package_task"
require "rake/clean"
-require "rake/gempackagetask"
require "rake/testtask"
-version = 1.5
+version = "1.6"
target_prefix = "numru"
# get options
-destdir = ENV["DESTDIR"]
-libdir = ENV["SITELIBDIR"] || Config::CONFIG["sitelibdir"]
-archdir = ENV["SITEARCHDIR"] || Config::CONFIG["sitearchdir"]
+destdir = ENV["DESTDIR"] || ""
+libdir = ENV["SITELIBDIR"] || RbConfig::CONFIG["sitelibdir"]
+archdir = ENV["SITEARCHDIR"] || RbConfig::CONFIG["sitearchdir"]
config_opts = ENV["CONFIG_OPTIONS"]
NAME = "lapack"
LIBS = FileList["lib/#{target_prefix}/*rb"]
-DLLIB = "ext/#{NAME}.so"
-so_file = File.join("lib", target_prefix, "#{NAME}.so")
+
+case RbConfig::CONFIG["host_os"]
+when /darwin/
+ extension = "bundle"
+else
+ extension = "so"
+end
+DLLIB = "ext/#{NAME}.#{extension}"
+so_file = File.join("lib", target_prefix, "#{NAME}.#{extension}")
task :default => so_file
@@ -56,7 +63,7 @@ task :install_rb => LIBS do
dst = File.join(destdir, libdir, target_prefix)
mkdir_p dst
LIBS.each do |lib|
- install lib, dst, :mode => 644
+ install lib, dst, :mode => 0644
end
end
@@ -99,23 +106,18 @@ EOL
end
-Rake::GemPackageTask.new(spec) do |pkg|
+Gem::PackageTask.new(spec) do |pkg|
pkg.need_tar_gz = true
pkg.need_tar_bz2 = true
end
-binary_pkg = "pkg/#{spec.name}-#{spec.version}-#{Config::CONFIG["arch"]}.gem"
+binary_pkg = "pkg/#{spec.name}-#{spec.version}-#{RbConfig::CONFIG["arch"]}.gem"
+gem_pkg = "pkg/#{spec.name}-#{spec.version}.gem"
desc "Build binary package"
task :binary_package => binary_pkg
-file binary_pkg => so_file do
- files = PKG_FILES.dup
- files.include so_file
- spec.platform = Gem::Platform::CURRENT
- spec.files = files
- spec.extensions = []
- Gem::Builder.new(spec).build
- mv File.basename(binary_pkg), binary_pkg
+file binary_pkg => gem_pkg do
+ system "gem compile --fat 1.8:ruby1.8,1.9:ruby1.9 #{gem_pkg}"
end
diff --git a/ext/extconf.rb b/ext/extconf.rb
index e7cbb43..fb06aa0 100644
--- a/ext/extconf.rb
+++ b/ext/extconf.rb
@@ -61,7 +61,7 @@ unless find_library("lapack", nil)
end
end
-sitearchdir = Config::CONFIG["sitearchdir"]
+sitearchdir = RbConfig::CONFIG["sitearchdir"]
dir_config("narray", sitearchdir, sitearchdir)
gem_path = nil
begin
diff --git a/lib/numru/lapack.rb b/lib/numru/lapack.rb
index ea4cfd6..252206c 100644
--- a/lib/numru/lapack.rb
+++ b/lib/numru/lapack.rb
@@ -1,3 +1,7 @@
+begin
+ require "rubygems"
+rescue LoadError
+end
require "narray"
require "numru/lapack.so"
diff --git a/samples/dpotrf.rb b/samples/dpotrf.rb
new file mode 100644
index 0000000..73ca47a
--- /dev/null
+++ b/samples/dpotrf.rb
@@ -0,0 +1,26 @@
+require "numru/lapack"
+
+uplo = "L"
+p a = NArray[[ 4.16, -3.12, 0.56, -0.10],
+ [-3.12, 5.03, -0.83, 1.18],
+ [ 0.56, -0.83, 0.76, 0.34],
+ [-0.10, 1.18, 0.34, 1.18]]
+a_org = a.dup
+info, a = NumRu::Lapack.dpotrf(uplo, a)
+
+p info
+p a
+
+for i in 0...a.shape[0]
+ for j in 0...i
+ a[j,i] = 0.0
+ end
+end
+
+a = NMatrix.ref(a)
+
+if (NArray.ref(a.transpose * a) - a_org).abs.gt(1.0e-10).count_true == 0
+ p "OK"
+else
+ p "NG"
+end
diff --git a/tests/lin/sy/test_sysv.rb b/tests/lin/sy/test_sysv.rb
new file mode 100644
index 0000000..c81c6b7
--- /dev/null
+++ b/tests/lin/sy/test_sysv.rb
@@ -0,0 +1,63 @@
+$:.push File.dirname(__FILE__) + "/../.."
+require "lapack_test"
+
+class SysvTest < Test::Unit::TestCase
+ include LapackTest
+
+ def setup
+ @a = Hash.new
+ @b = Hash.new
+ @b_exp = Hash.new
+ @ipiv_exp = Hash.new
+
+ @a[:r] = NMatrix[[-1.81, 2.06, 0.63, -1.15],
+ [ 2.06, 1.15, 1.87, 4.20],
+ [ 0.63, 1.87, -0.21, 3.87],
+ [-1.15, 4.20, 3.87, 2.07]].to_lm
+ @b[:r] = NVector[[0.96, 6.07, 8.38, 9.50]]
+ @b_exp[:r] = NArray[[-5.0, -2.0, 1.0, 4.0]]
+ @ipiv_exp[:r] = NArray[1, 2, -2, -2]
+
+ @a[:c] = NMatrix[[-0.56+0.12*I, -1.54-2.86*I, 5.32-1.59*I, 3.80+0.92*I],
+ [-1.54-2.86*I, -2.83-0.03*I, -3.52+0.58*I, -7.86-2.96*I],
+ [ 5.32-1.59*I, -3.52+0.58*I, 8.86+1.81*I, 5.14-0.64*I],
+ [ 3.80+0.92*I, -7.86-2.96*I, 5.14-0.64*I, -0.39-0.71*I]].to_lm
+ @b[:c] = NVector[[-6.43+19.24*I, -0.49-1.47*I, -48.18+66.0*I, -55.64+41.22*I]]
+ @b_exp[:c] = NArray[[-4.0+3.0*I, 3.0-2.0*I, -2.0+5.0*I, 1.0-1.0*I]]
+ @ipiv_exp[:c] = NArray[1, 2, -2, -2]
+ end
+
+ %w(s d c z).each do |x|
+ method = "#{x}sysv"
+ rc = LapackTest.get_rc(x)
+
+ define_method("test_#{method}") do
+ ipiv, work, info, a, b = NumRu::Lapack.send(method, "U", @a[rc], @b[rc])
+ assert_equal 0, info
+ assert_narray @b_exp[rc], b
+ assert_narray @ipiv_exp[rc], ipiv
+ end
+
+ define_method("test_#{method}_inquiring_lwork") do
+ rank, work, info, = NumRu::Lapack.send(method, "U", @a[rc], @b[rc], :lwork => -1)
+ assert_equal 0, info
+ lwork = get_int(work[0])
+ ipiv, work, info, a, b = NumRu::Lapack.send(method, "U", @a[rc], @b[rc], :lwork => lwork)
+ assert_equal 0, info
+ assert_equal lwork, get_int(work[0])
+ assert_narray @b_exp[rc], b
+ assert_narray @ipiv_exp[rc], ipiv
+ end
+
+ define_method("test_#{method}_inquiring_lwork_oldargstyle") do
+ rank, work, info, = NumRu::Lapack.send(method, "U", @a[rc], @b[rc], :lwork => -1)
+ assert_equal 0, info
+ lwork = get_int(work[0])
+ rank, work, info, = NumRu::Lapack.send(method, "U", @a[rc], @b[rc], -1)
+ assert_equal 0, info
+ assert_equal lwork, get_int(work[0])
+ end
+
+ end
+
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-lapack.git
More information about the Pkg-ruby-extras-commits
mailing list