numru-misc 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ Mon Aug 11 2011 T Horinouchi
2
+ * numru-misc-0.1.1 released (relase tag: numru-misc-0_1_1)
3
+ * LICENCE.txt: Added (BSD 2-clause licence)
4
+
5
+ Mon Mar 15 2010 T Horinouchi
6
+ * numru-misc-0.1.0 released (relase tag: numru-misc-0_1_0)
7
+
8
+ 2008-02-05 S Otsuka
9
+ * install.rb: for ruby 1.9
10
+
11
+ Fri May 13 2005 T Horinouchi
12
+ * numru-misc-0.0.6 released (relase tag: numru-misc-0_0_6)
13
+ * keywordopt.rb: KeywordOpt#keys --> public (returns @keys.dup).
14
+ Added KeywordOpt#select_keys.
15
+ Tue Aug 12 2004 T Horinouchi
16
+ * keywordopt.rb: modified KeywordOptAutoHelp#set to show help
17
+ message if 'help'==true.
18
+ Tue Aug 10 2004 T Horinouchi
19
+ * numru-misc-0.0.5 released (relase tag: numru-misc-0_0_5)
20
+ * package renamed from misc to numru-misc: started new CVS
21
+ Fri Mar 19 2004 T Horinouchi
22
+ * emath.rb: basically, a refactoring
23
+ * install.rb: debug
24
+ Wed Dec 10 2003 T Horinouchi
25
+ * misc-0.0.4 released
26
+ * emath.rb: NumRu::EMath --> NumRu::Misc::EMath
27
+ Documentation.
28
+ * misc.rb: documentation update for EMath.
29
+ Tue Oct 7 2003 T Horinouchi
30
+ * emath.rb: created
31
+ Mon Sep 1 2003 T Horinouchi
32
+ * misc-0.0.3 released
33
+ * keywordopt.rb: minor debug of the help messaging in
34
+ KeywordOptAutoHelp#interpret
35
+ Tue Aug 26 2003 T Horinouchi
36
+ * keywordopt.rb: added class KeywordOptAutoHelp. refined help.
37
+ allowed KeywordOpt.new to accept another KeywordOpt.
38
+ Mon Aug 25 2003 T Horinouchi
39
+ * keywordopt.rb: KeywordOpt#interpret slightly modified
40
+ Mon Aug 25 2003 T Horinouchi
41
+ * version 0.0.2 released
@@ -0,0 +1,34 @@
1
+ NumRu::Misc is copyrighted free software by Takeshi Horinouchi and
2
+ GFD Dennou Club (http://www.gfd-dennou.org/).
3
+
4
+ Copyright 2011 (C) Takeshi Horinouchi and GFD Dennou Club
5
+ (http://www.gfd-dennou.org/) All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ 1. Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+
14
+ 2. Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in
16
+ the documentation and/or other materials provided with the
17
+ distribution.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY GFD DENNOU CLUB AND CONTRIBUTORS ``AS IS''
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GFD DENNOU CLUB OR
23
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ The views and conclusions contained in the software and documentation
32
+ are those of the authors and should not be interpreted as representing
33
+ official policies, either expressed or implied, of Takeshi Horinouchi
34
+ and GFD Dennou Club.
@@ -0,0 +1,38 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ NAME = 'numru-misc'
4
+ VER = '0.1.1'
5
+
6
+ PKG_FILES = FileList[
7
+ '**',
8
+ 'lib/**/*',
9
+ 'doc/**/*'
10
+ ]
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = NAME
14
+ s.version = VER
15
+ s.authors = ["Takeshi Horinouchi"]
16
+ s.email = ['eriko@gfd-dennou.org']
17
+ s.homepage = 'http://www.gfd-dennou.org/arch/ruby/products/numru-misc/'
18
+ s.licenses = ["Takeshi Horinouchi", "GFD Dennou Club"]
19
+ s.platform = Gem::Platform::RUBY
20
+ s.summary = %q{Collection of miscellaneous functions and classes to facilitate programming.}
21
+ s.description = %q{Miscellaneous functions and classes to help Ruby programming. To be used in other NumRu libraries.}
22
+
23
+ s.files = PKG_FILES.to_a
24
+ s.require_paths = ['lib']
25
+ #s.test_files = Dir.glob("test/*")
26
+ #s.has_rdoc = true
27
+ s.required_ruby_version = Gem::Requirement.new(">= 1.6")
28
+ s.add_runtime_dependency(%q<narray>, [">= 0"])
29
+ #s.add_runtime_dependency(%q<narray_miss>, [">= 0"])
30
+ #s.extra_rdoc_files = ['README']
31
+
32
+ #s.extensions << "install.rb"
33
+ end
34
+
35
+ Rake::GemPackageTask.new(spec) do |pkg|
36
+ pkg.gem_spec = spec
37
+ pkg.need_tar = true
38
+ end
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <title>lib/numru/misc/emath.rb</title>
8
+ </head>
9
+ <body>
10
+ <h1><a name="label:0" id="label:0">module NumRu::Misc::EMath</a></h1><!-- RDLabel: "module NumRu::Misc::EMath" -->
11
+ <p>To be included instead of the Math predefined module (or NMath in NArray).
12
+ Unlike Math and NMath, EMath handles unknown classes by calling its
13
+ native instance method (assuming the same name).</p>
14
+ <p>Therefore, if included, its function (module method) is used as:</p>
15
+ <pre>cos( obj )</pre>
16
+ <p>and so on. If obj is not of a supported class, EMath calls, obj.cos in
17
+ this case. (If cos is not a method of obj, then an exception is
18
+ raised.) Supported classes are Numeric (by Math) and NArray (by
19
+ NMath). EMath stands for "good Math" (for obvious reason for a
20
+ Japanese).</p>
21
+ <p>Note: as for atan2(a,b), a.atan2(b) will be called if a or b
22
+ is not supported. This is the case for all functions that take
23
+ two or more arguments.</p>
24
+
25
+ </body>
26
+ </html>
@@ -0,0 +1,83 @@
1
+ <?xml version="1.0" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <title>lib/numru/misc/misc.rb</title>
8
+ </head>
9
+ <body>
10
+ <h1><a name="label:0" id="label:0">module NumRu::Misc</a></h1><!-- RDLabel: "module NumRu::Misc" -->
11
+ <h2><a name="label:1" id="label:1">Overview</a></h2><!-- RDLabel: "Overview" -->
12
+ <p>Miscellaneous functions and classes to facilitate programming.</p>
13
+ <h2><a name="label:2" id="label:2">Index</a></h2><!-- RDLabel: "Index" -->
14
+ <p>CLASSES</p>
15
+ <ul>
16
+ <li><a href="keywordopt.html">class KeywordOpt</a>
17
+ to support keyward arguments with default values.</li>
18
+ <li><a href="narray_ext.html">class NArray (enhancement of NArray made by M Tanaka)</a></li>
19
+ </ul>
20
+ <p>MODULES</p>
21
+ <ul>
22
+ <li><a href="md_iterators.html">module MD_Iterators</a> A Mixin for classes with
23
+ multi-dimension indexing support (such as NArray).</li>
24
+ <li><a href="emath.html">module EMath</a>
25
+ To be included instead of the Math predefined module (or NMath in NArray).
26
+ Unlike Math and NMath, EMath handles unknown classes by calling its
27
+ native instance method (assuming the same name).</li>
28
+ </ul>
29
+ <p>MODULE FUNCTIONS</p>
30
+ <ul>
31
+ <li><a href="#label:4">check_shape_consistency</a></li>
32
+ </ul>
33
+ <h2><a name="label:3" id="label:3">Module functions</a></h2><!-- RDLabel: "Module functions" -->
34
+ <dl>
35
+ <dt><a name="label:4" id="label:4"><code>check_shape_consistency(<var>cshapes</var>, *<var>args</var>)</code></a></dt><!-- RDLabel: "check_shape_consistency" -->
36
+ <dd>
37
+ <p>Check the consistency of array shapes (multi-dim such as NArray).
38
+ Exception is raised if inconsistent.</p>
39
+ <p>ARGUMENTS</p>
40
+ <ul>
41
+ <li>cshapes (String) : description of the shapes of the args.
42
+ Delimited by one-or-more spaces between arrays,
43
+ and the shape of each array is delimited by a comma. The lengths are
44
+ expressed with string names as identifiers (in that case, length
45
+ values are unquestioned) or specified as positive integers.
46
+ Use '..' or '...' for repetition of the last shape.
47
+ See EXAMPLES below.</li>
48
+ <li>args (multi-dim arrays such as NArray): arrays to be checked</li>
49
+ </ul>
50
+ <p>RETURN VALUE</p>
51
+ <ul>
52
+ <li>nil</li>
53
+ </ul>
54
+ <p>POSSIBLE EXCEPTIONS</p>
55
+ <ul>
56
+ <li>exception is raised if cshapes and args are inconsistent:
57
+ <ul>
58
+ <li>RuntimeError, if the arrays do not have shapes specified by cshapes.</li>
59
+ <li>ArgeumentError, if the number of args are inconsistent with cshapes.
60
+ This is likely a coding error of the user.</li>
61
+ </ul></li>
62
+ </ul>
63
+ <p>EXAMPLES</p>
64
+ <ul>
65
+ <li><p>to check whether three arrays u, v, and w are shaped as
66
+ u[nx], v[ny], and w[nx,ny], where nx and ny are any integer:</p>
67
+ <pre>NumRu::Misc.check_shape_consistency('nx ny nx,ny',u,v,w)</pre>
68
+ <p>Or equivalently,</p>
69
+ <pre>NumRu::Misc.check_shape_consistency('m n m,n',u,v,w)</pre>
70
+ <p>because actual strings does not matter.</p></li>
71
+ <li><p>To specify fixed lengths, use integers instead of names:</p>
72
+ <pre>NumRu::Misc.check_shape_consistency('4 n 4,n',u,v,w)</pre>
73
+ <p>In this case, u,v,w must have shapes [4], [ny], and [4,ny],
74
+ where ny is any length.</p></li>
75
+ <li><p>Use '..' or '...' to repeat the same shape:</p>
76
+ <pre>NumRu::Misc.check_shape_consistency('nx,ny ...',u,v,w)</pre>
77
+ <p>This ensures that u, v, and w are 2D arrays with the same shape.
78
+ Note: '..' and '...' are the same, so you can use whichever you like.</p></li>
79
+ </ul></dd>
80
+ </dl>
81
+
82
+ </body>
83
+ </html>
@@ -0,0 +1,179 @@
1
+ <?xml version="1.0" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <title>lib/numru/misc/keywordopt.rb</title>
8
+ </head>
9
+ <body>
10
+ <h2><a name="label:0" id="label:0">Index</a></h2><!-- RDLabel: "Index" -->
11
+ <ul>
12
+ <li><a href="#label:1">class NumRu::Misc::KeywordOpt</a></li>
13
+ <li><a href="#label:13">class NumRu::Misc::KeywordOptAutoHelp &lt; NumRu::Misc::KeywordOpt</a></li>
14
+ </ul>
15
+ <h1><a name="label:1" id="label:1">class NumRu::Misc::KeywordOpt</a></h1><!-- RDLabel: "class NumRu::Misc::KeywordOpt" -->
16
+ <h2><a name="label:2" id="label:2">Overview</a></h2><!-- RDLabel: "Overview" -->
17
+ <p>A class to facilitate optional keyword arguments. More specifically,
18
+ it helps the use of a Hash to mimic the keyword argument system.
19
+ With this, you can set default values and description to each
20
+ keyword argument.</p>
21
+ <h2><a name="label:3" id="label:3">Classes defined supplementarilly</a></h2><!-- RDLabel: "Classes defined supplementarilly" -->
22
+ <h3><a name="label:4" id="label:4">class NumRu::Misc::HelpMessagingException &lt; StandardError</a></h3><!-- RDLabel: "class NumRu::Misc::HelpMessagingException < StandardError" -->
23
+ <p>This is for your convenience. See the usage example below.</p>
24
+ <h2><a name="label:5" id="label:5">Usage example</a></h2><!-- RDLabel: "Usage example" -->
25
+ <p>Suppose that you introduce keyword arguments "flag" and "number"
26
+ to the method "hoge" in a class/module Foo. It can be done as
27
+ follows:</p>
28
+ <pre>require 'numru/misc' # or, specifically, require 'numru/misc/keywordopt'
29
+ include NumRu
30
+
31
+ class Foo
32
+ @@opt_hoge = Misc::KeywordOpt.new(
33
+ ['flag', false, 'whether or not ...'],
34
+ ['number', 1, 'number of ...'],
35
+ ['help', false, 'show help message']
36
+ )
37
+ def hoge(regular_arg1, regular_arg2, options=nil)
38
+ opt = @@opt_hoge.interpret(options)
39
+ if opt['help']
40
+ puts @@opt_hoge.help
41
+ puts ' Current values='+opt.inspect
42
+ raise Misc::HelpMessagingException, '** show help message and raise **'
43
+ end
44
+ # do what you want below
45
+ # (options are set in the Hash opt: opt['flag'] and opt['number'])
46
+ end
47
+ end</pre>
48
+ <p>Here, the options are defined in the class variable @@opt_hoge
49
+ with option names, default values, and descriptions (for help
50
+ messaging). One can use the method hoge as follows:</p>
51
+ <pre>foo = Foo.new
52
+ ...
53
+ x = ...
54
+ y = ...
55
+ ...
56
+ foo.hoge( x, y, {'flag'=&gt;true, 'number'=&gt;10} )</pre>
57
+ <p>Or equivalently,</p>
58
+ <pre>foo.hoge( x, y, 'flag'=&gt;true, 'number'=&gt;10 )</pre>
59
+ <p>because '{}' can be omitted here. </p>
60
+ <p>Tails of options names can be shortened as long as unambiguous:</p>
61
+ <pre>foo.hoge( x, y, 'fla'=&gt;true, 'num'=&gt;10 )</pre>
62
+ <p>To show the help message, call</p>
63
+ <pre>foo.hoge( x, y, 'help'=&gt;true )</pre>
64
+ <p>This will cause the following help message printed with the
65
+ exception HelpMessagingException raised.</p>
66
+ <pre>&lt;&lt; Description of options &gt;&gt;
67
+ option name =&gt; default value description:
68
+ "flag" =&gt; false whether or not ...
69
+ "number" =&gt; 1 number of ...
70
+ "help" =&gt; false show help message
71
+ Current values={"help"=&gt;true, "number"=&gt;1, "flag"=&gt;false}
72
+ NumRu::Misc::HelpMessagingException: ** help messaging done **
73
+ from (irb):78:in "hoge"
74
+ from (irb):83</pre>
75
+ <p>Do not affraid to write long descriptions. The help method
76
+ breaks lines nicely if they are long.</p>
77
+ <h2><a name="label:6" id="label:6">Class methods</a></h2><!-- RDLabel: "Class methods" -->
78
+ <dl>
79
+ <dt><a name="label:7" id="label:7"><code>KeywordOpt.new( *<var>args</var> )</code></a></dt><!-- RDLabel: "KeywordOpt.new" -->
80
+ <dd>
81
+ <p>Constructor.</p>
82
+ <p>ARGUMENTS</p>
83
+ <ul>
84
+ <li><p>args : (case 1) arrays of two or three elements: [option name,
85
+ default value, description ], or [option name, default value]
86
+ if you do not want to write descriptions. Option names and
87
+ descriptions must be String. (case 2) another KeywordOpt.
88
+ Cases 1 and 2 can be mixed. </p>
89
+ <p>When case 2, a link to the other KeywordOpt is kept. Thus, change
90
+ of values in it is reflected to the current one. However,
91
+ the link is deleted if values are changed by <a href="#label:10">set</a>.</p></li>
92
+ </ul>
93
+ <p>RETURN VALUE</p>
94
+ <ul>
95
+ <li>a KeywordOpt object</li>
96
+ </ul>
97
+ <p>EXAMPLE</p>
98
+ <ul>
99
+ <li>case 1</li>
100
+ </ul></dd>
101
+ </dl>
102
+ <pre>opt = Misc::KeywordOpt.new(
103
+ ['flag', false, 'whether or not ...'],
104
+ ['help', false, 'show help message']
105
+ )</pre>
106
+ <ul>
107
+ <li><p>case 2</p>
108
+ <pre>opt = Misc::KeywordOpt.new( optA, optB )</pre></li>
109
+ <li>case 1 &amp; 2</li>
110
+ </ul>
111
+ <pre>opt = Misc::KeywordOpt.new(
112
+ ['flag', false, 'whether or not ...'],
113
+ optA
114
+ )</pre>
115
+ <h2><a name="label:8" id="label:8">Methods</a></h2><!-- RDLabel: "Methods" -->
116
+ <dl>
117
+ <dt><a name="label:9" id="label:9"><code>interpret(<var>hash</var>)</code></a></dt><!-- RDLabel: "interpret" -->
118
+ <dd>
119
+ <p>Interprets a hash that specifies option values.</p>
120
+ <p>ARGUMENTS</p>
121
+ <ul>
122
+ <li>hash (Hash or nil) : a hash with string keys matching option names
123
+ (initializedwhen constructed). The matching is case sensitive and done
124
+ such that the tail of a option name can be omitted as long as
125
+ unambiguous (for example, 'num' for 'number').
126
+ If the argument is nil, the current values are returned.
127
+ If there are two options like 'max' and 'maxval', to use
128
+ a key 'max' (identical to the former paramer) is allowed, although
129
+ it matches 'maxval' as well. (Again 'ma' is regarded ambiguous.)</li>
130
+ </ul>
131
+ <p>RETURN VALUE</p>
132
+ <ul>
133
+ <li>a Hash containing the option values (default values overwritten
134
+ with hash).</li>
135
+ </ul>
136
+ <p>POSSIBLE EXCEPTION</p>
137
+ <ul>
138
+ <li>hash has a key that does not match any of the option names.</li>
139
+ <li>hash has a key that is ambiguous</li>
140
+ </ul></dd>
141
+ <dt><a name="label:10" id="label:10"><code>set(<var>hash</var>)</code></a></dt><!-- RDLabel: "set" -->
142
+ <dd>
143
+ <p>Similar to <a href="#label:9">interpret</a> but changes internal values.</p>
144
+ <p>ARGUMENTS</p>
145
+ <ul>
146
+ <li>hash (Hash) : see <a href="#label:9">interpret</a>. (Here, nil is not permitted though)</li>
147
+ </ul>
148
+ <p>RETURN VALUE</p>
149
+ <ul>
150
+ <li>a Hash containing the values replaced (the ones before calling this
151
+ method)</li>
152
+ </ul>
153
+ <p>POSSIBLE EXCEPTION</p>
154
+ <ul>
155
+ <li>the argument is not a Hash</li>
156
+ <li>others are same as in <a href="#label:9">interpret</a></li>
157
+ </ul></dd>
158
+ <dt><a name="label:11" id="label:11"><code>help</code></a></dt><!-- RDLabel: "help" -->
159
+ <dd>
160
+ <p>Returns a help message</p>
161
+ <p>RETURN VALUE</p>
162
+ <ul>
163
+ <li>a String describing the option names, default values, and descriptions</li>
164
+ </ul></dd>
165
+ <dt><a name="label:12" id="label:12"><code>[<var>key</var>]</code></a></dt><!-- RDLabel: "[]" -->
166
+ <dd>
167
+ <p>Returns a value associated with the key (exact matching unlike interpret)</p></dd>
168
+ </dl>
169
+ <h1><a name="label:13" id="label:13">class NumRu::Misc::KeywordOptAutoHelp &lt; NumRu::Misc::KeywordOpt</a></h1><!-- RDLabel: "class NumRu::Misc::KeywordOptAutoHelp < NumRu::Misc::KeywordOpt" -->
170
+ <p>Same as <a href="#label:1">class NumRu::Misc::KeywordOpt</a>, but the method <a href="#label:9">interpret</a>
171
+ shows a help message and raise an exception if option 'help' is provided
172
+ as an argument and is not nil or false
173
+ (<code>NumRu::Misc::HelpMessagingException &lt; StandardError</code>)
174
+ or if the arguments cannot be interpreted correctly (<code>ArgumentError</code>).
175
+ Option 'help' is automatically defined, so you do not have to define it
176
+ yourself.</p>
177
+
178
+ </body>
179
+ </html>
@@ -0,0 +1,86 @@
1
+ <?xml version="1.0" ?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <title>lib/numru/misc/md_iterators.rb</title>
8
+ </head>
9
+ <body>
10
+ <h1><a name="label:0" id="label:0">module NumRu::Misc::MD_Iterators</a></h1><!-- RDLabel: "module NumRu::Misc::MD_Iterators" -->
11
+ <p>A Mixin.
12
+ To be included in a class with multi-dimension indexing support
13
+ (such as NArray).</p>
14
+ <h2><a name="label:1" id="label:1">Index</a></h2><!-- RDLabel: "Index" -->
15
+ <ul>
16
+ <li><a href="#label:3">each_subary_at_dims</a></li>
17
+ <li><a href="#label:4">each_subary_at_dims_with_index</a></li>
18
+ </ul>
19
+ <h2><a name="label:2" id="label:2">Methods</a></h2><!-- RDLabel: "Methods" -->
20
+ <dl>
21
+ <dt><a name="label:3" id="label:3"><code>each_subary_at_dims( *<var>dims</var> )</code></a></dt><!-- RDLabel: "each_subary_at_dims" -->
22
+ <dd>
23
+ <p>Iterator for each sub-array (not each element) specified by dimensions.</p>
24
+ <p>ARGUMENT</p>
25
+ <ul>
26
+ <li><var>dims</var> (integers) : specifies subsets at dimensions
27
+ specified here with the beginning-to-end selection.
28
+ For example, [0, 1] to specify the first 2 dimensions
29
+ (subsets will be 2D then), and [2] to specify the 3rd
30
+ dimension (subsets will be 1D). Duplication has no effect,
31
+ so [0,0] and [0] are the same. Also, its order has no effect.
32
+ See EXAMPLE below for more.</li>
33
+ </ul>
34
+ <p>RETURN VALUE</p>
35
+ <ul>
36
+ <li>self</li>
37
+ </ul>
38
+ <p>POSSIBLE EXCEPTIONS</p>
39
+ <ul>
40
+ <li>exception is raised if ( dims.min&lt;0 || dims.max&gt;=self.rank ).</li>
41
+ </ul>
42
+ <p>EXAMPLE</p>
43
+ <ul>
44
+ <li><p>Suppose that you want to do something with 2D sub-arrays in a
45
+ multi-dimension NArray. First, you include this module as follows:</p>
46
+ <pre>require "narray"
47
+ class NArray
48
+ include NumRu::Misc::MD_Iterators
49
+ end</pre>
50
+ <p>And prepare the array if you have not (here, it is 4D):</p>
51
+ <pre>na = NArray.int(10,2,5,2).indgen!</pre>
52
+ <p>Then you do the job like this:</p>
53
+ <pre>na.each_subary_at_dims(0,2){ |sub|
54
+ ... # do whatever with sub
55
+ }</pre>
56
+ <p>This is equivalent to the following:</p>
57
+ <pre>(0...na.shape[3]).each{|j|
58
+ (0...na.shape[1]).each{|i|
59
+ sub = na[0..-1, i, 0..-1, j]
60
+ ... # do whatever with sub
61
+ }
62
+ }</pre>
63
+ <p>Note that the loop must be nested 3 times when na is a 5D array,
64
+ if the latter approach is used. On the other hand, it will still
65
+ require the same single loop with the former. </p></li>
66
+ </ul></dd>
67
+ <dt><a name="label:4" id="label:4"><code>each_subary_at_dims_with_index( *<var>dims</var> )</code></a></dt><!-- RDLabel: "each_subary_at_dims_with_index" -->
68
+ <dd>
69
+ <p>Like <a href="#label:3">each_subary_at_dims</a> but the block takes two arguments:
70
+ subset and the subset specifier (index).</p>
71
+ <p>EXAMPLE</p>
72
+ <ul>
73
+ <li><p>Suppose the example above in <a href="#label:3">each_subary_at_dims</a> (EXAMPLE).
74
+ And suppose that you want to overwrite na with the result
75
+ you get. You can do it like this:</p>
76
+ <pre>na.each_subary_at_dims_with_index(0,2){ |sub,idx|
77
+ result = (sub + 10) / 2
78
+ na[*idx] = result
79
+ }</pre>
80
+ <p>Here, idx is an Array to be fed in the []= or [] methods
81
+ with asterisk (ungrouping).</p></li>
82
+ </ul></dd>
83
+ </dl>
84
+
85
+ </body>
86
+ </html>