[SCM] narray-miss branch, master, updated. debian/1.2.2-1-4-g6199288

Youhei SASAKI uwabami at gfd-dennou.org
Mon Jan 9 08:20:47 UTC 2012


The following commit has been merged in the master branch:
commit c35544b3d810412f73505e582deec930cf928b34
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Mon Jan 9 17:07:57 2012 +0900

    Imported Upstream version 1.2.4

diff --git a/ChangeLog b/ChangeLog
deleted file mode 100644
index aab12cc..0000000
--- a/ChangeLog
+++ /dev/null
@@ -1,432 +0,0 @@
-2011-05-11 16:52  seiya
-
-	* LICENSE.txt: add LICENSE.txt of BSD 2-clause license
-
-2011-03-23 11:09  seiya
-
-	* lib/narray_miss.rb, test/test_narray_miss.rb: * remove some
-	  "eval"s * add some comments * add a unit test
-
-2011-03-18 21:29  seiya
-
-	* lib/narray_miss.rb, test/test_narray_miss.rb: * fixed bug: error
-	  in NMMath.covariance when the result would be a number *
-	  organized the source code
-
-2011-03-18 16:28  seiya
-
-	* lib/narray_miss.rb, test/test_narray_miss.rb: * add methods	*
-	  NArrayMiss#rms, rmsdev   * NMMath.csc, sec, cot, csch, sech,
-	  coth, acsc, asec, acot, acsch, asech, acoth, covariance * change
-	  return object from nil to NArrayMiss when all elements in the
-	  result are missing value   * NArrayMiss#sum, min, max, mean,
-	  stddev
-
-2010-03-24 15:58  mizuta
-
-	* lib/narray_miss.rb: Wed Mar 24 2010 R Mizuta	   *
-	  lib/narray_miss.rb bugfix for methods hton and htov
-
-2009-07-09 10:58  koshiro
-
-	* lib/narray_miss.rb: Thu Jul  9 2009 T Koshiro 	*
-	  lib/narray_miss.rb: (NArrayMiss#[], NArrayMiss#[]=)	  added
-	  support for masking with a byte NArrayMiss.
-
-2009-07-02 16:22  horinout
-
-	* lib/narray_miss.rb: * update for ruby 1.9
-
-2008-08-04 11:29  seiya
-
-	* lib/narray_miss.rb:
-	  * bugfix: typo
-
-2008-07-17 15:33  seiya
-
-	* lib/narray_miss.rb:
-	  * bugfix
-
-2007-11-05 12:46  seiya
-
-	* lib/narray_miss.rb:
-	  * commit patch from Masuo Nakano
-
-2006-03-09 15:06  seiya
-
-	* lib/narray_miss.rb:
-	  change routine1 to not change original arrays for calculation
-
-2005-08-25 11:00  seiya
-
-	* lib/narray_miss.rb:
-	  remove NArray#_load, _dump
-
-2005-06-30 15:53  seiya
-
-	* lib/narray_miss.rb:
-	  bugfix error in algebra when rank of first term is smaller than
-	  second one
-
-2005-06-30 15:22  seiya
-
-	* lib/narray_miss.rb:
-	  change array.class==NArray to array.is_a?(NArray)
-
-2005-05-26 15:14  seiya
-
-	* lib/narray_miss.rb:
-	  bugfix in #mediun, #sort,, and #sort_index
-
-2005-05-26 12:21  seiya
-
-	* lib/narray_miss.rb:
-	  bugfix for #median, #sort, #sort_index
-
-2005-05-26 11:23  seiya
-
-	* lib/narray_miss.rb:
-	  add new method #median
-
-2004-11-24 12:39  seiya
-
-	* lib/narray_miss.rb:
-	  new methods #all_valid?, #none_valid?, #all_invalid?, and
-	  #any_valid?
-
-2004-08-12 17:01  seiya
-
-	* lib/narray_miss.rb:
-	  bugfix for #-@, #abs, #~@ and #not, that was destructive methods.
-
-2004-08-11 11:18  seiya
-
-	* ChangeLog, README, narray_miss.rb, lib/narray_miss.rb:
-	  change structure of package change to use setup.rb change README
-
-2004-06-23 11:20  seiya
-
-	* narray_miss.rb:
-	  bugfixs
-
-2004-06-11 12:28  seiya
-
-	* narray_miss.rb:
-	  return nil when all missing_value for mean sum max min stddev
-	  mask.not instede of mask.where2[1]
-
-2004-03-29 12:13  seiya
-
-	* ChangeLog:
-	  releas 1.0.3
-
-2004-03-18 17:18  seiya
-
-	* narray_miss.rb:
-	  add NArray#_dump and NArray._load
-
-2004-03-18 17:17  seiya
-
-	* narray_miss.rb:
-	  add NArrayMiss#_dump and NArrayMiss._load
-
-2004-03-03 14:27  seiya
-
-	* narray_miss.rb:
-	  bugfix for NArrayMiss.to_nam bugfix for NArrayMiss#transpose
-
-2004-03-02 18:17  seiya
-
-	* ChangeLog, README:
-	  release for 1.0.2
-
-2004-03-02 17:17  seiya
-
-	* narray_miss.rb:
-	  bugfix for NArrayMiss[] bugfix for NArrayMiss#[] change to return
-	  NArrayMiss insted of Numeric when length==1 in [+,-,*,/, etc]
-
-2003-10-29 12:49  seiya
-
-	* narray_miss.rb:
-	  add option "min_count" to mean
-
-2003-10-06 19:44  seiya
-
-	* narray_miss.rb:
-	  change inspect for within 80 chars in 1 line
-
-2003-10-06 19:27  seiya
-
-	* narray_miss.rb:
-	  bugfix for inspect
-
-2003-10-06 17:12  seiya
-
-	* README:
-	  README for releas narray_miss-1.0.1
-
-2003-10-06 17:11  seiya
-
-	* ChangeLog:
-	  changelog for releas narray_miss-1.0.1
-
-2003-10-06 17:05  seiya
-
-	* narray_miss.rb:
-	  change NMMath and include to NArrayMiss class then x.sin is same
-	  NMMath::sin(x)
-
-2003-10-06 16:15  seiya
-
-	* narray_miss.rb:
-	  change format of NArrayMiss#inspect
-
-2003-10-06 12:52  seiya
-
-	* narray_miss.rb:
-	  add argument to eval (routine, nil, __FILE__, __LINE__+1)
-
-2003-09-01 17:06  seiya
-
-	* ChangeLog, README:
-	  rel for 1.0.0
-
-2003-08-19 16:28  seiya
-
-	* narray_miss.rb:
-	  hoge.nil! -> !hoge
-
-2003-08-19 15:47  seiya
-
-	* narray_miss.rb:
-	  change NArrayMiss[Numeric] return scalor new each_valid,
-	  each_valid_with_index change code for collect
-
-2003-08-19 15:35  seiya
-
-	* narray_miss.rb:
-	  to_na -> to_na! get_mask, get_array -> get_mask!, get_array!
-	  valiadation, invalidation -> set_valid, set_invalid
-
-2003-06-17 18:15  seiya
-
-	* README:
-	  change README
-
-2003-04-17 16:59  seiya
-
-	* narray_miss.rb:
-	  bugfix for NArrayMiss#stddev sometime return NaN when mean is
-	  dominant
-
-2003-04-16 20:36  seiya
-
-	* narray_miss.rb:
-	  several methods to return scalar if length==1 && valid
-
-2003-04-16 17:22  seiya
-
-	* narray_miss.rb:
-	  NArrayMiss#[in]validation to be able to get both of index and
-	  array of indeices for argument
-
-2003-04-11 17:50  seiya
-
-	* narray_miss.rb:
-	  enable for validation and invalidation to get Array of index for
-	  argument
-
-2003-04-11 13:14  seiya
-
-	* narray_miss.rb:
-	  make MArrayMiss#[hoge]= nil to invalidation
-
-2003-03-25 10:31  seiya
-
-	* narray_miss.rb:
-	  bugfix for set_mask
-
-2003-03-18 19:36  seiya
-
-	* ChangeLog:
-	  ChangeLog for releas 0.5
-
-2003-03-13 15:25  seiya
-
-	* narray_miss.rb:
-	  bugfix to_na
-
-2003-03-13 15:03  seiya
-
-	* narray_miss.rb:
-	  bug for +,-,*,.... when NArrayMiss.***(1,10)+NArrayMiss.***(10,1)
-
-2003-03-13 12:58  seiya
-
-	* narray_miss.rb:
-	  change to validate for indgen bugfix (stddev for no arg) bugfix
-	  (switch validation and invalidation)
-
-2003-03-06 10:55  seiya
-
-	* narray_miss.rb:
-	  missfix for document
-
-2003-02-24 12:29  seiya
-
-	* ChangeLog, README:
-	  ChangeLog and README for releas 0.4
-
-2003-02-24 12:21  seiya
-
-	* narray_miss.rb:
-	  document
-
-2003-02-24 12:17  seiya
-
-	* narray_miss.rb:
-	  new method NArrayMiss#set_without_validation change
-	  NArrayMiss#[]= to make valid elements bugfix
-
-2003-02-24 11:24  seiya
-
-	* narray_miss.rb:
-	  NArrayMiss#to_na -> NArrayMiss#to_na([missing_value])
-
-2003-02-21 19:22  seiya
-
-	* narray_miss.rb:
-	  new methods "all_valid", "all_invalid" bugfix for "mean" "mask"
-	  "set_mask"
-
-2003-02-21 18:10  seiya
-
-	* narray_miss.rb:
-	  new methods "size", "length"
-
-2003-02-20 14:45  seiya
-
-	* ChangeLog, narray_miss.rb:
-	  bugfix of set_missing_value
-
-2003-02-20 14:37  seiya
-
-	* ChangeLog, README:
-	  chage ChangeLog README
-
-2003-02-20 14:29  seiya
-
-	* narray_miss.rb:
-	  update document
-
-2003-02-20 14:27  seiya
-
-	* narray_miss.rb:
-	  bug fix
-
-2003-02-01 18:09  seiya
-
-	* narray_miss.rb:
-	  change document
-
-2003-02-01 17:16  seiya
-
-	* ChangeLog:
-	  change ChangeLog for releas narray_miss-0.2
-
-2003-02-01 17:11  seiya
-
-	* narray_miss.rb:
-	  make "min_count" option valid for accum, sum, min, max, mean and
-	  stddev methods.  new methods to_type change document for above
-	  change
-
-2003-01-31 19:58  seiya
-
-	* narray_miss.rb:
-	  update document for rd.
-
-2003-01-30 17:20  seiya
-
-	* narray_miss.html:
-	  remove narray_miss.html
-
-2003-01-30 17:19  seiya
-
-	* narray_miss.rb:
-	  change header for rd remove narray_miss.html for cvs
-
-2003-01-30 17:15  seiya
-
-	* narray_miss.html, narray_miss.rb:
-	  add narray_miss.html < rd2 narray_miss.rb new method	rondomn add
-	  args for rd
-
-2003-01-30 16:48  seiya
-
-	* narray_miss.rb:
-	  change for use rdtool == is obsolete all? none? any? was defined
-	  twice
-
-2003-01-30 15:03  seiya
-
-	* ChangeLog:
-	  add ChangeLog
-
-2003-01-30 14:59  seiya
-
-	* README:
-	  add README
-
-2003-01-09 17:13  seiya
-
-	* narray_miss.rb:
-	  some bug fixes some new methods
-
-2003-01-09 13:14  seiya
-
-	* narray_miss.rb:
-	  to_nam use dup Routine -> private method routine use coerce
-	  inprove count_[in]valid set_missing_value[!] some bug fixes
-
-2003-01-08 18:38  seiya
-
-	* narray_miss.rb:
-	  bug fix remove missing_value
-
-2003-01-08 18:01  seiya
-
-	* narray_miss.rb:
-	  @missing_value -> @default_missing_value
-
-2003-01-08 17:44  seiya
-
-	* narray_miss.rb:
-	  change to_nam
-
-2003-01-08 17:15  seiya
-
-	* narray_miss.rb:
-	  not make new array for to_nar alias hoge fuge -> alias :hoge
-	  :fuge
-
-2003-01-08 16:39  seiya
-
-	* narray_miss.rb:
-	  bug fix
-
-2003-01-06 11:41  seiya
-
-	* narray_miss.rb:
-	  pos -> private
-
-2003-01-06 11:22  seiya
-
-	* narray_miss.rb:
-	  class NArrayMiss
-
-2003-01-06 11:22  seiya
-
-	* narray_miss.rb: Initial revision
-
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..1850b53
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in narray_miss.gemspec
+gemspec
diff --git a/README b/README
deleted file mode 100644
index d45af08..0000000
--- a/README
+++ /dev/null
@@ -1,46 +0,0 @@
-NArrayMiss README
-============
-
-   NArrayMiss is an additional Class of NArray to handle missing value.
-
-Requirements
-------------
-
-  * ruby >= 1.6
-  * NArray
-
-Install
--------
-
-  De-Compress archive and enter its top directory.
-  Then type:
-
-    $ ruby setup.rb config
-   ($ su)
-    # ruby setup.rb install
-
-  You can also install files into your favorite directory
-  by supplying setup.rb some options. Try "ruby setup.rb --help".
-
-Usage
------
-
-  Please add following code before useing NArrayMiss class:
-
-    require "narray_miss"
-
-License
--------
-
-  GNU LGPL, Lesser General Public License version 2.
-
-
-Bug Reports
------------
-
-  Any kind of bug reports are welcom.
-  If you find bugs,  please email me.
-
-
-					 Seiya Nishizawa
-				seiya at kugi.kyoto-u.ac.jp
diff --git a/README.rdoc b/README.rdoc
new file mode 100644
index 0000000..80a7b26
--- /dev/null
+++ b/README.rdoc
@@ -0,0 +1,40 @@
+= What's NArrayMiss
+
+NArrayMiss is an additional Ruby class with processing of missing value
+to NArray which is a numerical multi-dimensional array Ruby class.
+
+
+= NArrayMiss home-page
+
+The URL of the NArrayMiss home-page is:
+ http://ruby.gfd-dennou.org/products/narray_miss/
+
+
+= Requires
+
+* Ruby (http://www.ruby-lang.org/)
+* NArray (http://narray.rubyforge.org/index.html.en)
+
+
+= Install
+
+ # gem install narray_miss
+
+
+= Copying
+
+See the file LICENSE.txt.
+
+
+= Usage
+
+To use this library, put the following in your script.
+ require 'narray_miss'
+
+
+= The Author
+
+Feel free to send comments and bug reports to the author.
+The author's e-mail addess is
+
+ seiya at gfd-dennou.org
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..e66f1df
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,5 @@
+require "bundler/gem_tasks"
+require "rake/testtask"
+
+Rake::TestTask.new
+task :default => :test
diff --git a/lib/narray_miss.rb b/lib/narray_miss.rb
index ce06777..1503bfe 100644
--- a/lib/narray_miss.rb
+++ b/lib/narray_miss.rb
@@ -1,1510 +1,2 @@
-# -*- coding: utf-8 -*-
-=begin
-= NArrayMiss Class
-
-NArrayMiss is a additional class processing of missing value with to
-((<NArray|URL:http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray>))
-for Ruby.
-
-To use NArrayMiss class, you need invoking "require 'narray_miss.rb'" in your script.
-
-== Index
-
-* ((<Class Constants>))
-* ((<Class Methods>))
-* ((<Class Instance Methods>))
-  * ((<NArrayMiss information>))
-  * ((<Slicing Array>))
-  * ((<Filling values>))
-  * ((<Arithmetic operator>))
-  * ((<Bitwise operator|Bitwise operator (only for byte, sint and int)>))
-  * ((<Comparison>))
-  * ((<Statistics>))
-  * ((<Sort>))
-  * ((<Transpose>))
-  * ((<Changing Shapes of indices>))
-  * ((<Type conversion>))
-  * ((<Iteration>))
-  * ((<Boolean and mask related|Boolean and mask related (only for byte, sint and int)>))
-  * ((<Complex compound number|Complex compound number (only for scomplex and complex)>))
-  * ((<Byte swap>))
-  * ((<Mask and missing value>))
-  * ((<Others>))
-
-
-=end
-
-require 'narray'
-
-
-class NArrayMiss
-
-=begin
-== Class Constants
---- NArrayMiss::BYTE
-     type code for 1 byte unsigned integer.
---- NArrayMiss::SINT
-     type code for 2 byte signed integer.
---- NArrayMiss::INT
-     type code for 4 byte signed integer.
---- NArrayMiss::SFLOAT
-     type code for single precision float.
---- NArrayMiss::FLOAT
-     type code for double precision float.
---- NArrayMiss::SCOMPLEX
-     type code for single precision complex.
---- NArrayMiss::COMPLEX
-     type code for double precision complex.
---- NArrayMiss::OBJECT
-     type code for Ruby object.
-
-go back to ((<Index>))
-=end
-
-  BYTE = NArray::BYTE
-  SINT = NArray::SINT
-  INT = NArray::INT
-  SFLOAT = NArray::SFLOAT
-  FLOAT = NArray::FLOAT
-  SCOMPLEX = NArray::SCOMPLEX
-  COMPLEX = NArray::COMPLEX
-  OBJECT = NArray::OBJECT
-
-  class << self
-    alias :__new__ :new
-    private :__new__
-  end
-
-  def initialize(array, mask)
-    if array.shape!=mask.shape
-      raise "array and mask must have the same shape"
-    end
-    @array = array
-    @mask = mask
-  end
-  private :initialize
-
-=begin
-== Class Methods
---- NArrayMiss.new(typecode, size, ...)
-     create (({NArrayMiss})) of ((|typecode|)).
-     All elements are initialized with 0.
---- NArrayMiss.byte(size, ...)
-     same as NArrayMiss.new(NArrayMiss::BYTE, ((|size|)), ...).
---- NArrayMiss.sint(size, ...)
-     same as NArrayMiss.new(NArrayMiss::SINT, ((|size|)), ...).
---- NArrayMiss.int(size, ...)
-     same as NArrayMiss.new(NArrayMiss::INT, ((|size|)), ...).
---- NArrayMiss.sfloat(size, ...)
-     same as NArrayMiss.new(NArrayMiss::SFLOAT, ((|size|)), ...).
---- NArrayMiss.float(size, ...)
-     same as NArrayMiss.new(NArrayMiss::FLOAT, ((|size|)), ...).
---- NArrayMiss.scomplex(size, ...)
-     same as NArrayMiss.new(NArrayMiss::SCOMPLEX, ((|size|)), ...).
---- NArrayMiss.complex(size, ...)
-     same as NArrayMiss.new(NArrayMiss::COMPLEX, ((|size|)), ...).
---- NArrayMiss.object(size, ...)
-     same as NArrayMiss.new(NArrayMiss::OBJECT, ((|size|)), ...).
---- NArrayMiss[](value, ...)
-     create (({NArrayMiss})) form [((|value|)), ...].
---- NArrayMiss.to_nam(array [,mask])
-     create (({NArrayMiss})) from ((|array|)).
-     ((|array|)) must be (({Numeric})) (({Array})) or (({NArray})).
---- NArrayMiss.to_nam_no_dup(array [,mask])
-     convert from ((|array|)) to (({NArrayMiss})).
-
-go back to ((<Index>))
-=end
-
-  def self.new(*arg)
-    array = NArray.new(*arg)
-    mask = NArray.byte(*arg[1..-1])
-    __new__(array, mask)
-  end
-  def self.byte(*arg)
-    NArrayMiss.new(BYTE,*arg)
-  end
-  def self.sint(*arg)
-    NArrayMiss.new(SINT,*arg)
-  end
-  def self.int(*arg)
-    NArrayMiss.new(INT,*arg)
-  end
-  def self.sfloat(*arg)
-    NArrayMiss.new(SFLOAT,*arg)
-  end
-  def self.float(*arg)
-    NArrayMiss.new(FLOAT,*arg)
-  end
-  def self.scomplex(*arg)
-    NArrayMiss.new(SCOMPLEX,*arg)
-  end
-  def self.complex(*arg)
-    NArrayMiss.new(COMPLEX,*arg)
-  end
-  def self.object(*arg)
-    NArrayMiss.new(OBJECT,*arg)
-  end
-  def self.[](*arg)
-    NArrayMiss.to_nam(NArray[*arg])
-  end
-  def self.to_nam_no_dup(*arg)
-    if arg.length > 2 || arg.length==0 then
-      raise("NArrayMiss.to_nar( array [,mask]] )")
-    end
-
-    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
-      raise("argument must be Numeric, NArray or Array")
-    end
-
-    if arg.length==2 then
-      mask = arg[1]
-      if Numeric===mask then mask = array.ne(mask) end
-      if Array===mask then
-	mask = NArray.to_na(mask).ne(0)
-      end
-      if mask.class == FalseClass then
-	mask = NArray.byte(*array.shape)
-      end
-      if mask.class == TrueClass then
-	mask = NArray.byte(*array.shape).fill(1)
-      end
-      if !(NArray===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)
-    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
-    end
-    NArrayMiss.to_nam_no_dup(*arg)
-  end
-
-
-=begin
-== Class Instance Methods
-=end
-
-
-=begin
-=== NArrayMiss information
---- NArrayMiss#dim
-     return the dimension which is the number of indices.
---- NArrayMiss#rank
-     same as (({NArrayMiss#dim})).
---- NArrayMiss#shape
-     return the (({Array})) of sizes of each index.
---- NArrayMiss#size
-     return the number of total elements.
---- NArrayMiss#total
-     alias to size
---- NArrayMiss#length
-     alias to size
---- NArrayMiss#rank_total
-     return the number of total of the shape.
---- NArrayMiss#typecode
-     return the typecode.
-=end
-
-  def dim
-    @array.dim
-  end
-  def rank
-    @array.rank
-  end
-  def shape
-    @array.shape
-  end
-  def size
-    @array.size
-  end
-  alias :total :size
-  alias :length :size
-
-  def rank_total(*arg)
-    @array.rank_total(*arg)
-  end
-
-  def typecode
-    @array.typecode
-  end
-
-
-=begin
-=== Slicing Array
---- NArrayMiss#[](index)
-     return the value at [((|index|))].
-     ((|index|)) must be (({Integer, Range, Array, true})).
-     Index order is FORTRAN type.
---- NArrayMiss#slice(index)
-     same as (({NArrayMiss#[]})) but keeps the rank of original array by not elimiting dimensions whose length became equal to 1 (which (({NArrayMiss#[]})) dose).
-     This is not the case with the 1-dimensional indexing and masking.
---- NArrayMiss#set_without_validation(index,value)
-     replace elements at ((|index|)) by ((|value|)).
---- NArrayMiss#[]=(index, value)
-     replace elements at ((|index|)) by ((|value|)) and
-     make replaced elements valid.     
-=end
-
-  def [](*arg)
-    if arg[0].class == NArrayMiss && arg[0].typecode == BYTE
-      obj = @array[arg[0].to_na(0)]
-      if Numeric===obj
-        return obj
-      else
-        return NArrayMiss.to_nam_no_dup(obj)
-      end
-    else
-      obj = @array[*arg]
-      if Numeric===obj
-        return obj
-      else
-        return NArrayMiss.to_nam_no_dup(obj, at mask[*arg])
-      end
-    end
-  end
-  def slice(*arg)
-    NArrayMiss.to_nam_no_dup(@array.slice(*arg), at mask.slice(*arg))
-  end
-
-  def set_without_validation(*arg)
-    if arg.length==1 then
-      if !arg[0] then
-	@mask[] = 0
-      elsif arg[0].class == NArrayMiss then
-	@array[] = arg[0].get_array!
-	@mask[] = arg[0].get_mask!
-      else
-	@array[] = arg[0]
-      end
-    else
-      if !arg[-1] then
-	@mask[*arg[0..-2]] = 0
-      elsif arg[-1].class == NArrayMiss then
-	@array[*arg[0..-2]] = arg[-1].get_array!
-	@mask[*arg[0..-2]] = arg[-1].get_mask!
-      else
-	@array[*arg[0..-2]] = arg[-1]
-      end
-    end
-    return self
-  end
-
-  def []=(*arg)
-    if arg.length == 2 && arg[0].class == NArrayMiss && arg[0].typecode == BYTE
-      idx = arg[0].to_na(0)
-      self.set_without_validation(idx,arg[-1])
-      if arg[-1].class != NArrayMiss && arg[-1] then
-        @mask[idx] = 1
-      end
-    else
-      self.set_without_validation(*arg)
-      if arg[-1].class != NArrayMiss && arg[-1] then
-        if arg.length==1 then
-          @mask=1
-        else
-          @mask[*arg[0..-2]] = 1
-        end
-      end
-    end
-    return self
-  end
-
-
-=begin
-=== Filling values
---- NArrayMiss#indgen!([start[,step]])
-     set values from ((|start|)) with ((|step|)) increment.
---- NArrayMiss#indgen([start[,step]])
-     same as (({NArrayMiss#indgen!})) but create new object.
---- NArrayMiss#fill!(value)
-     fill elements with ((|value|)).
---- NArrayMiss#fill(value)
-     same as (({NArrayMiss#fill!})) but create new object.
---- NArrayMiss#random!(max)
-     set random values between 0<=x<((|max|)).
---- NArrayMiss#random(max)
-     same as (({NArrayMiss#random!})) but create new object.
---- NArrayMiss#randomn(max)
-     set normally distributed random values with mean=0, dispersion=1 (Box-Muller)
-=end
-
-  for operator in ["indgen","fill","random","randomn"]
-    eval(<<-EOL,nil,__FILE__,__LINE__+1)
-    def #{operator}(*arg)
-      obj = self.dup
-      obj.#{operator}!(*arg)
-      obj
-    end
-    def #{operator}!(*arg)
-      @array = @array.#{operator}!(*arg)
-      @mask[true] = 1
-      self
-    end
-    EOL
-  end
-
-
-=begin
-=== Arithmetic operator
---- NArrayMiss#-@
---- NArrayMiss#+(other)
---- NArrayMiss#-(other)
---- NArrayMiss#*(other)
---- NArrayMiss#/(other)
---- NArrayMiss#%(other)
---- NArrayMiss#**(other)
---- NArrayMiss#abs
---- NArrayMiss#add!(other)
---- NArrayMiss#sbt!(other)
---- NArrayMiss#mul!(other)
---- NArrayMiss#div!(other)
---- NArrayMiss#mod!(other)
---- NArrayMiss#mul_add(other, dim, ...)
-=end
-
-  def -@
-    array = @array.dup
-    array[@mask] = - at array[@mask]
-    NArrayMiss.to_nam_no_dup(array, @mask.dup)
-  end
-  def +(arg)
-    binary_operation(arg, 0){|t1, t2| t1 + t2}
-  end
-  def -(arg)
-    binary_operation(arg, 0){|t1, t2| t1 - t2}
-  end
-  def *(arg)
-    binary_operation(arg, 1){|t1, t2| t1 * t2}
-  end
-  def /(arg)
-    binary_operation(arg, 1){|t1, t2| t1 / t2}
-  end
-  def %(arg)
-    binary_operation(arg, 1){|t1, t2| t1 % t2}
-  end
-  def **(arg)
-    binary_operation(arg, 1){|t1, t2| t1 ** t2}
-  end
-
-  def abs
-    array = @array.dup
-    array[@mask] = @array[@mask].abs
-    NArrayMiss.to_nam_no_dup(array, @mask.dup)
-  end
-
-  def add!(arg)
-    binary_operation(arg, 0){|t1, t2| t1.add!(t2)}
-  end
-  def sbt!(arg)
-    binary_operation(arg, 0){|t1, t2| t1.sbt!(t2)}
-  end
-  def mul!(arg)
-    binary_operation(arg, 1){|t1, t2| t1.mul!(t2)}
-  end
-  def div!(arg)
-    binary_operation(arg, 1){|t1, t2| t1.div!(t2)}
-  end
-  def mod!(arg)
-    binary_operation(arg, 1){|t1, t2| t1.mod!(t2)}
-  end
-
-  def mul_add(*arg)
-    if arg.length==1 then
-      return (self*arg[0]).sum
-    else
-      return (self*arg[0]).sum(*arg[1..-1])
-    end
-  end
-
-
-=begin
-=== Bitwise operator (only for byte, sint and int)
---- NArrayMiss#~@
---- NArrayMiss#&(other)
---- NArrayMiss#|(other)
---- NArrayMiss#^(other)
-=end
-
-  def ~@
-    NArrayMiss.to_nam_to_dup(~@array, @mask.dup)
-  end
-  def &(arg)
-    binary_operation(arg, 1){|t1, t2| t1 & t2}
-  end
-  def |(arg)
-    binary_operation(arg, 0){|t1, t2| t1 | t2}
-  end
-  def ^(arg)
-    binary_operation(arg, 1){|t1, t2| t1 ^ t2}
-  end
-
-
-=begin
-=== Comparison
---- NArrayMiss#eq(other)
---- NArrayMiss#ne(other)
---- NArrayMiss#gt(other)
---- NArrayMiss#ge(other)
---- NArrayMiss#lt(other)
---- NArrayMiss#le(other)
---- NArrayMiss#>(other)
---- NArrayMiss#>=(other)
---- NArrayMiss#<(other)
---- NArrayMiss#<=(other)
---- NArrayMiss#and(other)
---- NArrayMiss#or(other)
---- NArrayMiss#xor(other)
---- NArrayMiss#not(other)
-=end
-
-  def eq(arg)
-    binary_operation(arg, 0){|t1, t2| t1.eq t2}
-  end
-  def ne(arg)
-    binary_operation(arg, 0){|t1, t2| t1.ne t2}
-  end
-  def gt(arg)
-    binary_operation(arg, 0){|t1, t2| t1.gt t2}
-  end
-  def ge(arg)
-    binary_operation(arg, 0){|t1, t2| t1.ge t2}
-  end
-  def lt(arg)
-    binary_operation(arg, 0){|t1, t2| t1.lt t2}
-  end
-  def le(arg)
-    binary_operation(arg, 0){|t1, t2| t1.le t2}
-  end
-
-  def and(arg)
-    binary_operation(arg, 1){|t1, t2| t1.and t2}
-  end
-  def or(arg)
-    binary_operation(arg, 0){|t1, t2| t1.or t2}
-  end
-  def xor(arg)
-    binary_operation(arg, 1){|t1, t2| t1.xor t2}
-  end
-
-  def not
-    NArrayMiss.to_nam_no_dup(@array.not, @mask.dup)
-  end
-
-  def ==(arg)
-    if arg.kind_of?(NArrayMiss) then
-      @mask==arg.get_mask! && @array[@mask]==arg.get_array![@mask]
-    else
-      false
-    end
-  end
-
-
-=begin
-=== Statistics
---- NArrayMiss#sum(dim, ... ["min_count"=>i])
-     return summation of elements in specified dimensions.
-     Elements at which the number of elements for summation is less than ((|i|)) is invalid.
---- NArrayMiss#accum(dim, ...)
-     same as (({NArrayMiss#sum})) but not elimiting dimensions whose length became equal to 1.
---- NArrayMiss#min(dim, ...)
-     return minimum in specified dimensions.
-     Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
---- NArrayMiss#max(dim, ...)
-     return maximum in specified dimensions.
-     Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
---- NArrayMiss#median(dim, ...)
-     return median in specified dimensions.
-     Elements at which the number of valid elements in the dimension is less than ((|i|)) is invalid.
---- NArrayMiss#mean(dim, ...)
-     return mean of elements in specified dimensions.
-     Elements at which the number of elements for then mean is less than ((|i|)) is invalid.
---- NArrayMiss#stddev(dim, ...)
-     return standard deviation of elements in specified dimensions.
-     Elements at which the number of elements for calculation the standard deviation is less than ((|i|)) is invalid.
---- NArrayMiss#rms(dim, ...)
-     return root mean square of elements in specified dimensions.
-     Elements at which the number of elements for calculation the RMS is less than ((|i|)) is invalid.
---- NArrayMiss#rmsdev(dim, ...)
-     return root mean square deviation of elements in specified dimensions.
-     Elements at which the number of elements for calculation the RMS deviation is less than ((|i|)) is invalid.
-=end
-
-  def accum(*arg)
-    if @mask.count_true == 0 then
-      return nil
-    else
-      array = @array.dup
-      array[@mask.not] = 0
-      return NArrayMiss.to_nam_no_dup(array.accum(*arg),
-			       @mask.to_type(NArray::INT).accum(*arg).ne(0))
-    end
-  end
-
-  def sum(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 欠損値に 0 を入れて普通に sum する
-    ary0 = @array.dup
-    ary0[@mask.not] = 0
-    NArrayMiss.reduction(@mask, min_count, dims, false, typecode) do
-      ary0.sum(*dims)
-    end
-  end
-  def min(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 欠損値に最大値を入れて普通に min する
-    # byte,sint,int,sfloat,float の MAX の値を入れるように変更すべき
-    ary0 = @array.dup
-    ary0[@mask.not] = @array.max
-    NArrayMiss.reduction(@mask, min_count, dims, false, typecode) do
-      ary0.min(*dims)
-    end
-  end
-  def max(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 欠損値に最小値を入れて普通に max する
-    # byte,sint,int,sfloat,float の MIN の値を入れるように変更すべき
-    ary0 = @array.dup
-    ary0[@mask.not] = @array.min
-    NArrayMiss.reduction(@mask, min_count, dims, false, typecode) do
-      ary0.max(*dims)
-    end
-  end
-
-  def mean(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
-    NArrayMiss.reduction(@mask, min_count, dims, true, typecode) do |count_sum, count_accum|
-      var = ary0.sum(*dims)/count_sum
-    end
-  end
-  def stddev(*dims)
-    min_count = NArrayMiss.check_options(dims, 2)
-    # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
-    NArrayMiss.reduction(@mask, min_count, dims, true, typecode) do |count_sum, count_accum|
-      ary0 = ary0 - ary0.accum(*dims)/count_accum
-      ary0 = ary0.abs if ary0.complex?
-      ary0 = (ary0**2).sum(*dims) / (count_sum-1)
-      NMMath.sqrt(ary0)
-    end
-  end
-  def rms(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
-    NArrayMiss.reduction(@mask, min_count, dims, true, typecode) do |count_sum, count_accum|
-      ary0 = ary0.abs if ary0.complex?
-      ary0 = (ary0**2).sum(*dims) / count_sum
-      NMMath.sqrt(ary0)
-    end
-  end
-  def rmsdev(*dims)
-    min_count = NArrayMiss.check_options(dims, 1)
-    # 整数型の場合は浮動小数型へ変換
-    ary0 = self.integer? ? self.to_type(NArray::DFLOAT) : self
-    NArrayMiss.reduction(@mask, min_count, dims, true, typecode) do |count_sum, count_accum|
-      ary0 = ary0 - ary0.accum(*dims)/count_accum
-      ary0 = ary0.abs if ary0.complex?
-      ary0 = (ary0**2).sum(*dims) / count_sum
-      NMMath.sqrt(ary0)
-    end
-  end
-
-  def median(*arg)
-    if arg.length==0 then
-      return @array[@mask].median
-    else
-      nshape = NArray.to_na(@array.shape)
-      nshape[arg]=1
-      nslice = nshape[nshape.ne(1).where]
-      index = NArray.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[*index] = 1
-        mask = @mask&mask
-        if mask.count_true != 0 then
-          obj[*pos(i,nslice)] = @array[mask].median
-        end
-      end
-      return obj
-    end
-  end
-
-
-=begin
-=== Sort
---- NArrayMiss#sort(dim)
-     sort in the 0..((|dim|)) (All dimensions if omitted)
---- NArrayMiss#sort_index(dim)
-     return index of sort result.
-=end
-
-  for operator in ["sort","sort_index"]
-    eval(<<-EOL,nil,__FILE__,__LINE__+1)
-    def #{operator}(*arg)
-      obj=NArrayMiss.new(@array.typecode,*@array.shape)
-      if arg.length==0 then
-	obj[@mask] = @array[@mask].#{operator}
-        return obj
-      else
-        nshape = NArray.to_na(@array.shape)
-        nshape[arg]=1
-        nslice = nshape[nshape.ne(1).where]
-        index = NArray.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[*index] = 1
-          mask = @mask&mask
-          if mask.count_true != 0 then
-	    obj[mask] = @array[mask].#{operator}
-	  end
-	end
-	return obj
-      end
-    end
-    EOL
-  end
-
-
-=begin
-=== Transpose
---- NArrayMiss#transpose(dim0, dim1, ...)
-     transpose array. The 0-th dimension goes to the ((|dim0|))-th dimension of new array.
-=end
-
-  def transpose(*arg)
-    obj = self.dup
-    shape = arg.collect{|i| obj.shape[i]}
-    obj.reshape!(*shape)
-    obj.set_without_validation( @array.transpose(*arg) )
-    obj.set_mask(@mask.transpose(*arg))
-    obj
-  end
-
-
-=begin
-=== Changing Shapes of indices
---- NArrayMiss#reshape!(size, ...)
-     change shape of array.
---- NArrayMiss#reshape(size, ...)
-     same as (({NArrayMiss#reshape!})) but create new object.
---- NArrayMiss#shape=(size, ...)
-     same as (({NArrayMiss#reshape!})).
---- NArrayMiss#newdim!(dim)
-     insert new dimension with size=1
---- NArrayMiss#newdim(dim)
-     same as (({NArrayMiss#newdim!})) but create new object.
---- NArrayMiss#rewrank!(dim)
-     same as (({NArrayMiss#newdim!})).
---- NArrayMiss#rewrank=(dim)
-     same as (({NArrayMiss#newdim!})).
-=end
-
-  def reshape!(*arg)
-    @array = @array.reshape!(*arg)
-    @mask = @mask.reshape!(*arg)
-    self
-  end
-  def reshape(*arg)
-    obj = self.dup
-    obj.reshape!(*arg)
-  end
-  alias :shape= :reshape!
-  def newdim!(*arg)
-    @array = @array.newdim!(*arg)
-    @mask = @mask.newdim!(*arg)
-    self
-  end
-  alias :rewrank! :newdim!
-  alias :rewrank= :newdim!
-  def newdim(*arg)
-    obj = self.dup
-    obj.newdim!(*arg)
-  end
-  alias :rewrank :newdim
-
-
-=begin
-=== Type conversion
---- NArrayMiss#floor
-     return (({NArrayMiss})) of integer whose elements processed (({floor})).
---- NArrayMiss#ceil
-     return (({NArrayMiss})) of integer whose elements processed (({ceil})).
---- NArrayMiss#round
-     return (({NArrayMiss})) of integer whose elements processed (({round})).
---- NArrayMiss#to_i
-     return (({NArrayMiss})) of integer whose elements processed (({to_i})).
---- NArrayMiss#to_f
-     return (({NArrayMiss})) of float whose elements processed (({to_f})).
---- NArrayMiss#to_type(typecode)
-     return (({NArrayMiss})) of ((|typecode|)).
---- NArrayMiss#to_a
-     convert (({NArrayMiss})) to (({Array})).
---- NArrayMiss#to_na!([missing_value])
-     convert (({NArrayMiss})) to (({NArray})).
-     if there is argument, set missing_value for invalid elements.
---- NArrayMiss#to_na([missing_value])
-     convert (({NArrayMiss})) to (({NArray})).
-     if there is argument, set missing_value for invalid elements.
---- NArrayMiss#to_s
-     convert (({NArrayMiss})) to (({String})) as a binary data.
---- NArrayMiss#to_string
-     create (({NArrayMiss})) of object whose elements are processed (({to_s}))
-=end
-
-  def floor
-    NArrayMiss.to_nam_no_dup(@array.floor, @mask.dup)
-  end
-  def ceil
-    NArrayMiss.to_nam_no_dup(@array.ceil, @mask.dup)
-  end
-  def round
-    NArrayMiss.to_nam_no_dup(@array.round, @mask.dup)
-  end
-  def to_i
-    NArrayMiss.to_nam_no_dup(@array.to_i, @mask.dup)
-  end
-  def to_f
-    NArrayMiss.to_nam_no_dup(@array.to_f, @mask.dup)
-  end
-
-  def to_type(typecode)
-    NArrayMiss.to_nam_no_dup(@array.to_type(typecode), @mask.dup)
-  end
-  def to_a
-    @array.to_a
-  end
-  def to_na!(*arg)
-    if arg.length==0
-      return @array
-    elsif arg.length==1 then
-      self.set_missing_value!(arg[0])
-      return @array
-    else
-      raise(ArgumentError, "Usage: NArray#to_na([missing_value])")
-    end
-  end
-  def to_na(*arg)
-    return self.dup.to_na!(*arg)
-  end
-  def to_s
-    @array.to_s
-  end
-  def to_string
-    obj = NArrayMiss.obj(*@array.shape)
-    obj.set_without_validation( @array.to_string )
-    obh.set_mask(@mask)
-    obj
-  end
-
-
-=begin
-=== Iteration
---- NArrayMiss#each{|x| ...}
---- NArrayMiss#each_valid{|x| ...}
---- NArrayMiss#each_valid_with_index{|x,i| ...}
---- NArrayMiss#collect{|x| ...}
---- NArrayMiss#collect!{|x| ...}
-=end
-
-  def each
-    for i in 0..self.total-1
-      yield(@array[i])
-    end
-  end
-  def each_valid
-    for i in 0..self.total-1
-      yield(@array[i]) if @mask[i]
-    end
-  end
-  def each_valid_with_index
-    for i in 0..self.total-1
-      yield(@array[i],i) if @mask[i]
-    end
-  end
-  def collect!
-    for i in 0..self.total-1
-      self[i] = yield(self[i])
-    end
-    self
-  end
-  def collect(&blk)
-    self.dup.collect!(&blk)
-  end
-
-
-=begin
-=== Boolean and mask related (only for byte, sint and int)
---- NArrayMiss#count_false
-     return the number of elements whose value==0 and valid.
---- NArrayMiss#count_true
-     return the number of elements whose value!=0 and valid.
---- NArrayMiss#mask(mask)
-     return (({NArrayMiss#get_mask!&((|mask|))})).
---- NArrayMiss#all?
-     return true if all the valid elements are not 0, else false.
---- NArrayMiss#any?
-     return true if any valid element is not 0, else false.
---- NArrayMiss#none?
-     return true if none of the valid elements is not 0, else false.
---- NArrayMiss#where
-     return (({NArray})) of indices where valid elements are not 0.
---- NArrayMiss#where2
-     return (({Array})) including two (({NArray}))s of indices,
-     where valid elements are not 0, and 0, respectively.
-=end
-
-  def count_false
-    if @array.typecode==BYTE then
-      return @array.count_false- at mask.count_false
-    else
-      raise("cannot count_true NArrayMiss except BYTE type")
-    end
-  end
-  def count_true
-    if @array.typecode==BYTE then
-      return (@array&@mask).count_true
-    else
-      raise("cannot count_true NArrayMiss except BYTE type")
-    end
-  end
-  def mask(arg)
-    obj = self.dup
-    if arg.class==NArrayMiss then
-      arg = arg.get_array!&arg.get_mask!
-    end
-    obj.set_mask(@mask&arg)
-  end
-
-  def all?
-    @array[@mask].all?
-  end
-  def any?
-    @array[@mask].any?
-  end
-  def none?
-    @array[@mask].none?
-  end
-
-  def where
-    (@array&@mask).where
-  end
-  def where2
-    self.where- at mask.where
-  end
-
-
-
-
-=begin
-=== Complex compound number (only for scomplex and complex)
---- NArrayMiss#real
---- NArrayMiss#imag
---- NArrayMiss#conj
---- NArrayMiss#angle
---- NArrayMiss#imag=(other)
---- NArrayMiss#im
-=end
-
-  def real
-    NArrayMiss.to_nam_no_dup(@array.real, at mask)
-  end
-  def imag
-    NArrayMiss.to_nam_no_dup(@array.imag, at mask)
-  end
-  def conj
-    NArrayMiss.to_nam_no_dup(@array.conj, at mask)
-  end
-  def angle
-    NArrayMiss.to_nam_no_dup(@array.angle, at mask)
-  end
-  def imag=(arg)
-    @array.image=(arg)
-    self
-  end
-  def im
-    NArrayMiss.to_nam_no_dup(@array.im, at mask)
-  end
-
-
-=begin
-=== Byte swap
---- NArrayMiss#swap_byte
-     swap byte order.
---- NArrayMiss#hton
-     convert to network byte order.
---- NArrayMiss#ntoh
-     convert from network byte order.
---- NArrayMiss#htov
-     convert to VAX byte order.
---- NArrayMiss#vtoh
-     convert from VAX byte order.
-=end
-
-  def swap_byte
-    obj = self.dup
-    obj.set_without_validation(@array.swap_byte)
-    obj
-  end
-  def hton
-    NArrayMiss.to_nam(@array.hton, at mask.hton)
-  end
-  alias :ntoh :hton
-  def htov
-    NArrayMiss.to_nam(@array.htov, at mask.htov)
-  end
-  alias :vtoh :htov
-
-
-=begin
-=== Mask and missing value
---- NArrayMiss#set_valid(index)
-     validate element at ((|index|)).
-     ((|index|)) must be (({Integer, Range, Array, or ture})).
---- NArrayMiss#validation(index)
-     alias to set_valid
---- NArrayMiss#set_invalid(index)
-     invaliadate element at ((|index|)).
-     ((|index|)) must be (({Integer, Range, Array, or ture})).
---- NArrayMiss#invalidation(index)
-     alias to set_invalid
---- NArrayMiss#all_valid
-     set all elements valid
---- NArrayMiss#all_invalid
-     set all elements invalid
---- NArrayMiss#set_mask(mask)
-     masking by ((|mask|))
---- NArrayMiss#set_missing_value(value)
-     replace invalid elements by ((|value|)).
---- NArrayMiss#get_mask!
-     return (({NArray})) of byte as mask.
---- NArrayMiss#get_mask
-     return (({NArray})) of byte as mask.
---- NArrayMiss#get_array!
-     return (({NArray})) as data.
---- NArrayMiss#get_array
-     return (({NArray})) as data.
---- NArrayMiss#valid?
-     return (({Array})) whose elements are true or false corresponding to valid or invalid of elements, respectively.
---- NArrayMiss#all_valid?
-     return true if all elements are valid, else false.
---- NArrayMiss#none_valid?
-     return true if all elements are invalid, else false.
---- NArrayMiss#all_invalid?
-     alias to none_valid?
---- NArrayMiss#any_valid?
-     return true if any elements are valid, else false.
-     
---- NArrayMiss#count_valid
-     return the number of valid elements.
---- NArrayMiss#count_invalid
-     return the number of invalid elements.
-=end
-
-  def set_valid(*pos)
-    @mask[*pos] = 1
-    self
-  end
-  alias validation set_valid
-  def set_invalid(*pos)
-    @mask[*pos] = 0
-    self
-  end
-  alias invalidation set_invalid
-  def all_valid
-    @mask[true]=1
-    self
-  end
-  def all_invalid
-    @mask[true]=0
-    self
-  end
-  def set_mask(mask)
-    if mask.class == Array then
-      tmp = NArray.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.typecode != BYTE then
-	raise("mask must be NArrayMiss.byte, NArray.byte or Array")
-      end
-      if @array.shape != mask.shape then
-	raise("mask.shape must be same as array")
-      end
-      @mask = mask.dup
-      return self
-    else
-      raise("mask must be NArray.byte or Array")
-    end
-  end
-
-  def set_missing_value!(val)
-    @array[@mask.not] = val
-    self
-  end
-  def set_missing_value(val)
-    obj = self.dup
-    obj.set_missing_value!(val)
-  end
-
-  def get_mask!
-    @mask
-  end
-  def get_mask
-    @mask.dup
-  end
-  def get_array!
-    @array
-  end
-  def get_array
-    @array.dup
-  end
-
-  def valid?
-    where = self.get_mask!.where2
-    tf = Array.new(self.total)
-    for i in where[0]
-      tf[i] = true
-    end
-    for i in where[1]
-      tf[i] = false
-    end
-    tf
-  end
-  def all_valid?
-    @mask.all?
-  end
-  def none_valid?
-    @mask.none?
-  end
-  alias :all_invalid? :none_valid?
-  def any_valid?
-    @mask.any?
-  end
-
-  def count_valid(*arg)
-    if arg.length==0 then
-      return @mask.count_true
-    else
-      return @mask.to_type(NArray::INT).sum(*arg)
-    end    
-  end
-  def count_invalid(*arg)
-    if arg.length==0 then
-      return @mask.count_false
-    else
-      return NArray.int(*@mask.shape).fill(1).sum(*arg)-
-	     @mask.to_type(NArray::INT).sum(*arg)
-    end
-  end
-
-
-=begin
-=== Others
---- NArrayMiss#integer?
-     return true if (({NArrayMiss})) is byte, sint or int, else false.
---- NArrayMiss#complex?
-     return true if (({NArrayMiss})) is scomplex or complex, else false.
---- NArrayMiss#dup
---- NArrayMiss#coerce(object)
---- NArrayMiss#inspect
-
-go back to ((<Index>))
-=end
-
-  def integer?
-    @array.integer?
-  end
-  def complex?
-    @array.complex?
-  end
-
-
-  def dup
-    NArrayMiss.to_nam(@array, at mask)
-  end
-
-  alias __clone__ clone
-  def clone
-    obj = __clone__
-    obj.set_array(@array.clone)
-    obj.set_mask(@mask.clone)
-    return obj
-  end
-
-  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.to_nam(x), self]
-    else
-      raise("donnot know how to cange #{x.class} to NArrayMiss")
-    end
-  end
-
-
-  def inspect
-#    "array -> " + @array.inspect + "\nmask  -> " + @mask.inspect
-    count_line = 0
-    max_line = 10
-    max_col = 80
-    sep = ", "
-    const = Hash.new
-    NArray.constants.each{|c| const[NArray.const_get(c)] = c}
-    str_ret = "NArrayMiss."+const[typecode].to_s.downcase+"("+shape.join(",")+"):"
-    if rank == 0 then
-      str_ret << " []"
-      return str_ret
-    else
-       str_ret << "\n"
-    end
-    str = ""
-    index = Array.new(rank,0)
-    index[0] = true
-    i = 1
-    (rank-1).times{ str_ret << "[ " }
-    while(true)
-      i.times{ str_ret << "[ " }
-
-      str = @array[*index].inspect
-      ary = str[str.index("[")+1..str.index("]")-1].strip.split(/\s*,\s*/)
-      miss = @mask[*index].where2[1]
-      miss = miss[miss<ary.length].to_a
-      if ary[-1]=="..." && miss[-1]==ary.length-1 then miss.pop end
-      for j in miss
-	ary[j] = "-"
-      end
-      while ( rank*4+ary.join(", ").length > max_col )
-        ary.pop
-        ary[-1] = "..."
-      end
-      str_ret << ary.join(", ")
-      i = 1
-      while (i<rank)
-	if index[i]<shape[i]-1 then
-	  str_ret << " ]" << sep << "\n"
-	  count_line += 1
-	  index[i] += 1
-	  break
-	else
-	  str_ret << " ]"
-	  index[i] = 0
-	  i += 1
-	end
-      end
-
-      if i>=rank then
-	str_ret << " ]"
-	return str_ret
-      elsif count_line>=max_line then
-	str_ret << " ..."
-	return str_ret
-      end
-
-      (rank-i).times{ str_ret << "  " }
-    end
-    return str_ret
-  end
-
-
-  def _dump(limit)
-    Marshal::dump([@array._dump(nil), at mask._dump(nil)])
-  end
-  def self._load(o)
-    ary, mask = Marshal::load(o)
-    ary = NArray._load(ary)
-    mask = NArray._load(mask)
-    NArrayMiss.to_nam_no_dup(ary,mask)
-  end
-
-
-
-
-#  private
-  private
-  def pos(n,shape)
-    rank = shape.length
-    result = NArray.int(rank)
-    m=n
-    for i in 0..rank-2
-      j = rank-1-i
-      result[j] = m/shape[j-1]
-      m = m%shape[j-1]
-    end
-    result[0] = m
-    result
-  end
-  def binary_operation(arg, dummy)
-    # arg: 第2項目のオブジェクト
-    # dummy: 演算を行っても結果に影響を与えない特別な値。(欠損部分に代入する)
-    flag=true
-    case arg
-    when Numeric
-      term1 = @array
-      term2 = arg
-      mask = @mask
-    when Array, NArray
-      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項目は欠損無し
-      mask = @mask & mask
-    when NArrayMiss
-      term1 = @array.dup
-      term1[@mask.not] = dummy
-      mask = arg.get_mask!
-      term2 = arg.get_array
-      term2[mask.not] = dummy
-      mask = @mask & mask
-    else
-      term1, term2 = arg.coerce(self)
-      # 演算を arg のクラスに任せるため、yield の結果をそのまま返す
-      flag = false
-    end
-    result = yield(term1, term2)
-    result = NArrayMiss.to_nam_no_dup(result, mask) if flag
-    result
-  end
-
-
-  def self.reduction(mask, min_count, dims, flag, typecode)
-    # flag: リダクションを行う次元方向の有効な値の個数で、割り算を行うかどうかのフラグ
-    count_sum = mask.to_type(NArray::LINT).sum(*dims)
-    # 返り値が配列か、スカラーかによって分岐
-    if count_sum.kind_of?(NArray)
-      mask = count_sum.ge(min_count)
-      # すべての要素が欠損値にならないかチェック
-      if mask.any?
-        count_accum = NArray.ref(count_sum)
-        dims.collect{|d|d<0 ? d+mask.rank : d}.sort.each do |d|
-          count_accum.newdim!(d)
-        end
-        # 割り算を行う場合は、先に count_sum を NArrayMiss 化
-        #   yield の戻り値は NArrayMiss
-        # 割り算を行わない場合は、後で NArrayMiss 化
-        #   yield の戻り値は NArray
-        count_sum = NArrayMiss.to_nam_no_dup(count_sum,mask) if flag
-        ary = yield(count_sum, count_accum)
-        ary = NArrayMiss.to_nam_no_dup(ary, mask) unless flag
-      else
-        # すべての要素が欠損値の NArrayMiss を返す
-        na = NArray.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)
-        ary = yield(count_sum, count_accum)
-      else
-        # 有効な要素数が足りない場合は nil を返す
-        return nil
-      end
-    end
-    return ary
-  end
-
-    
-  # 引数にオプション (Hash) が指定されているかチェックし、
-  # されている場合は、オプションを取得し戻り値として返す。
-  # 現時点では、オプションは "min_count" のみ
-  def self.check_options(arg, default_mincount)
-    min_count = default_mincount
-    options = %w(min_count)
-    if arg.length!=0 && arg[-1].kind_of?(Hash)
-      option = arg.pop
-      option.each_key{|key|
-	if !options.index(key) then
-	  raise(ArgumentError,key+" option is not exist")
-	end
-      }
-      min_count = option["min_count"] || default_mincount
-      min_count = min_count.to_i
-      if min_count < default_mincount
-        raise(ArgumentError, "min_count must be >= #{default_mincount}")
-      end
-    end
-    return min_count
-  end
-end
-
-
-
-module NMMath
-
-
-  func1 =  ["sqrt","exp","log","log10","log2",
-            "sin","cos","tan","sinh","cosh","tanh",
-            "asin","acos","atan","asinh","acosh","atanh",
-            "csc", "sec", "cot", "csch", "sech", "coth",
-            "acsc", "asec", "acot", "acsch", "asech", "acoth",
-           ]
-  func2 = ["atan2"]
-
-  for operator in func1
-    eval <<-EOL,nil,__FILE__,__LINE__+1
-    def #{operator}(x)
-      case x
-      when Numeric, Array, NArray
-	NMath::#{operator}(x)
-      when NArrayMiss
-	obj = NArrayMiss.new(x.typecode,*x.shape)
-	mask = x.get_mask!
-	obj[mask] = NMath::#{operator}(x.get_array![mask])
-	obj[mask.not] = x[mask.not]
-	obj.set_mask(mask)
-        obj
-      else
-        raise ArgumentError, "argument is invalid class: \#{x.class}"
-      end
-    end
-    module_function :#{operator}
-    EOL
-  end
-
-  for operator in func2
-    eval <<-EOL,nil,__FILE__,__LINE__+1
-    def #{operator}(x,y)
-      obj = nil
-      case x
-      when Numeric, Array, NArray
-	mask1 = nil
-      when NArrayMiss
-	obj = NArrayMiss.new(x.typecode,*x.shape)
-	mask1 = x.get_mask!
-      else
-        raise ArgumentError, "argument is invalid class"
-      end
-      case y
-      when Numeric, Array, NArray
-	mask2 = nil
-      when NArrayMiss
-	obj ||= NArrayMiss.new(y.typecode,*y.shape)
-	mask2 = y.get_mask!
-      else
-        raise ArgumentError, "argument is invalid class"
-      end
-      if mask2.nil? then
-	if mask1.nil? then
-	  return NMath::#{operator}(x,y)
-	else
-	  obj[mask1] = NMath::#{operator}(x.get_array![mask1],y)
-	  obj[mask1.not] = x[mask1.not]
-	  obj.set_mask(mask1)
-	  return obj
-	end
-      else
-        if mask1.nil? then
-          obj[mask2] = NMath::#{operator}(x,y.get_array![mask2])
-          obj[mask2.not] = y[mask2.not]
-          obj.set_mask(mask2)
-          return obj
-        else
-          obj[mask1&mask2] = NMath::#{operator}(x.get_array![mask1],y.get_array![mask2])
-          obj[(mask1&mask2).not] = x[(mask1&mask2).not]
-          return obj
-        end
-      end
-    end
-    module_function :#{operator}
-    EOL
-  end
-
-  methods = Hash.new
-  methods["covariance"] = {:min_count => 2, :post => <<-EOL}
-    mean0 = ary0.accum(*dims) / count_accum
-    mean1 = ary1.accum(*dims) / count_accum
-    ary = ((ary0-mean0)*(ary1-mean1)).sum(*dims)
-    ary / (count_sum-1)
-  EOL
-  methods.each do |name, hash|
-    eval <<-EOL,nil,__FILE__,__LINE__+1
-      def #{name}(ary0,ary1,*dims)
-        min_count = NArrayMiss.check_options(dims, 2)
-        case ary0
-        when Numeric, Array, NArray
-          mask0 = nil
-        when NArrayMiss
-          mask0 = ary0.get_mask!
-        else
-          raise ArgumentError, "argument is invalid class"
-        end
-        case ary1
-        when Numeric, Array, NArray
-          mask1 = nil
-        when NArrayMiss
-          mask1 = ary1.get_mask!
-        else
-          raise ArgumentError, "argument is invalid class"
-        end
-        if mask1.nil? then
-          if mask0.nil? then
-            return NMath.#{name}(ary0, ary1, *dims)
-          else
-            ary1 = NArrayMiss.to_nam_no_dup(ary1, true)
-          end
-        else
-          if mask0.nil?
-            ary0 = NArrayMiss.to_nam_no_dup(ary0, true)
-          end
-        end
-        if ary1.shape != ary1.shape
-          raise "shape is different"
-        end
-        ary0 = ary0.to_type(NArray::DFLOAT)
-        ary1 = ary1.to_type(NArray::DFLOAT)
-        mask = mask0.nil? ? mask1 : mask1.nil? ? mask0 : mask0&mask1
-        ary0.set_mask(mask)
-        ary1.set_mask(mask)
-        NArrayMiss.reduction(mask, min_count, dims, true, NArray::DFLOAT) do |count_sum, count_accum|
-          #{hash[:post]}
-        end
-      end
-      module_function :#{name}
-    EOL
-  end
-
-  for operator in func1+func2+["covariance"]
-    eval <<-EOL,nil,__FILE__,__LINE__+1
-    def #{operator}(*x)
-      x = [self]+x if NArrayMiss===self
-      NMMath.#{operator}(*x)
-    end
-    EOL
- end
-
-end
-
-class NArrayMiss
-  include NMMath
-end
+require "narray_miss/version"
+require "narray_miss/narray_miss.rb"
diff --git a/lib/narray_miss.rb b/lib/narray_miss/narray_miss.rb
similarity index 98%
copy from lib/narray_miss.rb
copy to lib/narray_miss/narray_miss.rb
index ce06777..088ce7c 100644
--- a/lib/narray_miss.rb
+++ b/lib/narray_miss/narray_miss.rb
@@ -1010,8 +1010,9 @@ go back to ((<Index>))
      return (({NArray})) as data.
 --- NArrayMiss#get_array
      return (({NArray})) as data.
---- NArrayMiss#valid?
-     return (({Array})) whose elements are true or false corresponding to valid or invalid of elements, respectively.
+--- NArrayMiss#valid?(index)
+     return (({Array})) whose elements are true or false, 
+     or (({True}))/(({False})) corresponding to validity of the specified element(s) by the ((|index|))
 --- NArrayMiss#all_valid?
      return true if all elements are valid, else false.
 --- NArrayMiss#none_valid?
@@ -1090,16 +1091,23 @@ go back to ((<Index>))
     @array.dup
   end
 
-  def valid?
-    where = self.get_mask!.where2
-    tf = Array.new(self.total)
-    for i in where[0]
-      tf[i] = true
-    end
-    for i in where[1]
-      tf[i] = false
+  def valid?(*arg)
+    if arg.any?
+      # For the subset specified by the argument(s) (in the same way as for []).
+      # Returns true or false if a single value is specified.
+      # Otherwise, returns an Array of true of false
+      mask = @mask[*arg]
+      if mask.is_a?(Numeric)
+        return mask == 1  # true if mask (==1); false if not
+      end
+    else
+      # no argument
+      mask = @mask
     end
-    tf
+    ary = mask.to_a
+    ary.flatten!
+    ary.map!{|i| i==1}  # true if element == 1; false if not
+    return ary
   end
   def all_valid?
     @mask.all?
diff --git a/lib/narray_miss/version.rb b/lib/narray_miss/version.rb
new file mode 100644
index 0000000..24c207b
--- /dev/null
+++ b/lib/narray_miss/version.rb
@@ -0,0 +1,3 @@
+class NArrayMiss
+  VERSION = "1.2.4"
+end
diff --git a/narray_miss.gemspec b/narray_miss.gemspec
new file mode 100644
index 0000000..af78872
--- /dev/null
+++ b/narray_miss.gemspec
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "narray_miss/version"
+
+Gem::Specification.new do |s|
+  s.name        = "narray_miss"
+  s.version     = NArrayMiss::VERSION
+  s.authors     = ["Seiya Nishizawa"]
+  s.email       = ["seiya at gfd-dennou.org"]
+  s.homepage    = "http://ruby.gfd-dennou.org/products/narray_miss/"
+  s.summary     = %q{Additional class with processing of missing value to NArray}
+  s.description = %q{NArrayMiss is an additional class with processing of missing value to NArray which is a numeric multi-dimensional array class.}
+
+  s.rubyforge_project = "narray_miss"
+
+  s.files         = `git ls-files`.split("\n")
+  s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
+  s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+  s.require_paths = ["lib"]
+  #s.extensions << "ext/extconf.rb"
+
+  # specify any dependencies here; for example:
+  #s.add_development_dependency "rspec"
+  s.add_runtime_dependency "narray"
+end
diff --git a/setup.rb b/setup.rb
deleted file mode 100644
index 0807023..0000000
--- a/setup.rb
+++ /dev/null
@@ -1,1360 +0,0 @@
-#
-# setup.rb
-#
-# Copyright (c) 2000-2004 Minero Aoki
-#
-# This program is free software.
-# You can distribute/modify this program under the terms of
-# the GNU LGPL, Lesser General Public License version 2.1.
-#
-
-unless Enumerable.method_defined?(:map)   # Ruby 1.4.6
-  module Enumerable
-    alias map collect
-  end
-end
-
-unless File.respond_to?(:read)   # Ruby 1.6
-  def File.read(fname)
-    open(fname) {|f|
-      return f.read
-    }
-  end
-end
-
-def File.binread(fname)
-  open(fname, 'rb') {|f|
-    return f.read
-  }
-end
-
-# for corrupted windows stat(2)
-def File.dir?(path)
-  File.directory?((path[-1,1] == '/') ? path : path + '/')
-end
-
-
-class SetupError < StandardError; end
-
-def setup_rb_error(msg)
-  raise SetupError, msg
-end
-
-#
-# Config
-#
-
-if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
-  ARGV.delete(arg)
-  require arg.split(/=/, 2)[1]
-  $".push 'rbconfig.rb'
-else
-  require 'rbconfig'
-end
-
-def multipackage_install?
-  FileTest.directory?(File.dirname($0) + '/packages')
-end
-
-
-class ConfigItem
-  def initialize(name, template, default, desc)
-    @name = name.freeze
-    @template = template
-    @value = default
-    @default = default.dup.freeze
-    @description = desc
-  end
-
-  attr_reader :name
-  attr_reader :description
-
-  attr_accessor :default
-  alias help_default default
-
-  def help_opt
-    "--#{@name}=#{@template}"
-  end
-
-  def value
-    @value
-  end
-
-  def eval(table)
-    @value.gsub(%r<\$([^/]+)>) { table[$1] }
-  end
-
-  def set(val)
-    @value = check(val)
-  end
-
-  private
-
-  def check(val)
-    setup_rb_error "config: --#{name} requires argument" unless val
-    val
-  end
-end
-
-class BoolItem < ConfigItem
-  def config_type
-    'bool'
-  end
-
-  def help_opt
-    "--#{@name}"
-  end
-
-  private
-
-  def check(val)
-    return 'yes' unless val
-    unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ val
-      setup_rb_error "config: --#{@name} accepts only yes/no for argument"
-    end
-    (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'
-  end
-end
-
-class PathItem < ConfigItem
-  def config_type
-    'path'
-  end
-
-  private
-
-  def check(path)
-    setup_rb_error "config: --#{@name} requires argument"  unless path
-    path[0,1] == '$' ? path : File.expand_path(path)
-  end
-end
-
-class ProgramItem < ConfigItem
-  def config_type
-    'program'
-  end
-end
-
-class SelectItem < ConfigItem
-  def initialize(name, template, default, desc)
-    super
-    @ok = template.split('/')
-  end
-
-  def config_type
-    'select'
-  end
-
-  private
-
-  def check(val)
-    unless @ok.include?(val.strip)
-      setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
-    end
-    val.strip
-  end
-end
-
-class PackageSelectionItem < ConfigItem
-  def initialize(name, template, default, help_default, desc)
-    super name, template, default, desc
-    @help_default = help_default
-  end
-
-  attr_reader :help_default
-
-  def config_type
-    'package'
-  end
-
-  private
-
-  def check(val)
-    unless File.dir?("packages/#{val}")
-      setup_rb_error "config: no such package: #{val}"
-    end
-    val
-  end
-end
-
-class ConfigTable_class
-
-  def initialize(items)
-    @items = items
-    @table = {}
-    items.each do |i|
-      @table[i.name] = i
-    end
-    ALIASES.each do |ali, name|
-      @table[ali] = @table[name]
-    end
-  end
-
-  include Enumerable
-
-  def each(&block)
-    @items.each(&block)
-  end
-
-  def key?(name)
-    @table.key?(name)
-  end
-
-  def lookup(name)
-    @table[name] or raise ArgumentError, "no such config item: #{name}"
-  end
-
-  def add(item)
-    @items.push item
-    @table[item.name] = item
-  end
-
-  def remove(name)
-    item = lookup(name)
-    @items.delete_if {|i| i.name == name }
-    @table.delete_if {|name, i| i.name == name }
-    item
-  end
-
-  def new
-    dup()
-  end
-
-  def savefile
-    '.config'
-  end
-
-  def load
-    begin
-      t = dup()
-      File.foreach(savefile()) do |line|
-        k, v = *line.split(/=/, 2)
-        t[k] = v.strip
-      end
-      t
-    rescue Errno::ENOENT
-      setup_rb_error $!.message + "#{File.basename($0)} config first"
-    end
-  end
-
-  def save
-    @items.each {|i| i.value }
-    File.open(savefile(), 'w') {|f|
-      @items.each do |i|
-        f.printf "%s=%s\n", i.name, i.value if i.value
-      end
-    }
-  end
-
-  def [](key)
-    lookup(key).eval(self)
-  end
-
-  def []=(key, val)
-    lookup(key).set val
-  end
-
-end
-
-c = ::Config::CONFIG
-
-rubypath = c['bindir'] + '/' + c['ruby_install_name']
-
-major = c['MAJOR'].to_i
-minor = c['MINOR'].to_i
-teeny = c['TEENY'].to_i
-version = "#{major}.#{minor}"
-
-# ruby ver. >= 1.4.4?
-newpath_p = ((major >= 2) or
-             ((major == 1) and
-              ((minor >= 5) or
-               ((minor == 4) and (teeny >= 4)))))
-
-if c['rubylibdir']
-  # V < 1.6.3
-  _stdruby         = c['rubylibdir']
-  _siteruby        = c['sitedir']
-  _siterubyver     = c['sitelibdir']
-  _siterubyverarch = c['sitearchdir']
-elsif newpath_p
-  # 1.4.4 <= V <= 1.6.3
-  _stdruby         = "$prefix/lib/ruby/#{version}"
-  _siteruby        = c['sitedir']
-  _siterubyver     = "$siteruby/#{version}"
-  _siterubyverarch = "$siterubyver/#{c['arch']}"
-else
-  # V < 1.4.4
-  _stdruby         = "$prefix/lib/ruby/#{version}"
-  _siteruby        = "$prefix/lib/ruby/#{version}/site_ruby"
-  _siterubyver     = _siteruby
-  _siterubyverarch = "$siterubyver/#{c['arch']}"
-end
-libdir = '-* dummy libdir *-'
-stdruby = '-* dummy rubylibdir *-'
-siteruby = '-* dummy site_ruby *-'
-siterubyver = '-* dummy site_ruby version *-'
-parameterize = lambda {|path|
-  path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')\
-      .sub(/\A#{Regexp.quote(libdir)}/,      '$libdir')\
-      .sub(/\A#{Regexp.quote(stdruby)}/,     '$stdruby')\
-      .sub(/\A#{Regexp.quote(siteruby)}/,    '$siteruby')\
-      .sub(/\A#{Regexp.quote(siterubyver)}/, '$siterubyver')
-}
-libdir          = parameterize.call(c['libdir'])
-stdruby         = parameterize.call(_stdruby)
-siteruby        = parameterize.call(_siteruby)
-siterubyver     = parameterize.call(_siterubyver)
-siterubyverarch = parameterize.call(_siterubyverarch)
-
-if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
-  makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
-else
-  makeprog = 'make'
-end
-
-common_conf = [
-  PathItem.new('prefix', 'path', c['prefix'],
-               'path prefix of target environment'),
-  PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
-               'the directory for commands'),
-  PathItem.new('libdir', 'path', libdir,
-               'the directory for libraries'),
-  PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
-               'the directory for shared data'),
-  PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
-               'the directory for man pages'),
-  PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
-               'the directory for man pages'),
-  PathItem.new('stdruby', 'path', stdruby,
-               'the directory for standard ruby libraries'),
-  PathItem.new('siteruby', 'path', siteruby,
-      'the directory for version-independent aux ruby libraries'),
-  PathItem.new('siterubyver', 'path', siterubyver,
-               'the directory for aux ruby libraries'),
-  PathItem.new('siterubyverarch', 'path', siterubyverarch,
-               'the directory for aux ruby binaries'),
-  PathItem.new('rbdir', 'path', '$siterubyver',
-               'the directory for ruby scripts'),
-  PathItem.new('sodir', 'path', '$siterubyverarch',
-               'the directory for ruby extentions'),
-  PathItem.new('rubypath', 'path', rubypath,
-               'the path to set to #! line'),
-  ProgramItem.new('rubyprog', 'name', rubypath,
-                  'the ruby program using for installation'),
-  ProgramItem.new('makeprog', 'name', makeprog,
-                  'the make program to compile ruby extentions'),
-  SelectItem.new('shebang', 'all/ruby/never', 'ruby',
-                 'shebang line (#!) editing mode'),
-  BoolItem.new('without-ext', 'yes/no', 'no',
-               'does not compile/install ruby extentions')
-]
-class ConfigTable_class   # open again
-  ALIASES = {
-    'std-ruby'         => 'stdruby',
-    'site-ruby-common' => 'siteruby',     # For backward compatibility
-    'site-ruby'        => 'siterubyver',  # For backward compatibility
-    'bin-dir'          => 'bindir',
-    'bin-dir'          => 'bindir',
-    'rb-dir'           => 'rbdir',
-    'so-dir'           => 'sodir',
-    'data-dir'         => 'datadir',
-    'ruby-path'        => 'rubypath',
-    'ruby-prog'        => 'rubyprog',
-    'ruby'             => 'rubyprog',
-    'make-prog'        => 'makeprog',
-    'make'             => 'makeprog'
-  }
-end
-multipackage_conf = [
-  PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
-                           'package names that you want to install'),
-  PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
-                           'package names that you do not want to install')
-]
-if multipackage_install?
-  ConfigTable = ConfigTable_class.new(common_conf + multipackage_conf)
-else
-  ConfigTable = ConfigTable_class.new(common_conf)
-end
-
-
-module MetaConfigAPI
-
-  def eval_file_ifexist(fname)
-    instance_eval File.read(fname), fname, 1 if File.file?(fname)
-  end
-
-  def config_names
-    ConfigTable.map {|i| i.name }
-  end
-
-  def config?(name)
-    ConfigTable.key?(name)
-  end
-
-  def bool_config?(name)
-    ConfigTable.lookup(name).config_type == 'bool'
-  end
-
-  def path_config?(name)
-    ConfigTable.lookup(name).config_type == 'path'
-  end
-
-  def value_config?(name)
-    case ConfigTable.lookup(name).config_type
-    when 'bool', 'path'
-      true
-    else
-      false
-    end
-  end
-
-  def add_config(item)
-    ConfigTable.add item
-  end
-
-  def add_bool_config(name, default, desc)
-    ConfigTable.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
-  end
-
-  def add_path_config(name, default, desc)
-    ConfigTable.add PathItem.new(name, 'path', default, desc)
-  end
-
-  def set_config_default(name, default)
-    ConfigTable.lookup(name).default = default
-  end
-
-  def remove_config(name)
-    ConfigTable.remove(name)
-  end
-
-end
-
-
-#
-# File Operations
-#
-
-module FileOperations
-
-  def mkdir_p(dirname, prefix = nil)
-    dirname = prefix + File.expand_path(dirname) if prefix
-    $stderr.puts "mkdir -p #{dirname}" if verbose?
-    return if no_harm?
-
-    # does not check '/'... it's too abnormal case
-    dirs = File.expand_path(dirname).split(%r<(?=/)>)
-    if /\A[a-z]:\z/i =~ dirs[0]
-      disk = dirs.shift
-      dirs[0] = disk + dirs[0]
-    end
-    dirs.each_index do |idx|
-      path = dirs[0..idx].join('')
-      Dir.mkdir path unless File.dir?(path)
-    end
-  end
-
-  def rm_f(fname)
-    $stderr.puts "rm -f #{fname}" if verbose?
-    return if no_harm?
-
-    if File.exist?(fname) or File.symlink?(fname)
-      File.chmod 0777, fname
-      File.unlink fname
-    end
-  end
-
-  def rm_rf(dn)
-    $stderr.puts "rm -rf #{dn}" if verbose?
-    return if no_harm?
-
-    Dir.chdir dn
-    Dir.foreach('.') do |fn|
-      next if fn == '.'
-      next if fn == '..'
-      if File.dir?(fn)
-        verbose_off {
-          rm_rf fn
-        }
-      else
-        verbose_off {
-          rm_f fn
-        }
-      end
-    end
-    Dir.chdir '..'
-    Dir.rmdir dn
-  end
-
-  def move_file(src, dest)
-    File.unlink dest if File.exist?(dest)
-    begin
-      File.rename src, dest
-    rescue
-      File.open(dest, 'wb') {|f| f.write File.binread(src) }
-      File.chmod File.stat(src).mode, dest
-      File.unlink src
-    end
-  end
-
-  def install(from, dest, mode, prefix = nil)
-    $stderr.puts "install #{from} #{dest}" if verbose?
-    return if no_harm?
-
-    realdest = prefix ? prefix + File.expand_path(dest) : dest
-    realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
-    str = File.binread(from)
-    if diff?(str, realdest)
-      verbose_off {
-        rm_f realdest if File.exist?(realdest)
-      }
-      File.open(realdest, 'wb') {|f|
-        f.write str
-      }
-      File.chmod mode, realdest
-
-      File.open("#{objdir_root()}/InstalledFiles", 'a') {|f|
-        if prefix
-          f.puts realdest.sub(prefix, '')
-        else
-          f.puts realdest
-        end
-      }
-    end
-  end
-
-  def diff?(new_content, path)
-    return true unless File.exist?(path)
-    new_content != File.binread(path)
-  end
-
-  def command(str)
-    $stderr.puts str if verbose?
-    system str or raise RuntimeError, "'system #{str}' failed"
-  end
-
-  def ruby(str)
-    command config('rubyprog') + ' ' + str
-  end
-  
-  def make(task = '')
-    command config('makeprog') + ' ' + task
-  end
-
-  def extdir?(dir)
-    File.exist?(dir + '/MANIFEST')
-  end
-
-  def all_files_in(dirname)
-    Dir.open(dirname) {|d|
-      return d.select {|ent| File.file?("#{dirname}/#{ent}") }
-    }
-  end
-
-  REJECT_DIRS = %w(
-    CVS SCCS RCS CVS.adm .svn
-  )
-
-  def all_dirs_in(dirname)
-    Dir.open(dirname) {|d|
-      return d.select {|n| File.dir?("#{dirname}/#{n}") } - %w(. ..) - REJECT_DIRS
-    }
-  end
-
-end
-
-
-#
-# Main Installer
-#
-
-module HookUtils
-
-  def run_hook(name)
-    try_run_hook "#{curr_srcdir()}/#{name}" or
-    try_run_hook "#{curr_srcdir()}/#{name}.rb"
-  end
-
-  def try_run_hook(fname)
-    return false unless File.file?(fname)
-    begin
-      instance_eval File.read(fname), fname, 1
-    rescue
-      setup_rb_error "hook #{fname} failed:\n" + $!.message
-    end
-    true
-  end
-
-end
-
-
-module HookScriptAPI
-
-  def get_config(key)
-    @config[key]
-  end
-
-  alias config get_config
-
-  def set_config(key, val)
-    @config[key] = val
-  end
-
-  #
-  # srcdir/objdir (works only in the package directory)
-  #
-
-  #abstract srcdir_root
-  #abstract objdir_root
-  #abstract relpath
-
-  def curr_srcdir
-    "#{srcdir_root()}/#{relpath()}"
-  end
-
-  def curr_objdir
-    "#{objdir_root()}/#{relpath()}"
-  end
-
-  def srcfile(path)
-    "#{curr_srcdir()}/#{path}"
-  end
-
-  def srcexist?(path)
-    File.exist?(srcfile(path))
-  end
-
-  def srcdirectory?(path)
-    File.dir?(srcfile(path))
-  end
-  
-  def srcfile?(path)
-    File.file? srcfile(path)
-  end
-
-  def srcentries(path = '.')
-    Dir.open("#{curr_srcdir()}/#{path}") {|d|
-      return d.to_a - %w(. ..)
-    }
-  end
-
-  def srcfiles(path = '.')
-    srcentries(path).select {|fname|
-      File.file?(File.join(curr_srcdir(), path, fname))
-    }
-  end
-
-  def srcdirectories(path = '.')
-    srcentries(path).select {|fname|
-      File.dir?(File.join(curr_srcdir(), path, fname))
-    }
-  end
-
-end
-
-
-class ToplevelInstaller
-
-  Version   = '3.3.1'
-  Copyright = 'Copyright (c) 2000-2004 Minero Aoki'
-
-  TASKS = [
-    [ 'all',      'do config, setup, then install' ],
-    [ 'config',   'saves your configurations' ],
-    [ 'show',     'shows current configuration' ],
-    [ 'setup',    'compiles ruby extentions and others' ],
-    [ 'install',  'installs files' ],
-    [ 'clean',    "does `make clean' for each extention" ],
-    [ 'distclean',"does `make distclean' for each extention" ]
-  ]
-
-  def ToplevelInstaller.invoke
-    instance().invoke
-  end
-
-  @singleton = nil
-
-  def ToplevelInstaller.instance
-    @singleton ||= new(File.dirname($0))
-    @singleton
-  end
-
-  include MetaConfigAPI
-
-  def initialize(ardir_root)
-    @config = nil
-    @options = { 'verbose' => true }
-    @ardir = File.expand_path(ardir_root)
-  end
-
-  def inspect
-    "#<#{self.class} #{__id__()}>"
-  end
-
-  def invoke
-    run_metaconfigs
-    case task = parsearg_global()
-    when nil, 'all'
-      @config = load_config('config')
-      parsearg_config
-      init_installers
-      exec_config
-      exec_setup
-      exec_install
-    else
-      @config = load_config(task)
-      __send__ "parsearg_#{task}"
-      init_installers
-      __send__ "exec_#{task}"
-    end
-  end
-  
-  def run_metaconfigs
-    eval_file_ifexist "#{@ardir}/metaconfig"
-  end
-
-  def load_config(task)
-    case task
-    when 'config'
-      ConfigTable.new
-    when 'clean', 'distclean'
-      if File.exist?(ConfigTable.savefile)
-      then ConfigTable.load
-      else ConfigTable.new
-      end
-    else
-      ConfigTable.load
-    end
-  end
-
-  def init_installers
-    @installer = Installer.new(@config, @options, @ardir, File.expand_path('.'))
-  end
-
-  #
-  # Hook Script API bases
-  #
-
-  def srcdir_root
-    @ardir
-  end
-
-  def objdir_root
-    '.'
-  end
-
-  def relpath
-    '.'
-  end
-
-  #
-  # Option Parsing
-  #
-
-  def parsearg_global
-    valid_task = /\A(?:#{TASKS.map {|task,desc| task }.join '|'})\z/
-
-    while arg = ARGV.shift
-      case arg
-      when /\A\w+\z/
-        setup_rb_error "invalid task: #{arg}" unless valid_task =~ arg
-        return arg
-
-      when '-q', '--quiet'
-        @options['verbose'] = false
-
-      when       '--verbose'
-        @options['verbose'] = true
-
-      when '-h', '--help'
-        print_usage $stdout
-        exit 0
-
-      when '-v', '--version'
-        puts "#{File.basename($0)} version #{Version}"
-        exit 0
-      
-      when '--copyright'
-        puts Copyright
-        exit 0
-
-      else
-        setup_rb_error "unknown global option '#{arg}'"
-      end
-    end
-
-    nil
-  end
-
-
-  def parsearg_no_options
-    unless ARGV.empty?
-      setup_rb_error "#{task}:  unknown options: #{ARGV.join ' '}"
-    end
-  end
-
-  alias parsearg_show       parsearg_no_options
-  alias parsearg_setup      parsearg_no_options
-  alias parsearg_clean      parsearg_no_options
-  alias parsearg_distclean  parsearg_no_options
-
-  def parsearg_config
-    re = /\A--(#{ConfigTable.map {|i| i.name }.join('|')})(?:=(.*))?\z/
-    @options['config-opt'] = []
-
-    while i = ARGV.shift
-      if /\A--?\z/ =~ i
-        @options['config-opt'] = ARGV.dup
-        break
-      end
-      m = re.match(i)  or setup_rb_error "config: unknown option #{i}"
-      name, value = *m.to_a[1,2]
-      @config[name] = value
-    end
-  end
-
-  def parsearg_install
-    @options['no-harm'] = false
-    @options['install-prefix'] = ''
-    while a = ARGV.shift
-      case a
-      when /\A--no-harm\z/
-        @options['no-harm'] = true
-      when /\A--prefix=(.*)\z/
-        path = $1
-        path = File.expand_path(path) unless path[0,1] == '/'
-        @options['install-prefix'] = path
-      else
-        setup_rb_error "install: unknown option #{a}"
-      end
-    end
-  end
-
-  def print_usage(out)
-    out.puts 'Typical Installation Procedure:'
-    out.puts "  $ ruby #{File.basename $0} config"
-    out.puts "  $ ruby #{File.basename $0} setup"
-    out.puts "  # ruby #{File.basename $0} install (may require root privilege)"
-    out.puts
-    out.puts 'Detailed Usage:'
-    out.puts "  ruby #{File.basename $0} <global option>"
-    out.puts "  ruby #{File.basename $0} [<global options>] <task> [<task options>]"
-
-    fmt = "  %-24s %s\n"
-    out.puts
-    out.puts 'Global options:'
-    out.printf fmt, '-q,--quiet',   'suppress message outputs'
-    out.printf fmt, '   --verbose', 'output messages verbosely'
-    out.printf fmt, '-h,--help',    'print this message'
-    out.printf fmt, '-v,--version', 'print version and quit'
-    out.printf fmt, '   --copyright',  'print copyright and quit'
-    out.puts
-    out.puts 'Tasks:'
-    TASKS.each do |name, desc|
-      out.printf fmt, name, desc
-    end
-
-    fmt = "  %-24s %s [%s]\n"
-    out.puts
-    out.puts 'Options for CONFIG or ALL:'
-    ConfigTable.each do |item|
-      out.printf fmt, item.help_opt, item.description, item.help_default
-    end
-    out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
-    out.puts
-    out.puts 'Options for INSTALL:'
-    out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
-    out.printf fmt, '--prefix=path',  'install path prefix', '$prefix'
-    out.puts
-  end
-
-  #
-  # Task Handlers
-  #
-
-  def exec_config
-    @installer.exec_config
-    @config.save   # must be final
-  end
-
-  def exec_setup
-    @installer.exec_setup
-  end
-
-  def exec_install
-    @installer.exec_install
-  end
-
-  def exec_show
-    ConfigTable.each do |i|
-      printf "%-20s %s\n", i.name, i.value
-    end
-  end
-
-  def exec_clean
-    @installer.exec_clean
-  end
-
-  def exec_distclean
-    @installer.exec_distclean
-  end
-
-end
-
-
-class ToplevelInstallerMulti < ToplevelInstaller
-
-  include HookUtils
-  include HookScriptAPI
-  include FileOperations
-
-  def initialize(ardir)
-    super
-    @packages = all_dirs_in("#{@ardir}/packages")
-    raise 'no package exists' if @packages.empty?
-  end
-
-  def run_metaconfigs
-    eval_file_ifexist "#{@ardir}/metaconfig"
-    @packages.each do |name|
-      eval_file_ifexist "#{@ardir}/packages/#{name}/metaconfig"
-    end
-  end
-
-  def init_installers
-    @installers = {}
-    @packages.each do |pack|
-      @installers[pack] = Installer.new(@config, @options,
-                                       "#{@ardir}/packages/#{pack}",
-                                       "packages/#{pack}")
-    end
-
-    with    = extract_selection(config('with'))
-    without = extract_selection(config('without'))
-    @selected = @installers.keys.select {|name|
-                  (with.empty? or with.include?(name)) \
-                      and not without.include?(name)
-                }
-  end
-
-  def extract_selection(list)
-    a = list.split(/,/)
-    a.each do |name|
-      setup_rb_error "no such package: #{name}"  unless @installers.key?(name)
-    end
-    a
-  end
-
-  def print_usage(f)
-    super
-    f.puts 'Inluded packages:'
-    f.puts '  ' + @packages.sort.join(' ')
-    f.puts
-  end
-
-  #
-  # multi-package metaconfig API
-  #
-
-  attr_reader :packages
-
-  def declare_packages(list)
-    raise 'package list is empty' if list.empty?
-    list.each do |name|
-      raise "directory packages/#{name} does not exist"\
-              unless File.dir?("#{@ardir}/packages/#{name}")
-    end
-    @packages = list
-  end
-
-  #
-  # Task Handlers
-  #
-
-  def exec_config
-    run_hook 'pre-config'
-    each_selected_installers {|inst| inst.exec_config }
-    run_hook 'post-config'
-    @config.save   # must be final
-  end
-
-  def exec_setup
-    run_hook 'pre-setup'
-    each_selected_installers {|inst| inst.exec_setup }
-    run_hook 'post-setup'
-  end
-
-  def exec_install
-    run_hook 'pre-install'
-    each_selected_installers {|inst| inst.exec_install }
-    run_hook 'post-install'
-  end
-
-  def exec_clean
-    rm_f ConfigTable.savefile
-    run_hook 'pre-clean'
-    each_selected_installers {|inst| inst.exec_clean }
-    run_hook 'post-clean'
-  end
-
-  def exec_distclean
-    rm_f ConfigTable.savefile
-    run_hook 'pre-distclean'
-    each_selected_installers {|inst| inst.exec_distclean }
-    run_hook 'post-distclean'
-  end
-
-  #
-  # lib
-  #
-
-  def each_selected_installers
-    Dir.mkdir 'packages' unless File.dir?('packages')
-    @selected.each do |pack|
-      $stderr.puts "Processing the package `#{pack}' ..." if @options['verbose']
-      Dir.mkdir "packages/#{pack}" unless File.dir?("packages/#{pack}")
-      Dir.chdir "packages/#{pack}"
-      yield @installers[pack]
-      Dir.chdir '../..'
-    end
-  end
-
-  def verbose?
-    @options['verbose']
-  end
-
-  def no_harm?
-    @options['no-harm']
-  end
-
-end
-
-
-class Installer
-
-  FILETYPES = %w( bin lib ext data )
-
-  include HookScriptAPI
-  include HookUtils
-  include FileOperations
-
-  def initialize(config, opt, srcroot, objroot)
-    @config = config
-    @options = opt
-    @srcdir = File.expand_path(srcroot)
-    @objdir = File.expand_path(objroot)
-    @currdir = '.'
-  end
-
-  def inspect
-    "#<#{self.class} #{File.basename(@srcdir)}>"
-  end
-
-  #
-  # Hook Script API base methods
-  #
-
-  def srcdir_root
-    @srcdir
-  end
-
-  def objdir_root
-    @objdir
-  end
-
-  def relpath
-    @currdir
-  end
-
-  #
-  # configs/options
-  #
-
-  def no_harm?
-    @options['no-harm']
-  end
-
-  def verbose?
-    @options['verbose']
-  end
-
-  def verbose_off
-    begin
-      save, @options['verbose'] = @options['verbose'], false
-      yield
-    ensure
-      @options['verbose'] = save
-    end
-  end
-
-  #
-  # TASK config
-  #
-
-  def exec_config
-    exec_task_traverse 'config'
-  end
-
-  def config_dir_bin(rel)
-  end
-
-  def config_dir_lib(rel)
-  end
-
-  def config_dir_ext(rel)
-    extconf if extdir?(curr_srcdir())
-  end
-
-  def extconf
-    opt = @options['config-opt'].join(' ')
-    command "#{config('rubyprog')} #{curr_srcdir()}/extconf.rb #{opt}"
-  end
-
-  def config_dir_data(rel)
-  end
-
-  #
-  # TASK setup
-  #
-
-  def exec_setup
-    exec_task_traverse 'setup'
-  end
-
-  def setup_dir_bin(rel)
-    all_files_in(curr_srcdir()).each do |fname|
-      adjust_shebang "#{curr_srcdir()}/#{fname}"
-    end
-  end
-
-  def adjust_shebang(path)
-    return if no_harm?
-    tmpfile = File.basename(path) + '.tmp'
-    begin
-      File.open(path, 'rb') {|r|
-        first = r.gets
-        return unless File.basename(config('rubypath')) == 'ruby'
-        return unless File.basename(first.sub(/\A\#!/, '').split[0]) == 'ruby'
-        $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?
-        File.open(tmpfile, 'wb') {|w|
-          w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
-          w.write r.read
-        }
-        move_file tmpfile, File.basename(path)
-      }
-    ensure
-      File.unlink tmpfile if File.exist?(tmpfile)
-    end
-  end
-
-  def setup_dir_lib(rel)
-  end
-
-  def setup_dir_ext(rel)
-    make if extdir?(curr_srcdir())
-  end
-
-  def setup_dir_data(rel)
-  end
-
-  #
-  # TASK install
-  #
-
-  def exec_install
-    rm_f 'InstalledFiles'
-    exec_task_traverse 'install'
-  end
-
-  def install_dir_bin(rel)
-    install_files collect_filenames_auto(), "#{config('bindir')}/#{rel}", 0755
-  end
-
-  def install_dir_lib(rel)
-    install_files ruby_scripts(), "#{config('rbdir')}/#{rel}", 0644
-  end
-
-  def install_dir_ext(rel)
-    return unless extdir?(curr_srcdir())
-    install_files ruby_extentions('.'),
-                  "#{config('sodir')}/#{File.dirname(rel)}",
-                  0555
-  end
-
-  def install_dir_data(rel)
-    install_files collect_filenames_auto(), "#{config('datadir')}/#{rel}", 0644
-  end
-
-  def install_files(list, dest, mode)
-    mkdir_p dest, @options['install-prefix']
-    list.each do |fname|
-      install fname, dest, mode, @options['install-prefix']
-    end
-  end
-
-  def ruby_scripts
-    collect_filenames_auto().select {|n| /\.rb\z/ =~ n }
-  end
-  
-  # picked up many entries from cvs-1.11.1/src/ignore.c
-  reject_patterns = %w( 
-    core RCSLOG tags TAGS .make.state
-    .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
-    *~ *.old *.bak *.BAK *.orig *.rej _$* *$
-
-    *.org *.in .*
-  )
-  mapping = {
-    '.' => '\.',
-    '$' => '\$',
-    '#' => '\#',
-    '*' => '.*'
-  }
-  REJECT_PATTERNS = Regexp.new('\A(?:' +
-                               reject_patterns.map {|pat|
-                                 pat.gsub(/[\.\$\#\*]/) {|ch| mapping[ch] }
-                               }.join('|') +
-                               ')\z')
-
-  def collect_filenames_auto
-    mapdir((existfiles() - hookfiles()).reject {|fname|
-             REJECT_PATTERNS =~ fname
-           })
-  end
-
-  def existfiles
-    all_files_in(curr_srcdir()) | all_files_in('.')
-  end
-
-  def hookfiles
-    %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
-      %w( config setup install clean ).map {|t| sprintf(fmt, t) }
-    }.flatten
-  end
-
-  def mapdir(filelist)
-    filelist.map {|fname|
-      if File.exist?(fname)   # objdir
-        fname
-      else                    # srcdir
-        File.join(curr_srcdir(), fname)
-      end
-    }
-  end
-
-  def ruby_extentions(dir)
-    Dir.open(dir) {|d|
-      ents = d.select {|fname| /\.#{::Config::CONFIG['DLEXT']}\z/ =~ fname }
-      if ents.empty?
-        setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
-      end
-      return ents
-    }
-  end
-
-  #
-  # TASK clean
-  #
-
-  def exec_clean
-    exec_task_traverse 'clean'
-    rm_f ConfigTable.savefile
-    rm_f 'InstalledFiles'
-  end
-
-  def clean_dir_bin(rel)
-  end
-
-  def clean_dir_lib(rel)
-  end
-
-  def clean_dir_ext(rel)
-    return unless extdir?(curr_srcdir())
-    make 'clean' if File.file?('Makefile')
-  end
-
-  def clean_dir_data(rel)
-  end
-
-  #
-  # TASK distclean
-  #
-
-  def exec_distclean
-    exec_task_traverse 'distclean'
-    rm_f ConfigTable.savefile
-    rm_f 'InstalledFiles'
-  end
-
-  def distclean_dir_bin(rel)
-  end
-
-  def distclean_dir_lib(rel)
-  end
-
-  def distclean_dir_ext(rel)
-    return unless extdir?(curr_srcdir())
-    make 'distclean' if File.file?('Makefile')
-  end
-
-  #
-  # lib
-  #
-
-  def exec_task_traverse(task)
-    run_hook "pre-#{task}"
-    FILETYPES.each do |type|
-      if config('without-ext') == 'yes' and type == 'ext'
-        $stderr.puts 'skipping ext/* by user option' if verbose?
-        next
-      end
-      traverse task, type, "#{task}_dir_#{type}"
-    end
-    run_hook "post-#{task}"
-  end
-
-  def traverse(task, rel, mid)
-    dive_into(rel) {
-      run_hook "pre-#{task}"
-      __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
-      all_dirs_in(curr_srcdir()).each do |d|
-        traverse task, "#{rel}/#{d}", mid
-      end
-      run_hook "post-#{task}"
-    }
-  end
-
-  def dive_into(rel)
-    return unless File.dir?("#{@srcdir}/#{rel}")
-
-    dir = File.basename(rel)
-    Dir.mkdir dir unless File.dir?(dir)
-    prevdir = Dir.pwd
-    Dir.chdir dir
-    $stderr.puts '---> ' + rel if verbose?
-    @currdir = rel
-    yield
-    Dir.chdir prevdir
-    $stderr.puts '<--- ' + rel if verbose?
-    @currdir = File.dirname(rel)
-  end
-
-end
-
-
-if $0 == __FILE__
-  begin
-    if multipackage_install?
-      ToplevelInstallerMulti.invoke
-    else
-      ToplevelInstaller.invoke
-    end
-  rescue SetupError
-    raise if $DEBUG
-    $stderr.puts $!.message
-    $stderr.puts "Try 'ruby #{$0} --help' for detailed usage."
-    exit 1
-  end
-end
diff --git a/test/test_narray_miss.rb b/test/test_narray_miss.rb
index fa4d0b1..4e6ae84 100644
--- a/test/test_narray_miss.rb
+++ b/test/test_narray_miss.rb
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), "..", "lib", "narray_miss")
+$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
+require "narray_miss"
 require "test/unit"
 
 class NArrayMissTest < Test::Unit::TestCase
@@ -33,6 +34,15 @@ NArrayMiss.dfloat(4,4):
 =end
   end
 
+  def test_valid?
+    assert_equal([true,true,true,true,false,true,true,true,false,false,false,true,false,false,false,false], @int.valid?)
+    assert_equal([true,true,true,true], @int.valid?(true,0))
+    assert_equal([false,true,true,true], @int.valid?(true,1))
+    assert_equal([true,true,true,false], @int.valid?(3,true))
+    assert_equal(true, @int.valid?[7])
+    assert_equal(false, @int.valid?[10])
+  end
+
   def test_add
     ary = NArrayMiss.float(@n, at n)
     ary[true,0] = [0, 2, 4, 6]

-- 
Additional Ruby Class handling missing value



More information about the Pkg-grass-devel mailing list