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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>~/ntl-11.4.2/doc/matrix.cpp.html</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim7.4_v2">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="macvim">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
* { font-size: 1em; }
.PreProc { color: #1874cd; }
.Constant { color: #ff8c00; }
.Statement { color: #b03060; font-weight: bold; }
.Comment { color: #0000ee; font-style: italic; }
.Type { color: #008b00; font-weight: bold; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment">MODULE: matrix</span>
<span class="Comment">SUMMARY:</span>
<span class="Comment">Matrix templates.</span>
<span class="Comment">The declaration </span>
<span class="Comment"> Mat<T> M;</span>
<span class="Comment">creates a 0 x 0 matrix. </span>
<span class="Comment">We can make it have 10 rows and 20 columns like this:</span>
<span class="Comment"> M.SetDims(10, 20);</span>
<span class="Comment">A row can be accessed as M[i], indexing from 0, or as M(i), indexing from 1.</span>
<span class="Comment">A matrix entry can be accessed as M[i][j], indexing from 0, or as</span>
<span class="Comment">M(i, j), indexing from 1.</span>
<span class="Comment">A matrix is represented as a Vec< Vec<T> >: a vector of rows, where</span>
<span class="Comment">each row is a Vec<T>. Any attempt to resize one of the rows so</span>
<span class="Comment">as to create a non-rectangular matrix will result in a run-time </span>
<span class="Comment">error.</span>
<span class="Comment">The dimensions of an existing matrix may be changed. If the number of</span>
<span class="Comment">columns does not change, then the matrix is just "resized" like a vector,</span>
<span class="Comment">and no information is lost. Otherwise, if the number of columns changes,</span>
<span class="Comment">the matrix is completely destroyed, and a new matrix is created</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Comment">// EXCEPTIONS: all functions below do not throw any exceptions,</span>
<span class="Comment">// except as noted</span>
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">class</span> Mat {
<span class="Type">typedef</span> <span class="Type">typename</span> Vec<T>::value_type value_type;
<span class="Type">typedef</span> <span class="Type">typename</span> Vec<T>::reference reference;
<span class="Type">typedef</span> <span class="Type">typename</span> Vec<T>::const_reference const_reference;
Mat(); <span class="Comment">// initially 0 x 0</span>
Mat(<span class="Type">const</span> Mat<T>& a);
<span class="Comment">// copy constructor</span>
<span class="Comment">// EXCEPTIONS: may throw</span>
Mat& <span class="Statement">operator</span>=(<span class="Type">const</span> Mat<T>& a);
<span class="Comment">// assignment</span>
<span class="Comment">// EXCEPTIONS: may throw, weak ES (but dimensions of LHS</span>
<span class="Comment">// will be either that of old LHS or RHS)</span>
~Mat();
<span class="Comment">// destructor</span>
Mat(Mat&& other) <span class="Statement">noexcept</span>;
<span class="PreProc">#ifndef NTL_DISABLE_MOVE_ASSIGN</span>
Mat& <span class="Statement">operator</span>=(Mat&& other) <span class="Statement">noexcept</span>;
<span class="PreProc">#endif</span>
<span class="Comment">// move semantics (C++11 only)</span>
Mat(INIT_SIZE_TYPE, <span class="Type">long</span> n, <span class="Type">long</span> m);
<span class="Comment">// Mat(INIT_SIZE, n, m) initializes an n x m matrix, invoking</span>
<span class="Comment">// the default constructor for T to initialize entries.</span>
<span class="Comment">// EXCEPTIONS: may throw</span>
<span class="Type">void</span> SetDims(<span class="Type">long</span> n, <span class="Type">long</span> m);
<span class="Comment">// M.SetDims(n, m) makes M have dimension n x m. If the number of</span>
<span class="Comment">// columns (m) changes, previous storage is freed, and space for M</span>
<span class="Comment">// is reallocated and initialized; otherwise, more rows are</span>
<span class="Comment">// allocated as necessary (when number of rows increases), </span>
<span class="Comment">// excess rows are retained (when number of rows decreases),</span>
<span class="Comment">// and--importantly--the contents do not change.</span>
<span class="Comment">// EXCEPTIONS: strong ES (although underlying vector representation</span>
<span class="Comment">// may be reallocated)</span>
<span class="Type">void</span> kill(); free storage <span class="Statement">and</span> make <span class="Constant">0</span> x <span class="Constant">0</span>
<span class="Type">long</span> NumRows() <span class="Type">const</span>;
<span class="Comment">// M.NumRows() returns the number of rows of M</span>
<span class="Type">long</span> NumCols() <span class="Type">const</span>;
<span class="Comment">// M.NumCols() returns the number of columns of M</span>
Vec<T>& <span class="Statement">operator</span>[](<span class="Type">long</span> i);
<span class="Type">const</span> Vec<T>& <span class="Statement">operator</span>[](<span class="Type">long</span> i) <span class="Type">const</span>;
<span class="Comment">// access row i, initial index 0. </span>
<span class="Comment">// Even if one has read/write access to a row, any attempt</span>
<span class="Comment">// to change its length will raise an error.</span>
<span class="Comment">// EXCEPTIONS: may throw if range checking is turned on</span>
Vec<T>& <span class="Statement">operator</span>()(<span class="Type">long</span> i);
<span class="Type">const</span> Vec<T>& <span class="Statement">operator</span>()(<span class="Type">long</span> i) <span class="Type">const</span>;
<span class="Comment">// access row i, initial index 1. </span>
<span class="Comment">// Even if one has read/write access to a row, any attempt</span>
<span class="Comment">// to change its length will raise an error.</span>
<span class="Comment">// of this row will raise an error.</span>
<span class="Comment">// EXCEPTIONS: may throw if range checking is turned on</span>
reference <span class="Statement">operator</span>()(<span class="Type">long</span> i, <span class="Type">long</span> j);
const_reference <span class="Statement">operator</span>()(<span class="Type">long</span> i, <span class="Type">long</span> j) <span class="Type">const</span>;
<span class="Comment">// access element (i, j), both indices starting at 1</span>
<span class="Comment">// EXCEPTIONS: may throw if range checking is turned on</span>
const_reference get(<span class="Type">long</span> i, <span class="Type">long</span> j) <span class="Type">const</span>;
<span class="Comment">// access element (i, j), both indices starting at 0</span>
<span class="Comment">// EXCEPTIONS: may throw if range checking is turned on</span>
<span class="Type">void</span> put(<span class="Type">long</span> i, <span class="Type">long</span> j, <span class="Type">const</span> T& a);
<span class="Comment">// same as M[i].put(j, a)</span>
<span class="Type">template</span> <<span class="Type">class</span> U>
<span class="Type">void</span> put(<span class="Type">long</span> i, <span class="Type">long</span> j, <span class="Type">const</span> U& a);
<span class="Comment">// same as M[i].put(j, a)</span>
<span class="Type">long</span> position(<span class="Type">const</span> Vec<T>& a) <span class="Type">const</span>;
<span class="Comment">// returns index of a in matrix, or -1 if not present;</span>
<span class="Comment">// equivalent to rep(*this).position(a).</span>
<span class="Type">long</span> position1(<span class="Type">const</span> Vec<T>& a) <span class="Type">const</span>;
<span class="Comment">// returns index of a in matrix, or -1 if not present;</span>
<span class="Comment">// equivalent to rep(*this).position1(a).</span>
<span class="Type">long</span> alias(<span class="Type">const</span> Vec<T>& a) <span class="Type">const</span>;
<span class="Comment">// returns 1 if a aliases a row of the matrix, and 0 otherwise.</span>
<span class="Type">void</span> swap(Mat<T>& other);
<span class="Comment">// quick swap *this and other</span>
<span class="Type">void</span> move(Mat<T>& other);
<span class="Comment">// quick move other to *this</span>
};
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">const</span> Vec< Vec<T> >& rep(<span class="Type">const</span> Mat<T>& a);
<span class="Comment">// read-only access to underlying representation</span>
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">void</span> swap(Mat<T>& X, Mat<T>& Y);
<span class="Comment">// quick swap of X and Y </span>
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">void</span> MakeMatrix(Mat<T>& x, <span class="Type">const</span> vec_vec_T& a);
<span class="Comment">// copies a to x, checking that it is "rectangular"</span>
<span class="Comment">// EXCEPTIONS: may thow, weak ES (but dimensions of x either</span>
<span class="Comment">// remain unchanged or are set to the new dimensions implied by a)</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Input/Output</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">template</span><<span class="Type">class</span> T>
istream& <span class="Statement">operator</span>>>(istream&, Mat<T>&);
<span class="Comment">// EXCEPTIONS: may throw, weak ES</span>
<span class="Type">template</span><<span class="Type">class</span> T>
ostream& <span class="Statement">operator</span><<(ostream&, <span class="Type">const</span> Mat<T>&);
<span class="Comment">// EXCEPTIONS: may throw, weak ES</span>
<span class="Comment">/*</span><span class="Comment">*************************************************************************\</span>
<span class="Comment"> Equality Testing</span>
<span class="Comment">\*************************************************************************</span><span class="Comment">*/</span>
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">long</span> <span class="Statement">operator</span>==(<span class="Type">const</span> Mat<T>& a, <span class="Type">const</span> Mat<T>& b);
<span class="Type">template</span><<span class="Type">class</span> T>
<span class="Type">long</span> <span class="Statement">operator</span>!=(<span class="Type">const</span> Mat<T>& a, <span class="Type">const</span> Mat<T>& b);
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|