matrix_sparse.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta name="generator" content=
  6. "HTML Tidy for Linux/x86 (vers 1st March 2004), see www.w3.org" />
  7. <meta http-equiv="Content-Type" content=
  8. "text/html; charset=us-ascii" />
  9. <link rel="stylesheet" href="../../../../boost.css" type="text/css"/>
  10. <link rel="stylesheet" href="ublas.css" type="text/css" />
  11. <script type="text/javascript" src="js/jquery-1.3.2.min.js" async="async" ></script>
  12. <script type="text/javascript" src="js/jquery.toc-gw.js" async="async" ></script>
  13. <title>Sparse Matrix</title>
  14. </head>
  15. <body>
  16. <h1><img src="../../../../boost.png" align="middle" />Sparse Matricies</h1>
  17. <div class="toc" id="toc"></div>
  18. <h2><a name="mapped_matrix"></a>Mapped Matrix</h2>
  19. <h4>Description</h4>
  20. <p>The templated class <code>mapped_matrix&lt;T, F, A&gt;</code> is
  21. the base container adaptor for sparse matricies using element maps.
  22. For a <em>(m xn</em>)-dimensional sparse matrix and <em>0 &lt;= i &lt; m</em>,
  23. <em>0 &lt;= j &lt; n</em> the non-zero elements
  24. <em>m</em><sub><em>i, j</em></sub> are mapped via <em>(i x n +
  25. j)</em> for row major orientation or via <em>(i + j x m)</em> for
  26. column major orientation to consecutive elements of the associative
  27. container, i.e. for elements <em>k</em> =
  28. <em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
  29. <em>,j</em></sub><sub><sub><em>1</em></sub></sub>and <em>k + 1 =
  30. m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
  31. ,j</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
  32. <em>i</em><sub><em>1</em></sub> <em>&lt;
  33. i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
  34. <em>= i</em><sub><em>2</em></sub> and
  35. <em>j</em><sub><em>1</em></sub> <em>&lt;
  36. j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
  37. <em>j</em><sub><em>1</em></sub> <em>&lt;
  38. j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
  39. <em>= j</em><sub><em>2</em></sub> and
  40. <em>i</em><sub><em>1</em></sub> <em>&lt;
  41. i</em><sub><em>2</em></sub><em>)</em> with column major
  42. orientation.</p>
  43. <h4>Example</h4>
  44. <pre>
  45. #include &lt;boost/numeric/ublas/matrix_sparse.hpp&gt;
  46. #include &lt;boost/numeric/ublas/io.hpp&gt;
  47. int main () {
  48. using namespace boost::numeric::ublas;
  49. mapped_matrix&lt;double&gt; m (3, 3, 3 * 3);
  50. for (unsigned i = 0; i &lt; m.size1 (); ++ i)
  51. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  52. m (i, j) = 3 * i + j;
  53. std::cout &lt;&lt; m &lt;&lt; std::endl;
  54. }
  55. </pre>
  56. <h4>Definition</h4>
  57. <p>Defined in the header matrix_sparse.hpp.</p>
  58. <h4>Template parameters</h4>
  59. <table border="1" summary="parameters">
  60. <tbody>
  61. <tr>
  62. <th>Parameter</th>
  63. <th>Description</th>
  64. <th>Default</th>
  65. </tr>
  66. <tr>
  67. <td><code>T</code></td>
  68. <td>The type of object stored in the mapped matrix.</td>
  69. <td></td>
  70. </tr>
  71. <tr>
  72. <td><code>F</code></td>
  73. <td>Functor describing the storage organization. <a href=
  74. "#mapped_matrix_1">[1]</a></td>
  75. <td><code>row_major</code></td>
  76. </tr>
  77. <tr>
  78. <td><code>A</code></td>
  79. <td>The type of the adapted array. <a href=
  80. "#mapped_matrix_2">[2]</a></td>
  81. <td><code>map_std&lt;std::size_t, T&gt;</code></td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. <h4>Model of</h4>
  86. <p><a href="container_concept.html#matrix">Matrix</a> .</p>
  87. <h4>Type requirements</h4>
  88. <p>None, except for those imposed by the requirements of <a href=
  89. "container_concept.html#matrix">Matrix</a> .</p>
  90. <h4>Public base classes</h4>
  91. <p><code>matrix_container&lt;mapped_matrix&lt;T, F, A&gt;
  92. &gt;</code></p>
  93. <h4>Members</h4>
  94. <table border="1" summary="members">
  95. <tbody>
  96. <tr>
  97. <th>Member</th>
  98. <th>Description</th>
  99. </tr>
  100. <tr>
  101. <td><code>mapped_matrix ()</code></td>
  102. <td>Allocates a <code>mapped_matrix</code> that holds at most zero
  103. rows of zero elements.</td>
  104. </tr>
  105. <tr>
  106. <td><code>mapped_matrix (size_type size1, size_type2, size_type non_zeros = 0)</code></td>
  107. <td>Allocates a <code>mapped_matrix</code> that holds at most
  108. <code>size1</code> rows of <code>size2</code> elements.</td>
  109. </tr>
  110. <tr>
  111. <td><code>mapped_matrix (const mapped_matrix &amp;m)</code></td>
  112. <td>The copy constructor.</td>
  113. </tr>
  114. <tr>
  115. <td><code>template&lt;class AE&gt;<br />
  116. mapped_matrix (size_type non_zeros, const
  117. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  118. <td>The extended copy constructor.</td>
  119. </tr>
  120. <tr>
  121. <td><code>void resize (size_type size1, size_type size2, bool preserve = true)</code></td>
  122. <td>Reallocates a <code>mapped_matrix</code> to hold at most
  123. <code>size1</code> rows of <code>size2</code> elements. The
  124. existing elements of the <code>mapped_matrix</code> are preseved
  125. when specified.</td>
  126. </tr>
  127. <tr>
  128. <td><code>size_type size1 () const</code></td>
  129. <td>Returns the number of rows.</td>
  130. </tr>
  131. <tr>
  132. <td><code>size_type size2 () const</code></td>
  133. <td>Returns the number of columns.</td>
  134. </tr>
  135. <tr>
  136. <td><code>const_reference operator () (size_type i, size_type j)
  137. const</code></td>
  138. <td>Returns the value of the <code>j</code>-th element in the
  139. <code>i</code>-th row.</td>
  140. </tr>
  141. <tr>
  142. <td><code>reference operator () (size_type i, size_type
  143. j)</code></td>
  144. <td>Returns a reference of the <code>j</code>-th element in the
  145. <code>i</code>-th row.</td>
  146. </tr>
  147. <tr>
  148. <td><code>mapped_matrix &amp;operator = (const mapped_matrix
  149. &amp;m)</code></td>
  150. <td>The assignment operator.</td>
  151. </tr>
  152. <tr>
  153. <td><code>mapped_matrix &amp;assign_temporary (mapped_matrix
  154. &amp;m)</code></td>
  155. <td>Assigns a temporary. May change the mapped matrix
  156. <code>m</code> .</td>
  157. </tr>
  158. <tr>
  159. <td><code>template&lt;class AE&gt;<br />
  160. mapped_matrix &amp;operator = (const matrix_expression&lt;AE&gt;
  161. &amp;ae)</code></td>
  162. <td>The extended assignment operator.</td>
  163. </tr>
  164. <tr>
  165. <td><code>template&lt;class AE&gt;<br />
  166. mapped_matrix &amp;assign (const matrix_expression&lt;AE&gt;
  167. &amp;ae)</code></td>
  168. <td>Assigns a matrix expression to the mapped matrix. Left and
  169. right hand side of the assignment should be independent.</td>
  170. </tr>
  171. <tr>
  172. <td><code>template&lt;class AE&gt;<br />
  173. mapped_matrix &amp;operator += (const matrix_expression&lt;AE&gt;
  174. &amp;ae)</code></td>
  175. <td>A computed assignment operator. Adds the matrix expression to
  176. the mapped matrix.</td>
  177. </tr>
  178. <tr>
  179. <td><code>template&lt;class AE&gt;<br />
  180. mapped_matrix &amp;plus_assign (const matrix_expression&lt;AE&gt;
  181. &amp;ae)</code></td>
  182. <td>Adds a matrix expression to the mapped matrix. Left and right
  183. hand side of the assignment should be independent.</td>
  184. </tr>
  185. <tr>
  186. <td><code>template&lt;class AE&gt;<br />
  187. mapped_matrix &amp;operator -= (const matrix_expression&lt;AE&gt;
  188. &amp;ae)</code></td>
  189. <td>A computed assignment operator. Subtracts the matrix expression
  190. from the mapped matrix.</td>
  191. </tr>
  192. <tr>
  193. <td><code>template&lt;class AE&gt;<br />
  194. mapped_matrix &amp;minus_assign (const matrix_expression&lt;AE&gt;
  195. &amp;ae)</code></td>
  196. <td>Subtracts a matrix expression from the mapped matrix. Left and
  197. right hand side of the assignment should be independent.</td>
  198. </tr>
  199. <tr>
  200. <td><code>template&lt;class AT&gt;<br />
  201. mapped_matrix &amp;operator *= (const AT &amp;at)</code></td>
  202. <td>A computed assignment operator. Multiplies the mapped matrix
  203. with a scalar.</td>
  204. </tr>
  205. <tr>
  206. <td><code>template&lt;class AT&gt;<br />
  207. mapped_matrix &amp;operator /= (const AT &amp;at)</code></td>
  208. <td>A computed assignment operator. Divides the mapped matrix
  209. through a scalar.</td>
  210. </tr>
  211. <tr>
  212. <td><code>void swap (mapped_matrix &amp;m)</code></td>
  213. <td>Swaps the contents of the mapped matrices.</td>
  214. </tr>
  215. <tr>
  216. <td><code>true_refrence insert_element (size_type i, size_type j, const_reference
  217. t)</code></td>
  218. <td>Inserts the value <code>t</code> at the <code>j</code>-th
  219. element of the <code>i</code>-th row. Duplicates elements are not allowed.</td>
  220. </tr>
  221. <tr>
  222. <td><code>void erase_element (size_type i, size_type j)</code></td>
  223. <td>Erases the value at the <code>j</code>-th element of the
  224. <code>i</code>-th row.</td>
  225. </tr>
  226. <tr>
  227. <td><code>void clear ()</code></td>
  228. <td>Clears the mapped matrix.</td>
  229. </tr>
  230. <tr>
  231. <td><code>const_iterator1 begin1 () const</code></td>
  232. <td>Returns a <code>const_iterator1</code> pointing to the
  233. beginning of the <code>mapped_matrix</code>.</td>
  234. </tr>
  235. <tr>
  236. <td><code>const_iterator1 end1 () const</code></td>
  237. <td>Returns a <code>const_iterator1</code> pointing to the end of
  238. the <code>mapped_matrix</code>.</td>
  239. </tr>
  240. <tr>
  241. <td><code>iterator1 begin1 ()</code></td>
  242. <td>Returns a <code>iterator1</code> pointing to the beginning of
  243. the <code>mapped_matrix</code>.</td>
  244. </tr>
  245. <tr>
  246. <td><code>iterator1 end1 ()</code></td>
  247. <td>Returns a <code>iterator1</code> pointing to the end of the
  248. <code>mapped_matrix</code>.</td>
  249. </tr>
  250. <tr>
  251. <td><code>const_iterator2 begin2 () const</code></td>
  252. <td>Returns a <code>const_iterator2</code> pointing to the
  253. beginning of the <code>mapped_matrix</code>.</td>
  254. </tr>
  255. <tr>
  256. <td><code>const_iterator2 end2 () const</code></td>
  257. <td>Returns a <code>const_iterator2</code> pointing to the end of
  258. the <code>mapped_matrix</code>.</td>
  259. </tr>
  260. <tr>
  261. <td><code>iterator2 begin2 ()</code></td>
  262. <td>Returns a <code>iterator2</code> pointing to the beginning of
  263. the <code>mapped_matrix</code>.</td>
  264. </tr>
  265. <tr>
  266. <td><code>iterator2 end2 ()</code></td>
  267. <td>Returns a <code>iterator2</code> pointing to the end of the
  268. <code>mapped_matrix</code>.</td>
  269. </tr>
  270. <tr>
  271. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  272. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  273. beginning of the reversed <code>mapped_matrix</code>.</td>
  274. </tr>
  275. <tr>
  276. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  277. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  278. end of the reversed <code>mapped_matrix</code>.</td>
  279. </tr>
  280. <tr>
  281. <td><code>reverse_iterator1 rbegin1 ()</code></td>
  282. <td>Returns a <code>reverse_iterator1</code> pointing to the
  283. beginning of the reversed <code>mapped_matrix</code>.</td>
  284. </tr>
  285. <tr>
  286. <td><code>reverse_iterator1 rend1 ()</code></td>
  287. <td>Returns a <code>reverse_iterator1</code> pointing to the end of
  288. the reversed <code>mapped_matrix</code>.</td>
  289. </tr>
  290. <tr>
  291. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  292. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  293. beginning of the reversed <code>mapped_matrix</code>.</td>
  294. </tr>
  295. <tr>
  296. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  297. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  298. end of the reversed <code>mapped_matrix</code>.</td>
  299. </tr>
  300. <tr>
  301. <td><code>reverse_iterator2 rbegin2 ()</code></td>
  302. <td>Returns a <code>reverse_iterator2</code> pointing to the
  303. beginning of the reversed <code>mapped_matrix</code>.</td>
  304. </tr>
  305. <tr>
  306. <td><code>reverse_iterator2 rend2 ()</code></td>
  307. <td>Returns a <code>reverse_iterator2</code> pointing to the end of
  308. the reversed <code>mapped_matrix</code>.</td>
  309. </tr>
  310. </tbody>
  311. </table>
  312. <h4>Notes</h4>
  313. <p><a name="mapped_matrix_1">[1]</a> Supported
  314. parameters for the storage organization are <code>row_major</code>
  315. and <code>column_major</code>.</p>
  316. <p><a name="mapped_matrix_2">[2]</a> Supported
  317. parameters for the adapted array are
  318. <code>map_array&lt;std::size_t, T&gt;</code> and
  319. <code>map_std&lt;std::size_t, T&gt;</code>. The latter is
  320. equivalent to <code>std::map&lt;std::size_t, T&gt;</code>.</p>
  321. <h2><a name="compressed_matrix"></a>Compressed Matrix</h2>
  322. <h4>Description</h4>
  323. <p>The templated class <code>compressed_matrix&lt;T, F, IB, IA,
  324. TA&gt;</code> is the base container adaptor for compressed
  325. matrices. For a <em>(m x n</em> )-dimensional compressed matrix and
  326. <em>0 &lt;= i &lt; m</em>, <em>0 &lt;= j &lt; n</em> the non-zero
  327. elements <em>m</em><sub><em>i, j</em></sub> are mapped via <em>(i x
  328. n + j)</em> for row major orientation or via <em>(i + j x m)</em>
  329. for column major orientation to consecutive elements of the index
  330. and value containers, i.e. for elements <em>k</em> =
  331. <em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
  332. <em>,j</em></sub><sub><sub><em>1</em></sub></sub>and <em>k + 1 =
  333. m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
  334. ,j</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
  335. <em>i</em><sub><em>1</em></sub> <em>&lt;
  336. i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
  337. <em>= i</em><sub><em>2</em></sub> and
  338. <em>j</em><sub><em>1</em></sub> <em>&lt;
  339. j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
  340. <em>j</em><sub><em>1</em></sub> <em>&lt;
  341. j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
  342. <em>= j</em><sub><em>2</em></sub> and
  343. <em>i</em><sub><em>1</em></sub> <em>&lt;
  344. i</em><sub><em>2</em></sub><em>)</em> with column major
  345. orientation.</p>
  346. <h4>Example</h4>
  347. <pre>
  348. #include &lt;boost/numeric/ublas/matrix_sparse.hpp&gt;
  349. #include &lt;boost/numeric/ublas/io.hpp&gt;
  350. int main () {
  351. using namespace boost::numeric::ublas;
  352. compressed_matrix&lt;double&gt; m (3, 3, 3 * 3);
  353. for (unsigned i = 0; i &lt; m.size1 (); ++ i)
  354. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  355. m (i, j) = 3 * i + j;
  356. std::cout &lt;&lt; m &lt;&lt; std::endl;
  357. }
  358. </pre>
  359. <h4>Definition</h4>
  360. <p>Defined in the header matrix_sparse.hpp.</p>
  361. <h4>Template parameters</h4>
  362. <table border="1" summary="parameters">
  363. <tbody>
  364. <tr>
  365. <th>Parameter</th>
  366. <th>Description</th>
  367. <th>Default</th>
  368. </tr>
  369. <tr>
  370. <td><code>T</code></td>
  371. <td>The type of object stored in the compressed matrix.</td>
  372. <td></td>
  373. </tr>
  374. <tr>
  375. <td><code>F</code></td>
  376. <td>Functor describing the storage organization. <a href=
  377. "#compressed_matrix_1">[1]</a></td>
  378. <td><code>row_major</code></td>
  379. </tr>
  380. <tr>
  381. <td><code>IB</code></td>
  382. <td>The index base of the compressed vector. <a href=
  383. "#compressed_matrix_2">[2]</a></td>
  384. <td><code>0</code></td>
  385. </tr>
  386. <tr>
  387. <td><code>IA</code></td>
  388. <td>The type of the adapted array for indices. <a href=
  389. "#compressed_matrix_3">[3]</a></td>
  390. <td><code>unbounded_array&lt;std::size_t&gt;</code></td>
  391. </tr>
  392. <tr>
  393. <td><code>TA</code></td>
  394. <td>The type of the adapted array for values. <a href=
  395. "#compressed_matrix_3">[3]</a></td>
  396. <td><code>unbounded_array&lt;T&gt;</code></td>
  397. </tr>
  398. </tbody>
  399. </table>
  400. <h4>Model of</h4>
  401. <p><a href="container_concept.html#matrix">Matrix</a> .</p>
  402. <h4>Type requirements</h4>
  403. <p>None, except for those imposed by the requirements of <a href=
  404. "container_concept.html#matrix">Matrix</a> .</p>
  405. <h4>Public base classes</h4>
  406. <p><code>matrix_container&lt;compressed_matrix&lt;T, F, IB, IA,
  407. TA&gt; &gt;</code></p>
  408. <h4>Members</h4>
  409. <table border="1" summary="members">
  410. <tbody>
  411. <tr>
  412. <th>Member</th>
  413. <th>Description</th>
  414. </tr>
  415. <tr>
  416. <td><code>compressed_matrix ()</code></td>
  417. <td>Allocates a <code>compressed_matrix</code> that holds at most
  418. zero rows of zero elements.</td>
  419. </tr>
  420. <tr>
  421. <td><code>compressed_matrix (size_type size1, size_type2, size_type non_zeros = 0)</code></td>
  422. <td>Allocates a <code>compressed_matrix</code> that holds at most
  423. <code>size1</code> rows of <code>size2</code> elements.</td>
  424. </tr>
  425. <tr>
  426. <td><code>compressed_matrix (const compressed_matrix
  427. &amp;m)</code></td>
  428. <td>The copy constructor.</td>
  429. </tr>
  430. <tr>
  431. <td><code>template&lt;class AE&gt;<br />
  432. compressed_matrix (size_type non_zeros, const
  433. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  434. <td>The extended copy constructor.</td>
  435. </tr>
  436. <tr>
  437. <td><code>void resize (size_type size1, size_type size2, bool preserve = true)</code></td>
  438. <td>Reallocates a <code>compressed_matrix</code> to hold at most
  439. <code>size1</code> rows of <code>size2</code> elements. The
  440. existing elements of the <code>compressed_matrix</code> are
  441. preseved when specified.</td>
  442. </tr>
  443. <tr>
  444. <td><code>size_type size1 () const</code></td>
  445. <td>Returns the number of rows.</td>
  446. </tr>
  447. <tr>
  448. <td><code>size_type size2 () const</code></td>
  449. <td>Returns the number of columns.</td>
  450. </tr>
  451. <tr>
  452. <td><code>const_reference operator () (size_type i, size_type j)
  453. const</code></td>
  454. <td>Returns the value of the <code>j</code>-th element in the
  455. <code>i</code>-th row.</td>
  456. </tr>
  457. <tr>
  458. <td><code>reference operator () (size_type i, size_type
  459. j)</code></td>
  460. <td>Returns a reference of the <code>j</code>-th element in the
  461. <code>i</code>-th row.</td>
  462. </tr>
  463. <tr>
  464. <td><code>compressed_matrix &amp;operator = (const
  465. compressed_matrix &amp;m)</code></td>
  466. <td>The assignment operator.</td>
  467. </tr>
  468. <tr>
  469. <td><code>compressed_matrix &amp;assign_temporary
  470. (compressed_matrix &amp;m)</code></td>
  471. <td>Assigns a temporary. May change the compressed matrix
  472. <code>m</code>.</td>
  473. </tr>
  474. <tr>
  475. <td><code>template&lt;class AE&gt;<br />
  476. compressed_matrix &amp;operator = (const
  477. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  478. <td>The extended assignment operator.</td>
  479. </tr>
  480. <tr>
  481. <td><code>template&lt;class AE&gt;<br />
  482. compressed_matrix &amp;assign (const matrix_expression&lt;AE&gt;
  483. &amp;ae)</code></td>
  484. <td>Assigns a matrix expression to the compressed matrix. Left and
  485. right hand side of the assignment should be independent.</td>
  486. </tr>
  487. <tr>
  488. <td><code>template&lt;class AE&gt;<br />
  489. compressed_matrix &amp;operator += (const
  490. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  491. <td>A computed assignment operator. Adds the matrix expression to
  492. the compressed matrix.</td>
  493. </tr>
  494. <tr>
  495. <td><code>template&lt;class AE&gt;<br />
  496. compressed_matrix &amp;plus_assign (const
  497. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  498. <td>Adds a matrix expression to the compressed matrix. Left and
  499. right hand side of the assignment should be independent.</td>
  500. </tr>
  501. <tr>
  502. <td><code>template&lt;class AE&gt;<br />
  503. compressed_matrix &amp;operator -= (const
  504. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  505. <td>A computed assignment operator. Subtracts the matrix expression
  506. from the compressed matrix.</td>
  507. </tr>
  508. <tr>
  509. <td><code>template&lt;class AE&gt;<br />
  510. compressed_matrix &amp;minus_assign (const
  511. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  512. <td>Subtracts a matrix expression from the compressed matrix. Left
  513. and right hand side of the assignment should be independent.</td>
  514. </tr>
  515. <tr>
  516. <td><code>template&lt;class AT&gt;<br />
  517. compressed_matrix &amp;operator *= (const AT &amp;at)</code></td>
  518. <td>A computed assignment operator. Multiplies the compressed
  519. matrix with a scalar.</td>
  520. </tr>
  521. <tr>
  522. <td><code>template&lt;class AT&gt;<br />
  523. compressed_matrix &amp;operator /= (const AT &amp;at)</code></td>
  524. <td>A computed assignment operator. Divides the compressed matrix
  525. through a scalar.</td>
  526. </tr>
  527. <tr>
  528. <td><code>void swap (compressed_matrix &amp;m)</code></td>
  529. <td>Swaps the contents of the compressed matrices.</td>
  530. </tr>
  531. <tr>
  532. <td><code>true_reference insert_element (size_type i, size_type j, const_reference
  533. t)</code></td>
  534. <td>Inserts the value <code>t</code> at the <code>j</code>-th
  535. element of the <code>i</code>-th row. Duplicates elements are not allowed.</td>
  536. </tr>
  537. <tr>
  538. <td><code>void erase_element (size_type i, size_type j)</code></td>
  539. <td>Erases the value at the <code>j</code>-th element of the
  540. <code>i</code>-th row.</td>
  541. </tr>
  542. <tr>
  543. <td><code>void clear ()</code></td>
  544. <td>Clears the compressed matrix.</td>
  545. </tr>
  546. <tr>
  547. <td><code>const_iterator1 begin1 () const</code></td>
  548. <td>Returns a <code>const_iterator1</code> pointing to the
  549. beginning of the <code>compressed_matrix</code>.</td>
  550. </tr>
  551. <tr>
  552. <td><code>const_iterator1 end1 () const</code></td>
  553. <td>Returns a <code>const_iterator1</code> pointing to the end of
  554. the <code>compressed_matrix</code>.</td>
  555. </tr>
  556. <tr>
  557. <td><code>iterator1 begin1 ()</code></td>
  558. <td>Returns a <code>iterator1</code> pointing to the beginning of
  559. the <code>compressed_matrix</code>.</td>
  560. </tr>
  561. <tr>
  562. <td><code>iterator1 end1 ()</code></td>
  563. <td>Returns a <code>iterator1</code> pointing to the end of the
  564. <code>compressed_matrix</code>.</td>
  565. </tr>
  566. <tr>
  567. <td><code>const_iterator2 begin2 () const</code></td>
  568. <td>Returns a <code>const_iterator2</code> pointing to the
  569. beginning of the <code>compressed_matrix</code>.</td>
  570. </tr>
  571. <tr>
  572. <td><code>const_iterator2 end2 () const</code></td>
  573. <td>Returns a <code>const_iterator2</code> pointing to the end of
  574. the <code>compressed_matrix</code>.</td>
  575. </tr>
  576. <tr>
  577. <td><code>iterator2 begin2 ()</code></td>
  578. <td>Returns a <code>iterator2</code> pointing to the beginning of
  579. the <code>compressed_matrix</code>.</td>
  580. </tr>
  581. <tr>
  582. <td><code>iterator2 end2 ()</code></td>
  583. <td>Returns a <code>iterator2</code> pointing to the end of the
  584. <code>compressed_matrix</code>.</td>
  585. </tr>
  586. <tr>
  587. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  588. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  589. beginning of the reversed <code>compressed_matrix</code>.</td>
  590. </tr>
  591. <tr>
  592. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  593. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  594. end of the reversed <code>compressed_matrix</code>.</td>
  595. </tr>
  596. <tr>
  597. <td><code>reverse_iterator1 rbegin1 ()</code></td>
  598. <td>Returns a <code>reverse_iterator1</code> pointing to the
  599. beginning of the reversed <code>compressed_matrix</code>.</td>
  600. </tr>
  601. <tr>
  602. <td><code>reverse_iterator1 rend1 ()</code></td>
  603. <td>Returns a <code>reverse_iterator1</code> pointing to the end of
  604. the reversed <code>compressed_matrix</code>.</td>
  605. </tr>
  606. <tr>
  607. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  608. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  609. beginning of the reversed <code>compressed_matrix</code>.</td>
  610. </tr>
  611. <tr>
  612. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  613. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  614. end of the reversed <code>compressed_matrix</code>.</td>
  615. </tr>
  616. <tr>
  617. <td><code>reverse_iterator2 rbegin2 ()</code></td>
  618. <td>Returns a <code>reverse_iterator2</code> pointing to the
  619. beginning of the reversed <code>compressed_matrix</code>.</td>
  620. </tr>
  621. <tr>
  622. <td><code>reverse_iterator2 rend2 ()</code></td>
  623. <td>Returns a <code>reverse_iterator2</code> pointing to the end of
  624. the reversed <code>compressed_matrix</code>.</td>
  625. </tr>
  626. </tbody>
  627. </table>
  628. <h4>Notes</h4>
  629. <p><a name="compressed_matrix_1">[1]</a>
  630. Supported parameters for the storage organization are
  631. <code>row_major</code> and <code>column_major</code>.</p>
  632. <p><a name="compressed_matrix_2">[2]</a>
  633. Supported parameters for the index base are <code>0</code> and
  634. <code>1</code> at least.</p>
  635. <p><a name="compressed_matrix_3">[3]</a>
  636. Supported parameters for the adapted array are
  637. <code>unbounded_array&lt;&gt;</code> ,
  638. <code>bounded_array&lt;&gt;</code> and
  639. <code>std::vector&lt;&gt;</code> .</p>
  640. <h2><a name="coordinate_matrix"></a>Coordinate Matrix</h2>
  641. <h4>Description</h4>
  642. <p>The templated class <code>coordinate_matrix&lt;T, F, IB, IA,
  643. TA&gt;</code> is the base container adaptor for compressed
  644. matrices. For a <em>(m x n</em> )-dimensional sorted coordinate
  645. matrix and <em>0 &lt;= i &lt; m</em>, <em>0 &lt;= j &lt; n</em> the
  646. non-zero elements <em>m</em><sub><em>i, j</em></sub> are mapped via
  647. <em>(i x n + j)</em> for row major orientation or via <em>(i + j x
  648. m)</em> for column major orientation to consecutive elements of the
  649. index and value containers, i.e. for elements <em>k</em> =
  650. <em>m</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub><sub>
  651. <em>,j</em></sub><sub><sub><em>1</em></sub></sub>and <em>k + 1 =
  652. m</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub><sub><em>
  653. ,j</em></sub><sub><sub><em>2</em></sub></sub>of the container holds
  654. <em>i</em><sub><em>1</em></sub> <em>&lt;
  655. i</em><sub><em>2</em></sub> or <em>(i</em><sub><em>1</em></sub>
  656. <em>= i</em><sub><em>2</em></sub> and
  657. <em>j</em><sub><em>1</em></sub> <em>&lt;
  658. j</em><sub><em>2</em></sub><em>)</em> with row major orientation or
  659. <em>j</em><sub><em>1</em></sub> <em>&lt;
  660. j</em><sub><em>2</em></sub> or <em>(j</em><sub><em>1</em></sub>
  661. <em>= j</em><sub><em>2</em></sub> and
  662. <em>i</em><sub><em>1</em></sub> <em>&lt;
  663. i</em><sub><em>2</em></sub><em>)</em> with column major
  664. orientation.</p>
  665. <h4>Example</h4>
  666. <pre>
  667. #include &lt;boost/numeric/ublas/matrix_sparse.hpp&gt;
  668. #include &lt;boost/numeric/ublas/io.hpp&gt;
  669. int main () {
  670. using namespace boost::numeric::ublas;
  671. coordinate_matrix&lt;double&gt; m (3, 3, 3 * 3);
  672. for (unsigned i = 0; i &lt; m.size1 (); ++ i)
  673. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  674. m (i, j) = 3 * i + j;
  675. std::cout &lt;&lt; m &lt;&lt; std::endl;
  676. }
  677. </pre>
  678. <h4>Definition</h4>
  679. <p>Defined in the header matrix_sparse.hpp.</p>
  680. <h4>Template parameters</h4>
  681. <table border="1" summary="parameters">
  682. <tbody>
  683. <tr>
  684. <th>Parameter</th>
  685. <th>Description</th>
  686. <th>Default</th>
  687. </tr>
  688. <tr>
  689. <td><code>T</code></td>
  690. <td>The type of object stored in the coordinate matrix.</td>
  691. <td></td>
  692. </tr>
  693. <tr>
  694. <td><code>F</code></td>
  695. <td>Functor describing the storage organization. <a href=
  696. "#coordinate_matrix_1">[1]</a></td>
  697. <td><code>row_major</code></td>
  698. </tr>
  699. <tr>
  700. <td><code>IB</code></td>
  701. <td>The index base of the coordinate vector. <a href=
  702. "#coordinate_matrix_2">[2]</a></td>
  703. <td><code>0</code></td>
  704. </tr>
  705. <tr>
  706. <td><code>IA</code></td>
  707. <td>The type of the adapted array for indices. <a href=
  708. "#coordinate_matrix_3">[3]</a></td>
  709. <td><code>unbounded_array&lt;std::size_t&gt;</code></td>
  710. </tr>
  711. <tr>
  712. <td><code>TA</code></td>
  713. <td>The type of the adapted array for values. <a href=
  714. "#coordinate_matrix_3">[3]</a></td>
  715. <td><code>unbounded_array&lt;T&gt;</code></td>
  716. </tr>
  717. </tbody>
  718. </table>
  719. <h4>Model of</h4>
  720. <p><a href="container_concept.html#matrix">Matrix</a> .</p>
  721. <h4>Type requirements</h4>
  722. <p>None, except for those imposed by the requirements of <a href=
  723. "container_concept.html#matrix">Matrix</a> .</p>
  724. <h4>Public base classes</h4>
  725. <p><code>matrix_container&lt;coordinate_matrix&lt;T, F, IB, IA,
  726. TA&gt; &gt;</code></p>
  727. <h4>Members</h4>
  728. <table border="1" summary="members">
  729. <tbody>
  730. <tr>
  731. <th>Member</th>
  732. <th>Description</th>
  733. </tr>
  734. <tr>
  735. <td><code>coordinate_matrix ()</code></td>
  736. <td>Allocates a <code>coordinate_matrix</code> that holds at most
  737. zero rows of zero elements.</td>
  738. </tr>
  739. <tr>
  740. <td><code>coordinate_matrix (size_type size1, size_type2, size_type non_zeros = 0)</code></td>
  741. <td>Allocates a <code>coordinate_matrix</code> that holds at most
  742. <code>size1</code> rows of <code>size2</code> elements.</td>
  743. </tr>
  744. <tr>
  745. <td><code>coordinate_matrix (const coordinate_matrix
  746. &amp;m)</code></td>
  747. <td>The copy constructor.</td>
  748. </tr>
  749. <tr>
  750. <td><code>template&lt;class AE&gt;<br />
  751. coordinate_matrix (size_type non_zeros, const
  752. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  753. <td>The extended copy constructor.</td>
  754. </tr>
  755. <tr>
  756. <td><code>void resize (size_type size1, size_type size2, bool preserve = true)</code></td>
  757. <td>Reallocates a <code>coordinate_matrix</code> to hold at most
  758. <code>size1</code> rows of <code>size2</code> elements. The
  759. existing elements of the <code>coordinate_matrix</code> are
  760. preseved when specified.</td>
  761. </tr>
  762. <tr>
  763. <td><code>size_type size1 () const</code></td>
  764. <td>Returns the number of rows.</td>
  765. </tr>
  766. <tr>
  767. <td><code>size_type size2 () const</code></td>
  768. <td>Returns the number of columns.</td>
  769. </tr>
  770. <tr>
  771. <td><code>const_reference operator () (size_type i, size_type j)
  772. const</code></td>
  773. <td>Returns the value of the <code>j</code>-th element in the
  774. <code>i</code>-th row.</td>
  775. </tr>
  776. <tr>
  777. <td><code>reference operator () (size_type i, size_type
  778. j)</code></td>
  779. <td>Returns a reference of the <code>j</code>-th element in the
  780. <code>i</code>-th row.</td>
  781. </tr>
  782. <tr>
  783. <td><code>coordinate_matrix &amp;operator = (const
  784. coordinate_matrix &amp;m)</code></td>
  785. <td>The assignment operator.</td>
  786. </tr>
  787. <tr>
  788. <td><code>coordinate_matrix &amp;assign_temporary
  789. (coordinate_matrix &amp;m)</code></td>
  790. <td>Assigns a temporary. May change the coordinate matrix
  791. <code>m</code>.</td>
  792. </tr>
  793. <tr>
  794. <td><code>template&lt;class AE&gt;<br />
  795. coordinate_matrix &amp;operator = (const
  796. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  797. <td>The extended assignment operator.</td>
  798. </tr>
  799. <tr>
  800. <td><code>template&lt;class AE&gt;<br />
  801. coordinate_matrix &amp;assign (const matrix_expression&lt;AE&gt;
  802. &amp;ae)</code></td>
  803. <td>Assigns a matrix expression to the coordinate matrix. Left and
  804. right hand side of the assignment should be independent.</td>
  805. </tr>
  806. <tr>
  807. <td><code>template&lt;class AE&gt;<br />
  808. coordinate_matrix &amp;operator += (const
  809. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  810. <td>A computed assignment operator. Adds the matrix expression to
  811. the coordinate matrix.</td>
  812. </tr>
  813. <tr>
  814. <td><code>template&lt;class AE&gt;<br />
  815. coordinate_matrix &amp;plus_assign (const
  816. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  817. <td>Adds a matrix expression to the coordinate matrix. Left and
  818. right hand side of the assignment should be independent.</td>
  819. </tr>
  820. <tr>
  821. <td><code>template&lt;class AE&gt;<br />
  822. coordinate_matrix &amp;operator -= (const
  823. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  824. <td>A computed assignment operator. Subtracts the matrix expression
  825. from the coordinate matrix.</td>
  826. </tr>
  827. <tr>
  828. <td><code>template&lt;class AE&gt;<br />
  829. coordinate_matrix &amp;minus_assign (const
  830. matrix_expression&lt;AE&gt; &amp;ae)</code></td>
  831. <td>Subtracts a matrix expression from the coordinate matrix. Left
  832. and right hand side of the assignment should be independent.</td>
  833. </tr>
  834. <tr>
  835. <td><code>template&lt;class AT&gt;<br />
  836. coordinate_matrix &amp;operator *= (const AT &amp;at)</code></td>
  837. <td>A computed assignment operator. Multiplies the coordinate
  838. matrix with a scalar.</td>
  839. </tr>
  840. <tr>
  841. <td><code>template&lt;class AT&gt;<br />
  842. coordinate_matrix &amp;operator /= (const AT &amp;at)</code></td>
  843. <td>A computed assignment operator. Divides the coordinate matrix
  844. through a scalar.</td>
  845. </tr>
  846. <tr>
  847. <td><code>void swap (coordinate_matrix &amp;m)</code></td>
  848. <td>Swaps the contents of the coordinate matrices.</td>
  849. </tr>
  850. <tr>
  851. <td><code>true_reference insert_element (size_type i, size_type j, const_reference
  852. t)</code></td>
  853. <td>Inserts the value <code>t</code> at the <code>j</code>-th
  854. element of the <code>i</code>-th row. Duplicates elements are not allowed.</td>
  855. </tr>
  856. <tr>
  857. <td><code>void append_element (size_type i, size_type j, const_reference t)</code></td>
  858. <td>Appends the value <code>t</code> at the <code>j</code>-th element of the <code>i</code>-th row.
  859. Duplicate elements can be appended to a <code>coordinate_matrix</code>. They are merged into a single
  860. arithmetically summed element by the <code>sort</code> function.</td>
  861. </tr>
  862. <tr>
  863. <td><code>void erase_element (size_type i, size_type j)</code></td>
  864. <td>Erases the value at the <code>j</code>-th element of the
  865. <code>i</code>-th row.</td>
  866. </tr>
  867. <tr>
  868. <td><code>void clear ()</code></td>
  869. <td>Clears the coordinate matrix.</td>
  870. </tr>
  871. <tr>
  872. <td><code>const_iterator1 begin1 () const</code></td>
  873. <td>Returns a <code>const_iterator1</code> pointing to the
  874. beginning of the <code>coordinate_matrix</code>.</td>
  875. </tr>
  876. <tr>
  877. <td><code>const_iterator1 end1 () const</code></td>
  878. <td>Returns a <code>const_iterator1</code> pointing to the end of
  879. the <code>coordinate_matrix</code>.</td>
  880. </tr>
  881. <tr>
  882. <td><code>iterator1 begin1 ()</code></td>
  883. <td>Returns a <code>iterator1</code> pointing to the beginning of
  884. the <code>coordinate_matrix</code>.</td>
  885. </tr>
  886. <tr>
  887. <td><code>iterator1 end1 ()</code></td>
  888. <td>Returns a <code>iterator1</code> pointing to the end of the
  889. <code>coordinate_matrix</code>.</td>
  890. </tr>
  891. <tr>
  892. <td><code>const_iterator2 begin2 () const</code></td>
  893. <td>Returns a <code>const_iterator2</code> pointing to the
  894. beginning of the <code>coordinate_matrix</code>.</td>
  895. </tr>
  896. <tr>
  897. <td><code>const_iterator2 end2 () const</code></td>
  898. <td>Returns a <code>const_iterator2</code> pointing to the end of
  899. the <code>coordinate_matrix</code>.</td>
  900. </tr>
  901. <tr>
  902. <td><code>iterator2 begin2 ()</code></td>
  903. <td>Returns a <code>iterator2</code> pointing to the beginning of
  904. the <code>coordinate_matrix</code>.</td>
  905. </tr>
  906. <tr>
  907. <td><code>iterator2 end2 ()</code></td>
  908. <td>Returns a <code>iterator2</code> pointing to the end of the
  909. <code>coordinate_matrix</code>.</td>
  910. </tr>
  911. <tr>
  912. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  913. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  914. beginning of the reversed <code>coordinate_matrix</code>.</td>
  915. </tr>
  916. <tr>
  917. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  918. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  919. end of the reversed <code>coordinate_matrix</code>.</td>
  920. </tr>
  921. <tr>
  922. <td><code>reverse_iterator1 rbegin1 ()</code></td>
  923. <td>Returns a <code>reverse_iterator1</code> pointing to the
  924. beginning of the reversed <code>coordinate_matrix</code>.</td>
  925. </tr>
  926. <tr>
  927. <td><code>reverse_iterator1 rend1 ()</code></td>
  928. <td>Returns a <code>reverse_iterator1</code> pointing to the end of
  929. the reversed <code>coordinate_matrix</code>.</td>
  930. </tr>
  931. <tr>
  932. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  933. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  934. beginning of the reversed <code>coordinate_matrix</code>.</td>
  935. </tr>
  936. <tr>
  937. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  938. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  939. end of the reversed <code>coordinate_matrix</code>.</td>
  940. </tr>
  941. <tr>
  942. <td><code>reverse_iterator2 rbegin2 ()</code></td>
  943. <td>Returns a <code>reverse_iterator2</code> pointing to the
  944. beginning of the reversed <code>coordinate_matrix</code>.</td>
  945. </tr>
  946. <tr>
  947. <td><code>reverse_iterator2 rend2 ()</code></td>
  948. <td>Returns a <code>reverse_iterator2</code> pointing to the end of
  949. the reversed <code>coordinate_matrix</code>.</td>
  950. </tr>
  951. </tbody>
  952. </table>
  953. <h4>Notes</h4>
  954. <p><a name="coordinate_matrix_1">[1]</a>
  955. Supported parameters for the storage organization are
  956. <code>row_major</code> and <code>column_major</code>.</p>
  957. <p><a name="coordinate_matrix_2">[2]</a>
  958. Supported parameters for the index base are <code>0</code> and
  959. <code>1</code> at least.</p>
  960. <p><a name="coordinate_matrix_3">[3]</a>
  961. Supported parameters for the adapted array are
  962. <code>unbounded_array&lt;&gt;</code> ,
  963. <code>bounded_array&lt;&gt;</code> and
  964. <code>std::vector&lt;&gt;</code> .</p>
  965. <hr />
  966. <p>Copyright (&copy;) 2000-2002 Joerg Walter, Mathias Koch<br />
  967. Use, modification and distribution are subject to the
  968. Boost Software License, Version 1.0.
  969. (See accompanying file LICENSE_1_0.txt
  970. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  971. http://www.boost.org/LICENSE_1_0.txt
  972. </a>).
  973. </p>
  974. <script type="text/javascript">
  975. (function($) {
  976. $('#toc').toc();
  977. })(jQuery);
  978. </script>
  979. </body>
  980. </html>