1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<?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/numru/misc/misc.rb</title>
</head>
<body>
<h1><a name="label:0" id="label:0">module NumRu::Misc</a></h1><!-- RDLabel: "module NumRu::Misc" -->
<h2><a name="label:1" id="label:1">Overview</a></h2><!-- RDLabel: "Overview" -->
<p>Miscellaneous functions and classes to facilitate programming.</p>
<h2><a name="label:2" id="label:2">Index</a></h2><!-- RDLabel: "Index" -->
<p>CLASSES</p>
<ul>
<li><a href="keywordopt.html">class KeywordOpt</a>
to support keyward arguments with default values.</li>
<li><a href="narray_ext.html">class NArray (enhancement of NArray made by M Tanaka)</a></li>
</ul>
<p>MODULES</p>
<ul>
<li><a href="md_iterators.html">module MD_Iterators</a> A Mixin for classes with
multi-dimension indexing support (such as NArray).</li>
<li><a href="emath.html">module EMath</a>
To be included instead of the Math predefined module (or NMath in NArray).
Unlike Math and NMath, EMath handles unknown classes by calling its
native instance method (assuming the same name).</li>
</ul>
<p>MODULE FUNCTIONS</p>
<ul>
<li><a href="#label:4">check_shape_consistency</a></li>
</ul>
<h2><a name="label:3" id="label:3">Module functions</a></h2><!-- RDLabel: "Module functions" -->
<dl>
<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" -->
<dd>
<p>Check the consistency of array shapes (multi-dim such as NArray).
Exception is raised if inconsistent.</p>
<p>ARGUMENTS</p>
<ul>
<li>cshapes (String) : description of the shapes of the args.
Delimited by one-or-more spaces between arrays,
and the shape of each array is delimited by a comma. The lengths are
expressed with string names as identifiers (in that case, length
values are unquestioned) or specified as positive integers.
Use '..' or '...' for repetition of the last shape.
See EXAMPLES below.</li>
<li>args (multi-dim arrays such as NArray): arrays to be checked</li>
</ul>
<p>RETURN VALUE</p>
<ul>
<li>nil</li>
</ul>
<p>POSSIBLE EXCEPTIONS</p>
<ul>
<li>exception is raised if cshapes and args are inconsistent:
<ul>
<li>RuntimeError, if the arrays do not have shapes specified by cshapes.</li>
<li>ArgeumentError, if the number of args are inconsistent with cshapes.
This is likely a coding error of the user.</li>
</ul></li>
</ul>
<p>EXAMPLES</p>
<ul>
<li><p>to check whether three arrays u, v, and w are shaped as
u[nx], v[ny], and w[nx,ny], where nx and ny are any integer:</p>
<pre>NumRu::Misc.check_shape_consistency('nx ny nx,ny',u,v,w)</pre>
<p>Or equivalently,</p>
<pre>NumRu::Misc.check_shape_consistency('m n m,n',u,v,w)</pre>
<p>because actual strings does not matter.</p></li>
<li><p>To specify fixed lengths, use integers instead of names:</p>
<pre>NumRu::Misc.check_shape_consistency('4 n 4,n',u,v,w)</pre>
<p>In this case, u,v,w must have shapes [4], [ny], and [4,ny],
where ny is any length.</p></li>
<li><p>Use '..' or '...' to repeat the same shape:</p>
<pre>NumRu::Misc.check_shape_consistency('nx,ny ...',u,v,w)</pre>
<p>This ensures that u, v, and w are 2D arrays with the same shape.
Note: '..' and '...' are the same, so you can use whichever you like.</p></li>
</ul></dd>
</dl>
</body>
</html>
|