File: matrix.cpp.html

package info (click to toggle)
ntl 11.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,820 kB
  • sloc: cpp: 92,194; sh: 10,577; ansic: 3,058; makefile: 536
file content (232 lines) | stat: -rw-r--r-- 12,199 bytes parent folder | download | duplicates (2)
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&lt;T&gt; 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&lt; Vec&lt;T&gt; &gt;: a vector of rows, where</span>
<span class="Comment">each row is a Vec&lt;T&gt;.  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 &quot;resized&quot; 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>&lt;<span class="Type">class</span> T&gt;
<span class="Type">class</span> Mat {

   <span class="Type">typedef</span> <span class="Type">typename</span> Vec&lt;T&gt;::value_type value_type;
   <span class="Type">typedef</span> <span class="Type">typename</span> Vec&lt;T&gt;::reference reference;
   <span class="Type">typedef</span> <span class="Type">typename</span> Vec&lt;T&gt;::const_reference const_reference;


   Mat(); <span class="Comment">// initially 0 x 0</span>

   Mat(<span class="Type">const</span> Mat&lt;T&gt;&amp; a);
   <span class="Comment">// copy constructor</span>

   <span class="Comment">// EXCEPTIONS: may throw</span>


   Mat&amp; <span class="Statement">operator</span>=(<span class="Type">const</span> Mat&lt;T&gt;&amp; 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&amp;&amp; other) <span class="Statement">noexcept</span>;
<span class="PreProc">#ifndef NTL_DISABLE_MOVE_ASSIGN</span>
   Mat&amp; <span class="Statement">operator</span>=(Mat&amp;&amp; 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&lt;T&gt;&amp; <span class="Statement">operator</span>[](<span class="Type">long</span> i);
   <span class="Type">const</span> Vec&lt;T&gt;&amp; <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&lt;T&gt;&amp; <span class="Statement">operator</span>()(<span class="Type">long</span> i);
   <span class="Type">const</span> Vec&lt;T&gt;&amp; <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&amp; a);
   <span class="Comment">// same as M[i].put(j, a)</span>

   <span class="Type">template</span> &lt;<span class="Type">class</span> U&gt;
   <span class="Type">void</span> put(<span class="Type">long</span> i, <span class="Type">long</span> j, <span class="Type">const</span> U&amp; a);
   <span class="Comment">// same as M[i].put(j, a)</span>

   <span class="Type">long</span> position(<span class="Type">const</span> Vec&lt;T&gt;&amp; 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&lt;T&gt;&amp; 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&lt;T&gt;&amp; 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&lt;T&gt;&amp; other);
   <span class="Comment">// quick swap *this and other</span>

   <span class="Type">void</span> move(Mat&lt;T&gt;&amp; other);
   <span class="Comment">// quick move other to *this</span>

};

<span class="Type">template</span>&lt;<span class="Type">class</span> T&gt;
<span class="Type">const</span> Vec&lt; Vec&lt;T&gt; &gt;&amp; rep(<span class="Type">const</span> Mat&lt;T&gt;&amp; a);
<span class="Comment">// read-only access to underlying representation</span>

<span class="Type">template</span>&lt;<span class="Type">class</span> T&gt;
<span class="Type">void</span> swap(Mat&lt;T&gt;&amp; X, Mat&lt;T&gt;&amp; Y);
<span class="Comment">// quick swap of X and Y </span>

<span class="Type">template</span>&lt;<span class="Type">class</span> T&gt;
<span class="Type">void</span> MakeMatrix(Mat&lt;T&gt;&amp; x, <span class="Type">const</span> vec_vec_T&amp; a);
<span class="Comment">// copies a to x, checking that it is &quot;rectangular&quot;</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>&lt;<span class="Type">class</span> T&gt;
istream&amp; <span class="Statement">operator</span>&gt;&gt;(istream&amp;, Mat&lt;T&gt;&amp;);

<span class="Comment">// EXCEPTIONS: may throw, weak ES</span>

<span class="Type">template</span>&lt;<span class="Type">class</span> T&gt;
ostream&amp; <span class="Statement">operator</span>&lt;&lt;(ostream&amp;, <span class="Type">const</span> Mat&lt;T&gt;&amp;);

<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>&lt;<span class="Type">class</span> T&gt;
<span class="Type">long</span> <span class="Statement">operator</span>==(<span class="Type">const</span> Mat&lt;T&gt;&amp; a, <span class="Type">const</span> Mat&lt;T&gt;&amp; b);

<span class="Type">template</span>&lt;<span class="Type">class</span> T&gt;
<span class="Type">long</span> <span class="Statement">operator</span>!=(<span class="Type">const</span> Mat&lt;T&gt;&amp; a, <span class="Type">const</span> Mat&lt;T&gt;&amp; b);

</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->