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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<html>
<head>
<title>Blitz++ User's Guide </title>
</head>
<body fgcolor="#27408B" bgcolor="#FFFAF0" >
<hr>
<ul>
<li> <a href="blitz08.html">Next chapter</a>
<li> <a href="blitz06.html">Previous chapter</a>
<li> <a href="blitz.html">Table of contents</a>
</ul>
<hr>
<a name="l108"></a>
<h1>Chapter 7: TinyVector</h1>
<a name="tinyvector"></a>
<!-- BZINDEX TinyVector --><a name="index00424">
<p>The <code>TinyVector</code> class provides a small, lightweight vector
object whose size is known at compile time. It is included
via the header <code><blitz/tinyvec.h></code>.
<p>Note that <code>TinyVector</code> lives in the <code>blitz</code> namespace,
so you will need to refer to it as <code>blitz::TinyVector</code>,
or use the directive <code>using namespace blitz;</code>.
<p>The Blitz++ <code>Array</code> object uses <code>TinyVector</code> internally, so
if you include <code><blitz/array.h></code>, the TinyVector
header is automatically included.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.1: Template parameters and types</font></td></tr></table><br><a name="l109"></a>
<p>The <code>TinyVector<T,N></code> class has two template parameters:
<p><dl>
<p><p></p><dt><strong><code>T</code></strong><dd> is the numeric type of the vector (float, double, int,
<code>complex<float></code>, etc.;
<p><p></p><dt><strong><code>N</code></strong><dd> is the number of elements in the vector.
<p></dl>
<p>Inside the <code>TinyVector</code> class, these types are declared:
<p><dl>
<p><p></p><dt><strong><code>T_numtype</code></strong><dd> is the numeric type stored in the vector (the
template parameter <code>T</code>)
<p><p></p><dt><strong><code>T_vector</code></strong><dd> is the vector type <code>TinyVector<T,N></code>.
<p><p></p><dt><strong><code>iterator</code></strong><dd> is an STL-style iterator.
<p><p></p><dt><strong><code>constIterator</code></strong><dd> is an STL-style const iterator.
<p></dl>
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.2: Constructors</font></td></tr></table><br><a name="l110"></a>
<p><strong><pre>TinyVector();
</pre></strong>
The elements of the vector are left uninitialized.
<p><strong><pre>TinyVector(const TinyVector<T,N>& x);
</pre></strong>
The elements of vector <code>x</code> are copied.
<p><strong><pre>TinyVector(T value);
</pre></strong>
All elements are initialized to <code>value</code>.
<p><strong><pre>TinyVector(T value1, T value2, ...)
</pre></strong>
The vector is initialized with the list of values given.
These constructors are provided for up to N=11.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.3: Member functions</font></td></tr></table><br><a name="l111"></a>
<p><strong><pre>TinyVector<T,N>::iterator begin();
TinyVector<T,N>::const_iterator begin() const;
</pre></strong>
Returns an STL-style iterator for the vector, positioned
at the beginning of the data.
<p><strong><pre>TinyVector<T,N>::iterator end();
TinyVector<T,N>::const_iterator end() const;
</pre></strong>
Returns an STL-style iterator for the vector, positioned
at the end of the data.
<p><strong><pre>T_numtype* [restrict] data();
const T_numtype* [restrict] data() const;
</pre></strong>
Returns a pointer to the first element in the vector.
<p><strong><pre>int length() const;
</pre></strong>
Returns the length of the vector (the template parameter <code>N</code>).
<p><strong><pre>T_numtype operator()(int i) const;
T_numtype& operator()(int i);
T_numtype operator[](int i) const;
T_numtype& operator[](int i);
</pre></strong>
Returns the <code>i</code>th element of the vector. If the
code is compiled with debugging enabled (<code>-DBZ_DEBUG</code>),
bounds checking is performed.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.4: Assignment operators</font></td></tr></table><br><a name="l112"></a>
<p>The assignment operators =, +=, -=, *=, /=, %=, ^=, &=, |=, >>= and <<=
are all provided. The right hand side of an assignment may be a
scalar of type <code>T_numtype</code>, a <code>TinyVector</code> of any type but the
same size, or a vector expression.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.5: Expressions</font></td></tr></table><br><a name="l113"></a>
<p>Expressions involving tiny vectors may contain any combination
of the operators
<p><code>+ - * / % ^ & | >> <<</code>
<p>with operands of type TinyVector, scalar, or vector expressions.
The usual math functions (see the Array documentation) are supported
on TinyVector.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.6: Global functions</font></td></tr></table><br><a name="l114"></a>
<p><strong><pre>dot(TinyVector, TinyVector);
dot(vector-expr, TinyVector);
dot(TinyVector, vector-expr);
dot(vector-expr, vector-expr);
</pre></strong>
These functions calculate a dot product between TinyVectors
(or vector expressions). The result is a scalar; the type
of the scalar follows the usual type promotion rules.
<p><strong><pre>product(TinyVector);
</pre></strong>
Returns the product of all the elements in the vector.
<p><strong><pre>sum(TinyVector);
</pre></strong>
Returns the sum of the elements in the vector.
<p><strong><pre>TinyVector<T,3> cross(TinyVector<T,3> x, TinyVector<T,3> y);
</pre></strong>
Returns the cross product of <code>x</code> and <code>y</code>.
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.7: Arrays of TinyVector</font></td></tr></table><br><a name="l115"></a>
<p><br><br><br><table width="100%" border="0" cellpadding=10 align=center><tr><td align="left" bgcolor="#0b6698"><font color="#ffffff" face="Helvetica" size=+5>7.8: Input/output</font></td></tr></table><br><a name="l116"></a>
<p><strong><pre>ostream& operator<<(ostream&, const TinyVector<T,N>& x)
</pre></strong>
This function outputs a TinyVector onto a stream. Here's
an illustration of the format for a length 3 vector:
<p><strong><pre>[ 0.5 0.2 0.9 ]
</pre></strong>
<p>
<hr>
<ul>
<li> <a href="blitz08.html">Next chapter</a>
<li> <a href="blitz06.html">Previous chapter</a>
<li> <a href="blitz.html">Table of contents</a>
</ul>
<hr>
</body>
</html>
|