[narray-miss] 02/08: Imported Upstream version 1.3.1

Youhei SASAKI uwabami-guest at moszumanska.debian.org
Thu Jul 21 04:51:57 UTC 2016


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch master
in repository narray-miss.

commit 4df71c1055f0fa7a05c49118ceddb3f376a37202
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Sun Jul 3 19:17:31 2016 +0900

    Imported Upstream version 1.3.1
---
 lib/narray_miss/narray_miss.rb | 84 ++++++++++++++++++++++--------------------
 lib/narray_miss/version.rb     |  2 +-
 metadata.yml                   | 68 ----------------------------------
 narray_miss.gemspec            |  3 +-
 4 files changed, 48 insertions(+), 109 deletions(-)

diff --git a/lib/narray_miss/narray_miss.rb b/lib/narray_miss/narray_miss.rb
index 0071431..cd19326 100644
--- a/lib/narray_miss/narray_miss.rb
+++ b/lib/narray_miss/narray_miss.rb
@@ -34,18 +34,26 @@ To use NArrayMiss class, you need invoking "require 'narray_miss.rb'" in your sc
 
 =end
 
-begin
-  require 'numru/narray'
+if defined?(NumRu::NArray)
   NARRAY = NumRu::NArray
-rescue LoadError
-  err = $!
+elsif defined?(NArray)
+  NARRAY = NArray
+else
+
   begin
     require 'narray'
     NARRAY = NArray
   rescue LoadError
-    STDERR.puts "You should install numru-narray or narray"
-    raise err
+    err = $!
+    begin
+      require 'numru/narray'
+      NARRAY = NumRu::NArray
+    rescue LoadError
+      STDERR.puts "You should install numru-narray or narray"
+      raise err
+    end
   end
+
 end
 
 
@@ -185,7 +193,7 @@ go back to ((<Index>))
     array = arg[0]
     if Numeric===array then array = NARRAY[array] end
     if Array===array then array = NARRAY.to_na(array) end
-    if !array.is_a?(NARRAY) then
+    unless array.is_a?(NARRAY) || /NArray/=~ array.class.to_s then
       raise("argument must be Numeric, NArray or Array")
     end
 
@@ -193,29 +201,26 @@ go back to ((<Index>))
       mask = arg[1]
       if Numeric===mask then mask = array.ne(mask) end
       if Array===mask then
-	mask = NARRAY.to_na(mask).ne(0)
+	mask = array.class.to_na(mask).ne(0)
       end
       if mask.class == FalseClass then
-	mask = NARRAY.byte(*array.shape)
+	mask = array.class.byte(*array.shape)
       end
       if mask.class == TrueClass then
-	mask = NARRAY.byte(*array.shape).fill(1)
+	mask = array.class.byte(*array.shape).fill(1)
       end
-      if !(NARRAY===mask && mask.typecode==BYTE) then
+      if !(array.class===mask && mask.typecode==BYTE) then
 	  raise("mask must be Numeric, Array, true, false or NArray(byte)")
       end
       if mask.length!=array.length
         raise "mask.length must be same as array.length"
       end
     else
-      mask = NARRAY.byte(*array.shape).fill(1)
+      mask = array.class.byte(*array.shape).fill(1)
     end
     __new__(array,mask)
   end
   def self.to_nam(*arg)
-    if !(Numeric===arg[0]) && !(Array===arg[0]) && !arg[0].is_a?(NARRAY)
-      raise "first argument must be Numeric, NArray or Array"
-    end
     arg[0] = arg[0].dup if !(Numeric===arg[0])
     if arg.length==2 && !(Numeric===arg[1]) && arg[1].class!=TrueClass && arg[1].class!=FalseClass then
       arg[1] = arg[1].dup
@@ -617,7 +622,7 @@ go back to ((<Index>))
   def mean(*dims)
     min_count = NArrayMiss.check_options(dims, 1)
     # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NARRAY::DFLOAT) : self
+    ary0 = self.integer? ? self.to_type(@array.class.const_get(:DFLOAT)) : self
     NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
       ary0.sum(*dims)/count_sum
     end
@@ -625,7 +630,7 @@ go back to ((<Index>))
   def stddev(*dims)
     min_count = NArrayMiss.check_options(dims, 2)
     # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NARRAY::DFLOAT) : self
+    ary0 = self.integer? ? self.to_type(@array.class.const_get(:DFLOAT)) : self
     NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
       ary0 = ary0 - ary0.accum(*dims)/count_accum
       ary0 = ary0.abs if ary0.complex?
@@ -636,7 +641,7 @@ go back to ((<Index>))
   def rms(*dims)
     min_count = NArrayMiss.check_options(dims, 1)
     # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NARRAY::DFLOAT) : self
+    ary0 = self.integer? ? self.to_type(@array.class.const_get(:DFLOAT)) : self
     NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
       ary0 = ary0.abs if ary0.complex?
       ary0 = (ary0**2).sum(*dims) / count_sum
