[SCM] narray-miss branch, master, updated. debian/1.2.1-1-6-g644db12
Youhei SASAKI
uwabami at gfd-dennou.org
Wed Jun 8 06:50:02 UTC 2011
The following commit has been merged in the master branch:
commit c70435be2d133a5d8f50ed25381383ceaeba280c
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date: Wed May 11 17:23:36 2011 +0900
Imported Upstream version 1.2.2
diff --git a/ChangeLog b/ChangeLog
index e38244b..aab12cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+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 *
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..9115e2f
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,34 @@
+NArrayMiss is copyrighted free software by Seiya Nishizawa and GFD
+Dennou Club (http://www.gfd-dennou.org/).
+
+Copyright 2001 (C) Seiya Nishizawa and GFD Dennou Club
+(http://www.gfd-dennou.org/) All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+THIS SOFTWARE IS PROVIDED BY GFD DENNOU CLUB AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GFD DENNOU CLUB OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation
+are those of the authors and should not be interpreted as representing
+official policies, either expressed or implied, of Seiya Nishizawa
+and GFD Dennou Club.
diff --git a/doc/narray_miss.html b/doc/narray_miss.html
deleted file mode 100644
index 3a88ecb..0000000
--- a/doc/narray_miss.html
+++ /dev/null
@@ -1,469 +0,0 @@
-<?xml version="1.0" ?>
-<!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>../lib/narray_miss.rb</title>
-</head>
-<body>
-<h1><a name="label-0" id="label-0">NArrayMiss Class</a></h1><!-- RDLabel: "NArrayMiss Class" -->
-<p>NArrayMiss is a additional class processing of missing value with to
-<a href="http://www.ruby-lang.org/en/raa-list.rhtml?name=NArray">NArray</a>
-for Ruby.</p>
-<p>To use NArrayMiss class, you need invoking "require 'narray_miss.rb'" in your script.</p>
-<h2><a name="label-1" id="label-1">Index</a></h2><!-- RDLabel: "Index" -->
-<ul>
-<li><a href="#label-2">Class Constants</a></li>
-<li><a href="#label-11">Class Methods</a></li>
-<li><a href="#label-24">Class Instance Methods</a>
-<ul>
-<li><a href="#label-25">NArrayMiss information</a></li>
-<li><a href="#label-34">Slicing Array</a></li>
-<li><a href="#label-39">Filling values</a></li>
-<li><a href="#label-47">Arithmetic operator</a></li>
-<li><a href="#label-62">Bitwise operator</a></li>
-<li><a href="#label-67">Comparison</a></li>
-<li><a href="#label-82">Statistics</a></li>
-<li><a href="#label-90">Sort</a></li>
-<li><a href="#label-93">Transpose</a></li>
-<li><a href="#label-95">Changing Shapes of indices</a></li>
-<li><a href="#label-103">Type conversion</a></li>
-<li><a href="#label-115">Iteration</a></li>
-<li><a href="#label-121">Boolean and mask related</a></li>
-<li><a href="#label-130">Complex compound number</a></li>
-<li><a href="#label-137">Byte swap</a></li>
-<li><a href="#label-143">Mask and missing value</a></li>
-<li><a href="#label-163">Others</a></li>
-</ul></li>
-</ul>
-<h2><a name="label-2" id="label-2">Class Constants</a></h2><!-- RDLabel: "Class Constants" -->
-<dl>
-<dt><a name="label-3" id="label-3"><code>NArrayMiss::BYTE</code></a></dt><!-- RDLabel: "NArrayMiss::BYTE" -->
-<dd>
-type code for 1 byte unsigned integer.</dd>
-<dt><a name="label-4" id="label-4"><code>NArrayMiss::SINT</code></a></dt><!-- RDLabel: "NArrayMiss::SINT" -->
-<dd>
-type code for 2 byte signed integer.</dd>
-<dt><a name="label-5" id="label-5"><code>NArrayMiss::INT</code></a></dt><!-- RDLabel: "NArrayMiss::INT" -->
-<dd>
-type code for 4 byte signed integer.</dd>
-<dt><a name="label-6" id="label-6"><code>NArrayMiss::SFLOAT</code></a></dt><!-- RDLabel: "NArrayMiss::SFLOAT" -->
-<dd>
-type code for single precision float.</dd>
-<dt><a name="label-7" id="label-7"><code>NArrayMiss::FLOAT</code></a></dt><!-- RDLabel: "NArrayMiss::FLOAT" -->
-<dd>
-type code for double precision float.</dd>
-<dt><a name="label-8" id="label-8"><code>NArrayMiss::SCOMPLEX</code></a></dt><!-- RDLabel: "NArrayMiss::SCOMPLEX" -->
-<dd>
-type code for single precision complex.</dd>
-<dt><a name="label-9" id="label-9"><code>NArrayMiss::COMPLEX</code></a></dt><!-- RDLabel: "NArrayMiss::COMPLEX" -->
-<dd>
-type code for double precision complex.</dd>
-<dt><a name="label-10" id="label-10"><code>NArrayMiss::OBJECT</code></a></dt><!-- RDLabel: "NArrayMiss::OBJECT" -->
-<dd>
-type code for Ruby object.</dd>
-</dl>
-<p>go back to <a href="#label-1">Index</a></p>
-<h2><a name="label-11" id="label-11">Class Methods</a></h2><!-- RDLabel: "Class Methods" -->
-<dl>
-<dt><a name="label-12" id="label-12"><code>NArrayMiss.new(<var>typecode</var>, <var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.new" -->
-<dd>
-create <code>NArrayMiss</code> of <var>typecode</var>.
-All elements are initialized with 0.</dd>
-<dt><a name="label-13" id="label-13"><code>NArrayMiss.byte(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.byte" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::BYTE, <var>size</var>, ...).</dd>
-<dt><a name="label-14" id="label-14"><code>NArrayMiss.sint(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.sint" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::SINT, <var>size</var>, ...).</dd>
-<dt><a name="label-15" id="label-15"><code>NArrayMiss.int(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.int" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::INT, <var>size</var>, ...).</dd>
-<dt><a name="label-16" id="label-16"><code>NArrayMiss.sfloat(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.sfloat" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::SFLOAT, <var>size</var>, ...).</dd>
-<dt><a name="label-17" id="label-17"><code>NArrayMiss.float(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.float" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::FLOAT, <var>size</var>, ...).</dd>
-<dt><a name="label-18" id="label-18"><code>NArrayMiss.scomplex(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.scomplex" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::SCOMPLEX, <var>size</var>, ...).</dd>
-<dt><a name="label-19" id="label-19"><code>NArrayMiss.complex(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.complex" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::COMPLEX, <var>size</var>, ...).</dd>
-<dt><a name="label-20" id="label-20"><code>NArrayMiss.object(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss.object" -->
-<dd>
-same as NArrayMiss.new(NArrayMiss::OBJECT, <var>size</var>, ...).</dd>
-<dt><a name="label-21" id="label-21"><code>NArrayMiss[](<var>value</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss[]" -->
-<dd>
-create <code>NArrayMiss</code> form [<var>value</var>, ...].</dd>
-<dt><a name="label-22" id="label-22"><code>NArrayMiss.to_nam(<var>array</var> [,<var>mask</var>])</code></a></dt><!-- RDLabel: "NArrayMiss.to_nam" -->
-<dd>
-create <code>NArrayMiss</code> from <var>array</var>.
-<var>array</var> must be <code>Numeric</code> <code>Array</code> or <code>NArray</code>.</dd>
-<dt><a name="label-23" id="label-23"><code>NArrayMiss.to_nam_no_dup(<var>array</var> [,<var>mask</var>])</code></a></dt><!-- RDLabel: "NArrayMiss.to_nam_no_dup" -->
-<dd>
-convert from <var>array</var> to <code>NArrayMiss</code>.</dd>
-</dl>
-<p>go back to <a href="#label-1">Index</a></p>
-<h2><a name="label-24" id="label-24">Class Instance Methods</a></h2><!-- RDLabel: "Class Instance Methods" -->
-<h3><a name="label-25" id="label-25">NArrayMiss information</a></h3><!-- RDLabel: "NArrayMiss information" -->
-<dl>
-<dt><a name="label-26" id="label-26"><code>NArrayMiss#dim</code></a></dt><!-- RDLabel: "NArrayMiss#dim" -->
-<dd>
-return the dimension which is the number of indices.</dd>
-<dt><a name="label-27" id="label-27"><code>NArrayMiss#rank</code></a></dt><!-- RDLabel: "NArrayMiss#rank" -->
-<dd>
-same as <code>NArrayMiss#dim</code>.</dd>
-<dt><a name="label-28" id="label-28"><code>NArrayMiss#shape</code></a></dt><!-- RDLabel: "NArrayMiss#shape" -->
-<dd>
-return the <code>Array</code> of sizes of each index.</dd>
-<dt><a name="label-29" id="label-29"><code>NArrayMiss#size</code></a></dt><!-- RDLabel: "NArrayMiss#size" -->
-<dd>
-return the number of total elements.</dd>
-<dt><a name="label-30" id="label-30"><code>NArrayMiss#total</code></a></dt><!-- RDLabel: "NArrayMiss#total" -->
-<dd>
-alias to size</dd>
-<dt><a name="label-31" id="label-31"><code>NArrayMiss#length</code></a></dt><!-- RDLabel: "NArrayMiss#length" -->
-<dd>
-alias to size</dd>
-<dt><a name="label-32" id="label-32"><code>NArrayMiss#rank_total</code></a></dt><!-- RDLabel: "NArrayMiss#rank_total" -->
-<dd>
-return the number of total of the shape.</dd>
-<dt><a name="label-33" id="label-33"><code>NArrayMiss#typecode</code></a></dt><!-- RDLabel: "NArrayMiss#typecode" -->
-<dd>
-return the typecode.</dd>
-</dl>
-<h3><a name="label-34" id="label-34">Slicing Array</a></h3><!-- RDLabel: "Slicing Array" -->
-<dl>
-<dt><a name="label-35" id="label-35"><code>NArrayMiss#[<var>index</var>]</code></a></dt><!-- RDLabel: "NArrayMiss#[]" -->
-<dd>
-return the value at [<var>index</var>].
-<var>index</var> must be <code>Integer, Range, Array, true</code>.
-Index order is FORTRAN type.</dd>
-<dt><a name="label-36" id="label-36"><code>NArrayMiss#slice(<var>index</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#slice" -->
-<dd>
-same as <code>NArrayMiss#[]</code> but keeps the rank of original array by not elimiting dimensions whose length became equal to 1 (which <code>NArrayMiss#[]</code> dose).
-This is not the case with the 1-dimensional indexing and masking.</dd>
-<dt><a name="label-37" id="label-37"><code>NArrayMiss#set_without_validation(<var>index</var>,<var>value</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#set_without_validation" -->
-<dd>
-replace elements at <var>index</var> by <var>value</var>.</dd>
-<dt><a name="label-38" id="label-38"><code>NArrayMiss#[<var>index</var>] = <var>value</var></code></a></dt><!-- RDLabel: "NArrayMiss#[]=" -->
-<dd>
-replace elements at <var>index</var> by <var>value</var> and
-make replaced elements valid. </dd>
-</dl>
-<h3><a name="label-39" id="label-39">Filling values</a></h3><!-- RDLabel: "Filling values" -->
-<dl>
-<dt><a name="label-40" id="label-40"><code>NArrayMiss#indgen!([<var>start</var>[,<var>step</var>]])</code></a></dt><!-- RDLabel: "NArrayMiss#indgen!" -->
-<dd>
-set values from <var>start</var> with <var>step</var> increment.</dd>
-<dt><a name="label-41" id="label-41"><code>NArrayMiss#indgen([<var>start</var>[,<var>step</var>]])</code></a></dt><!-- RDLabel: "NArrayMiss#indgen" -->
-<dd>
-same as <code>NArrayMiss#indgen!</code> but create new object.</dd>
-<dt><a name="label-42" id="label-42"><code>NArrayMiss#fill!(<var>value</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#fill!" -->
-<dd>
-fill elements with <var>value</var>.</dd>
-<dt><a name="label-43" id="label-43"><code>NArrayMiss#fill(<var>value</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#fill" -->
-<dd>
-same as <code>NArrayMiss#fill!</code> but create new object.</dd>
-<dt><a name="label-44" id="label-44"><code>NArrayMiss#random!(<var>max</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#random!" -->
-<dd>
-set random values between 0<=x<<var>max</var>.</dd>
-<dt><a name="label-45" id="label-45"><code>NArrayMiss#random(<var>max</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#random" -->
-<dd>
-same as <code>NArrayMiss#random!</code> but create new object.</dd>
-<dt><a name="label-46" id="label-46"><code>NArrayMiss#randomn(<var>max</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#randomn" -->
-<dd>
-set normally distributed random values with mean=0, dispersion=1 (Box-Muller)</dd>
-</dl>
-<h3><a name="label-47" id="label-47">Arithmetic operator</a></h3><!-- RDLabel: "Arithmetic operator" -->
-<dl>
-<dt><a name="label-48" id="label-48"><code>NArrayMiss#-@</code></a></dt><!-- RDLabel: "NArrayMiss#-@" -->
-<dt><a name="label-49" id="label-49"><code>NArrayMiss#+(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#+" -->
-<dt><a name="label-50" id="label-50"><code>NArrayMiss#-(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#-" -->
-<dt><a name="label-51" id="label-51"><code>NArrayMiss#*(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#*" -->
-<dt><a name="label-52" id="label-52"><code>NArrayMiss#/(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#/" -->
-<dt><a name="label-53" id="label-53"><code>NArrayMiss#%(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#%" -->
-<dt><a name="label-54" id="label-54"><code>NArrayMiss#**(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#**" -->
-<dt><a name="label-55" id="label-55"><code>NArrayMiss#abs</code></a></dt><!-- RDLabel: "NArrayMiss#abs" -->
-<dt><a name="label-56" id="label-56"><code>NArrayMiss#add!(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#add!" -->
-<dt><a name="label-57" id="label-57"><code>NArrayMiss#sbt!(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#sbt!" -->
-<dt><a name="label-58" id="label-58"><code>NArrayMiss#mul!(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#mul!" -->
-<dt><a name="label-59" id="label-59"><code>NArrayMiss#div!(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#div!" -->
-<dt><a name="label-60" id="label-60"><code>NArrayMiss#mod!(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#mod!" -->
-<dt><a name="label-61" id="label-61"><code>NArrayMiss#mul_add(<var>other</var>, <var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#mul_add" -->
-</dl>
-<h3><a name="label-62" id="label-62">Bitwise operator (only for byte, sint and int)</a></h3><!-- RDLabel: "Bitwise operator (only for byte, sint and int)" -->
-<dl>
-<dt><a name="label-63" id="label-63"><code>NArrayMiss#~@</code></a></dt><!-- RDLabel: "NArrayMiss#~@" -->
-<dt><a name="label-64" id="label-64"><code>NArrayMiss#&(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#&" -->
-<dt><a name="label-65" id="label-65"><code>NArrayMiss#|(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#|" -->
-<dt><a name="label-66" id="label-66"><code>NArrayMiss#^(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#^" -->
-</dl>
-<h3><a name="label-67" id="label-67">Comparison</a></h3><!-- RDLabel: "Comparison" -->
-<dl>
-<dt><a name="label-68" id="label-68"><code>NArrayMiss#eq(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#eq" -->
-<dt><a name="label-69" id="label-69"><code>NArrayMiss#ne(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#ne" -->
-<dt><a name="label-70" id="label-70"><code>NArrayMiss#gt(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#gt" -->
-<dt><a name="label-71" id="label-71"><code>NArrayMiss#ge(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#ge" -->
-<dt><a name="label-72" id="label-72"><code>NArrayMiss#lt(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#lt" -->
-<dt><a name="label-73" id="label-73"><code>NArrayMiss#le(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#le" -->
-<dt><a name="label-74" id="label-74"><code>NArrayMiss#>(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#>" -->
-<dt><a name="label-75" id="label-75"><code>NArrayMiss#>=(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#>=" -->
-<dt><a name="label-76" id="label-76"><code>NArrayMiss#<(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#<" -->
-<dt><a name="label-77" id="label-77"><code>NArrayMiss#<=(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#<=" -->
-<dt><a name="label-78" id="label-78"><code>NArrayMiss#and(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#and" -->
-<dt><a name="label-79" id="label-79"><code>NArrayMiss#or(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#or" -->
-<dt><a name="label-80" id="label-80"><code>NArrayMiss#xor(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#xor" -->
-<dt><a name="label-81" id="label-81"><code>NArrayMiss#not(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#not" -->
-</dl>
-<h3><a name="label-82" id="label-82">Statistics</a></h3><!-- RDLabel: "Statistics" -->
-<dl>
-<dt><a name="label-83" id="label-83"><code>NArrayMiss#sum(<var>dim</var>, ... ["<var>min_count</var>"=><var>i</var>])</code></a></dt><!-- RDLabel: "NArrayMiss#sum" -->
-<dd>
-return summation of elements in specified dimensions.
-Elements at which the number of elements for summation is less than <var>i</var> is invalid.</dd>
-<dt><a name="label-84" id="label-84"><code>NArrayMiss#accum(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#accum" -->
-<dd>
-same as <code>NArrayMiss#sum</code> but not elimiting dimensions whose length became equal to 1.</dd>
-<dt><a name="label-85" id="label-85"><code>NArrayMiss#min(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#min" -->
-<dd>
-return minimum in specified dimensions.
-Elements at which the number of valid elements in the dimension is less than <var>i</var> is invalid.</dd>
-<dt><a name="label-86" id="label-86"><code>NArrayMiss#max(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#max" -->
-<dd>
-return maximum in specified dimensions.
-Elements at which the number of valid elements in the dimension is less than <var>i</var> is invalid.</dd>
-<dt><a name="label-87" id="label-87"><code>NArrayMiss#median(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#median" -->
-<dd>
-return median in specified dimensions.
-Elements at which the number of valid elements in the dimension is less than <var>i</var> is invalid.</dd>
-<dt><a name="label-88" id="label-88"><code>NArrayMiss#mean(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#mean" -->
-<dd>
-return mean of elements in specified dimensions.
-Elements at which the number of elements for then mean is less than <var>i</var> is invalid.</dd>
-<dt><a name="label-89" id="label-89"><code>NArrayMiss#stddev(<var>dim</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#stddev" -->
-<dd>
-return standard deviation of elements in specified dimensions.
-Elements at which the number of elements for calculation the standard deviation is less than <var>i</var> is invalid.</dd>
-</dl>
-<h3><a name="label-90" id="label-90">Sort</a></h3><!-- RDLabel: "Sort" -->
-<dl>
-<dt><a name="label-91" id="label-91"><code>NArrayMiss#sort(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#sort" -->
-<dd>
-sort in the 0..<var>dim</var> (All dimensions if omitted)</dd>
-<dt><a name="label-92" id="label-92"><code>NArrayMiss#sort_index(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#sort_index" -->
-<dd>
-return index of sort result.</dd>
-</dl>
-<h3><a name="label-93" id="label-93">Transpose</a></h3><!-- RDLabel: "Transpose" -->
-<dl>
-<dt><a name="label-94" id="label-94"><code>NArrayMiss#transpose(<var>dim0</var>, <var>dim1</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#transpose" -->
-<dd>
-transpose array. The 0-th dimension goes to the <var>dim0</var>-th dimension of new array.</dd>
-</dl>
-<h3><a name="label-95" id="label-95">Changing Shapes of indices</a></h3><!-- RDLabel: "Changing Shapes of indices" -->
-<dl>
-<dt><a name="label-96" id="label-96"><code>NArrayMiss#reshape!(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#reshape!" -->
-<dd>
-change shape of array.</dd>
-<dt><a name="label-97" id="label-97"><code>NArrayMiss#reshape(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#reshape" -->
-<dd>
-same as <code>NArrayMiss#reshape!</code> but create new object.</dd>
-<dt><a name="label-98" id="label-98"><code>NArrayMiss#shape=(<var>size</var>, ...)</code></a></dt><!-- RDLabel: "NArrayMiss#shape=" -->
-<dd>
-same as <code>NArrayMiss#reshape!</code>.</dd>
-<dt><a name="label-99" id="label-99"><code>NArrayMiss#newdim!(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#newdim!" -->
-<dd>
-insert new dimension with size=1</dd>
-<dt><a name="label-100" id="label-100"><code>NArrayMiss#newdim(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#newdim" -->
-<dd>
-same as <code>NArrayMiss#newdim!</code> but create new object.</dd>
-<dt><a name="label-101" id="label-101"><code>NArrayMiss#rewrank!(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#rewrank!" -->
-<dd>
-same as <code>NArrayMiss#newdim!</code>.</dd>
-<dt><a name="label-102" id="label-102"><code>NArrayMiss#rewrank=(<var>dim</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#rewrank=" -->
-<dd>
-same as <code>NArrayMiss#newdim!</code>.</dd>
-</dl>
-<h3><a name="label-103" id="label-103">Type conversion</a></h3><!-- RDLabel: "Type conversion" -->
-<dl>
-<dt><a name="label-104" id="label-104"><code>NArrayMiss#floor</code></a></dt><!-- RDLabel: "NArrayMiss#floor" -->
-<dd>
-return <code>NArrayMiss</code> of integer whose elements processed <code>floor</code>.</dd>
-<dt><a name="label-105" id="label-105"><code>NArrayMiss#ceil</code></a></dt><!-- RDLabel: "NArrayMiss#ceil" -->
-<dd>
-return <code>NArrayMiss</code> of integer whose elements processed <code>ceil</code>.</dd>
-<dt><a name="label-106" id="label-106"><code>NArrayMiss#round</code></a></dt><!-- RDLabel: "NArrayMiss#round" -->
-<dd>
-return <code>NArrayMiss</code> of integer whose elements processed <code>round</code>.</dd>
-<dt><a name="label-107" id="label-107"><code>NArrayMiss#to_i</code></a></dt><!-- RDLabel: "NArrayMiss#to_i" -->
-<dd>
-return <code>NArrayMiss</code> of integer whose elements processed <code>to_i</code>.</dd>
-<dt><a name="label-108" id="label-108"><code>NArrayMiss#to_f</code></a></dt><!-- RDLabel: "NArrayMiss#to_f" -->
-<dd>
-return <code>NArrayMiss</code> of float whose elements processed <code>to_f</code>.</dd>
-<dt><a name="label-109" id="label-109"><code>NArrayMiss#to_type(<var>typecode</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#to_type" -->
-<dd>
-return <code>NArrayMiss</code> of <var>typecode</var>.</dd>
-<dt><a name="label-110" id="label-110"><code>NArrayMiss#to_a</code></a></dt><!-- RDLabel: "NArrayMiss#to_a" -->
-<dd>
-convert <code>NArrayMiss</code> to <code>Array</code>.</dd>
-<dt><a name="label-111" id="label-111"><code>NArrayMiss#to_na!([<var>missing_value</var>])</code></a></dt><!-- RDLabel: "NArrayMiss#to_na!" -->
-<dd>
-convert <code>NArrayMiss</code> to <code>NArray</code>.
-if there is argument, set missing_value for invalid elements.</dd>
-<dt><a name="label-112" id="label-112"><code>NArrayMiss#to_na([<var>missing_value</var>])</code></a></dt><!-- RDLabel: "NArrayMiss#to_na" -->
-<dd>
-convert <code>NArrayMiss</code> to <code>NArray</code>.
-if there is argument, set missing_value for invalid elements.</dd>
-<dt><a name="label-113" id="label-113"><code>NArrayMiss#to_s</code></a></dt><!-- RDLabel: "NArrayMiss#to_s" -->
-<dd>
-convert <code>NArrayMiss</code> to <code>String</code> as a binary data.</dd>
-<dt><a name="label-114" id="label-114"><code>NArrayMiss#to_string</code></a></dt><!-- RDLabel: "NArrayMiss#to_string" -->
-<dd>
-create <code>NArrayMiss</code> of object whose elements are processed <code>to_s</code></dd>
-</dl>
-<h3><a name="label-115" id="label-115">Iteration</a></h3><!-- RDLabel: "Iteration" -->
-<dl>
-<dt><a name="label-116" id="label-116"><code>NArrayMiss#each{|<var>x</var>| ...}</code></a></dt><!-- RDLabel: "NArrayMiss#each" -->
-<dt><a name="label-117" id="label-117"><code>NArrayMiss#each_valid{|<var>x</var>| ...}</code></a></dt><!-- RDLabel: "NArrayMiss#each_valid" -->
-<dt><a name="label-118" id="label-118"><code>NArrayMiss#each_valid_with_index{|<var>x</var>,<var>i</var>| ...}</code></a></dt><!-- RDLabel: "NArrayMiss#each_valid_with_index" -->
-<dt><a name="label-119" id="label-119"><code>NArrayMiss#collect{|<var>x</var>| ...}</code></a></dt><!-- RDLabel: "NArrayMiss#collect" -->
-<dt><a name="label-120" id="label-120"><code>NArrayMiss#collect!{|<var>x</var>| ...}</code></a></dt><!-- RDLabel: "NArrayMiss#collect!" -->
-</dl>
-<h3><a name="label-121" id="label-121">Boolean and mask related (only for byte, sint and int)</a></h3><!-- RDLabel: "Boolean and mask related (only for byte, sint and int)" -->
-<dl>
-<dt><a name="label-122" id="label-122"><code>NArrayMiss#count_false</code></a></dt><!-- RDLabel: "NArrayMiss#count_false" -->
-<dd>
-return the number of elements whose value==0 and valid.</dd>
-<dt><a name="label-123" id="label-123"><code>NArrayMiss#count_true</code></a></dt><!-- RDLabel: "NArrayMiss#count_true" -->
-<dd>
-return the number of elements whose value!=0 and valid.</dd>
-<dt><a name="label-124" id="label-124"><code>NArrayMiss#mask(<var>mask</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#mask" -->
-<dd>
-return <code>NArrayMiss#get_mask!&<var>mask</var></code>.</dd>
-<dt><a name="label-125" id="label-125"><code>NArrayMiss#all?</code></a></dt><!-- RDLabel: "NArrayMiss#all?" -->
-<dd>
-return true if all the valid elements are not 0, else false.</dd>
-<dt><a name="label-126" id="label-126"><code>NArrayMiss#any?</code></a></dt><!-- RDLabel: "NArrayMiss#any?" -->
-<dd>
-return true if any valid element is not 0, else false.</dd>
-<dt><a name="label-127" id="label-127"><code>NArrayMiss#none?</code></a></dt><!-- RDLabel: "NArrayMiss#none?" -->
-<dd>
-return true if none of the valid elements is not 0, else false.</dd>
-<dt><a name="label-128" id="label-128"><code>NArrayMiss#where</code></a></dt><!-- RDLabel: "NArrayMiss#where" -->
-<dd>
-return <code>NArray</code> of indices where valid elements are not 0.</dd>
-<dt><a name="label-129" id="label-129"><code>NArrayMiss#where2</code></a></dt><!-- RDLabel: "NArrayMiss#where2" -->
-<dd>
-return <code>Array</code> including two <code>NArray</code>s of indices,
-where valid elements are not 0, and 0, respectively.</dd>
-</dl>
-<h3><a name="label-130" id="label-130">Complex compound number (only for scomplex and complex)</a></h3><!-- RDLabel: "Complex compound number (only for scomplex and complex)" -->
-<dl>
-<dt><a name="label-131" id="label-131"><code>NArrayMiss#real</code></a></dt><!-- RDLabel: "NArrayMiss#real" -->
-<dt><a name="label-132" id="label-132"><code>NArrayMiss#imag</code></a></dt><!-- RDLabel: "NArrayMiss#imag" -->
-<dt><a name="label-133" id="label-133"><code>NArrayMiss#conj</code></a></dt><!-- RDLabel: "NArrayMiss#conj" -->
-<dt><a name="label-134" id="label-134"><code>NArrayMiss#angle</code></a></dt><!-- RDLabel: "NArrayMiss#angle" -->
-<dt><a name="label-135" id="label-135"><code>NArrayMiss#imag=(<var>other</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#imag=" -->
-<dt><a name="label-136" id="label-136"><code>NArrayMiss#im</code></a></dt><!-- RDLabel: "NArrayMiss#im" -->
-</dl>
-<h3><a name="label-137" id="label-137">Byte swap</a></h3><!-- RDLabel: "Byte swap" -->
-<dl>
-<dt><a name="label-138" id="label-138"><code>NArrayMiss#swap_byte</code></a></dt><!-- RDLabel: "NArrayMiss#swap_byte" -->
-<dd>
-swap byte order.</dd>
-<dt><a name="label-139" id="label-139"><code>NArrayMiss#hton</code></a></dt><!-- RDLabel: "NArrayMiss#hton" -->
-<dd>
-convert to network byte order.</dd>
-<dt><a name="label-140" id="label-140"><code>NArrayMiss#ntoh</code></a></dt><!-- RDLabel: "NArrayMiss#ntoh" -->
-<dd>
-convert from network byte order.</dd>
-<dt><a name="label-141" id="label-141"><code>NArrayMiss#htov</code></a></dt><!-- RDLabel: "NArrayMiss#htov" -->
-<dd>
-convert to VAX byte order.</dd>
-<dt><a name="label-142" id="label-142"><code>NArrayMiss#vtoh</code></a></dt><!-- RDLabel: "NArrayMiss#vtoh" -->
-<dd>
-convert from VAX byte order.</dd>
-</dl>
-<h3><a name="label-143" id="label-143">Mask and missing value</a></h3><!-- RDLabel: "Mask and missing value" -->
-<dl>
-<dt><a name="label-144" id="label-144"><code>NArrayMiss#set_valid(<var>index</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#set_valid" -->
-<dd>
-validate element at <var>index</var>.
-<var>index</var> must be <code>Integer, Range, Array, or ture</code>.</dd>
-<dt><a name="label-145" id="label-145"><code>NArrayMiss#validation(<var>index</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#validation" -->
-<dd>
-alias to set_valid</dd>
-<dt><a name="label-146" id="label-146"><code>NArrayMiss#set_invalid(<var>index</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#set_invalid" -->
-<dd>
-invaliadate element at <var>index</var>.
-<var>index</var> must be <code>Integer, Range, Array, or ture</code>.</dd>
-<dt><a name="label-147" id="label-147"><code>NArrayMiss#invalidation(<var>index</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#invalidation" -->
-<dd>
-alias to set_invalid</dd>
-<dt><a name="label-148" id="label-148"><code>NArrayMiss#all_valid</code></a></dt><!-- RDLabel: "NArrayMiss#all_valid" -->
-<dd>
-set all elements valid</dd>
-<dt><a name="label-149" id="label-149"><code>NArrayMiss#all_invalid</code></a></dt><!-- RDLabel: "NArrayMiss#all_invalid" -->
-<dd>
-set all elements invalid</dd>
-<dt><a name="label-150" id="label-150"><code>NArrayMiss#set_mask(<var>mask</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#set_mask" -->
-<dd>
-masking by <var>mask</var></dd>
-<dt><a name="label-151" id="label-151"><code>NArrayMiss#set_missing_value(<var>value</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#set_missing_value" -->
-<dd>
-replace invalid elements by <var>value</var>.</dd>
-<dt><a name="label-152" id="label-152"><code>NArrayMiss#get_mask!</code></a></dt><!-- RDLabel: "NArrayMiss#get_mask!" -->
-<dd>
-return <code>NArray</code> of byte as mask.</dd>
-<dt><a name="label-153" id="label-153"><code>NArrayMiss#get_mask</code></a></dt><!-- RDLabel: "NArrayMiss#get_mask" -->
-<dd>
-return <code>NArray</code> of byte as mask.</dd>
-<dt><a name="label-154" id="label-154"><code>NArrayMiss#get_array!</code></a></dt><!-- RDLabel: "NArrayMiss#get_array!" -->
-<dd>
-return <code>NArray</code> as data.</dd>
-<dt><a name="label-155" id="label-155"><code>NArrayMiss#get_array</code></a></dt><!-- RDLabel: "NArrayMiss#get_array" -->
-<dd>
-return <code>NArray</code> as data.</dd>
-<dt><a name="label-156" id="label-156"><code>NArrayMiss#valid?</code></a></dt><!-- RDLabel: "NArrayMiss#valid?" -->
-<dd>
-return <code>Array</code> whose elements are true or false corresponding to valid or invalid of elements, respectively.</dd>
-<dt><a name="label-157" id="label-157"><code>NArrayMiss#all_valid?</code></a></dt><!-- RDLabel: "NArrayMiss#all_valid?" -->
-<dd>
-return true if all elements are valid, else false.</dd>
-<dt><a name="label-158" id="label-158"><code>NArrayMiss#none_valid?</code></a></dt><!-- RDLabel: "NArrayMiss#none_valid?" -->
-<dd>
-return true if all elements are invalid, else false.</dd>
-<dt><a name="label-159" id="label-159"><code>NArrayMiss#all_invalid?</code></a></dt><!-- RDLabel: "NArrayMiss#all_invalid?" -->
-<dd>
-alias to none_valid?</dd>
-<dt><a name="label-160" id="label-160"><code>NArrayMiss#any_valid?</code></a></dt><!-- RDLabel: "NArrayMiss#any_valid?" -->
-<dd>
-return true if any elements are valid, else false.</dd>
-<dt><a name="label-161" id="label-161"><code>NArrayMiss#count_valid</code></a></dt><!-- RDLabel: "NArrayMiss#count_valid" -->
-<dd>
-return the number of valid elements.</dd>
-<dt><a name="label-162" id="label-162"><code>NArrayMiss#count_invalid</code></a></dt><!-- RDLabel: "NArrayMiss#count_invalid" -->
-<dd>
-return the number of invalid elements.</dd>
-</dl>
-<h3><a name="label-163" id="label-163">Others</a></h3><!-- RDLabel: "Others" -->
-<dl>
-<dt><a name="label-164" id="label-164"><code>NArrayMiss#integer?</code></a></dt><!-- RDLabel: "NArrayMiss#integer?" -->
-<dd>
-return true if <code>NArrayMiss</code> is byte, sint or int, else false.</dd>
-<dt><a name="label-165" id="label-165"><code>NArrayMiss#complex?</code></a></dt><!-- RDLabel: "NArrayMiss#complex?" -->
-<dd>
-return true if <code>NArrayMiss</code> is scomplex or complex, else false.</dd>
-<dt><a name="label-166" id="label-166"><code>NArrayMiss#dup</code></a></dt><!-- RDLabel: "NArrayMiss#dup" -->
-<dt><a name="label-167" id="label-167"><code>NArrayMiss#coerce(<var>object</var>)</code></a></dt><!-- RDLabel: "NArrayMiss#coerce" -->
-<dt><a name="label-168" id="label-168"><code>NArrayMiss#inspect</code></a></dt><!-- RDLabel: "NArrayMiss#inspect" -->
-</dl>
-<p>go back to <a href="#label-1">Index</a></p>
-
-</body>
-</html>
diff --git a/lib/narray_miss.rb b/lib/narray_miss.rb
index e275af2..ce06777 100644
--- a/lib/narray_miss.rb
+++ b/lib/narray_miss.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
=begin
= NArrayMiss Class
@@ -342,7 +343,7 @@ go back to ((<Index>))
set normally distributed random values with mean=0, dispersion=1 (Box-Muller)
=end
- for operator in ["indgen","fill","random"]
+ for operator in ["indgen","fill","random","randomn"]
eval(<<-EOL,nil,__FILE__,__LINE__+1)
def #{operator}(*arg)
obj = self.dup
@@ -356,11 +357,6 @@ go back to ((<Index>))
end
EOL
end
- def randomn
- obj = self.dup
- obj[@mask] = @array[@mask].randomn
- obj
- end
=begin
@@ -386,37 +382,47 @@ go back to ((<Index>))
array[@mask] = - at array[@mask]
NArrayMiss.to_nam_no_dup(array, @mask.dup)
end
- for operator in ["+","-","*","/","%","**"]
- dummy = {"+"=>0,"-"=>0,"*"=>1,"/"=>1,"%"=>1,"**"=>1}[operator]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- if !arg then
- @mask = 0
- return self
- else
- term1,term2,mask,flag = routine1(arg,#{dummy})
- result = term1 #{operator} term2
- routine2(result,mask,flag)
- end
- end
- EOL
+ 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
- for operator in ["add!","sbt!","mul!","div!","mod!"]
- dummy = {"add!"=>0,"sbt!"=>0,"mul!"=>1,"div!"=>1,"mod!"=>1}[operator]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- term1,term2,mask,flag = routine1(arg,#{dummy})
- result = term1.#{operator} term2
- routine2(result,mask,flag)
- end
- EOL
+ 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
@@ -437,15 +443,14 @@ go back to ((<Index>))
def ~@
NArrayMiss.to_nam_to_dup(~@array, @mask.dup)
end
- for operator in ["&","|","^"]
- dummy = {"&"=>1,"|"=>0,"^"=>1}[operator]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- term1,term2,mask,flag = routine1(arg,#{dummy})
- result = term1 #{operator} term2
- routine2(result,mask,flag)
- end
- EOL
+ 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
@@ -467,46 +472,46 @@ go back to ((<Index>))
--- NArrayMiss#not(other)
=end
- for operator in ["eq","ne","gt","ge","lt","le"]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- term1,term2,mask,flag = routine1(arg,0)
- result = term1.#{operator} term2
- routine2(result,mask,flag)
- end
- EOL
+ def eq(arg)
+ binary_operation(arg, 0){|t1, t2| t1.eq t2}
end
- for operator in [">",">=","<","<="]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- term1,term2,mask,flag = routine1(arg,0)
- result = term1 #{operator} term2
- routine2(result,mask,flag)
- end
- EOL
+ 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
- for operator in ["and","or","xor"]
- dummy = {"and"=>1,"or"=>0,"xor"=>1}[operator]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(arg)
- term1,term2,mask,flag = routine1(arg,#{dummy})
- result = term1.#{operator} term2
- routine2(result,mask,flag)
- end
- EOL
+ 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 art.kind_of?(NArrayMiss) then
-# @array==arg.get_array! && @mask==arg.get_mask!
-# else
-# false
-# end
-# end
+ def ==(arg)
+ if arg.kind_of?(NArrayMiss) then
+ @mask==arg.get_mask! && @array[@mask]==arg.get_array![@mask]
+ else
+ false
+ end
+ end
=begin
@@ -531,6 +536,12 @@ go back to ((<Index>))
--- 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)
@@ -544,119 +555,75 @@ go back to ((<Index>))
end
end
- for operator in ["sum","min","max"]
- str = {"sum"=>"0","min"=>"array.max","max"=>"array.min",}[operator]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}(*arg)
- if @mask.count_true == 0 then
- return nil
- end
- min_count=1
- options = ["min_count"]
- if arg.length!=0 && arg[-1].class==Hash then
- option = arg[-1]
- arg = arg[0..-2]
- option.each_key{|key|
- if !options.index(key) then
- raise(ArgumentError,key+" option is not exist")
- end
- }
- min_count = option["min_count"]
- end
- mask = @mask.to_type(NArray::INT)
- array = @array.dup
- array[@mask.not] = #{str}
- mask = mask.sum(*arg)
- if NArray===mask then
- if mask.ge(min_count).count_true == 0 then
- return nil
- else
- return NArrayMiss.to_nam_no_dup(array.#{operator}(*arg),
- mask.ge(min_count))
- end
- else
- if mask < min_count
- return nil
- else
- return array.#{operator}
- 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
- EOL
end
- def mean(*arg)
- if @mask.count_true == 0 then
- return nil
- end
- min_count = 1
- options=["min_count"]
- if arg.length!=0 && arg[-1].class==Hash then
- option = arg[-1]
- arg2=arg[0..-2]
- option.each_key{|key|
- if !options.index(key) then
- raise(ArgumentError,key+" option is not exist")
- end
- }
- min_count = option["min_count"]
- else
- arg2=arg
+ 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
- count = @mask.to_type(NArray::INT).sum(*arg2)
- if count.class == NArray then
- count = NArrayMiss.to_nam(count,count.ge(min_count))
- if count.ge(min_count).count_true == 0
- return nil
- else
- return self.sum(*arg2)/count
- end
- else
- if count < min_count then
- return nil
- else
- return self.sum(*arg2)/count
- 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 stddev(*arg)
- if @mask.count_true == 0 then
- return nil
+
+ 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
- min_count=2
- options=["min_count"]
- if arg.length!=0 && arg[-1].class==Hash then
- option = arg[-1]
- arg = arg[0..-2]
- option.each_key{|key|
- if !options.index(key) then
- raise(ArgumentError,key+" option is not exist")
- end
- }
- min_count = option["min_count"].to_i
- if min_count<2
- raise(ArgumentError, "min_count must be >= 2")
- 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
- count = @mask.to_type(NArray::INT).sum(*arg)
- count2 = @mask.to_type(NArray::INT).accum(*arg)
- if count.class==NArray then
- count = NArrayMiss.to_nam_no_dup(count,count.ge(min_count))
- if count.get_mask!.count_true == 0
- return nil
- end
- else
- if count < min_count then
- return nil
- 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
- if self.integer? then
- a = self.to_f
- else
- a = self
+ 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
- var = ( (a-a.accum(*arg)/count2)**2 ).sum(*arg)/(count-1)
- obj = NMMath::sqrt(var)
- return obj
end
def median(*arg)
@@ -811,13 +778,22 @@ go back to ((<Index>))
create (({NArrayMiss})) of object whose elements are processed (({to_s}))
=end
- for operator in ["floor","ceil","round","to_i","to_f"]
- eval(<<-EOL,nil,__FILE__,__LINE__+1)
- def #{operator}
- NArrayMiss.to_nam_no_dup(@array.#{operator}, @mask.dup)
- end
- EOL
+ 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
@@ -1207,18 +1183,18 @@ go back to ((<Index>))
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 += " []"
+ str_ret << " []"
return str_ret
else
- str_ret += "\n"
+ str_ret << "\n"
end
str = ""
index = Array.new(rank,0)
index[0] = true
i = 1
- (rank-1).times{ str_ret += "[ " }
+ (rank-1).times{ str_ret << "[ " }
while(true)
- i.times{ str_ret += "[ " }
+ i.times{ str_ret << "[ " }
str = @array[*index].inspect
ary = str[str.index("[")+1..str.index("]")-1].strip.split(/\s*,\s*/)
@@ -1232,30 +1208,30 @@ go back to ((<Index>))
ary.pop
ary[-1] = "..."
end
- str_ret += ary.join(", ")
+ str_ret << ary.join(", ")
i = 1
while (i<rank)
if index[i]<shape[i]-1 then
- str_ret += " ]"+sep+"\n"
+ str_ret << " ]" << sep << "\n"
count_line += 1
index[i] += 1
break
else
- str_ret += " ]"
+ str_ret << " ]"
index[i] = 0
i += 1
end
end
if i>=rank then
- str_ret += " ]"
+ str_ret << " ]"
return str_ret
elsif count_line>=max_line then
- str_ret += " ..."
+ str_ret << " ..."
return str_ret
end
- (rank-i).times{ print(" ") }
+ (rank-i).times{ str_ret << " " }
end
return str_ret
end
@@ -1288,54 +1264,98 @@ go back to ((<Index>))
result[0] = m
result
end
- def routine1(arg,dummy)
+ def binary_operation(arg, dummy)
+ # arg: 第2項目のオブジェクト
+ # dummy: 演算を行っても結果に影響を与えない特別な値。(欠損部分に代入する)
flag=true
- if Numeric===arg then
- term1 = @array.dup
- term2 = arg
- mask = true
- elsif arg.class == Array then
+ case arg
+ when Numeric
term1 = @array
- term1[@mask.not] = dummy
- term2 = NArray.to_na(arg)
- mask = NArray.byte(*term2.shape).fill(1)
- elsif arg.class == NArray then
+ term2 = arg
+ mask = @mask
+ when Array, NArray
term1 = @array.dup
- term1[@mask.not] = dummy
- term2 = arg.dup
- mask = NArray.byte(*term2.shape).fill(1)
- elsif arg.class == NArrayMiss then
- mask = arg.get_mask
+ 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
- term2 = arg.to_na
- term2[arg.get_mask!.not] = dummy
+ mask = arg.get_mask!
+ term2 = arg.get_array
+ term2[mask.not] = dummy
+ mask = @mask & mask
else
- term1,term2 = arg.coerce(self)
- flag=false
+ term1, term2 = arg.coerce(self)
+ # 演算を arg のクラスに任せるため、yield の結果をそのまま返す
+ flag = false
end
- [term1,term2,mask,flag]
+ result = yield(term1, term2)
+ result = NArrayMiss.to_nam_no_dup(result, mask) if flag
+ result
end
- def routine2(result,mask,flag)
- if flag then
- obj = NArrayMiss.to_nam_no_dup(result)
- if mask==true then
- obj.set_mask(@mask)
+
+
+ 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
- mask = @mask+mask
- obj.set_mask(mask.eq(2))
+ # すべての要素が欠損値の NArrayMiss を返す
+ na = NArray.new(typecode, *mask.shape)
+ ary = NArrayMiss.to_nam_no_dup(na, false)
end
-# obj.set_without_validation(@mask.not, at array[@mask.not])
- if Numeric===obj && obj.get_mask![0]==1 then
- return obj.get_array[0]
+ else
+ # 有効な要素数があるかチェック
+ if count_sum >= min_count
+ count_accum = NArray.int(*([1]*mask.rank)).fill!(count_sum)
+ ary = yield(count_sum, count_accum)
else
- return obj
+ # 有効な要素数が足りない場合は nil を返す
+ return nil
end
- else
- result
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
@@ -1345,21 +1365,27 @@ module NMMath
func1 = ["sqrt","exp","log","log10","log2",
"sin","cos","tan","sinh","cosh","tanh",
- "asin","acos","atan","asinh","acosh","atanh"]
+ "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)
- if Numeric===x || x.class==Array || x.class==NArray then
+ case x
+ when Numeric, Array, NArray
NMath::#{operator}(x)
- elsif x.class == NArrayMiss then
+ 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}
@@ -1369,17 +1395,24 @@ module NMMath
for operator in func2
eval <<-EOL,nil,__FILE__,__LINE__+1
def #{operator}(x,y)
- if Numeric===x || x.class==Array || x.class==NArray then
+ obj = nil
+ case x
+ when Numeric, Array, NArray
mask1 = nil
- elsif x.class == NArrayMiss then
+ when NArrayMiss
obj = NArrayMiss.new(x.typecode,*x.shape)
mask1 = x.get_mask!
+ else
+ raise ArgumentError, "argument is invalid class"
end
- if Numeric===y || y.class==Array || y.class==NArray then
+ case y
+ when Numeric, Array, NArray
mask2 = nil
- elsif y.class == NArrayMiss then
- obj = NArrayMiss.new(y.typecode,*y.shape)
+ 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
@@ -1398,7 +1431,6 @@ module NMMath
return obj
else
obj[mask1&mask2] = NMath::#{operator}(x.get_array![mask1],y.get_array![mask2])
- obj[(mask1&mask2).not] = y[(mask1&mask2).not]
obj[(mask1&mask2).not] = x[(mask1&mask2).not]
return obj
end
@@ -1408,14 +1440,69 @@ module NMMath
EOL
end
- for operator in func1+func2
+ 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)
+ NMMath.#{operator}(*x)
end
EOL
- end
+ end
+
end
class NArrayMiss
diff --git a/test/test_narray_miss.rb b/test/test_narray_miss.rb
new file mode 100644
index 0000000..fa4d0b1
--- /dev/null
+++ b/test/test_narray_miss.rb
@@ -0,0 +1,146 @@
+require File.join(File.dirname(__FILE__), "..", "lib", "narray_miss")
+require "test/unit"
+
+class NArrayMissTest < Test::Unit::TestCase
+
+ def assert_equal(expected, actual, message=nil)
+ if expected.kind_of?(Float)
+ assert((expected-actual)/expected < 1.0e-10, message || <<EOF)
+<#{expected}> expected but was
+<#{actual}>.
+EOF
+ else
+ super(expected, actual, message)
+ end
+ end
+
+ def setup
+ @n = 4
+ @mask = NArray.byte(@n, at n)
+ @mask[true,0] = 1
+ @mask[1..-1,1] = 1
+ @mask[-1,2] = 1
+ @float = NArrayMiss.float(@n, at n).indgen; @float.set_mask(@mask)
+ @int = NArrayMiss.int(@n, at n).indgen; @int.set_mask(@mask)
+=begin
+ @float #=>
+NArrayMiss.dfloat(4,4):
+ [ [ 0.0, 1.0, 2.0, 3.0 ],
+ [ - , 5.0, 6.0, 7.0 ],
+ [ - , - , - , 11.0 ],
+ [ - , - , - , - ]
+ ]
+=end
+ end
+
+ def test_add
+ ary = NArrayMiss.float(@n, at n)
+ ary[true,0] = [0, 2, 4, 6]
+ ary[1..-1,1] = [10, 12, 14]
+ ary[-1,2] = 22
+ a1 = @float.dup
+ a2 = @int.dup
+ assert_equal(ary, a1 + a2)
+ assert_equal(@float, a1)
+ assert_equal(@int, a2)
+ end
+
+ def test_sum
+ assert_equal(35.0, @float.sum)
+ assert_equal(35, @int.sum)
+
+ assert_equal(NArrayMiss.to_nam([6.0,18.0,11.0,0.0],[1,1,1,0]), @float.sum(0))
+ assert_equal(NArrayMiss.to_nam([6,18,11,0],[1,1,1,0]), @int.sum(0))
+
+ assert_equal(NArrayMiss.to_nam([6.0,18.0,0.0,0.0],[1,1,0,0]), @float.sum(0, "min_count"=>2))
+
+ assert_equal(NArrayMiss.to_nam([0.0,6.0,8.0,21.0],[1,1,1,1]), @float.sum(1))
+ assert_equal(NArrayMiss.to_nam([0,6,8,21],[1,1,1,1]), @int.sum(1))
+
+ assert_equal(NArrayMiss.to_nam([0.0,6.0,8.0,21.0],[0,1,1,1]), @float.sum(1, "min_count"=>2))
+ end
+
+ def test_mean
+ assert_equal(4.375, @float.mean)
+ assert_equal(4.375, @int.mean)
+
+ ary = [1.5, 6, 11, 0]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,0]), @float.mean(0))
+ assert_equal(NArrayMiss.to_nam(ary,[1,0,0,0]), @float.mean(0, "min_count"=>4))
+
+ ary = [0.0, 3, 4, NArray[3,7,11].mean]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,1]), @float.mean(1))
+ assert_equal(NArrayMiss.to_nam(ary,[0,0,0,1]), @float.mean(1, "min_count"=>3))
+ end
+
+ def test_stddev
+ assert_equal(3.62284418654736, @float.stddev)
+ assert_equal(3.62284418654736, @int.stddev)
+
+ ary = [NArray[0,1,2,3].stddev, NArray[5,6,7].stddev, 0, 0]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,0,0]), @float.stddev(0))
+ assert_equal(NArrayMiss.to_nam(ary,[1,0,0,0]), @float.stddev(0, "min_count"=>4))
+
+ ary = [0, NArray[1,5].stddev, NArray[2,6].stddev, NArray[3,7,11].stddev]
+ assert_equal(NArrayMiss.to_nam(ary,[0,1,1,1]), @float.stddev(1))
+ assert_equal(NArrayMiss.to_nam(ary,[0,0,0,1]), @float.stddev(1, "min_count"=>3))
+ end
+
+ def test_rms
+ assert_equal(5.53398590529466, @float.rms)
+ assert_equal(5.53398590529466, @int.rms)
+
+ ary = [NArray[0,1,2,3].rms, NArray[5,6,7].rms, 11, 0]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,0]), @float.rms(0))
+ assert_equal(NArrayMiss.to_nam(ary,[1,0,0,0]), @float.rms(0, "min_count"=>4))
+
+ ary = [0.0, NArray[1,5].rms, NArray[2,6].rms, NArray[3,7,11].rms]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,1]), @float.rms(1))
+ assert_equal(NArrayMiss.to_nam(ary,[0,0,0,1]), @float.rms(1, "min_count"=>3))
+ end
+
+ def test_rmsdev
+ assert_equal(3.38886042793149, @float.rms)
+ assert_equal(3.38886042793149, @int.rmsdev)
+
+ ary = [NArray[0,1,2,3].rmsdev, NArray[5,6,7].rmsdev, 0, 0]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,0]), @float.rmsdev(0))
+ assert_equal(NArrayMiss.to_nam(ary,[1,0,0,0]), @float.rmsdev(0, "min_count"=>4))
+
+ ary = [0.0, NArray[1,5].rmsdev, NArray[2,6].rmsdev, NArray[3,7,11].rmsdev]
+ assert_equal(NArrayMiss.to_nam(ary,[1,1,1,1]), @float.rmsdev(1))
+ assert_equal(NArrayMiss.to_nam(ary,[0,0,0,1]), @float.rmsdev(1, "min_count"=>3))
+ end
+
+ def test_covariance
+ x = @float
+ ary = NArray.float(@n, at n).indgen(0,2)
+ mask = NArray.byte(@n, at n).fill(1)
+ mask[-1,0] = 0
+ y = NArrayMiss.to_nam(ary,mask)
+=begin
+y #=>
+NArrayMiss.float(4,4)
+[ [ 0.0, 2.0, 4.0, - ],
+ [ 8.0, 10.0, 12.0, 14.0 ],
+ [ 16.0, 18.0, 20.0, 22.0 ],
+ [ 24.0, 26.0, 28.0, 30.0 ]
+]
+NArrayMiss.dfloat(4,4):
+ [ [ 0.0, 1.0, 2.0, 3.0 ],
+ [ - , 5.0, 6.0, 7.0 ],
+ [ - , - , - , 11.0 ],
+ [ - , - , - , - ]
+ ]
+=end
+ assert_equal(NMath.covariance(NArray[0,1,2,4,5,7,11],NArray[0,2,4,10,12,14,22]), NMMath.covariance(x,y))
+
+ ary = Array.new(@n)
+ ary[0] = 0.0
+ ary[1] = NMath.covariance(NArray[1,5],NArray[2,10])
+ ary[2] = NMath.covariance(NArray[2,6],NArray[4,12])
+ ary[3] = NMath.covariance(NArray[7,11],NArray[14,22])
+ assert_equal(NArrayMiss.to_nam(ary,[0,1,1,1]), NMMath.covariance(x,y,1))
+ assert_equal(NArrayMiss.to_nam(ary,[0,0,0,0]), NMMath.covariance(x,y,1,"min_count"=>3))
+ end
+end
--
Additional Ruby Class handling missing value
More information about the Pkg-grass-devel
mailing list