vector_sparse.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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 href="ublas.css" type="text/css" />
  10. <link rel="stylesheet" href="../../../../boost.css" type="text/css"/>
  11. <link rel="stylesheet" href="ublas.css" type="text/css" />
  12. <script type="text/javascript" src="js/jquery-1.3.2.min.js" async="async" ></script>
  13. <script type="text/javascript" src="js/jquery.toc-gw.js" async="async" ></script>
  14. </head>
  15. <body>
  16. <h1><img src="../../../../boost.png" align="middle" />Sparse Vector</h1>
  17. <div class="toc" id="toc"></div>
  18. <h2><a name="mapped_vector"></a>Mapped Vector</h2>
  19. <h4>Description</h4>
  20. <p>The templated class <code>mapped_vector&lt;T, A&gt;</code> is
  21. the base container adaptor for sparse vectors using element maps. For a
  22. <em>n</em>-dimensional sparse vector and <em>0 &lt;= i &lt; n</em>
  23. the non-zero elements <em>v</em><sub><em>i</em></sub> are mapped to
  24. consecutive elements of the associative container, i.e. for
  25. elements <em>k</em> =
  26. <em>v</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub>and
  27. <em>k + 1 =
  28. v</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub>of the
  29. container holds <em>i</em><sub><em>1</em></sub> <em>&lt;
  30. i</em><sub><em>2</em></sub>.</p>
  31. <h4>Example</h4>
  32. <pre>
  33. #include &lt;boost/numeric/ublas/vector_sparse.hpp&gt;
  34. #include &lt;boost/numeric/ublas/io.hpp&gt;
  35. int main () {
  36. using namespace boost::numeric::ublas;
  37. mapped_vector&lt;double&gt; v (3, 3);
  38. for (unsigned i = 0; i &lt; v.size (); ++ i)
  39. v (i) = i;
  40. std::cout &lt;&lt; v &lt;&lt; std::endl;
  41. }
  42. </pre>
  43. <h4>Definition</h4>
  44. <p>Defined in the header vector_sparse.hpp.</p>
  45. <h4>Template parameters</h4>
  46. <table border="1" summary="parameters">
  47. <tbody>
  48. <tr>
  49. <th>Parameter</th>
  50. <th>Description</th>
  51. <th>Default</th>
  52. </tr>
  53. <tr>
  54. <td><code>T</code></td>
  55. <td>The type of object stored in the mapped vector.</td>
  56. <td></td>
  57. </tr>
  58. <tr>
  59. <td><code>A</code></td>
  60. <td>The type of the adapted array. <a href=
  61. "#mapped_vector_1">[1]</a></td>
  62. <td><code>map_std&lt;std::size_t, T&gt;</code></td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. <h4>Model of</h4>
  67. <p><a href="container_concept.html#vector">Vector</a> .</p>
  68. <h4>Type requirements</h4>
  69. <p>None, except for those imposed by the requirements of <a href=
  70. "container_concept.html#vector">Vector</a> .</p>
  71. <h4>Public base classes</h4>
  72. <p><code>vector_container&lt;mapped_vector&lt;T, A&gt;
  73. &gt;</code></p>
  74. <h4>Members</h4>
  75. <table border="1" summary="members">
  76. <tbody>
  77. <tr>
  78. <th>Member</th>
  79. <th>Description</th>
  80. </tr>
  81. <tr>
  82. <td><code>mapped_vector ()</code></td>
  83. <td>Allocates a <code>mapped_vector</code> that holds zero
  84. elements.</td>
  85. </tr>
  86. <tr>
  87. <td><code>mapped_vector (size_type size, size_type
  88. non_zeros = 0)</code></td>
  89. <td>Allocates a <code>mapped_vector</code> that holds at most
  90. <code>size</code> elements.</td>
  91. </tr>
  92. <tr>
  93. <td><code>mapped_vector (const mapped_vector &amp;v)</code></td>
  94. <td>The copy constructor.</td>
  95. </tr>
  96. <tr>
  97. <td><code>template&lt;class AE&gt;<br />
  98. mapped_vector (size_type non_zeros, const
  99. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  100. <td>The extended copy constructor.</td>
  101. </tr>
  102. <tr>
  103. <td><code>void resize (size_type size, bool
  104. preserve = true)</code></td>
  105. <td>Reallocates a <code>mapped_vector</code> to hold at most
  106. <code>size</code> elements. The existing elements of the
  107. <code>mapped_vector</code> are preseved when specified.</td>
  108. </tr>
  109. <tr>
  110. <td><code>size_type size () const</code></td>
  111. <td>Returns the size of the <code>mapped_vector</code>.</td>
  112. </tr>
  113. <tr>
  114. <td><code>const_reference operator () (size_type i)
  115. const</code></td>
  116. <td>Returns the value of the <code>i</code>-th element.</td>
  117. </tr>
  118. <tr>
  119. <td><code>reference operator () (size_type i)</code></td>
  120. <td>Returns a reference of the <code>i</code>-th element.</td>
  121. </tr>
  122. <tr>
  123. <td><code>const_reference operator [] (size_type i)
  124. const</code></td>
  125. <td>Returns the value of the <code>i</code>-th element.</td>
  126. </tr>
  127. <tr>
  128. <td><code>reference operator [] (size_type i)</code></td>
  129. <td>Returns a reference of the <code>i</code>-th element.</td>
  130. </tr>
  131. <tr>
  132. <td><code>mapped_vector &amp;operator = (const mapped_vector
  133. &amp;v)</code></td>
  134. <td>The assignment operator.</td>
  135. </tr>
  136. <tr>
  137. <td><code>mapped_vector &amp;assign_temporary (mapped_vector
  138. &amp;v)</code></td>
  139. <td>Assigns a temporary. May change the mapped vector
  140. <code>v</code> .</td>
  141. </tr>
  142. <tr>
  143. <td><code>template&lt;class AE&gt;<br />
  144. mapped_vector &amp;operator = (const vector_expression&lt;AE&gt;
  145. &amp;ae)</code></td>
  146. <td>The extended assignment operator.</td>
  147. </tr>
  148. <tr>
  149. <td><code>template&lt;class AE&gt;<br />
  150. mapped_vector &amp;assign (const vector_expression&lt;AE&gt;
  151. &amp;ae)</code></td>
  152. <td>Assigns a vector expression to the mapped vector. Left and
  153. right hand side of the assignment should be independent.</td>
  154. </tr>
  155. <tr>
  156. <td><code>template&lt;class AE&gt;<br />
  157. mapped_vector &amp;operator += (const vector_expression&lt;AE&gt;
  158. &amp;ae)</code></td>
  159. <td>A computed assignment operator. Adds the vector expression to
  160. the mapped vector.</td>
  161. </tr>
  162. <tr>
  163. <td><code>template&lt;class AE&gt;<br />
  164. mapped_vector &amp;plus_assign (const vector_expression&lt;AE&gt;
  165. &amp;ae)</code></td>
  166. <td>Adds a vector expression to the mapped vector. Left and right
  167. hand side of the assignment should be independent.</td>
  168. </tr>
  169. <tr>
  170. <td><code>template&lt;class AE&gt;<br />
  171. mapped_vector &amp;operator -= (const vector_expression&lt;AE&gt;
  172. &amp;ae)</code></td>
  173. <td>A computed assignment operator. Subtracts the vector expression
  174. from the mapped vector.</td>
  175. </tr>
  176. <tr>
  177. <td><code>template&lt;class AE&gt;<br />
  178. mapped_vector &amp;minus_assign (const vector_expression&lt;AE&gt;
  179. &amp;ae)</code></td>
  180. <td>Subtracts a vector expression from the mapped vector. Left and
  181. right hand side of the assignment should be independent.</td>
  182. </tr>
  183. <tr>
  184. <td><code>template&lt;class AT&gt;<br />
  185. mapped_vector &amp;operator *= (const AT &amp;at)</code></td>
  186. <td>A computed assignment operator. Multiplies the mapped vector
  187. with a scalar.</td>
  188. </tr>
  189. <tr>
  190. <td><code>template&lt;class AT&gt;<br />
  191. mapped_vector &amp;operator /= (const AT &amp;at)</code></td>
  192. <td>A computed assignment operator. Divides the mapped vector
  193. through a scalar.</td>
  194. </tr>
  195. <tr>
  196. <td><code>void swap (mapped_vector &amp;v)</code></td>
  197. <td>Swaps the contents of the mapped vectors.</td>
  198. </tr>
  199. <tr>
  200. <td><code>true_reference insert_element (size_type i, const_reference t)</code></td>
  201. <td>Inserts the value <code>t</code> at the <code>i</code>-th
  202. element. Duplicates elements are not allowed.</td>
  203. </tr>
  204. <tr>
  205. <td><code>void erase_element (size_type i)</code></td>
  206. <td>Erases the value at the <code>i</code>-th element.</td>
  207. </tr>
  208. <tr>
  209. <td><code>void clear ()</code></td>
  210. <td>Clears the mapped vector.</td>
  211. </tr>
  212. <tr>
  213. <td><code>const_iterator begin () const</code></td>
  214. <td>Returns a <code>const_iterator</code> pointing to the beginning
  215. of the <code>mapped_vector</code>.</td>
  216. </tr>
  217. <tr>
  218. <td><code>const_iterator end () const</code></td>
  219. <td>Returns a <code>const_iterator</code> pointing to the end of
  220. the <code>mapped_vector</code>.</td>
  221. </tr>
  222. <tr>
  223. <td><code>iterator begin ()</code></td>
  224. <td>Returns a <code>iterator</code> pointing to the beginning of
  225. the <code>mapped_vector</code>.</td>
  226. </tr>
  227. <tr>
  228. <td><code>iterator end ()</code></td>
  229. <td>Returns a <code>iterator</code> pointing to the end of the
  230. <code>mapped_vector</code>.</td>
  231. </tr>
  232. <tr>
  233. <td><code>const_reverse_iterator rbegin () const</code></td>
  234. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  235. beginning of the reversed <code>mapped_vector</code>.</td>
  236. </tr>
  237. <tr>
  238. <td><code>const_reverse_iterator rend () const</code></td>
  239. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  240. end of the reversed <code>mapped_vector</code>.</td>
  241. </tr>
  242. <tr>
  243. <td><code>reverse_iterator rbegin ()</code></td>
  244. <td>Returns a <code>reverse_iterator</code> pointing to the
  245. beginning of the reversed <code>mapped_vector</code>.</td>
  246. </tr>
  247. <tr>
  248. <td><code>reverse_iterator rend ()</code></td>
  249. <td>Returns a <code>reverse_iterator</code> pointing to the end of
  250. the reversed <code>mapped_vector</code>.</td>
  251. </tr>
  252. </tbody>
  253. </table>
  254. <h4>Notes</h4>
  255. <p><a name="mapped_vector_1">[1]</a> Supported
  256. parameters for the adapted array are
  257. <code>map_array&lt;std::size_t, T&gt;</code> and
  258. <code>map_std&lt;std::size_t, T&gt;</code>. The latter is
  259. equivalent to <code>std::map&lt;std::size_t, T&gt;</code>.</p>
  260. <h2><a name="compressed_vector"></a>Compressed Vector</h2>
  261. <h4>Description</h4>
  262. <p>The templated class <code>compressed_vector&lt;T, IB, IA,
  263. TA&gt;</code> is the base container adaptor for compressed vectors.
  264. For a <em>n</em>-dimensional compressed vector and <em>0 &lt;= i
  265. &lt; n</em> the non-zero elements <em>v</em><sub><em>i</em></sub>
  266. are mapped to consecutive elements of the index and value
  267. container, i.e. for elements <em>k</em> =
  268. <em>v</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub>and
  269. <em>k + 1 =
  270. v</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub>of these
  271. containers holds <em>i</em><sub><em>1</em></sub> <em>&lt;
  272. i</em><sub><em>2</em></sub>.</p>
  273. <h4>Example</h4>
  274. <pre>
  275. #include &lt;boost/numeric/ublas/vector_sparse.hpp&gt;
  276. #include &lt;boost/numeric/ublas/io.hpp&gt;
  277. int main () {
  278. using namespace boost::numeric::ublas;
  279. compressed_vector&lt;double&gt; v (3, 3);
  280. for (unsigned i = 0; i &lt; v.size (); ++ i)
  281. v (i) = i;
  282. std::cout &lt;&lt; v &lt;&lt; std::endl;
  283. }
  284. </pre>
  285. <h4>Definition</h4>
  286. <p>Defined in the header vector_sparse.hpp.</p>
  287. <h4>Template parameters</h4>
  288. <table border="1" summary="parameters">
  289. <tbody>
  290. <tr>
  291. <th>Parameter</th>
  292. <th>Description</th>
  293. <th>Default</th>
  294. </tr>
  295. <tr>
  296. <td><code>T</code></td>
  297. <td>The type of object stored in the compressed vector.</td>
  298. <td></td>
  299. </tr>
  300. <tr>
  301. <td><code>IB</code></td>
  302. <td>The index base of the compressed vector. <a href=
  303. "#compressed_vector_1">[1]</a></td>
  304. <td><code>0</code></td>
  305. </tr>
  306. <tr>
  307. <td><code>IA</code></td>
  308. <td>The type of the adapted array for indices. <a href=
  309. "#compressed_vector_2">[2]</a></td>
  310. <td><code>unbounded_array&lt;std::size_t&gt;</code></td>
  311. </tr>
  312. <tr>
  313. <td><code>TA</code></td>
  314. <td>The type of the adapted array for values. <a href=
  315. "#compressed_vector_2">[2]</a></td>
  316. <td><code>unbounded_array&lt;T&gt;</code></td>
  317. </tr>
  318. </tbody>
  319. </table>
  320. <h4>Model of</h4>
  321. <p><a href="container_concept.html#vector">Vector</a> .</p>
  322. <h4>Type requirements</h4>
  323. <p>None, except for those imposed by the requirements of <a href=
  324. "container_concept.html#vector">Vector</a> .</p>
  325. <h4>Public base classes</h4>
  326. <p><code>vector_container&lt;compressed_vector&lt;T, IB, IA,
  327. TA&gt; &gt;</code></p>
  328. <h4>Members</h4>
  329. <table border="1" summary="members">
  330. <tbody>
  331. <tr>
  332. <th>Member</th>
  333. <th>Description</th>
  334. </tr>
  335. <tr>
  336. <td><code>compressed_vector ()</code></td>
  337. <td>Allocates a <code>compressed_vector</code> that holds zero
  338. elements.</td>
  339. </tr>
  340. <tr>
  341. <td><code>compressed_vector (size_type size, size_type
  342. non_zeros)</code></td>
  343. <td>Allocates a <code>compressed_vector</code> that holds at most
  344. <code>size</code> elements.</td>
  345. </tr>
  346. <tr>
  347. <td><code>compressed_vector (const compressed_vector
  348. &amp;v)</code></td>
  349. <td>The copy constructor.</td>
  350. </tr>
  351. <tr>
  352. <td><code>template&lt;class AE&gt;<br />
  353. compressed_vector (size_type non_zeros, const
  354. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  355. <td>The extended copy constructor.</td>
  356. </tr>
  357. <tr>
  358. <td><code>void resize (size_type size, bool
  359. preserve = true)</code></td>
  360. <td>Reallocates a <code>compressed_vector</code> to hold at most
  361. <code>size</code> elements. The existing elements of the
  362. <code>compress_vector</code> are preseved when specified.</td>
  363. </tr>
  364. <tr>
  365. <td><code>size_type size () const</code></td>
  366. <td>Returns the size of the <code>compressed_vector</code>.</td>
  367. </tr>
  368. <tr>
  369. <td><code>const_reference operator () (size_type i)
  370. const</code></td>
  371. <td>Returns the value of the <code>i</code>-th element.</td>
  372. </tr>
  373. <tr>
  374. <td><code>reference operator () (size_type i)</code></td>
  375. <td>Returns a reference of the <code>i</code>-th element.</td>
  376. </tr>
  377. <tr>
  378. <td><code>const_reference operator [] (size_type i)
  379. const</code></td>
  380. <td>Returns the value of the <code>i</code>-th element.</td>
  381. </tr>
  382. <tr>
  383. <td><code>reference operator [] (size_type i)</code></td>
  384. <td>Returns a reference of the <code>i</code>-th element.</td>
  385. </tr>
  386. <tr>
  387. <td><code>compressed_vector &amp;operator = (const
  388. compressed_vector &amp;v)</code></td>
  389. <td>The assignment operator.</td>
  390. </tr>
  391. <tr>
  392. <td><code>compressed_vector &amp;assign_temporary
  393. (compressed_vector &amp;v)</code></td>
  394. <td>Assigns a temporary. May change the compressed vector
  395. <code>v</code>.</td>
  396. </tr>
  397. <tr>
  398. <td><code>template&lt;class AE&gt;<br />
  399. compressed_vector &amp;operator = (const
  400. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  401. <td>The extended assignment operator.</td>
  402. </tr>
  403. <tr>
  404. <td><code>template&lt;class AE&gt;<br />
  405. compressed_vector &amp;assign (const vector_expression&lt;AE&gt;
  406. &amp;ae)</code></td>
  407. <td>Assigns a vector expression to the compressed vector. Left and
  408. right hand side of the assignment should be independent.</td>
  409. </tr>
  410. <tr>
  411. <td><code>template&lt;class AE&gt;<br />
  412. compressed_vector &amp;operator += (const
  413. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  414. <td>A computed assignment operator. Adds the vector expression to
  415. the compressed vector.</td>
  416. </tr>
  417. <tr>
  418. <td><code>template&lt;class AE&gt;<br />
  419. compressed_vector &amp;plus_assign (const
  420. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  421. <td>Adds a vector expression to the compressed vector. Left and
  422. right hand side of the assignment should be independent.</td>
  423. </tr>
  424. <tr>
  425. <td><code>template&lt;class AE&gt;<br />
  426. compressed_vector &amp;operator -= (const
  427. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  428. <td>A computed assignment operator. Subtracts the vector expression
  429. from the compressed vector.</td>
  430. </tr>
  431. <tr>
  432. <td><code>template&lt;class AE&gt;<br />
  433. compressed_vector &amp;minus_assign (const
  434. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  435. <td>Subtracts a vector expression from the compressed vector. Left
  436. and right hand side of the assignment should be independent.</td>
  437. </tr>
  438. <tr>
  439. <td><code>template&lt;class AT&gt;<br />
  440. compressed_vector &amp;operator *= (const AT &amp;at)</code></td>
  441. <td>A computed assignment operator. Multiplies the compressed
  442. vector with a scalar.</td>
  443. </tr>
  444. <tr>
  445. <td><code>template&lt;class AT&gt;<br />
  446. compressed_vector &amp;operator /= (const AT &amp;at)</code></td>
  447. <td>A computed assignment operator. Divides the compressed vector
  448. through a scalar.</td>
  449. </tr>
  450. <tr>
  451. <td><code>void swap (compressed_vector &amp;v)</code></td>
  452. <td>Swaps the contents of the compressed vectors.</td>
  453. </tr>
  454. <tr>
  455. <td><code>true_reference insert_element (size_type i, const_reference t)</code></td>
  456. <td>Inserts the value <code>t</code> at the <code>i</code>-th
  457. element. Duplicates elements are not allowed.</td>
  458. </tr>
  459. <tr>
  460. <td><code>void erase_element (size_type i)</code></td>
  461. <td>Erases the value at the <code>i</code>-th element.</td>
  462. </tr>
  463. <tr>
  464. <td><code>void clear ()</code></td>
  465. <td>Clears the compressed vector.</td>
  466. </tr>
  467. <tr>
  468. <td><code>const_iterator begin () const</code></td>
  469. <td>Returns a <code>const_iterator</code> pointing to the beginning
  470. of the <code>compressed_vector</code>.</td>
  471. </tr>
  472. <tr>
  473. <td><code>const_iterator end () const</code></td>
  474. <td>Returns a <code>const_iterator</code> pointing to the end of
  475. the <code>compressed_vector</code>.</td>
  476. </tr>
  477. <tr>
  478. <td><code>iterator begin ()</code></td>
  479. <td>Returns a <code>iterator</code> pointing to the beginning of
  480. the <code>compressed_vector</code>.</td>
  481. </tr>
  482. <tr>
  483. <td><code>iterator end ()</code></td>
  484. <td>Returns a <code>iterator</code> pointing to the end of the
  485. <code>compressed_vector</code>.</td>
  486. </tr>
  487. <tr>
  488. <td><code>const_reverse_iterator rbegin () const</code></td>
  489. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  490. beginning of the reversed <code>compressed_vector</code>.</td>
  491. </tr>
  492. <tr>
  493. <td><code>const_reverse_iterator rend () const</code></td>
  494. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  495. end of the reversed <code>compressed_vector</code>.</td>
  496. </tr>
  497. <tr>
  498. <td><code>reverse_iterator rbegin ()</code></td>
  499. <td>Returns a <code>reverse_iterator</code> pointing to the
  500. beginning of the reversed <code>compressed_vector</code>.</td>
  501. </tr>
  502. <tr>
  503. <td><code>reverse_iterator rend ()</code></td>
  504. <td>Returns a <code>reverse_iterator</code> pointing to the end of
  505. the reversed <code>compressed_vector</code>.</td>
  506. </tr>
  507. </tbody>
  508. </table>
  509. <h4>Notes</h4>
  510. <p><a name="compressed_vector_1">[1]</a>
  511. Supported parameters for the index base are <code>0</code> and
  512. <code>1</code> at least.</p>
  513. <p><a name="compressed_vector_2">[2]</a>
  514. Supported parameters for the adapted array are
  515. <code>unbounded_array&lt;&gt;</code> ,
  516. <code>bounded_array&lt;&gt;</code> and
  517. <code>std::vector&lt;&gt;</code> .</p>
  518. <h2><a name="coordinate_vector"></a>Coordinate Vector</h2>
  519. <h4>Description</h4>
  520. <p>The templated class <code>coordinate_vector&lt;T, IB, IA,
  521. TA&gt;</code> is the base container adaptor for compressed vectors.
  522. For a <em>n</em>-dimensional sorted coordinate vector and <em>0
  523. &lt;= i &lt; n</em> the non-zero elements
  524. <em>v</em><sub><em>i</em></sub> are mapped to consecutive elements
  525. of the index and value container, i.e. for elements <em>k</em> =
  526. <em>v</em><sub><em>i</em></sub><sub><sub><em>1</em></sub></sub>and
  527. <em>k + 1 =
  528. v</em><sub><em>i</em></sub><sub><sub><em>2</em></sub></sub>of these
  529. containers holds <em>i</em><sub><em>1</em></sub> <em>&lt;
  530. i</em><sub><em>2</em></sub>.</p>
  531. <h4>Example</h4>
  532. <pre>
  533. #include &lt;boost/numeric/ublas/vector_sparse.hpp&gt;
  534. #include &lt;boost/numeric/ublas/io.hpp&gt;
  535. int main () {
  536. using namespace boost::numeric::ublas;
  537. coordinate_vector&lt;double&gt; v (3, 3);
  538. for (unsigned i = 0; i &lt; v.size (); ++ i)
  539. v (i) = i;
  540. std::cout &lt;&lt; v &lt;&lt; std::endl;
  541. }
  542. </pre>
  543. <h4>Definition</h4>
  544. <p>Defined in the header vector_sparse.hpp.</p>
  545. <h4>Template parameters</h4>
  546. <table border="1" summary="parameters">
  547. <tbody>
  548. <tr>
  549. <th>Parameter</th>
  550. <th>Description</th>
  551. <th>Default</th>
  552. </tr>
  553. <tr>
  554. <td><code>T</code></td>
  555. <td>The type of object stored in the coordinate vector.</td>
  556. <td></td>
  557. </tr>
  558. <tr>
  559. <td><code>IB</code></td>
  560. <td>The index base of the coordinate vector. <a href=
  561. "#coordinate_vector_1">[1]</a></td>
  562. <td><code>0</code></td>
  563. </tr>
  564. <tr>
  565. <td><code>IA</code></td>
  566. <td>The type of the adapted array for indices. <a href=
  567. "#coordinate_vector_2">[2]</a></td>
  568. <td><code>unbounded_array&lt;std::size_t&gt;</code></td>
  569. </tr>
  570. <tr>
  571. <td><code>TA</code></td>
  572. <td>The type of the adapted array for values. <a href=
  573. "#coordinate_vector_2">[2]</a></td>
  574. <td><code>unbounded_array&lt;T&gt;</code></td>
  575. </tr>
  576. </tbody>
  577. </table>
  578. <h4>Model of</h4>
  579. <p><a href="container_concept.html#vector">Vector</a> .</p>
  580. <h4>Type requirements</h4>
  581. <p>None, except for those imposed by the requirements of <a href=
  582. "container_concept.html#vector">Vector</a> .</p>
  583. <h4>Public base classes</h4>
  584. <p><code>vector_container&lt;coordinate_vector&lt;T, IB, IA,
  585. TA&gt; &gt;</code></p>
  586. <h4>Members</h4>
  587. <table border="1" summary="members">
  588. <tbody>
  589. <tr>
  590. <th>Member</th>
  591. <th>Description</th>
  592. </tr>
  593. <tr>
  594. <td><code>coordinate_vector ()</code></td>
  595. <td>Allocates a <code>coordinate_vector</code> that holds zero
  596. elements.</td>
  597. </tr>
  598. <tr>
  599. <td><code>coordinate_vector (size_type size, size_type
  600. non_zeros)</code></td>
  601. <td>Allocates a <code>coordinate_vector</code> that holds at most
  602. <code>size</code> elements.</td>
  603. </tr>
  604. <tr>
  605. <td><code>coordinate_vector (const coordinate_vector
  606. &amp;v)</code></td>
  607. <td>The copy constructor.</td>
  608. </tr>
  609. <tr>
  610. <td><code>template&lt;class AE&gt;<br />
  611. coordinate_vector (size_type non_zeros, const
  612. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  613. <td>The extended copy constructor.</td>
  614. </tr>
  615. <tr>
  616. <td><code>void resize (size_type size, bool
  617. preserve = true)</code></td>
  618. <td>Reallocates a <code>coordinate_vector</code> to hold at most
  619. <code>size</code> elements. The existing elements of the
  620. <code>coordinate_vector</code> are preseved when specified.</td>
  621. </tr>
  622. <tr>
  623. <td><code>size_type size () const</code></td>
  624. <td>Returns the size of the <code>coordinate_vector</code>.</td>
  625. </tr>
  626. <tr>
  627. <td><code>const_reference operator () (size_type i)
  628. const</code></td>
  629. <td>Returns the value of the <code>i</code>-th element.</td>
  630. </tr>
  631. <tr>
  632. <td><code>reference operator () (size_type i)</code></td>
  633. <td>Returns a reference of the <code>i</code>-th element.</td>
  634. </tr>
  635. <tr>
  636. <td><code>const_reference operator [] (size_type i)
  637. const</code></td>
  638. <td>Returns the value of the <code>i</code>-th element.</td>
  639. </tr>
  640. <tr>
  641. <td><code>reference operator [] (size_type i)</code></td>
  642. <td>Returns a reference of the <code>i</code>-th element.</td>
  643. </tr>
  644. <tr>
  645. <td><code>coordinate_vector &amp;operator = (const
  646. coordinate_vector &amp;v)</code></td>
  647. <td>The assignment operator.</td>
  648. </tr>
  649. <tr>
  650. <td><code>coordinate_vector &amp;assign_temporary
  651. (coordinate_vector &amp;v)</code></td>
  652. <td>Assigns a temporary. May change the coordinate vector
  653. <code>v</code>.</td>
  654. </tr>
  655. <tr>
  656. <td><code>template&lt;class AE&gt;<br />
  657. coordinate_vector &amp;operator = (const
  658. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  659. <td>The extended assignment operator.</td>
  660. </tr>
  661. <tr>
  662. <td><code>template&lt;class AE&gt;<br />
  663. coordinate_vector &amp;assign (const vector_expression&lt;AE&gt;
  664. &amp;ae)</code></td>
  665. <td>Assigns a vector expression to the coordinate vector. Left and
  666. right hand side of the assignment should be independent.</td>
  667. </tr>
  668. <tr>
  669. <td><code>template&lt;class AE&gt;<br />
  670. coordinate_vector &amp;operator += (const
  671. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  672. <td>A computed assignment operator. Adds the vector expression to
  673. the coordinate vector.</td>
  674. </tr>
  675. <tr>
  676. <td><code>template&lt;class AE&gt;<br />
  677. coordinate_vector &amp;plus_assign (const
  678. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  679. <td>Adds a vector expression to the coordinate vector. Left and
  680. right hand side of the assignment should be independent.</td>
  681. </tr>
  682. <tr>
  683. <td><code>template&lt;class AE&gt;<br />
  684. coordinate_vector &amp;operator -= (const
  685. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  686. <td>A computed assignment operator. Subtracts the vector expression
  687. from the coordinate vector.</td>
  688. </tr>
  689. <tr>
  690. <td><code>template&lt;class AE&gt;<br />
  691. coordinate_vector &amp;minus_assign (const
  692. vector_expression&lt;AE&gt; &amp;ae)</code></td>
  693. <td>Subtracts a vector expression from the coordinate vector. Left
  694. and right hand side of the assignment should be independent.</td>
  695. </tr>
  696. <tr>
  697. <td><code>template&lt;class AT&gt;<br />
  698. coordinate_vector &amp;operator *= (const AT &amp;at)</code></td>
  699. <td>A computed assignment operator. Multiplies the coordinate
  700. vector with a scalar.</td>
  701. </tr>
  702. <tr>
  703. <td><code>template&lt;class AT&gt;<br />
  704. coordinate_vector &amp;operator /= (const AT &amp;at)</code></td>
  705. <td>A computed assignment operator. Divides the coordinate vector
  706. through a scalar.</td>
  707. </tr>
  708. <tr>
  709. <td><code>void swap (coordinate_vector &amp;v)</code></td>
  710. <td>Swaps the contents of the coordinate vectors.</td>
  711. </tr>
  712. <tr>
  713. <td><code>true_reference insert_element (size_type i, const_reference t)</code></td>
  714. <td>Inserts the value <code>t</code> at the <code>i</code>-th
  715. element. Duplicates elements are not allowed.</td>
  716. </tr>
  717. <tr>
  718. <td><code>void append_element (size_type i, size_type j, const_reference t)</code></td>
  719. <td>Appends the value <code>t</code> at the <code>i</code>-th element.
  720. Duplicate elements can be appended to a <code>coordinate_vector</code>. They are merged into a single
  721. arithmetically summed element by the <code>sort</code> function.</td>
  722. </tr>
  723. <tr>
  724. <td><code>void erase_element (size_type i)</code></td>
  725. <td>Erases the value at the <code>i</code>-th element.</td>
  726. </tr>
  727. <tr>
  728. <td><code>void clear ()</code></td>
  729. <td>Clears the coordinate vector.</td>
  730. </tr>
  731. <tr>
  732. <td><code>const_iterator begin () const</code></td>
  733. <td>Returns a <code>const_iterator</code> pointing to the beginning
  734. of the <code>coordinate_vector</code>.</td>
  735. </tr>
  736. <tr>
  737. <td><code>const_iterator end () const</code></td>
  738. <td>Returns a <code>const_iterator</code> pointing to the end of
  739. the <code>coordinate_vector</code>.</td>
  740. </tr>
  741. <tr>
  742. <td><code>iterator begin ()</code></td>
  743. <td>Returns a <code>iterator</code> pointing to the beginning of
  744. the <code>coordinate_vector</code>.</td>
  745. </tr>
  746. <tr>
  747. <td><code>iterator end ()</code></td>
  748. <td>Returns a <code>iterator</code> pointing to the end of the
  749. <code>coordinate_vector</code>.</td>
  750. </tr>
  751. <tr>
  752. <td><code>const_reverse_iterator rbegin () const</code></td>
  753. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  754. beginning of the reversed <code>coordinate_vector</code>.</td>
  755. </tr>
  756. <tr>
  757. <td><code>const_reverse_iterator rend () const</code></td>
  758. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  759. end of the reversed <code>coordinate_vector</code>.</td>
  760. </tr>
  761. <tr>
  762. <td><code>reverse_iterator rbegin ()</code></td>
  763. <td>Returns a <code>reverse_iterator</code> pointing to the
  764. beginning of the reversed <code>coordinate_vector</code>.</td>
  765. </tr>
  766. <tr>
  767. <td><code>reverse_iterator rend ()</code></td>
  768. <td>Returns a <code>reverse_iterator</code> pointing to the end of
  769. the reversed <code>coordinate_vector</code>.</td>
  770. </tr>
  771. </tbody>
  772. </table>
  773. <h4>Notes</h4>
  774. <p><a name="coordinate_vector_1">[1]</a>
  775. Supported parameters for the index base are <code>0</code> and
  776. <code>1</code> at least.</p>
  777. <p><a name="coordinate_vector_2">[2]</a>
  778. Supported parameters for the adapted array are
  779. <code>unbounded_array&lt;&gt;</code> ,
  780. <code>bounded_array&lt;&gt;</code> and
  781. <code>std::vector&lt;&gt;</code> .</p>
  782. <hr />
  783. <p>Copyright (&copy;) 2000-2002 Joerg Walter, Mathias Koch<br />
  784. Use, modification and distribution are subject to the
  785. Boost Software License, Version 1.0.
  786. (See accompanying file LICENSE_1_0.txt
  787. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  788. http://www.boost.org/LICENSE_1_0.txt
  789. </a>).
  790. </p>
  791. <script type="text/javascript">
  792. (function($) {
  793. $('#toc').toc();
  794. })(jQuery);
  795. </script>
  796. </body>
  797. </html>