@@ -646,7 +651,7 @@ go back to ((<Index>))
   def rmsdev(*dims)
     min_count = NArrayMiss.check_options(dims, 1)
     # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NARRAY::DFLOAT) : self
+    ary0 = self.integer? ? self.to_type(@array.class.const_get(:DFLOAT)) : self
     NArrayMiss.reduction(@mask, rank, min_count, dims, true, typecode) do |count_sum, count_accum|
       ary0 = ary0 - ary0.accum(*dims)/count_accum
       ary0 = ary0.abs if ary0.complex?
@@ -659,17 +664,17 @@ go back to ((<Index>))
     if arg.length==0 then
       return @array[@mask].median
     else
-      nshape = NARRAY.to_na(@array.shape)
+      nshape = @array.class.to_na(@array.shape)
       nshape[arg]=1
       nslice = nshape[nshape.ne(1).where]
-      index = NARRAY.object(@mask.rank)
+      index = @array.class.object(@mask.rank)
       index[nshape.eq(1).where] = true
       obj = NArrayMiss.new(@array.typecode,*nslice.to_a)
       total = 1
       nslice.each{|n| total *= n}
       for i in 0...total
         index[nshape.ne(1).where] = pos(i,nslice)
-        mask = NARRAY.byte(*@array.shape).fill(0)
+        mask = @array.class.byte(*@array.shape).fill(0)
         mask[*index] = 1
         mask = @mask&mask
         if mask.count_true != 0 then
@@ -697,17 +702,17 @@ go back to ((<Index>))
 	obj[@mask] = @array[@mask].#{operator}
         return obj
       else
-        nshape = NARRAY.to_na(@array.shape)
+        nshape = @array.class.to_na(@array.shape)
         nshape[arg]=1
         nslice = nshape[nshape.ne(1).where]
-        index = NARRAY.object(@mask.rank)
+        index = @array.class.object(@mask.rank)
         index[nshape.eq(1).where] = true
         obj = NArrayMiss.new(@array.typecode,*@array.shape)
         total = 1
         nslice.each{|n| total *= n}
         for i in 0...total
           index[nshape.ne(1).where] = pos(i,nslice)
-          mask = NARRAY.byte(*@array.shape).fill(0)
+          mask = @array.class.byte(*@array.shape).fill(0)
           mask[*index] = 1
           mask = @mask&mask
           if mask.count_true != 0 then
@@ -1077,14 +1082,14 @@ go back to ((<Index>))
   end
   def set_mask(mask)
     if mask.class == Array then
-      tmp = NARRAY.byte(*@mask.shape)
+      tmp = @array.class.byte(*@mask.shape)
       tmp[true] = mask
       mask = tmp
     end
     if mask.class == NArrayMiss then
       mask = mask.to_na(0)
     end
-    if mask.class == NARRAY then
+    if mask.class == @array.class then
       if mask.typecode != BYTE then
 	raise("mask must be NArrayMiss.byte, NArray.byte or Array")
       end
@@ -1160,7 +1165,7 @@ go back to ((<Index>))
     if arg.length==0 then
       return @mask.count_false
     else
-      return NARRAY.int(*@mask.shape).fill(1).sum(*arg)-
+      return @array.class.int(*@mask.shape).fill(1).sum(*arg)-
 	     @mask.to_type(MINT).sum(*arg)
     end
   end
@@ -1201,8 +1206,8 @@ go back to ((<Index>))
 
   def coerce(x)
     if Numeric===x then
-      return [NArrayMiss.new(NARRAY[x].typecode,*self.shape).fill(x),self]
-    elsif x.class==Array || x.class==NARRAY then
+      return [NArrayMiss.new(@array.class[x].typecode,*self.shape).fill(x),self]
+    elsif x.class==Array || x.class==@array.class then
       return [NArrayMiss.to_nam(x), self]
     else
       raise("donnot know how to cange #{x.class} to NArrayMiss")
@@ -1217,7 +1222,7 @@ go back to ((<Index>))
     max_col = 80
     sep = ", "
     const = Hash.new
-    NARRAY.constants.each{|c| const[NARRAY.const_get(c)] = c}
+    @array.class.constants.each{|c| const[@array.class.const_get(c)] = c}
     str_ret = "NArrayMiss."+const[typecode].to_s.downcase+"("+shape.join(",")+"):"
     if rank == 0 then
       str_ret << " []"
@@ -1291,7 +1296,7 @@ go back to ((<Index>))
   private
   def pos(n,shape)
     rank = shape.length
-    result = NARRAY.int(rank)
+    result = @array.class.int(rank)
     m=n
     for i in 0..rank-2
       j = rank-1-i
@@ -1310,11 +1315,11 @@ go back to ((<Index>))
       term1 = @array
       term2 = arg
       mask = @mask
-    when Array, NARRAY
+    when Array, @array.class
       term1 = @array.dup
       term1[@mask.not] = dummy # 欠損部分に dummy を代入
