matrix_expression.html 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  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>Matrix Expressions</title>
  14. </head>
  15. <body>
  16. <h1><img src="../../../../boost.png" align="middle" />Matrix Expressions</h1>
  17. <div class="toc" id="toc"></div>
  18. <h2><a name="matrix_expression"></a>Matrix Expression</h2>
  19. <h4>Description</h4>
  20. <p>The templated class <code>matrix_expression&lt;E&gt;</code>
  21. is required to be a public base of all classes which model the Matrix Expression concept.</p>
  22. <h4>Definition</h4>
  23. <p>Defined in the header expression_types.hpp.</p>
  24. <h4>Template parameters</h4>
  25. <table border="1" summary="parameters">
  26. <tbody>
  27. <tr>
  28. <th>Parameter</th>
  29. <th>Description</th>
  30. <th>Default</th>
  31. </tr>
  32. <tr>
  33. <td><code>E</code></td>
  34. <td>The type of the matrix expression.</td>
  35. <td>&nbsp;</td>
  36. </tr>
  37. </tbody>
  38. </table>
  39. <h4>Model of</h4>
  40. <p>None. <u>Not a Matrix Expression</u>!
  41. </p>
  42. <h4>Type requirements</h4>
  43. <p>None.</p>
  44. <h4>Public base classes</h4>
  45. <p>None.</p>
  46. <h4>Members</h4>
  47. <table border="1" summary="members">
  48. <tbody>
  49. <tr>
  50. <th>Member</th>
  51. <th>Description</th>
  52. </tr>
  53. <tr>
  54. <td><code>const expression_type &amp;operator () ()
  55. const</code></td>
  56. <td>Returns a <code>const</code> reference of the expression.</td>
  57. </tr>
  58. <tr>
  59. <td><code>expression_type &amp;operator () ()</code></td>
  60. <td>Returns a reference of the expression.</td>
  61. </tr>
  62. </tbody>
  63. </table>
  64. <h4>Notes</h4>
  65. <p>The <code>operator[]</code>, <code>row</code>, <code>column</code>, <code>range</code>, <code>slice</code> and <code>project</code> functions have been removed. Use the free functions defined in <a href="matrix_proxy.html">matrix proxy</a> instead.</p>
  66. <h2><a name="matrix_container"></a>Matrix Container</h2>
  67. <h4>Description</h4>
  68. <p>The templated class <code>matrix_container&lt;C&gt;</code>
  69. is required to be a public base of all classes which model the Matrix concept.
  70. This includes the class <code>matrix</code> itself.</p>
  71. <h4>Definition</h4>
  72. <p>Defined in the header expression_types.hpp.</p>
  73. <h4>Template parameters</h4>
  74. <table border="1" summary="parameters">
  75. <tbody>
  76. <tr>
  77. <th>Parameter</th>
  78. <th>Description</th>
  79. <th>Default</th>
  80. </tr>
  81. <tr>
  82. <td><code>E</code></td>
  83. <td>The type of the matrix expression.</td>
  84. <td>&nbsp;</td>
  85. </tr>
  86. </tbody>
  87. </table>
  88. <h4>Model of</h4>
  89. <p>None. <u>Not a Matrix Expression OR Matrix</u>!
  90. </p>
  91. <h4>Type requirements</h4>
  92. <p>None.</p>
  93. <h4>Public base classes</h4>
  94. <p><code>matrix_expression&lt;C&gt;</code></p>
  95. <h4>Members</h4>
  96. <table border="1" summary="members">
  97. <tbody>
  98. <tr>
  99. <th>Member</th>
  100. <th>Description</th>
  101. </tr>
  102. <tr>
  103. <td><code>const container_type &amp;operator () ()
  104. const</code></td>
  105. <td>Returns a <code>const</code> reference of the container.</td>
  106. </tr>
  107. <tr>
  108. <td><code>container_type &amp;operator () ()</code></td>
  109. <td>Returns a reference of the container.</td>
  110. </tr>
  111. </tbody>
  112. </table>
  113. <h2><a name="matrix_references"></a>Matrix References</h2>
  114. <h3>Reference</h3>
  115. <h4>Description</h4>
  116. <p>The templated class <code>matrix_reference&lt;E&gt;</code>
  117. contains a reference to a matrix expression.</p>
  118. <h4>Definition</h4>
  119. <p>Defined in the header matrix_expression.hpp.</p>
  120. <h4>Template parameters</h4>
  121. <table border="1" summary="parameters">
  122. <tbody>
  123. <tr>
  124. <th>Parameter</th>
  125. <th>Description</th>
  126. <th>Default</th>
  127. </tr>
  128. <tr>
  129. <td><code>E</code></td>
  130. <td>The type of the matrix expression.</td>
  131. <td>&nbsp;</td>
  132. </tr>
  133. </tbody>
  134. </table>
  135. <h4>Model of</h4>
  136. <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  137. .</p>
  138. <h4>Type requirements</h4>
  139. <p>None, except for those imposed by the requirements of <a href=
  140. "expression_concept.html#matrix_expression">Matrix Expression</a> .</p>
  141. <h4>Public base classes</h4>
  142. <p><code>matrix_expression&lt;matrix_reference&lt;E&gt;
  143. &gt;</code></p>
  144. <h4>Members</h4>
  145. <table border="1" summary="members">
  146. <tbody>
  147. <tr>
  148. <th>Member</th>
  149. <th>Description</th>
  150. </tr>
  151. <tr>
  152. <td><code>matrix_reference (expression_type &amp;e)</code></td>
  153. <td>Constructs a constant reference of the expression.</td>
  154. </tr>
  155. <tr>
  156. <td><code>void resize (size_type size1, size2)</code></td>
  157. <td>Resizes the expression to hold at most <code>size1</code> rows
  158. of <code>size2</code> elements.</td>
  159. </tr>
  160. <tr>
  161. <td><code>size_type size1 () const</code></td>
  162. <td>Returns the number of rows.</td>
  163. </tr>
  164. <tr>
  165. <td><code>size_type size2 () const</code></td>
  166. <td>Returns the number of columns.</td>
  167. </tr>
  168. <tr>
  169. <td><code>const_reference operator () (size_type i, size_type j)
  170. const</code></td>
  171. <td>Returns the value of the <code>j</code>-th element in the
  172. <code>i</code>-th row.</td>
  173. </tr>
  174. <tr>
  175. <td><code>reference operator () (size_type i, size_type
  176. j)</code></td>
  177. <td>Returns a reference of the <code>j</code>-th element in the
  178. <code>i</code>-th row.</td>
  179. </tr>
  180. <tr>
  181. <td><code>const_iterator1 begin1 () const</code></td>
  182. <td>Returns a <code>const_iterator1</code> pointing to the
  183. beginning of the expression.</td>
  184. </tr>
  185. <tr>
  186. <td><code>const_iterator1 end1 () const</code></td>
  187. <td>Returns a <code>const_iterator1</code> pointing to the end of
  188. the expression.</td>
  189. </tr>
  190. <tr>
  191. <td><code>iterator1 begin1 ()</code></td>
  192. <td>Returns a <code>iterator1</code> pointing to the beginning of
  193. the expression.</td>
  194. </tr>
  195. <tr>
  196. <td><code>iterator1 end1 ()</code></td>
  197. <td>Returns a <code>iterator1</code> pointing to the end of the
  198. expression.</td>
  199. </tr>
  200. <tr>
  201. <td><code>const_iterator2 begin2 () const</code></td>
  202. <td>Returns a <code>const_iterator2</code> pointing to the
  203. beginning of the expression.</td>
  204. </tr>
  205. <tr>
  206. <td><code>const_iterator2 end2 () const</code></td>
  207. <td>Returns a <code>const_iterator2</code> pointing to the end of
  208. the expression.</td>
  209. </tr>
  210. <tr>
  211. <td><code>iterator2 begin2 ()</code></td>
  212. <td>Returns a <code>iterator2</code> pointing to the beginning of
  213. the expression.</td>
  214. </tr>
  215. <tr>
  216. <td><code>iterator2 end2 ()</code></td>
  217. <td>Returns a <code>iterator2</code> pointing to the end of the
  218. expression.</td>
  219. </tr>
  220. <tr>
  221. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  222. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  223. beginning of the reversed expression.</td>
  224. </tr>
  225. <tr>
  226. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  227. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  228. end of the reversed expression.</td>
  229. </tr>
  230. <tr>
  231. <td><code>reverse_iterator1 rbegin1 ()</code></td>
  232. <td>Returns a <code>reverse_iterator1</code> pointing to the
  233. beginning of the reversed expression.</td>
  234. </tr>
  235. <tr>
  236. <td><code>reverse_iterator1 rend1 ()</code></td>
  237. <td>Returns a <code>reverse_iterator1</code> pointing to the end of
  238. the reversed expression.</td>
  239. </tr>
  240. <tr>
  241. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  242. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  243. beginning of the reversed expression.</td>
  244. </tr>
  245. <tr>
  246. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  247. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  248. end of the reversed expression.</td>
  249. </tr>
  250. <tr>
  251. <td><code>reverse_iterator2 rbegin2 ()</code></td>
  252. <td>Returns a <code>reverse_iterator2</code> pointing to the
  253. beginning of the reversed expression.</td>
  254. </tr>
  255. <tr>
  256. <td><code>reverse_iterator2 rend2 ()</code></td>
  257. <td>Returns a <code>reverse_iterator2</code> pointing to the end of
  258. the reversed expression.</td>
  259. </tr>
  260. </tbody>
  261. </table>
  262. <h2><a name="matrix_operations"></a>Matrix Operations</h2>
  263. <h3>Unary Operation Description</h3>
  264. <h4>Description</h4>
  265. <p>The templated classes <code>matrix_unary1&lt;E, F&gt;</code> and
  266. <code>matrix_unary2&lt;E, F&gt;</code> describe unary matrix
  267. operations.</p>
  268. <h4>Definition</h4>
  269. <p>Defined in the header matrix_expression.hpp.</p>
  270. <h4>Template parameters</h4>
  271. <table border="1" summary="parameters">
  272. <tbody>
  273. <tr>
  274. <th>Parameter</th>
  275. <th>Description</th>
  276. <th>Default</th>
  277. </tr>
  278. <tr>
  279. <td><code>E</code></td>
  280. <td>The type of the matrix expression.</td>
  281. <td>&nbsp;</td>
  282. </tr>
  283. <tr>
  284. <td><code>F</code></td>
  285. <td>The type of the operation.</td>
  286. <td>&nbsp;</td>
  287. </tr>
  288. </tbody>
  289. </table>
  290. <h4>Model of</h4>
  291. <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  292. .</p>
  293. <h4>Type requirements</h4>
  294. <p>None, except for those imposed by the requirements of <a href=
  295. "expression_concept.html#matrix_expression">Matrix Expression</a> .</p>
  296. <h4>Public base classes</h4>
  297. <p><code>matrix_expression&lt;matrix_unary1&lt;E, F&gt; &gt;</code>
  298. and <code>matrix_expression&lt;matrix_unary2&lt;E, F&gt;
  299. &gt;</code> resp.</p>
  300. <h4>Members</h4>
  301. <table border="1" summary="members">
  302. <tbody>
  303. <tr>
  304. <th>Member</th>
  305. <th>Description</th>
  306. </tr>
  307. <tr>
  308. <td><code>matrix_unary1 (const expression_type &amp;e)</code></td>
  309. <td>Constructs a description of the expression.</td>
  310. </tr>
  311. <tr>
  312. <td><code>matrix_unary2 (const expression_type &amp;e)</code></td>
  313. <td>Constructs a description of the expression.</td>
  314. </tr>
  315. <tr>
  316. <td><code>size_type size1 () const</code></td>
  317. <td>Returns the number of rows.</td>
  318. </tr>
  319. <tr>
  320. <td><code>size_type size2 () const</code></td>
  321. <td>Returns the number of columns.</td>
  322. </tr>
  323. <tr>
  324. <td><code>const_reference operator () (size_type i, size_type j)
  325. const</code></td>
  326. <td>Returns the value of the <code>j</code>-th element in the
  327. <code>i</code>-th row.</td>
  328. </tr>
  329. <tr>
  330. <td><code>const_iterator1 begin1 () const</code></td>
  331. <td>Returns a <code>const_iterator1</code> pointing to the
  332. beginning of the expression.</td>
  333. </tr>
  334. <tr>
  335. <td><code>const_iterator1 end1 () const</code></td>
  336. <td>Returns a <code>const_iterator1</code> pointing to the end of
  337. the expression.</td>
  338. </tr>
  339. <tr>
  340. <td><code>const_iterator2 begin2 () const</code></td>
  341. <td>Returns a <code>const_iterator2</code> pointing to the
  342. beginning of the expression.</td>
  343. </tr>
  344. <tr>
  345. <td><code>const_iterator2 end2 () const</code></td>
  346. <td>Returns a <code>const_iterator2</code> pointing to the end of
  347. the expression.</td>
  348. </tr>
  349. <tr>
  350. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  351. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  352. beginning of the reversed expression.</td>
  353. </tr>
  354. <tr>
  355. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  356. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  357. end of the reversed expression.</td>
  358. </tr>
  359. <tr>
  360. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  361. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  362. beginning of the reversed expression.</td>
  363. </tr>
  364. <tr>
  365. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  366. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  367. end of the reversed expression.</td>
  368. </tr>
  369. </tbody>
  370. </table>
  371. <h3>Unary Operations</h3>
  372. <h4>Prototypes</h4>
  373. <pre>
  374. <code>template&lt;class E, class F&gt;
  375. struct matrix_unary1_traits {
  376. typedef matrix_unary1&lt;typename E::const_closure_type, F&gt; expression_type;
  377. typedef expression_type result_type;
  378. };
  379. // (- m) [i] [j] = - m [i] [j]
  380. template&lt;class E&gt;
  381. typename matrix_unary1_traits&lt;E, scalar_negate&lt;typename E::value_type&gt; &gt;::result_type
  382. operator - (const matrix_expression&lt;E&gt; &amp;e);
  383. // (conj m) [i] [j] = conj (m [i] [j])
  384. template&lt;class E&gt;
  385. typename matrix_unary1_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
  386. conj (const matrix_expression&lt;E&gt; &amp;e);
  387. // (real m) [i] [j] = real (m [i] [j])
  388. template&lt;class E&gt;
  389. typename matrix_unary1_traits&lt;E, scalar_real&lt;typename E::value_type&gt; &gt;::result_type
  390. real (const matrix_expression&lt;E&gt; &amp;e);
  391. // (imag m) [i] [j] = imag (m [i] [j])
  392. template&lt;class E&gt;
  393. typename matrix_unary1_traits&lt;E, scalar_imag&lt;typename E::value_type&gt; &gt;::result_type
  394. imag (const matrix_expression&lt;E&gt; &amp;e);
  395. template&lt;class E, class F&gt;
  396. struct matrix_unary2_traits {
  397. typedef matrix_unary2&lt;typename E::const_closure_type, F&gt; expression_type;
  398. typedef expression_type result_type;
  399. };
  400. // (trans m) [i] [j] = m [j] [i]
  401. template&lt;class E&gt;
  402. typename matrix_unary2_traits&lt;E, scalar_identity&lt;typename E::value_type&gt; &gt;::result_type
  403. trans (const matrix_expression&lt;E&gt; &amp;e);
  404. // (herm m) [i] [j] = conj (m [j] [i])
  405. template&lt;class E&gt;
  406. typename matrix_unary2_traits&lt;E, scalar_conj&lt;typename E::value_type&gt; &gt;::result_type
  407. herm (const matrix_expression&lt;E&gt; &amp;e);</code>
  408. </pre>
  409. <h4>Description</h4>
  410. <p><code>operator -</code> computes the additive inverse of a
  411. matrix expression. <code>conj</code> computes the complex conjugate
  412. of a matrix expression. <code>real</code> and <code>imag</code>
  413. compute the real and imaginary parts of a matrix expression.
  414. <code>trans</code> computes the transpose of a matrix expression.
  415. <code>herm</code> computes the hermitian, i.e. the complex
  416. conjugate of the transpose of a matrix expression.</p>
  417. <h4>Definition</h4>
  418. <p>Defined in the header matrix_expression.hpp.</p>
  419. <h4>Type requirements</h4>
  420. <ul>
  421. <li><code>E</code> is a model of <a href=
  422. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  423. </ul>
  424. <h4>Preconditions</h4>
  425. <p>None.</p>
  426. <h4>Complexity</h4>
  427. <p>Quadratic depending from the size of the matrix expression.</p>
  428. <h4>Examples</h4>
  429. <pre>
  430. #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  431. #include &lt;boost/numeric/ublas/io.hpp&gt;
  432. int main () {
  433. using namespace boost::numeric::ublas;
  434. matrix&lt;std::complex&lt;double&gt; &gt; m (3, 3);
  435. for (unsigned i = 0; i &lt; m.size1 (); ++ i)
  436. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  437. m (i, j) = std::complex&lt;double&gt; (3 * i + j, 3 * i + j);
  438. std::cout &lt;&lt; - m &lt;&lt; std::endl;
  439. std::cout &lt;&lt; conj (m) &lt;&lt; std::endl;
  440. std::cout &lt;&lt; real (m) &lt;&lt; std::endl;
  441. std::cout &lt;&lt; imag (m) &lt;&lt; std::endl;
  442. std::cout &lt;&lt; trans (m) &lt;&lt; std::endl;
  443. std::cout &lt;&lt; herm (m) &lt;&lt; std::endl;
  444. }
  445. </pre>
  446. <h3>Binary Operation Description</h3>
  447. <h4>Description</h4>
  448. <p>The templated class <code>matrix_binary&lt;E1, E2, F&gt;</code>
  449. describes a binary matrix operation.</p>
  450. <h4>Definition</h4>
  451. <p>Defined in the header matrix_expression.hpp.</p>
  452. <h4>Template parameters</h4>
  453. <table border="1" summary="parameters">
  454. <tbody>
  455. <tr>
  456. <th>Parameter</th>
  457. <th>Description</th>
  458. <th>Default</th>
  459. </tr>
  460. <tr>
  461. <td><code>E1</code></td>
  462. <td>The type of the first matrix expression.</td>
  463. <td></td>
  464. </tr>
  465. <tr>
  466. <td><code>E2</code></td>
  467. <td>The type of the second matrix expression.</td>
  468. <td></td>
  469. </tr>
  470. <tr>
  471. <td><code>F</code></td>
  472. <td>The type of the operation.</td>
  473. <td></td>
  474. </tr>
  475. </tbody>
  476. </table>
  477. <h4>Model of</h4>
  478. <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  479. .</p>
  480. <h4>Type requirements</h4>
  481. <p>None, except for those imposed by the requirements of <a href=
  482. "expression_concept.html#matrix_expression">Matrix Expression</a> .</p>
  483. <h4>Public base classes</h4>
  484. <p><code>matrix_expression&lt;matrix_binary&lt;E1, E2, F&gt;
  485. &gt;</code>.</p>
  486. <h4>Members</h4>
  487. <table border="1" summary="members">
  488. <tbody>
  489. <tr>
  490. <th>Member</th>
  491. <th>Description</th>
  492. </tr>
  493. <tr>
  494. <td><code>matrix_binary (const expression1_type &amp;e1, const
  495. expression2_type &amp;e2)</code></td>
  496. <td>Constructs a description of the expression.</td>
  497. </tr>
  498. <tr>
  499. <td><code>size_type size1 () const</code></td>
  500. <td>Returns the number of rows.</td>
  501. </tr>
  502. <tr>
  503. <td><code>size_type size2 () const</code></td>
  504. <td>Returns the number of columns.</td>
  505. </tr>
  506. <tr>
  507. <td><code>const_reference operator () (size_type i, size_type j)
  508. const</code></td>
  509. <td>Returns the value of the <code>j</code>-th element in the
  510. <code>i</code>-th row.</td>
  511. </tr>
  512. <tr>
  513. <td><code>const_iterator1 begin1 () const</code></td>
  514. <td>Returns a <code>const_iterator1</code> pointing to the
  515. beginning of the expression.</td>
  516. </tr>
  517. <tr>
  518. <td><code>const_iterator1 end1 () const</code></td>
  519. <td>Returns a <code>const_iterator1</code> pointing to the end of
  520. the expression.</td>
  521. </tr>
  522. <tr>
  523. <td><code>const_iterator2 begin2 () const</code></td>
  524. <td>Returns a <code>const_iterator2</code> pointing to the
  525. beginning of the expression.</td>
  526. </tr>
  527. <tr>
  528. <td><code>const_iterator2 end2 () const</code></td>
  529. <td>Returns a <code>const_iterator2</code> pointing to the end of
  530. the expression.</td>
  531. </tr>
  532. <tr>
  533. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  534. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  535. beginning of the reversed expression.</td>
  536. </tr>
  537. <tr>
  538. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  539. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  540. end of the reversed expression.</td>
  541. </tr>
  542. <tr>
  543. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  544. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  545. beginning of the reversed expression.</td>
  546. </tr>
  547. <tr>
  548. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  549. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  550. end of the reversed expression.</td>
  551. </tr>
  552. </tbody>
  553. </table>
  554. <h3>Binary Operations</h3>
  555. <h4>Prototypes</h4>
  556. <pre>
  557. <code>template&lt;class E1, class E2, class F&gt;
  558. struct matrix_binary_traits {
  559. typedef matrix_binary&lt;typename E1::const_closure_type,
  560. typename E2::const_closure_type, F&gt; expression_type;
  561. typedef expression_type result_type;
  562. };
  563. // (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
  564. template&lt;class E1, class E2&gt;
  565. typename matrix_binary_traits&lt;E1, E2, scalar_plus&lt;typename E1::value_type,
  566. typename E2::value_type&gt; &gt;::result_type
  567. operator + (const matrix_expression&lt;E1&gt; &amp;e1,
  568. const matrix_expression&lt;E2&gt; &amp;e2);
  569. // (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
  570. template&lt;class E1, class E2&gt;
  571. typename matrix_binary_traits&lt;E1, E2, scalar_minus&lt;typename E1::value_type,
  572. typename E2::value_type&gt; &gt;::result_type
  573. operator - (const matrix_expression&lt;E1&gt; &amp;e1,
  574. const matrix_expression&lt;E2&gt; &amp;e2);</code>
  575. </pre>
  576. <h4>Description</h4>
  577. <p><code>operator +</code> computes the sum of two matrix
  578. expressions. <code>operator -</code> computes the difference of two
  579. matrix expressions.</p>
  580. <h4>Definition</h4>
  581. <p>Defined in the header matrix_expression.hpp.</p>
  582. <h4>Type requirements</h4>
  583. <ul>
  584. <li><code>E1</code> is a model of <a href=
  585. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  586. <li><code>E2</code> is a model of <a href=
  587. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  588. </ul>
  589. <h4>Preconditions</h4>
  590. <ul>
  591. <li><code>e1 ().size1 () == e2 ().size1 ()</code></li>
  592. <li><code>e1 ().size2 () == e2 ().size2 ()</code></li>
  593. </ul>
  594. <h4>Complexity</h4>
  595. <p>Quadratic depending from the size of the matrix expressions.</p>
  596. <h4>Examples</h4>
  597. <pre>
  598. #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  599. #include &lt;boost/numeric/ublas/io.hpp&gt;
  600. int main () {
  601. using namespace boost::numeric::ublas;
  602. matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
  603. for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
  604. for (unsigned j = 0; j &lt; std::min (m1.size2 (), m2.size2 ()); ++ j)
  605. m1 (i, j) = m2 (i, j) = 3 * i + j;
  606. std::cout &lt;&lt; m1 + m2 &lt;&lt; std::endl;
  607. std::cout &lt;&lt; m1 - m2 &lt;&lt; std::endl;
  608. }
  609. </pre>
  610. <h3>Scalar Matrix Operation Description</h3>
  611. <h4>Description</h4>
  612. <p>The templated classes <code>matrix_binary_scalar1&lt;E1, E2,
  613. F&gt;</code> and <code>matrix_binary_scalar2&lt;E1, E2,
  614. F&gt;</code> describe binary operations between a scalar and a
  615. matrix.</p>
  616. <h4>Definition</h4>
  617. <p>Defined in the header matrix_expression.hpp.</p>
  618. <h4>Template parameters</h4>
  619. <table border="1" summary="parameters">
  620. <tbody>
  621. <tr>
  622. <th>Parameter</th>
  623. <th>Description</th>
  624. <th>Default</th>
  625. </tr>
  626. <tr>
  627. <td><code>E1/E2</code></td>
  628. <td>The type of the scalar expression.</td>
  629. <td></td>
  630. </tr>
  631. <tr>
  632. <td><code>E2/E1</code></td>
  633. <td>The type of the matrix expression.</td>
  634. <td></td>
  635. </tr>
  636. <tr>
  637. <td><code>F</code></td>
  638. <td>The type of the operation.</td>
  639. <td></td>
  640. </tr>
  641. </tbody>
  642. </table>
  643. <h4>Model of</h4>
  644. <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  645. .</p>
  646. <h4>Type requirements</h4>
  647. <p>None, except for those imposed by the requirements of <a href=
  648. "expression_concept.html#matrix_expression">Matrix Expression</a> .</p>
  649. <h4>Public base classes</h4>
  650. <p><code>matrix_expression&lt;matrix_binary_scalar1&lt;E1, E2,
  651. F&gt; &gt;</code> and
  652. <code>matrix_expression&lt;matrix_binary_scalar2&lt;E1, E2, F&gt;
  653. &gt;</code> resp.</p>
  654. <h4>Members</h4>
  655. <table border="1" summary="members">
  656. <tbody>
  657. <tr>
  658. <th>Member</th>
  659. <th>Description</th>
  660. </tr>
  661. <tr>
  662. <td><code>matrix_binary_scalar1 (const expression1_type &amp;e1,
  663. const expression2_type &amp;e2)</code></td>
  664. <td>Constructs a description of the expression.</td>
  665. </tr>
  666. <tr>
  667. <td><code>matrix_binary_scalar1 (const expression1_type &amp;e1,
  668. const expression2_type &amp;e2)</code></td>
  669. <td>Constructs a description of the expression.</td>
  670. </tr>
  671. <tr>
  672. <td><code>size_type size1 () const</code></td>
  673. <td>Returns the number of rows.</td>
  674. </tr>
  675. <tr>
  676. <td><code>size_type size2 () const</code></td>
  677. <td>Returns the number of columns.</td>
  678. </tr>
  679. <tr>
  680. <td><code>const_reference operator () (size_type i, size_type j)
  681. const</code></td>
  682. <td>Returns the value of the <code>j</code>-th element in the
  683. <code>i</code>-th row.</td>
  684. </tr>
  685. <tr>
  686. <td><code>const_iterator1 begin1 () const</code></td>
  687. <td>Returns a <code>const_iterator1</code> pointing to the
  688. beginning of the expression.</td>
  689. </tr>
  690. <tr>
  691. <td><code>const_iterator1 end1 () const</code></td>
  692. <td>Returns a <code>const_iterator1</code> pointing to the end of
  693. the expression.</td>
  694. </tr>
  695. <tr>
  696. <td><code>const_iterator2 begin2 () const</code></td>
  697. <td>Returns a <code>const_iterator2</code> pointing to the
  698. beginning of the expression.</td>
  699. </tr>
  700. <tr>
  701. <td><code>const_iterator2 end2 () const</code></td>
  702. <td>Returns a <code>const_iterator2</code> pointing to the end of
  703. the expression.</td>
  704. </tr>
  705. <tr>
  706. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  707. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  708. beginning of the reversed expression.</td>
  709. </tr>
  710. <tr>
  711. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  712. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  713. end of the reversed expression.</td>
  714. </tr>
  715. <tr>
  716. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  717. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  718. beginning of the reversed expression.</td>
  719. </tr>
  720. <tr>
  721. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  722. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  723. end of the reversed expression.</td>
  724. </tr>
  725. </tbody>
  726. </table>
  727. <h3>Scalar Matrix Operations</h3>
  728. <h4>Prototypes</h4>
  729. <pre>
  730. <code>template&lt;class T1, class E2, class F&gt;
  731. struct matrix_binary_scalar1_traits {
  732. typedef matrix_binary_scalar1&lt;scalar_const_reference&lt;T1&gt;,
  733. typename E2::const_closure_type, F&gt; expression_type;
  734. typedef expression_type result_type;
  735. };
  736. // (t * m) [i] [j] = t * m [i] [j]
  737. template&lt;class T1, class E2&gt;
  738. typename matrix_binary_scalar1_traits&lt;T1, E2, scalar_multiplies&lt;T1, typename E2::value_type&gt; &gt;::result_type
  739. operator * (const T1 &amp;e1,
  740. const matrix_expression&lt;E2&gt; &amp;e2);
  741. template&lt;class E1, class T2, class F&gt;
  742. struct matrix_binary_scalar2_traits {
  743. typedef matrix_binary_scalar2&lt;typename E1::const_closure_type,
  744. scalar_const_reference&lt;T2&gt;, F&gt; expression_type;
  745. typedef expression_type result_type;
  746. };
  747. // (m * t) [i] [j] = m [i] [j] * t
  748. template&lt;class E1, class T2&gt;
  749. typename matrix_binary_scalar2_traits&lt;E1, T2, scalar_multiplies&lt;typename E1::value_type, T2&gt; &gt;::result_type
  750. operator * (const matrix_expression&lt;E1&gt; &amp;e1,
  751. const T2 &amp;e2);
  752. // (m / t) [i] [j] = m [i] [j] / t
  753. template&lt;class E1, class T2&gt;
  754. typename matrix_binary_scalar2_traits&lt;E1, T2, scalar_divides&lt;typename E1::value_type, T2&gt; &gt;::result_type
  755. operator / (const matrix_expression&lt;E1&gt; &amp;e1,
  756. const T2 &amp;e2);</code>
  757. </pre>
  758. <h4>Description</h4>
  759. <p><code>operator *</code> computes the product of a scalar and a
  760. matrix expression. <code>operator /</code> multiplies the matrix
  761. with the reciprocal of the scalar.</p>
  762. <h4>Definition</h4>
  763. <p>Defined in the header matrix_expression.hpp.</p>
  764. <h4>Type requirements</h4>
  765. <ul>
  766. <li><code>T1/T2</code> is a model of <a href=
  767. "expression_concept.html#scalar_expression">Scalar Expression</a> .</li>
  768. <li><code>E2/E1</code> is a model of <a href=
  769. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  770. </ul>
  771. <h4>Preconditions</h4>
  772. <p>None.</p>
  773. <h4>Complexity</h4>
  774. <p>Quadratic depending from the size of the matrix expression.</p>
  775. <h4>Examples</h4>
  776. <pre>
  777. #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  778. #include &lt;boost/numeric/ublas/io.hpp&gt;
  779. int main () {
  780. using namespace boost::numeric::ublas;
  781. matrix&lt;double&gt; m (3, 3);
  782. for (unsigned i = 0; i &lt; m.size1 (); ++ i)
  783. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  784. m (i, j) = 3 * i + j;
  785. std::cout &lt;&lt; 2.0 * m &lt;&lt; std::endl;
  786. std::cout &lt;&lt; m * 2.0 &lt;&lt; std::endl;
  787. }
  788. </pre>
  789. <h2><a name="matrix_vector_operations"></a>Matrix Vector Operations</h2>
  790. <h3>Binary Operation Description</h3>
  791. <h4>Description</h4>
  792. <p>The templated classes <code>matrix_vector_binary1&lt;E1, E2,
  793. F&gt;</code> and <code>matrix_vector_binary2&lt;E1, E2,
  794. F&gt;</code> describe binary matrix vector operations.</p>
  795. <h4>Definition</h4>
  796. <p>Defined in the header matrix_expression.hpp.</p>
  797. <h4>Template parameters</h4>
  798. <table border="1" summary="parameters">
  799. <tbody>
  800. <tr>
  801. <th>Parameter</th>
  802. <th>Description</th>
  803. <th>Default</th>
  804. </tr>
  805. <tr>
  806. <td><code>E1</code></td>
  807. <td>The type of the matrix or vector expression.</td>
  808. <td></td>
  809. </tr>
  810. <tr>
  811. <td><code>E2</code></td>
  812. <td>The type of the vector or matrix expression.</td>
  813. <td></td>
  814. </tr>
  815. <tr>
  816. <td><code>F</code></td>
  817. <td>The type of the operation.</td>
  818. <td></td>
  819. </tr>
  820. </tbody>
  821. </table>
  822. <h4>Model of</h4>
  823. <p><a href="expression_concept.html#vector_expression">Vector Expression</a>
  824. .</p>
  825. <h4>Type requirements</h4>
  826. <p>None, except for those imposed by the requirements of <a href=
  827. "expression_concept.html#vector_expression">Vector Expression</a> .</p>
  828. <h4>Public base classes</h4>
  829. <p><code>vector_expression&lt;matrix_vector_binary1&lt;E1, E2,
  830. F&gt; &gt;</code> and
  831. <code>vector_expression&lt;matrix_vector_binary2&lt;E1, E2, F&gt;
  832. &gt;</code> resp.</p>
  833. <h4>Members</h4>
  834. <table border="1" summary="members">
  835. <tbody>
  836. <tr>
  837. <th>Member</th>
  838. <th>Description</th>
  839. </tr>
  840. <tr>
  841. <td><code>matrix_vector_binary1 (const expression1_type &amp;e1,
  842. const expression2_type &amp;e2)</code></td>
  843. <td>Constructs a description of the expression.</td>
  844. </tr>
  845. <tr>
  846. <td><code>matrix_vector_binary2 (const expression1_type &amp;e1,
  847. const expression2_type &amp;e2)</code></td>
  848. <td>Constructs a description of the expression.</td>
  849. </tr>
  850. <tr>
  851. <td><code>size_type size () const</code></td>
  852. <td>Returns the size of the expression.</td>
  853. </tr>
  854. <tr>
  855. <td><code>const_reference operator () (size_type i)
  856. const</code></td>
  857. <td>Returns the value of the <code>i</code>-th element.</td>
  858. </tr>
  859. <tr>
  860. <td><code>const_iterator begin () const</code></td>
  861. <td>Returns a <code>const_iterator</code> pointing to the beginning
  862. of the expression.</td>
  863. </tr>
  864. <tr>
  865. <td><code>const_iterator end () const</code></td>
  866. <td>Returns a <code>const_iterator</code> pointing to the end of
  867. the expression.</td>
  868. </tr>
  869. <tr>
  870. <td><code>const_reverse_iterator rbegin () const</code></td>
  871. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  872. beginning of the reversed expression.</td>
  873. </tr>
  874. <tr>
  875. <td><code>const_reverse_iterator rend () const</code></td>
  876. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  877. end of the reversed expression.</td>
  878. </tr>
  879. </tbody>
  880. </table>
  881. <h3>Binary Operations</h3>
  882. <h4>Prototypes</h4>
  883. <pre>
  884. <code>template&lt;class T1, class E1, class T2, class E2&gt;
  885. struct matrix_vector_binary1_traits {
  886. typedef row_major_tag dispatch_category;
  887. typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
  888. typedef matrix_vector_binary1&lt;typename E1::const_closure_type,
  889. typename E2::const_closure_type,
  890. matrix_vector_prod1&lt;T1, T2, promote_type&gt; &gt; expression_type;
  891. typedef expression_type result_type;
  892. };
  893. template&lt;class E1, class E2&gt;
  894. typename matrix_vector_binary1_traits&lt;typename E1::value_type, E1,
  895. typename E2::value_type, E2&gt;::result_type
  896. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  897. const vector_expression&lt;E2&gt; &amp;e2,
  898. row_major_tag);
  899. // Dispatcher
  900. template&lt;class E1, class E2&gt;
  901. typename matrix_vector_binary1_traits&lt;typename E1::value_type, E1,
  902. typename E2::value_type, E2&gt;::result_type
  903. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  904. const vector_expression&lt;E2&gt; &amp;e2);
  905. template&lt;class E1, class E2&gt;
  906. typename matrix_vector_binary1_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  907. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  908. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  909. const vector_expression&lt;E2&gt; &amp;e2,
  910. row_major_tag);
  911. // Dispatcher
  912. template&lt;class E1, class E2&gt;
  913. typename matrix_vector_binary1_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  914. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  915. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  916. const vector_expression&lt;E2&gt; &amp;e2);
  917. template&lt;class V, class E1, class E2&gt;
  918. V
  919. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  920. const vector_expression&lt;E2&gt; &amp;e2);
  921. template&lt;class V, class E1, class E2&gt;
  922. V
  923. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  924. const vector_expression&lt;E2&gt; &amp;e2);
  925. template&lt;class T1, class E1, class T2, class E2&gt;
  926. struct matrix_vector_binary2_traits {
  927. typedef column_major_tag dispatch_category;
  928. typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
  929. typedef matrix_vector_binary2&lt;typename E1::const_closure_type,
  930. typename E2::const_closure_type,
  931. matrix_vector_prod2&lt;T1, T2, promote_type&gt; &gt; expression_type;
  932. typedef expression_type result_type;
  933. };
  934. template&lt;class E1, class E2&gt;
  935. typename matrix_vector_binary2_traits&lt;typename E1::value_type, E1,
  936. typename E2::value_type, E2&gt;::result_type
  937. prod (const vector_expression&lt;E1&gt; &amp;e1,
  938. const matrix_expression&lt;E2&gt; &amp;e2,
  939. column_major_tag);
  940. // Dispatcher
  941. template&lt;class E1, class E2&gt;
  942. typename matrix_vector_binary2_traits&lt;typename E1::value_type, E1,
  943. typename E2::value_type, E2&gt;::result_type
  944. prod (const vector_expression&lt;E1&gt; &amp;e1,
  945. const matrix_expression&lt;E2&gt; &amp;e2);
  946. template&lt;class E1, class E2&gt;
  947. typename matrix_vector_binary2_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  948. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  949. prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
  950. const matrix_expression&lt;E2&gt; &amp;e2,
  951. column_major_tag);
  952. // Dispatcher
  953. template&lt;class E1, class E2&gt;
  954. typename matrix_vector_binary2_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  955. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  956. prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
  957. const matrix_expression&lt;E2&gt; &amp;e2);
  958. template&lt;class V, class E1, class E2&gt;
  959. V
  960. prod (const vector_expression&lt;E1&gt; &amp;e1,
  961. const matrix_expression&lt;E2&gt; &amp;e2);
  962. template&lt;class V, class E1, class E2&gt;
  963. V
  964. prec_prod (const vector_expression&lt;E1&gt; &amp;e1,
  965. const matrix_expression&lt;E2&gt; &amp;e2);</code>
  966. </pre>
  967. <h4>Description</h4>
  968. <p><code>prod</code> computes the product of the matrix and the
  969. vector expression. <code>prec_prod</code> computes the double
  970. precision product of the matrix and the vector expression.</p>
  971. <h4>Definition</h4>
  972. <p>Defined in the header matrix_expression.hpp.</p>
  973. <h4>Type requirements</h4>
  974. <ul>
  975. <li><code>E1</code> is a model of <a href=
  976. "expression_concept.html#matrix_expression">Matrix Expression</a> or
  977. <a href="expression_concept.html#vector_expression">Vector Expression</a>
  978. .</li>
  979. <li><code>E2</code> is a model of <a href=
  980. "expression_concept.html#vector_expression">Vector Expression</a> or
  981. <a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  982. .</li>
  983. </ul>
  984. <h4>Preconditions</h4>
  985. <ul>
  986. <li><code>e1 ().size2 () == e2 ().size ()</code></li>
  987. <li><code>e1 ().size () == e2 ().size1 ()</code></li>
  988. </ul>
  989. <h4>Complexity</h4>
  990. <p>Quadratic depending from the size of the matrix expression.</p>
  991. <h4>Examples</h4>
  992. <pre>
  993. #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  994. #include &lt;boost/numeric/ublas/io.hpp&gt;
  995. int main () {
  996. using namespace boost::numeric::ublas;
  997. matrix&lt;double&gt; m (3, 3);
  998. vector&lt;double&gt; v (3);
  999. for (unsigned i = 0; i &lt; std::min (m.size1 (), v.size ()); ++ i) {
  1000. for (unsigned j = 0; j &lt; m.size2 (); ++ j)
  1001. m (i, j) = 3 * i + j;
  1002. v (i) = i;
  1003. }
  1004. std::cout &lt;&lt; prod (m, v) &lt;&lt; std::endl;
  1005. std::cout &lt;&lt; prod (v, m) &lt;&lt; std::endl;
  1006. }
  1007. </pre>
  1008. <h3>Triangular Solver</h3>
  1009. <h4>Prototypes</h4>
  1010. <pre>
  1011. <code>template&lt;class E1, class E2&gt;
  1012. struct matrix_vector_solve_traits {
  1013. typedef typename promote_traits&lt;typename E1::value_type, typename E2::value_type&gt;::promote_type promote_type;
  1014. typedef vector&lt;promote_type&gt; result_type;
  1015. };
  1016. template&lt;class E1, class E2&gt;
  1017. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1018. E2 &amp;e2,
  1019. lower_tag,
  1020. vector_tag);
  1021. template&lt;class E1, class E2&gt;
  1022. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1023. E2 &amp;e2,
  1024. upper_tag,
  1025. vector_tag);
  1026. template&lt;class E1, class E2&gt;
  1027. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1028. E2 &amp;e2,
  1029. unit_lower_tag,
  1030. vector_tag);
  1031. template&lt;class E1, class E2&gt;
  1032. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1033. E2 &amp;e2,
  1034. unit_upper_tag,
  1035. vector_tag);
  1036. template&lt;class E1, class E2, class C&gt;
  1037. typename matrix_vector_solve_traits&lt;E1, E2&gt;::result_type
  1038. solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1039. const vector_expression&lt;E2&gt; &amp;e2,
  1040. C);
  1041. template&lt;class E1, class E2&gt;
  1042. void inplace_solve (E1 &amp;e1,
  1043. const matrix_expression&lt;E2&gt; &amp;e2,
  1044. vector_tag,
  1045. lower_tag);
  1046. template&lt;class E1, class E2&gt;
  1047. void inplace_solve (E1 &amp;e1,
  1048. const matrix_expression&lt;E2&gt; &amp;e2,
  1049. vector_tag,
  1050. upper_tag);
  1051. template&lt;class E1, class E2&gt;
  1052. void inplace_solve (E1 &amp;e1,
  1053. const matrix_expression&lt;E2&gt; &amp;e2,
  1054. vector_tag,
  1055. unit_lower_tag);
  1056. template&lt;class E1, class E2&gt;
  1057. void inplace_solve (E1 &amp;e1,
  1058. const matrix_expression&lt;E2&gt; &amp;e2,
  1059. vector_tag,
  1060. unit_upper_tag);
  1061. template&lt;class E1, class E2, class C&gt;
  1062. typename matrix_vector_solve_traits&lt;E1, E2&gt;::result_type
  1063. solve (const vector_expression&lt;E1&gt; &amp;e1,
  1064. const matrix_expression&lt;E2&gt; &amp;e2,
  1065. C);</code>
  1066. </pre>
  1067. <h4>Description</h4>
  1068. <p><code>solve</code> solves a linear equation for lower or upper
  1069. (unit) triangular matrices.</p>
  1070. <h4>Definition</h4>
  1071. <p>Defined in the header triangular.hpp.</p>
  1072. <h4>Type requirements</h4>
  1073. <ul>
  1074. <li><code>E1</code> is a model of <a href=
  1075. "expression_concept.html#matrix_expression">Matrix Expression</a> or
  1076. <a href="expression_concept.html#vector_expression">Vector Expression</a>
  1077. .</li>
  1078. <li><code>E2</code> is a model of <a href=
  1079. "expression_concept.html#vector_expression">Vector Expression</a> or
  1080. <a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  1081. .</li>
  1082. </ul>
  1083. <h4>Preconditions</h4>
  1084. <ul>
  1085. <li><code>e1 ().size1 () == e1 ().size2 ()</code></li>
  1086. <li><code>e1 ().size2 () == e2 ().size ()</code></li>
  1087. <li><code>e1 ().size () == e2 ().size1 ()</code></li>
  1088. <li><code>e2 ().size1 () == e2 ().size2 ()</code></li>
  1089. </ul>
  1090. <h4>Complexity</h4>
  1091. <p>Quadratic depending from the size of the matrix expression.</p>
  1092. <h4>Examples</h4>
  1093. <pre>
  1094. #include &lt;boost/numeric/ublas/triangular.hpp&gt;
  1095. #include &lt;boost/numeric/ublas/io.hpp&gt;
  1096. int main () {
  1097. using namespace boost::numeric::ublas;
  1098. matrix&lt;double&gt; m (3, 3);
  1099. vector&lt;double&gt; v (3);
  1100. for (unsigned i = 0; i &lt; std::min (m.size1 (), v.size ()); ++ i) {
  1101. for (unsigned j = 0; j &lt;= i; ++ j)
  1102. m (i, j) = 3 * i + j + 1;
  1103. v (i) = i;
  1104. }
  1105. std::cout &lt;&lt; solve (m, v, lower_tag ()) &lt;&lt; std::endl;
  1106. std::cout &lt;&lt; solve (v, m, lower_tag ()) &lt;&lt; std::endl;
  1107. }
  1108. </pre>
  1109. <h2><a name="matrix_matrix_operations"></a>Matrix Matrix Operations</h2>
  1110. <h3>Binary Operation Description</h3>
  1111. <h4>Description</h4>
  1112. <p>The templated class <code>matrix_matrix_binary&lt;E1, E2,
  1113. F&gt;</code> describes a binary matrix operation.</p>
  1114. <h4>Definition</h4>
  1115. <p>Defined in the header matrix_expression.hpp.</p>
  1116. <h4>Template parameters</h4>
  1117. <table border="1" summary="parameters">
  1118. <tbody>
  1119. <tr>
  1120. <th>Parameter</th>
  1121. <th>Description</th>
  1122. <th>Default</th>
  1123. </tr>
  1124. <tr>
  1125. <td><code>E1</code></td>
  1126. <td>The type of the first matrix expression.</td>
  1127. <td></td>
  1128. </tr>
  1129. <tr>
  1130. <td><code>E2</code></td>
  1131. <td>The type of the second matrix expression.</td>
  1132. <td></td>
  1133. </tr>
  1134. <tr>
  1135. <td><code>F</code></td>
  1136. <td>The type of the operation.</td>
  1137. <td></td>
  1138. </tr>
  1139. </tbody>
  1140. </table>
  1141. <h4>Model of</h4>
  1142. <p><a href="expression_concept.html#matrix_expression">Matrix Expression</a>
  1143. .</p>
  1144. <h4>Type requirements</h4>
  1145. <p>None, except for those imposed by the requirements of <a href=
  1146. "expression_concept.html#matrix_expression">Matrix Expression</a> .</p>
  1147. <h4>Public base classes</h4>
  1148. <p><code>matrix_expression&lt;matrix_matrix_binary&lt;E1, E2, F&gt;
  1149. &gt;</code> .</p>
  1150. <h4>Members</h4>
  1151. <table border="1" summary="members">
  1152. <tbody>
  1153. <tr>
  1154. <th>Member</th>
  1155. <th>Description</th>
  1156. </tr>
  1157. <tr>
  1158. <td><code>matrix_matrix_binary (const expression1_type &amp;e1,
  1159. const expression2_type &amp;e2)</code></td>
  1160. <td>Constructs a description of the expression.</td>
  1161. </tr>
  1162. <tr>
  1163. <td><code>size_type size1 () const</code></td>
  1164. <td>Returns the number of rows.</td>
  1165. </tr>
  1166. <tr>
  1167. <td><code>size_type size2 () const</code></td>
  1168. <td>Returns the number of columns.</td>
  1169. </tr>
  1170. <tr>
  1171. <td><code>const_reference operator () (size_type i, size_type j)
  1172. const</code></td>
  1173. <td>Returns the value of the <code>j</code>-th element in the
  1174. <code>i</code>-th row.</td>
  1175. </tr>
  1176. <tr>
  1177. <td><code>const_iterator1 begin1 () const</code></td>
  1178. <td>Returns a <code>const_iterator1</code> pointing to the
  1179. beginning of the expression.</td>
  1180. </tr>
  1181. <tr>
  1182. <td><code>const_iterator1 end1 () const</code></td>
  1183. <td>Returns a <code>const_iterator1</code> pointing to the end of
  1184. the expression.</td>
  1185. </tr>
  1186. <tr>
  1187. <td><code>const_iterator2 begin2 () const</code></td>
  1188. <td>Returns a <code>const_iterator2</code> pointing to the
  1189. beginning of the expression.</td>
  1190. </tr>
  1191. <tr>
  1192. <td><code>const_iterator2 end2 () const</code></td>
  1193. <td>Returns a <code>const_iterator2</code> pointing to the end of
  1194. the expression.</td>
  1195. </tr>
  1196. <tr>
  1197. <td><code>const_reverse_iterator1 rbegin1 () const</code></td>
  1198. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  1199. beginning of the reversed expression.</td>
  1200. </tr>
  1201. <tr>
  1202. <td><code>const_reverse_iterator1 rend1 () const</code></td>
  1203. <td>Returns a <code>const_reverse_iterator1</code> pointing to the
  1204. end of the reversed expression.</td>
  1205. </tr>
  1206. <tr>
  1207. <td><code>const_reverse_iterator2 rbegin2 () const</code></td>
  1208. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  1209. beginning of the reversed expression.</td>
  1210. </tr>
  1211. <tr>
  1212. <td><code>const_reverse_iterator2 rend2 () const</code></td>
  1213. <td>Returns a <code>const_reverse_iterator2</code> pointing to the
  1214. end of the reversed expression.</td>
  1215. </tr>
  1216. </tbody>
  1217. </table>
  1218. <h3>Binary Operations</h3>
  1219. <h4>Prototypes</h4>
  1220. <pre>
  1221. <code>template&lt;class T1, class E1, class T2, class E2&gt;
  1222. struct matrix_matrix_binary_traits {
  1223. typedef unknown_orientation_tag dispatch_category;
  1224. typedef typename promote_traits&lt;T1, T2&gt;::promote_type promote_type;
  1225. typedef matrix_matrix_binary&lt;typename E1::const_closure_type,
  1226. typename E2::const_closure_type,
  1227. matrix_matrix_prod&lt;T1, T2, promote_type&gt; &gt; expression_type;
  1228. typedef expression_type result_type;
  1229. };
  1230. template&lt;class E1, class E2&gt;
  1231. typename matrix_matrix_binary_traits&lt;typename E1::value_type, E1,
  1232. typename E2::value_type, E2&gt;::result_type
  1233. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1234. const matrix_expression&lt;E2&gt; &amp;e2,
  1235. unknown_orientation_tag);
  1236. // Dispatcher
  1237. template&lt;class E1, class E2&gt;
  1238. typename matrix_matrix_binary_traits&lt;typename E1::value_type, E1,
  1239. typename E2::value_type, E2&gt;::result_type
  1240. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1241. const matrix_expression&lt;E2&gt; &amp;e2);
  1242. template&lt;class E1, class E2&gt;
  1243. typename matrix_matrix_binary_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  1244. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  1245. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1246. const matrix_expression&lt;E2&gt; &amp;e2,
  1247. unknown_orientation_tag);
  1248. // Dispatcher
  1249. template&lt;class E1, class E2&gt;
  1250. typename matrix_matrix_binary_traits&lt;typename type_traits&lt;typename E1::value_type&gt;::precision_type, E1,
  1251. typename type_traits&lt;typename E2::value_type&gt;::precision_type, E2&gt;::result_type
  1252. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1253. const matrix_expression&lt;E2&gt; &amp;e2);
  1254. template&lt;class M, class E1, class E2&gt;
  1255. M
  1256. prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1257. const matrix_expression&lt;E2&gt; &amp;e2);
  1258. template&lt;class M, class E1, class E2&gt;
  1259. M
  1260. prec_prod (const matrix_expression&lt;E1&gt; &amp;e1,
  1261. const matrix_expression&lt;E2&gt; &amp;e2);</code>
  1262. </pre>
  1263. <h4>Description</h4>
  1264. <p><code>prod</code> computes the product of the matrix
  1265. expressions. <code>prec_prod</code> computes the double precision
  1266. product of the matrix expressions.</p>
  1267. <h4>Definition</h4>
  1268. <p>Defined in the header matrix_expression.hpp.</p>
  1269. <h4>Type requirements</h4>
  1270. <ul>
  1271. <li><code>E1</code> is a model of <a href=
  1272. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  1273. <li><code>E2</code> is a model of <a href=
  1274. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  1275. </ul>
  1276. <h4>Preconditions</h4>
  1277. <ul>
  1278. <li><code>e1 ().size2 () == e2 ().size1 ()</code></li>
  1279. </ul>
  1280. <h4>Complexity</h4>
  1281. <p>Cubic depending from the size of the matrix expression.</p>
  1282. <h4>Examples</h4>
  1283. <pre>
  1284. #include &lt;boost/numeric/ublas/matrix.hpp&gt;
  1285. #include &lt;boost/numeric/ublas/io.hpp&gt;
  1286. int main () {
  1287. using namespace boost::numeric::ublas;
  1288. matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
  1289. for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
  1290. for (unsigned j = 0; j &lt; std::min (m1.size2 (), m2.size2 ()); ++ j)
  1291. m1 (i, j) = m2 (i, j) = 3 * i + j;
  1292. std::cout &lt;&lt; prod (m1, m2) &lt;&lt; std::endl;
  1293. }
  1294. </pre>
  1295. <h3>Triangular Solvers</h3>
  1296. <h4>Prototypes</h4>
  1297. <pre>
  1298. <code>template&lt;class E1, class E2&gt;
  1299. struct matrix_matrix_solve_traits {
  1300. typedef typename promote_traits&lt;typename E1::value_type, typename E2::value_type&gt;::promote_type promote_type;
  1301. typedef matrix&lt;promote_type&gt; result_type;
  1302. };
  1303. template&lt;class E1, class E2&gt;
  1304. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1305. E2 &amp;e2,
  1306. lower_tag,
  1307. matrix_tag);
  1308. template&lt;class E1, class E2&gt;
  1309. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1310. E2 &amp;e2,
  1311. upper_tag,
  1312. matrix_tag);
  1313. template&lt;class E1, class E2&gt;
  1314. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1315. E2 &amp;e2,
  1316. unit_lower_tag,
  1317. matrix_tag);
  1318. template&lt;class E1, class E2&gt;
  1319. void inplace_solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1320. E2 &amp;e2,
  1321. unit_upper_tag,
  1322. matrix_tag);
  1323. template&lt;class E1, class E2, class C&gt;
  1324. typename matrix_matrix_solve_traits&lt;E1, E2&gt;::result_type
  1325. solve (const matrix_expression&lt;E1&gt; &amp;e1,
  1326. const matrix_expression&lt;E2&gt; &amp;e2,
  1327. C);</code>
  1328. </pre>
  1329. <h4>Description</h4>
  1330. <p><code>solve</code> solves a linear equation for lower or upper
  1331. (unit) triangular matrices.</p>
  1332. <h4>Definition</h4>
  1333. <p>Defined in the header triangular.hpp.</p>
  1334. <h4>Type requirements</h4>
  1335. <ul>
  1336. <li><code>E1</code> is a model of <a href=
  1337. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  1338. <li><code>E2</code> is a model of <a href=
  1339. "expression_concept.html#matrix_expression">Matrix Expression</a> .</li>
  1340. </ul>
  1341. <h4>Preconditions</h4>
  1342. <ul>
  1343. <li><code>e1 ().size1 () == e1 ().size2 ()</code></li>
  1344. <li><code>e1 ().size2 () == e2 ().size1 ()</code></li>
  1345. </ul>
  1346. <h4>Complexity</h4>
  1347. <p>Cubic depending from the size of the matrix expressions.</p>
  1348. <h4>Examples</h4>
  1349. <pre>
  1350. #include &lt;boost/numeric/ublas/triangular.hpp&gt;
  1351. #include &lt;boost/numeric/ublas/io.hpp&gt;
  1352. int main () {
  1353. using namespace boost::numeric::ublas;
  1354. matrix&lt;double&gt; m1 (3, 3), m2 (3, 3);
  1355. for (unsigned i = 0; i &lt; std::min (m1.size1 (), m2.size1 ()); ++ i)
  1356. for (unsigned j = 0; j &lt;= i; ++ j)
  1357. m1 (i, j) = m2 (i, j) = 3 * i + j + 1;
  1358. std::cout &lt;&lt; solve (m1, m2, lower_tag ()) &lt;&lt; std::endl;
  1359. }
  1360. </pre>
  1361. <hr />
  1362. <p>Copyright (&copy;) 2000-2002 Joerg Walter, Mathias Koch<br />
  1363. Use, modification and distribution are subject to the
  1364. Boost Software License, Version 1.0.
  1365. (See accompanying file LICENSE_1_0.txt
  1366. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  1367. http://www.boost.org/LICENSE_1_0.txt
  1368. </a>).
  1369. </p>
  1370. <script type="text/javascript">
  1371. (function($) {
  1372. $('#toc').toc();
  1373. })(jQuery);
  1374. </script>
  1375. </body>
  1376. </html>