-      term2 = arg.kind_of?(NARRAY) ? arg : NARRAY.to_na(arg) # Array -> NArray
-      mask = NARRAY.byte(*term2.shape).fill(1) # 2項目は欠損無し
+      term2 = arg.kind_of?(@array.class) ? arg : @array.class.to_na(arg) # Array -> NArray
+      mask = @array.class.byte(*term2.shape).fill(1) # 2項目は欠損無し
       mask = @mask & mask
     when NArrayMiss
       term1 = @array.dup
@@ -1337,12 +1342,13 @@ go back to ((<Index>))
   def self.reduction(mask, rank, min_count, dims, flag, typecode)
     # flag: リダクションを行う次元方向の有効な値の個数で、割り算を行うかどうかのフラグ
     count_sum = mask.to_type(MINT).sum(*dims)
+    klass = mask.class
     # 返り値が配列か、スカラーかによって分岐
-    if count_sum.kind_of?(NARRAY)
+    if count_sum.kind_of?(klass)
       mask = count_sum.ge(min_count)
       # すべての要素が欠損値にならないかチェック
       if mask.any?
-        count_accum = NARRAY.ref(count_sum)
+        count_accum = klass.ref(count_sum)
         dims.collect{|d|d<0 ? d+rank : d}.sort.each do |d|
           count_accum.newdim!(d)
         end
@@ -1355,13 +1361,13 @@ go back to ((<Index>))
         ary = NArrayMiss.to_nam_no_dup(ary, mask) unless flag
       else
         # すべての要素が欠損値の NArrayMiss を返す
-        na = NARRAY.new(typecode, *mask.shape)
+        na = klass.new(typecode, *mask.shape)
         ary = NArrayMiss.to_nam_no_dup(na, false)
       end
     else
       # 有効な要素数があるかチェック
       if count_sum >= min_count
-        count_accum = NARRAY.int(*([1]*mask.rank)).fill!(count_sum)
+        count_accum = klass.int(*([1]*mask.rank)).fill!(count_sum)
         ary = yield(count_sum, count_accum)
       else
         # 有効な要素数が足りない場合は nil を返す
diff --git a/lib/narray_miss/version.rb b/lib/narray_miss/version.rb
index b9eca9b..675aef4 100644
--- a/lib/narray_miss/version.rb
+++ b/lib/narray_miss/version.rb
@@ -1,3 +1,3 @@
 class NArrayMiss
-  VERSION = "1.3.0"
+  VERSION = "1.3.1"
 end
diff --git a/metadata.yml b/metadata.yml
deleted file mode 100644
index d94c8e6..0000000
--- a/metadata.yml
+++ /dev/null
@@ -1,68 +0,0 @@
---- !ruby/object:Gem::Specification
-name: narray_miss
-version: !ruby/object:Gem::Version
-  version: 1.3.0
-platform: ruby
-authors:
-- Seiya Nishizawa
-autorequire: 
-bindir: bin
-cert_chain: []
-date: 2016-02-15 00:00:00.000000000 Z
-dependencies:
-- !ruby/object:Gem::Dependency
-  name: numru-narray
-  requirement: !ruby/object:Gem::Requirement
-    requirements:
-    - - ">="
-      - !ruby/object:Gem::Version
-        version: '0'
-  type: :runtime
-  prerelease: false
-  version_requirements: !ruby/object:Gem::Requirement
-    requirements:
-    - - ">="
-      - !ruby/object:Gem::Version
-        version: '0'
-description: NArrayMiss is an additional class with processing of missing value to
-  NArray which is a numeric multi-dimensional array class.
-email:
-- seiya at gfd-dennou.org
-executables: []
-extensions: []
-extra_rdoc_files: []
-files:
-- Gemfile
-- LICENSE.txt
-- README.rdoc
-- Rakefile
-- lib/narray_miss.rb
-- lib/narray_miss/narray_miss.rb
-- lib/narray_miss/version.rb
-- narray_miss.gemspec
-- test/test_narray_miss.rb
-homepage: http://ruby.gfd-dennou.org/products/narray_miss/
-licenses: []
-metadata: {}
-post_install_message: 
-rdoc_options: []
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - ">="
-    - !ruby/object:Gem::Version
-      version: '0'
-required_rubygems_version: !ruby/object:Gem::Requirement
-  requirements:
-  - - ">="
-    - !ruby/object:Gem::Version
-      version: '0'
-requirements: []
-rubyforge_project: narray_miss
-rubygems_version: 2.4.8
-signing_key: 
-specification_version: 4
-summary: Additional class with processing of missing value to NArray
-test_files:
-- test/test_narray_miss.rb
diff --git a/narray_miss.gemspec b/narray_miss.gemspec
index f8582db..4e17098 100644
--- a/narray_miss.gemspec
+++ b/narray_miss.gemspec
@@ -31,5 +31,6 @@ Gem::Specification.new do |s|
 
   # specify any dependencies here; for example:
   #s.add_development_dependency "rspec"
-  s.add_runtime_dependency "numru-narray"
+  s.add_runtime_dependency "narray"
+  #s.add_runtime_dependency "numru-narray"
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/narray-miss.git



More information about the Pkg-grass-devel mailing list