1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: smat.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>smat.h</h1><a href="smat_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00029"></a>00029 <span class="preprocessor">#ifndef SMAT_H</span> |
---|
67 | <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#define SMAT_H</span> |
---|
68 | <a name="l00031"></a>00031 <span class="preprocessor"></span> |
---|
69 | <a name="l00032"></a>00032 <span class="preprocessor">#ifndef _MSC_VER</span> |
---|
70 | <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor"># include <itpp/config.h></span> |
---|
71 | <a name="l00034"></a>00034 <span class="preprocessor">#else</span> |
---|
72 | <a name="l00035"></a>00035 <span class="preprocessor"></span><span class="preprocessor"># include <itpp/config_msvc.h></span> |
---|
73 | <a name="l00036"></a>00036 <span class="preprocessor">#endif</span> |
---|
74 | <a name="l00037"></a>00037 <span class="preprocessor"></span> |
---|
75 | <a name="l00038"></a>00038 <span class="preprocessor">#include <<a class="code" href="svec_8h.html" title="Sparse Vector Class definitions.">itpp/base/svec.h</a>></span> |
---|
76 | <a name="l00039"></a>00039 |
---|
77 | <a name="l00040"></a>00040 |
---|
78 | <a name="l00041"></a>00041 <span class="keyword">namespace </span>itpp |
---|
79 | <a name="l00042"></a>00042 { |
---|
80 | <a name="l00043"></a>00043 |
---|
81 | <a name="l00044"></a>00044 <span class="comment">// Declaration of class Vec</span> |
---|
82 | <a name="l00045"></a>00045 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">class </span>Vec; |
---|
83 | <a name="l00046"></a>00046 <span class="comment">// Declaration of class Mat</span> |
---|
84 | <a name="l00047"></a>00047 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">class </span>Mat; |
---|
85 | <a name="l00048"></a>00048 <span class="comment">// Declaration of class Sparse_Vec</span> |
---|
86 | <a name="l00049"></a>00049 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">class </span>Sparse_Vec; |
---|
87 | <a name="l00050"></a>00050 <span class="comment">// Declaration of class Sparse_Mat</span> |
---|
88 | <a name="l00051"></a>00051 <span class="keyword">template</span> <<span class="keyword">class</span> T> <span class="keyword">class </span>Sparse_Mat; |
---|
89 | <a name="l00052"></a>00052 |
---|
90 | <a name="l00053"></a>00053 <span class="comment">// ------------------------ Sparse_Mat Friends -------------------------------------</span> |
---|
91 | <a name="l00054"></a>00054 |
---|
92 | <a name="l00056"></a>00056 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
93 | <a name="l00057"></a>00057 Sparse_Mat<T> <a class="code" href="group__fixed.html#g683d6c037357e472e84756fe1b1faae8" title="Fix + cfixmat.">operator+</a>(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2); |
---|
94 | <a name="l00058"></a>00058 |
---|
95 | <a name="l00060"></a>00060 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
96 | <a name="l00061"></a>00061 Sparse_Mat<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> T &c, <span class="keyword">const</span> Sparse_Mat<T> &m); |
---|
97 | <a name="l00062"></a>00062 |
---|
98 | <a name="l00064"></a>00064 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
99 | <a name="l00065"></a>00065 Sparse_Mat<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2); |
---|
100 | <a name="l00066"></a>00066 |
---|
101 | <a name="l00068"></a>00068 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
102 | <a name="l00069"></a>00069 Sparse_Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Sparse_Vec<T> &v); |
---|
103 | <a name="l00070"></a>00070 |
---|
104 | <a name="l00072"></a>00072 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
105 | <a name="l00073"></a>00073 Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Vec<T> &v); |
---|
106 | <a name="l00074"></a>00074 |
---|
107 | <a name="l00076"></a>00076 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
108 | <a name="l00077"></a>00077 Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Vec<T> &v, <span class="keyword">const</span> Sparse_Mat<T> &m); |
---|
109 | <a name="l00078"></a>00078 |
---|
110 | <a name="l00080"></a>00080 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
111 | <a name="l00081"></a>00081 Mat<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m); |
---|
112 | <a name="l00082"></a>00082 |
---|
113 | <a name="l00084"></a>00084 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
114 | <a name="l00085"></a>00085 Sparse_Mat<T> trans_mult_s(<span class="keyword">const</span> Sparse_Mat<T> &m); |
---|
115 | <a name="l00086"></a>00086 |
---|
116 | <a name="l00088"></a>00088 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
117 | <a name="l00089"></a>00089 Sparse_Mat<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2); |
---|
118 | <a name="l00090"></a>00090 |
---|
119 | <a name="l00092"></a>00092 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
120 | <a name="l00093"></a>00093 Vec<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Vec<T> &v); |
---|
121 | <a name="l00094"></a>00094 |
---|
122 | <a name="l00096"></a>00096 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
123 | <a name="l00097"></a>00097 Sparse_Mat<T> mult_trans(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2); |
---|
124 | <a name="l00098"></a>00098 |
---|
125 | <a name="l00112"></a>00112 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
126 | <a name="l00113"></a><a class="code" href="classitpp_1_1Sparse__Mat.html">00113</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat</a> |
---|
127 | <a name="l00114"></a>00114 { |
---|
128 | <a name="l00115"></a>00115 <span class="keyword">public</span>: |
---|
129 | <a name="l00116"></a>00116 |
---|
130 | <a name="l00118"></a>00118 <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat</a>(); |
---|
131 | <a name="l00119"></a>00119 |
---|
132 | <a name="l00130"></a>00130 <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat</a>(<span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#98f82f4aca56a2b8083df057f0c5c359" title="Returns the number of rows of the sparse matrix.">rows</a>, <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#18ab90bb7cd0db31722374889e3d74c8" title="Returns the number of columns of the sparse matrix.">cols</a>, <span class="keywordtype">int</span> row_data_init = 200); |
---|
133 | <a name="l00131"></a>00131 |
---|
134 | <a name="l00133"></a>00133 <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
135 | <a name="l00134"></a>00134 |
---|
136 | <a name="l00136"></a>00136 <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m); |
---|
137 | <a name="l00137"></a>00137 |
---|
138 | <a name="l00143"></a>00143 <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m, T epsilon); |
---|
139 | <a name="l00144"></a>00144 |
---|
140 | <a name="l00146"></a>00146 <a class="code" href="classitpp_1_1Sparse__Mat.html#77cb0033b6f39bd586543769b3a8d50a" title="Destructor.">~Sparse_Mat</a>(); |
---|
141 | <a name="l00147"></a>00147 |
---|
142 | <a name="l00158"></a>00158 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#bede37fe2203b2bae86c7000c6fa78f4" title="Set the size of the sparse matrix.">set_size</a>(<span class="keywordtype">int</span> rows, <span class="keywordtype">int</span> cols, <span class="keywordtype">int</span> row_data_init = -1); |
---|
143 | <a name="l00159"></a>00159 |
---|
144 | <a name="l00161"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#98f82f4aca56a2b8083df057f0c5c359">00161</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#98f82f4aca56a2b8083df057f0c5c359" title="Returns the number of rows of the sparse matrix.">rows</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> n_rows; } |
---|
145 | <a name="l00162"></a>00162 |
---|
146 | <a name="l00164"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#18ab90bb7cd0db31722374889e3d74c8">00164</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#18ab90bb7cd0db31722374889e3d74c8" title="Returns the number of columns of the sparse matrix.">cols</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> n_cols; } |
---|
147 | <a name="l00165"></a>00165 |
---|
148 | <a name="l00167"></a>00167 <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4" title="The number of non-zero elements in the sparse matrix.">nnz</a>(); |
---|
149 | <a name="l00168"></a>00168 |
---|
150 | <a name="l00170"></a>00170 <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#43589606be7d9563d82fc3355f97c107" title="Returns the density of the sparse matrix: (number of non-zero elements)/(total number...">density</a>(); |
---|
151 | <a name="l00171"></a>00171 |
---|
152 | <a name="l00173"></a>00173 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5" title="Set the maximum number of non-zero elements in each column equal to the actual number...">compact</a>(); |
---|
153 | <a name="l00174"></a>00174 |
---|
154 | <a name="l00176"></a>00176 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948" title="Returns a full, dense matrix.">full</a>(<a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m) <span class="keyword">const</span>; |
---|
155 | <a name="l00177"></a>00177 |
---|
156 | <a name="l00179"></a>00179 <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948" title="Returns a full, dense matrix.">full</a>() <span class="keyword">const</span>; |
---|
157 | <a name="l00180"></a>00180 |
---|
158 | <a name="l00182"></a>00182 T <a class="code" href="classitpp_1_1Sparse__Mat.html#404ced4fa4a5a8a7a6050851caa312d2" title="Returns element of row r and column c.">operator()</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c) <span class="keyword">const</span>; |
---|
159 | <a name="l00183"></a>00183 |
---|
160 | <a name="l00185"></a>00185 <span class="keywordtype">void</span> <span class="keyword">set</span>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, T v); |
---|
161 | <a name="l00186"></a>00186 |
---|
162 | <a name="l00188"></a>00188 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#a2d45bc984af880390d434d03afb2c8c" title="Set a new element with index (r, c ) equal to v.">set_new</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, T v); |
---|
163 | <a name="l00189"></a>00189 |
---|
164 | <a name="l00191"></a>00191 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#ddb256b1bc9bdf0a57b56c019ab2b1f5" title="Add the element in row r and column c with v.">add_elem</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> r, <span class="keyword">const</span> <span class="keywordtype">int</span> c, <span class="keyword">const</span> T v); |
---|
165 | <a name="l00192"></a>00192 |
---|
166 | <a name="l00194"></a>00194 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#4d10d2107caa9f08e2f724bee5e10090" title="Set the sparse matrix to the all zero matrix (removes all non-zero elements).">zeros</a>(); |
---|
167 | <a name="l00195"></a>00195 |
---|
168 | <a name="l00197"></a>00197 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#597931c72c2ae675c0ecc2522774474d" title="Set the element in row r and column c to zero (i.e. clear that element if it contains...">zero_elem</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> r, <span class="keyword">const</span> <span class="keywordtype">int</span> c); |
---|
169 | <a name="l00198"></a>00198 |
---|
170 | <a name="l00200"></a>00200 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#12b5fb55f2b16c350c462ee876ec7ade" title="Clear all non-zero elements of the sparse matrix.">clear</a>(); |
---|
171 | <a name="l00201"></a>00201 |
---|
172 | <a name="l00203"></a>00203 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#5f9083bb9615a53c6abfce4ca28be21a" title="Clear the element in row r and column c (if it contains a non-zero value).">clear_elem</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> r, <span class="keyword">const</span> <span class="keywordtype">int</span> c); |
---|
173 | <a name="l00204"></a>00204 |
---|
174 | <a name="l00206"></a>00206 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#133ec46db675573d8736296ae388ad09" title="Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.">set_submatrix</a>(<span class="keywordtype">int</span> r1, <span class="keywordtype">int</span> r2, <span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m); |
---|
175 | <a name="l00207"></a>00207 |
---|
176 | <a name="l00209"></a>00209 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#133ec46db675573d8736296ae388ad09" title="Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.">set_submatrix</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a>& m); |
---|
177 | <a name="l00210"></a>00210 |
---|
178 | <a name="l00212"></a>00212 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#e969584f109b897c04fb85c71ab6fc9a" title="Returns the sub-matrix from rows r1 to r2 and columns c1 to c2.">get_submatrix</a>(<span class="keywordtype">int</span> r1, <span class="keywordtype">int</span> r2, <span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2) <span class="keyword">const</span>; |
---|
179 | <a name="l00213"></a>00213 |
---|
180 | <a name="l00215"></a>00215 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#aecf3287d3bb4192eb7555b93d5dfac1" title="Returns the sub-matrix from columns c1 to c2 (all rows).">get_submatrix_cols</a>(<span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2) <span class="keyword">const</span>; |
---|
181 | <a name="l00216"></a>00216 |
---|
182 | <a name="l00218"></a>00218 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">get_col</a>(<span class="keywordtype">int</span> c, <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> &v) <span class="keyword">const</span>; |
---|
183 | <a name="l00219"></a>00219 |
---|
184 | <a name="l00221"></a>00221 <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">get_col</a>(<span class="keywordtype">int</span> c) <span class="keyword">const</span>; |
---|
185 | <a name="l00222"></a>00222 |
---|
186 | <a name="l00224"></a>00224 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#e15d124adfa11120960ecfd11ad90ef0" title="Set column c of the Sparse_Mat.">set_col</a>(<span class="keywordtype">int</span> c, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> &v); |
---|
187 | <a name="l00225"></a>00225 |
---|
188 | <a name="l00230"></a>00230 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">transpose</a>(<a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) <span class="keyword">const</span>; |
---|
189 | <a name="l00231"></a>00231 |
---|
190 | <a name="l00236"></a>00236 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">transpose</a>() <span class="keyword">const</span>; |
---|
191 | <a name="l00237"></a>00237 |
---|
192 | <a name="l00242"></a>00242 <span class="comment">// Sparse_Mat<T> T() const { return this->transpose(); };</span> |
---|
193 | <a name="l00243"></a>00243 |
---|
194 | <a name="l00245"></a>00245 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#cf3ddc3a3af57157e51c00b3d6e423ce" title="Assign sparse matrix the value and dimensions of the sparse matrix m.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
195 | <a name="l00246"></a>00246 |
---|
196 | <a name="l00248"></a>00248 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#cf3ddc3a3af57157e51c00b3d6e423ce" title="Assign sparse matrix the value and dimensions of the sparse matrix m.">operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m); |
---|
197 | <a name="l00249"></a>00249 |
---|
198 | <a name="l00251"></a>00251 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#1eb8891a51aa9c69fadcb8ab623c5d36" title="Returns the sign inverse of all elements in the sparse matrix.">operator-</a>() <span class="keyword">const</span>; |
---|
199 | <a name="l00252"></a>00252 |
---|
200 | <a name="l00254"></a>00254 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#ee53a24c0f6be2927b512b64fadd650b" title="Compare two sparse matricies. False if wrong sizes or different values.">operator==</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) <span class="keyword">const</span>; |
---|
201 | <a name="l00255"></a>00255 |
---|
202 | <a name="l00257"></a>00257 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#901025d686820e6e2379701fcc4786fc" title="Add sparse matrix v to all non-zero elements of the sparse matrix.">operator+=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &v); |
---|
203 | <a name="l00258"></a>00258 |
---|
204 | <a name="l00260"></a>00260 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#901025d686820e6e2379701fcc4786fc" title="Add sparse matrix v to all non-zero elements of the sparse matrix.">operator+=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &v); |
---|
205 | <a name="l00261"></a>00261 |
---|
206 | <a name="l00263"></a>00263 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9f42dce24f97723ed307eb2d2988de57" title="Subtract sparse matrix v from all non-zero elements of the sparse matrix.">operator-=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &v); |
---|
207 | <a name="l00264"></a>00264 |
---|
208 | <a name="l00266"></a>00266 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9f42dce24f97723ed307eb2d2988de57" title="Subtract sparse matrix v from all non-zero elements of the sparse matrix.">operator-=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &v); |
---|
209 | <a name="l00267"></a>00267 |
---|
210 | <a name="l00269"></a>00269 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#f209ca65dde352cc53fa7b0db747d698" title="Multiply all non-zero elements of the sparse matrix with the scalar v.">operator*=</a>(<span class="keyword">const</span> T &v); |
---|
211 | <a name="l00270"></a>00270 |
---|
212 | <a name="l00272"></a>00272 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#5962d40e4865536207f2ae9c204d9796" title="Divide all non-zero elements of the sparse matrix with the scalar v.">operator/=</a>(<span class="keyword">const</span> T &v); |
---|
213 | <a name="l00273"></a>00273 |
---|
214 | <a name="l00275"></a>00275 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> operator+<>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m1, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m2); |
---|
215 | <a name="l00276"></a>00276 |
---|
216 | <a name="l00278"></a>00278 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> operator*<>(<span class="keyword">const</span> T &c, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
217 | <a name="l00279"></a>00279 |
---|
218 | <a name="l00281"></a>00281 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> operator*<>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m1, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m2); |
---|
219 | <a name="l00282"></a>00282 |
---|
220 | <a name="l00284"></a>00284 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> operator*<>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> &v); |
---|
221 | <a name="l00285"></a>00285 |
---|
222 | <a name="l00287"></a>00287 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> operator*<>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> &v); |
---|
223 | <a name="l00288"></a>00288 |
---|
224 | <a name="l00290"></a>00290 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> operator*<>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> &v, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
225 | <a name="l00291"></a>00291 |
---|
226 | <a name="l00293"></a>00293 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> trans_mult <>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
227 | <a name="l00294"></a>00294 |
---|
228 | <a name="l00296"></a>00296 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> trans_mult_s <>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m); |
---|
229 | <a name="l00297"></a>00297 |
---|
230 | <a name="l00299"></a>00299 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> trans_mult <>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m1, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m2); |
---|
231 | <a name="l00300"></a>00300 |
---|
232 | <a name="l00302"></a>00302 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> trans_mult <>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Vec.html">Vec<T></a> &v); |
---|
233 | <a name="l00303"></a>00303 |
---|
234 | <a name="l00305"></a>00305 <span class="keyword">friend</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> mult_trans <>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m1, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m2); |
---|
235 | <a name="l00306"></a>00306 |
---|
236 | <a name="l00307"></a>00307 <span class="keyword">private</span>: |
---|
237 | <a name="l00308"></a>00308 <span class="keywordtype">void</span> init(); |
---|
238 | <a name="l00309"></a>00309 <span class="keywordtype">void</span> alloc_empty(); |
---|
239 | <a name="l00310"></a>00310 <span class="keywordtype">void</span> alloc(<span class="keywordtype">int</span> row_data_size = 200); |
---|
240 | <a name="l00311"></a>00311 <span class="keywordtype">void</span> free(); |
---|
241 | <a name="l00312"></a>00312 |
---|
242 | <a name="l00313"></a>00313 <span class="keywordtype">int</span> n_rows, n_cols; |
---|
243 | <a name="l00314"></a>00314 <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> *col; |
---|
244 | <a name="l00315"></a>00315 }; |
---|
245 | <a name="l00316"></a>00316 |
---|
246 | <a name="l00321"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#781278e3d947fb084c54e568110c09d6">00321</a> <span class="keyword">typedef</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<int></a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">sparse_imat</a>; |
---|
247 | <a name="l00322"></a>00322 |
---|
248 | <a name="l00327"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#8575a5d0dd547034677dc41da3f85138">00327</a> <span class="keyword">typedef</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<double></a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">sparse_mat</a>; |
---|
249 | <a name="l00328"></a>00328 |
---|
250 | <a name="l00333"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#1cc7ca3875e7da48495a7d67b14ea716">00333</a> <span class="keyword">typedef</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<std::complex<double></a> > <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">sparse_cmat</a>; |
---|
251 | <a name="l00334"></a>00334 |
---|
252 | <a name="l00335"></a>00335 <span class="comment">//---------------------- Implementation starts here --------------------------------</span> |
---|
253 | <a name="l00336"></a>00336 |
---|
254 | <a name="l00337"></a>00337 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
255 | <a name="l00338"></a>00338 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T>::init</a>() |
---|
256 | <a name="l00339"></a>00339 { |
---|
257 | <a name="l00340"></a>00340 n_rows = 0; |
---|
258 | <a name="l00341"></a>00341 n_cols = 0; |
---|
259 | <a name="l00342"></a>00342 col = 0; |
---|
260 | <a name="l00343"></a>00343 } |
---|
261 | <a name="l00344"></a>00344 |
---|
262 | <a name="l00345"></a>00345 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
263 | <a name="l00346"></a>00346 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T>::alloc_empty</a>() |
---|
264 | <a name="l00347"></a>00347 { |
---|
265 | <a name="l00348"></a>00348 <span class="keywordflow">if</span> (n_cols == 0) |
---|
266 | <a name="l00349"></a>00349 col = 0; |
---|
267 | <a name="l00350"></a>00350 <span class="keywordflow">else</span> |
---|
268 | <a name="l00351"></a>00351 col = <span class="keyword">new</span> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a>[n_cols]; |
---|
269 | <a name="l00352"></a>00352 } |
---|
270 | <a name="l00353"></a>00353 |
---|
271 | <a name="l00354"></a>00354 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
272 | <a name="l00355"></a>00355 <span class="keywordtype">void</span> Sparse_Mat<T>::alloc(<span class="keywordtype">int</span> row_data_init) |
---|
273 | <a name="l00356"></a>00356 { |
---|
274 | <a name="l00357"></a>00357 <span class="keywordflow">if</span> (n_cols == 0) |
---|
275 | <a name="l00358"></a>00358 col = 0; |
---|
276 | <a name="l00359"></a>00359 <span class="keywordflow">else</span> |
---|
277 | <a name="l00360"></a>00360 col = <span class="keyword">new</span> Sparse_Vec<T>[n_cols]; |
---|
278 | <a name="l00361"></a>00361 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
279 | <a name="l00362"></a>00362 col[c].set_size(n_rows, row_data_init); |
---|
280 | <a name="l00363"></a>00363 } |
---|
281 | <a name="l00364"></a>00364 |
---|
282 | <a name="l00365"></a>00365 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
283 | <a name="l00366"></a>00366 <span class="keywordtype">void</span> Sparse_Mat<T>::free() |
---|
284 | <a name="l00367"></a>00367 { |
---|
285 | <a name="l00368"></a>00368 <span class="keyword">delete</span> [] col; |
---|
286 | <a name="l00369"></a>00369 col = 0; |
---|
287 | <a name="l00370"></a>00370 } |
---|
288 | <a name="l00371"></a>00371 |
---|
289 | <a name="l00372"></a>00372 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
290 | <a name="l00373"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595">00373</a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T>::Sparse_Mat</a>() |
---|
291 | <a name="l00374"></a>00374 { |
---|
292 | <a name="l00375"></a>00375 init(); |
---|
293 | <a name="l00376"></a>00376 } |
---|
294 | <a name="l00377"></a>00377 |
---|
295 | <a name="l00378"></a>00378 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
296 | <a name="l00379"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#721a28a89f8082a9c753a9dfcd0b24ed">00379</a> <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat<T>::Sparse_Mat</a>(<span class="keywordtype">int</span> rows, <span class="keywordtype">int</span> cols, <span class="keywordtype">int</span> row_data_init) |
---|
297 | <a name="l00380"></a>00380 { |
---|
298 | <a name="l00381"></a>00381 init(); |
---|
299 | <a name="l00382"></a>00382 n_rows = rows; |
---|
300 | <a name="l00383"></a>00383 n_cols = cols; |
---|
301 | <a name="l00384"></a>00384 alloc(row_data_init); |
---|
302 | <a name="l00385"></a>00385 } |
---|
303 | <a name="l00386"></a>00386 |
---|
304 | <a name="l00387"></a>00387 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
305 | <a name="l00388"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#b9c06a886adcb6c4cb97b2a7710152b9">00388</a> <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat<T>::Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) |
---|
306 | <a name="l00389"></a>00389 { |
---|
307 | <a name="l00390"></a>00390 init(); |
---|
308 | <a name="l00391"></a>00391 n_rows = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a>; |
---|
309 | <a name="l00392"></a>00392 n_cols = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a>; |
---|
310 | <a name="l00393"></a>00393 alloc_empty(); |
---|
311 | <a name="l00394"></a>00394 |
---|
312 | <a name="l00395"></a>00395 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
313 | <a name="l00396"></a>00396 col[c] = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c]; |
---|
314 | <a name="l00397"></a>00397 } |
---|
315 | <a name="l00398"></a>00398 |
---|
316 | <a name="l00399"></a>00399 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
317 | <a name="l00400"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#18f755291e07f729eafb09d207984d50">00400</a> <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat<T>::Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m) |
---|
318 | <a name="l00401"></a>00401 { |
---|
319 | <a name="l00402"></a>00402 init(); |
---|
320 | <a name="l00403"></a>00403 n_rows = m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>(); |
---|
321 | <a name="l00404"></a>00404 n_cols = m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>(); |
---|
322 | <a name="l00405"></a>00405 alloc(); |
---|
323 | <a name="l00406"></a>00406 |
---|
324 | <a name="l00407"></a>00407 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
325 | <a name="l00408"></a>00408 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < n_rows; r++) { |
---|
326 | <a name="l00409"></a>00409 <span class="comment">//if (abs(m(r,c)) != T(0))</span> |
---|
327 | <a name="l00410"></a>00410 <span class="keywordflow">if</span> (m(r, c) != T(0)) |
---|
328 | <a name="l00411"></a>00411 col[c].set_new(r, m(r, c)); |
---|
329 | <a name="l00412"></a>00412 } |
---|
330 | <a name="l00413"></a>00413 col[c].compact(); |
---|
331 | <a name="l00414"></a>00414 } |
---|
332 | <a name="l00415"></a>00415 } |
---|
333 | <a name="l00416"></a>00416 |
---|
334 | <a name="l00417"></a>00417 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
335 | <a name="l00418"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#922d170164eeaa595b17c7962931a073">00418</a> <a class="code" href="classitpp_1_1Sparse__Mat.html#bc8361f34d846404fb7b491c94aef595" title="Default constructor.">Sparse_Mat<T>::Sparse_Mat</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m, T epsilon) |
---|
336 | <a name="l00419"></a>00419 { |
---|
337 | <a name="l00420"></a>00420 init(); |
---|
338 | <a name="l00421"></a>00421 n_rows = m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>(); |
---|
339 | <a name="l00422"></a>00422 n_cols = m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>(); |
---|
340 | <a name="l00423"></a>00423 alloc(); |
---|
341 | <a name="l00424"></a>00424 |
---|
342 | <a name="l00425"></a>00425 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
343 | <a name="l00426"></a>00426 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < n_rows; r++) { |
---|
344 | <a name="l00427"></a>00427 <span class="keywordflow">if</span> (<a class="code" href="group__fixed.html#ge0a38d51b2bf99a0ba07f2f8885e6adc" title="Absolute value.">std::abs</a>(m(r, c)) > <a class="code" href="group__fixed.html#ge0a38d51b2bf99a0ba07f2f8885e6adc" title="Absolute value.">std::abs</a>(epsilon)) |
---|
345 | <a name="l00428"></a>00428 col[c].set_new(r, m(r, c)); |
---|
346 | <a name="l00429"></a>00429 } |
---|
347 | <a name="l00430"></a>00430 col[c].compact(); |
---|
348 | <a name="l00431"></a>00431 } |
---|
349 | <a name="l00432"></a>00432 } |
---|
350 | <a name="l00433"></a>00433 |
---|
351 | <a name="l00434"></a>00434 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
352 | <a name="l00435"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#77cb0033b6f39bd586543769b3a8d50a">00435</a> <a class="code" href="classitpp_1_1Sparse__Mat.html#77cb0033b6f39bd586543769b3a8d50a" title="Destructor.">Sparse_Mat<T>::~Sparse_Mat</a>() |
---|
353 | <a name="l00436"></a>00436 { |
---|
354 | <a name="l00437"></a>00437 free(); |
---|
355 | <a name="l00438"></a>00438 } |
---|
356 | <a name="l00439"></a>00439 |
---|
357 | <a name="l00440"></a>00440 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
358 | <a name="l00441"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#bede37fe2203b2bae86c7000c6fa78f4">00441</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#bede37fe2203b2bae86c7000c6fa78f4" title="Set the size of the sparse matrix.">Sparse_Mat<T>::set_size</a>(<span class="keywordtype">int</span> rows, <span class="keywordtype">int</span> cols, <span class="keywordtype">int</span> row_data_init) |
---|
359 | <a name="l00442"></a>00442 { |
---|
360 | <a name="l00443"></a>00443 n_rows = rows; |
---|
361 | <a name="l00444"></a>00444 |
---|
362 | <a name="l00445"></a>00445 <span class="comment">//Allocate new memory for data if the number of columns has changed or if row_data_init != -1</span> |
---|
363 | <a name="l00446"></a>00446 <span class="keywordflow">if</span> (cols != n_cols || row_data_init != -1) { |
---|
364 | <a name="l00447"></a>00447 n_cols = cols; |
---|
365 | <a name="l00448"></a>00448 free(); |
---|
366 | <a name="l00449"></a>00449 alloc(row_data_init); |
---|
367 | <a name="l00450"></a>00450 } |
---|
368 | <a name="l00451"></a>00451 } |
---|
369 | <a name="l00452"></a>00452 |
---|
370 | <a name="l00453"></a>00453 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
371 | <a name="l00454"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4">00454</a> <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4" title="The number of non-zero elements in the sparse matrix.">Sparse_Mat<T>::nnz</a>() |
---|
372 | <a name="l00455"></a>00455 { |
---|
373 | <a name="l00456"></a>00456 <span class="keywordtype">int</span> n = 0; |
---|
374 | <a name="l00457"></a>00457 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
375 | <a name="l00458"></a>00458 n += col[c].<a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4" title="The number of non-zero elements in the sparse matrix.">nnz</a>(); |
---|
376 | <a name="l00459"></a>00459 |
---|
377 | <a name="l00460"></a>00460 <span class="keywordflow">return</span> n; |
---|
378 | <a name="l00461"></a>00461 } |
---|
379 | <a name="l00462"></a>00462 |
---|
380 | <a name="l00463"></a>00463 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
381 | <a name="l00464"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#43589606be7d9563d82fc3355f97c107">00464</a> <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#43589606be7d9563d82fc3355f97c107" title="Returns the density of the sparse matrix: (number of non-zero elements)/(total number...">Sparse_Mat<T>::density</a>() |
---|
382 | <a name="l00465"></a>00465 { |
---|
383 | <a name="l00466"></a>00466 <span class="comment">//return static_cast<double>(nnz())/(n_rows*n_cols);</span> |
---|
384 | <a name="l00467"></a>00467 <span class="keywordflow">return</span> double(<a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4" title="The number of non-zero elements in the sparse matrix.">nnz</a>()) / (n_rows*n_cols); |
---|
385 | <a name="l00468"></a>00468 } |
---|
386 | <a name="l00469"></a>00469 |
---|
387 | <a name="l00470"></a>00470 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
388 | <a name="l00471"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5">00471</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5" title="Set the maximum number of non-zero elements in each column equal to the actual number...">Sparse_Mat<T>::compact</a>() |
---|
389 | <a name="l00472"></a>00472 { |
---|
390 | <a name="l00473"></a>00473 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
391 | <a name="l00474"></a>00474 col[c].<a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5" title="Set the maximum number of non-zero elements in each column equal to the actual number...">compact</a>(); |
---|
392 | <a name="l00475"></a>00475 } |
---|
393 | <a name="l00476"></a>00476 |
---|
394 | <a name="l00477"></a>00477 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
395 | <a name="l00478"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#d4b0d7f6c49a884e048c62f1c81bb7a9">00478</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948" title="Returns a full, dense matrix.">Sparse_Mat<T>::full</a>(<a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m)<span class="keyword"> const</span> |
---|
396 | <a name="l00479"></a>00479 <span class="keyword"></span>{ |
---|
397 | <a name="l00480"></a>00480 m.<a class="code" href="classitpp_1_1Mat.html#1136d376109f2af8843593bccf9de88f" title="Set size of matrix. If copy = true then keep the data before resizing.">set_size</a>(n_rows, n_cols); |
---|
398 | <a name="l00481"></a>00481 m = T(0); |
---|
399 | <a name="l00482"></a>00482 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
400 | <a name="l00483"></a>00483 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p = 0; p < col[c].nnz(); p++) |
---|
401 | <a name="l00484"></a>00484 m(col[c].get_nz_index(p), c) = col[c].get_nz_data(p); |
---|
402 | <a name="l00485"></a>00485 } |
---|
403 | <a name="l00486"></a>00486 } |
---|
404 | <a name="l00487"></a>00487 |
---|
405 | <a name="l00488"></a>00488 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
406 | <a name="l00489"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948">00489</a> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948" title="Returns a full, dense matrix.">Sparse_Mat<T>::full</a>()<span class="keyword"> const</span> |
---|
407 | <a name="l00490"></a>00490 <span class="keyword"></span>{ |
---|
408 | <a name="l00491"></a>00491 <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> r(n_rows, n_cols); |
---|
409 | <a name="l00492"></a>00492 <a class="code" href="classitpp_1_1Sparse__Mat.html#b3cd8be888ec514a4817770a74fd4948" title="Returns a full, dense matrix.">full</a>(r); |
---|
410 | <a name="l00493"></a>00493 <span class="keywordflow">return</span> r; |
---|
411 | <a name="l00494"></a>00494 } |
---|
412 | <a name="l00495"></a>00495 |
---|
413 | <a name="l00496"></a>00496 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
414 | <a name="l00497"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#404ced4fa4a5a8a7a6050851caa312d2">00497</a> T <a class="code" href="classitpp_1_1Sparse__Mat.html#404ced4fa4a5a8a7a6050851caa312d2" title="Returns element of row r and column c.">Sparse_Mat<T>::operator()</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c)<span class="keyword"> const</span> |
---|
415 | <a name="l00498"></a>00498 <span class="keyword"></span>{ |
---|
416 | <a name="l00499"></a>00499 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
417 | <a name="l00500"></a>00500 <span class="keywordflow">return</span> col[c](r); |
---|
418 | <a name="l00501"></a>00501 } |
---|
419 | <a name="l00502"></a>00502 |
---|
420 | <a name="l00503"></a>00503 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
421 | <a name="l00504"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#2e2d250f37e9795b516b1ce3fe28e2fa">00504</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#2e2d250f37e9795b516b1ce3fe28e2fa" title="Set element (r, c ) equal to v.">Sparse_Mat<T>::set</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, T v) |
---|
422 | <a name="l00505"></a>00505 { |
---|
423 | <a name="l00506"></a>00506 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
424 | <a name="l00507"></a>00507 col[c].set(r, v); |
---|
425 | <a name="l00508"></a>00508 } |
---|
426 | <a name="l00509"></a>00509 |
---|
427 | <a name="l00510"></a>00510 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
428 | <a name="l00511"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#a2d45bc984af880390d434d03afb2c8c">00511</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#a2d45bc984af880390d434d03afb2c8c" title="Set a new element with index (r, c ) equal to v.">Sparse_Mat<T>::set_new</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, T v) |
---|
429 | <a name="l00512"></a>00512 { |
---|
430 | <a name="l00513"></a>00513 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
431 | <a name="l00514"></a>00514 col[c].set_new(r, v); |
---|
432 | <a name="l00515"></a>00515 } |
---|
433 | <a name="l00516"></a>00516 |
---|
434 | <a name="l00517"></a>00517 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
435 | <a name="l00518"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#ddb256b1bc9bdf0a57b56c019ab2b1f5">00518</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#ddb256b1bc9bdf0a57b56c019ab2b1f5" title="Add the element in row r and column c with v.">Sparse_Mat<T>::add_elem</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, T v) |
---|
436 | <a name="l00519"></a>00519 { |
---|
437 | <a name="l00520"></a>00520 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
438 | <a name="l00521"></a>00521 col[c].add_elem(r, v); |
---|
439 | <a name="l00522"></a>00522 } |
---|
440 | <a name="l00523"></a>00523 |
---|
441 | <a name="l00524"></a>00524 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
442 | <a name="l00525"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#4d10d2107caa9f08e2f724bee5e10090">00525</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#4d10d2107caa9f08e2f724bee5e10090" title="Set the sparse matrix to the all zero matrix (removes all non-zero elements).">Sparse_Mat<T>::zeros</a>() |
---|
443 | <a name="l00526"></a>00526 { |
---|
444 | <a name="l00527"></a>00527 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
445 | <a name="l00528"></a>00528 col[c].<a class="code" href="classitpp_1_1Sparse__Mat.html#4d10d2107caa9f08e2f724bee5e10090" title="Set the sparse matrix to the all zero matrix (removes all non-zero elements).">zeros</a>(); |
---|
446 | <a name="l00529"></a>00529 } |
---|
447 | <a name="l00530"></a>00530 |
---|
448 | <a name="l00531"></a>00531 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
449 | <a name="l00532"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#597931c72c2ae675c0ecc2522774474d">00532</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#597931c72c2ae675c0ecc2522774474d" title="Set the element in row r and column c to zero (i.e. clear that element if it contains...">Sparse_Mat<T>::zero_elem</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> r, <span class="keyword">const</span> <span class="keywordtype">int</span> c) |
---|
450 | <a name="l00533"></a>00533 { |
---|
451 | <a name="l00534"></a>00534 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
452 | <a name="l00535"></a>00535 col[c].zero_elem(r); |
---|
453 | <a name="l00536"></a>00536 } |
---|
454 | <a name="l00537"></a>00537 |
---|
455 | <a name="l00538"></a>00538 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
456 | <a name="l00539"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#12b5fb55f2b16c350c462ee876ec7ade">00539</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#12b5fb55f2b16c350c462ee876ec7ade" title="Clear all non-zero elements of the sparse matrix.">Sparse_Mat<T>::clear</a>() |
---|
457 | <a name="l00540"></a>00540 { |
---|
458 | <a name="l00541"></a>00541 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
459 | <a name="l00542"></a>00542 col[c].<a class="code" href="classitpp_1_1Sparse__Mat.html#12b5fb55f2b16c350c462ee876ec7ade" title="Clear all non-zero elements of the sparse matrix.">clear</a>(); |
---|
460 | <a name="l00543"></a>00543 } |
---|
461 | <a name="l00544"></a>00544 |
---|
462 | <a name="l00545"></a>00545 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
463 | <a name="l00546"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#5f9083bb9615a53c6abfce4ca28be21a">00546</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#5f9083bb9615a53c6abfce4ca28be21a" title="Clear the element in row r and column c (if it contains a non-zero value).">Sparse_Mat<T>::clear_elem</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> r, <span class="keyword">const</span> <span class="keywordtype">int</span> c) |
---|
464 | <a name="l00547"></a>00547 { |
---|
465 | <a name="l00548"></a>00548 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r<n_rows && c >= 0 && c < n_cols, <span class="stringliteral">"Incorrect input indexes given"</span>); |
---|
466 | <a name="l00549"></a>00549 col[c].clear_elem(r); |
---|
467 | <a name="l00550"></a>00550 } |
---|
468 | <a name="l00551"></a>00551 |
---|
469 | <a name="l00552"></a>00552 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
470 | <a name="l00553"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#133ec46db675573d8736296ae388ad09">00553</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#133ec46db675573d8736296ae388ad09" title="Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.">Sparse_Mat<T>::set_submatrix</a>(<span class="keywordtype">int</span> r1, <span class="keywordtype">int</span> r2, <span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a>& m) |
---|
471 | <a name="l00554"></a>00554 { |
---|
472 | <a name="l00555"></a>00555 <span class="keywordflow">if</span> (r1 == -1) r1 = n_rows - 1; |
---|
473 | <a name="l00556"></a>00556 <span class="keywordflow">if</span> (r2 == -1) r2 = n_rows - 1; |
---|
474 | <a name="l00557"></a>00557 <span class="keywordflow">if</span> (c1 == -1) c1 = n_cols - 1; |
---|
475 | <a name="l00558"></a>00558 <span class="keywordflow">if</span> (c2 == -1) c2 = n_cols - 1; |
---|
476 | <a name="l00559"></a>00559 |
---|
477 | <a name="l00560"></a>00560 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r1 >= 0 && r2 >= 0 && r1 < n_rows && r2 < n_rows && |
---|
478 | <a name="l00561"></a>00561 c1 >= 0 && c2 >= 0 && c1 < n_cols && c2 < n_cols, <span class="stringliteral">"Sparse_Mat<Num_T>::set_submatrix(): index out of range"</span>); |
---|
479 | <a name="l00562"></a>00562 |
---|
480 | <a name="l00563"></a>00563 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r2 >= r1 && c2 >= c1, <span class="stringliteral">"Sparse_Mat<Num_T>::set_submatrix: r2<r1 or c2<c1"</span>); |
---|
481 | <a name="l00564"></a>00564 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() == r2 - r1 + 1 && m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() == c2 - c1 + 1, <span class="stringliteral">"Mat<Num_T>::set_submatrix(): sizes don't match"</span>); |
---|
482 | <a name="l00565"></a>00565 |
---|
483 | <a name="l00566"></a>00566 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0 ; i < m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() ; i++) { |
---|
484 | <a name="l00567"></a>00567 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0 ; j < m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() ; j++) { |
---|
485 | <a name="l00568"></a>00568 <span class="keyword">set</span>(r1 + i, c1 + j, m(i, j)); |
---|
486 | <a name="l00569"></a>00569 } |
---|
487 | <a name="l00570"></a>00570 } |
---|
488 | <a name="l00571"></a>00571 } |
---|
489 | <a name="l00572"></a>00572 |
---|
490 | <a name="l00573"></a>00573 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
491 | <a name="l00574"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#02715ff681128d656bcb661573633b91">00574</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#133ec46db675573d8736296ae388ad09" title="Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.">Sparse_Mat<T>::set_submatrix</a>(<span class="keywordtype">int</span> r, <span class="keywordtype">int</span> c, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a>& m) |
---|
492 | <a name="l00575"></a>00575 { |
---|
493 | <a name="l00576"></a>00576 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r >= 0 && r + m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() <= n_rows && |
---|
494 | <a name="l00577"></a>00577 c >= 0 && c + m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() <= n_cols, <span class="stringliteral">"Sparse_Mat<Num_T>::set_submatrix(): index out of range"</span>); |
---|
495 | <a name="l00578"></a>00578 |
---|
496 | <a name="l00579"></a>00579 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0 ; i < m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() ; i++) { |
---|
497 | <a name="l00580"></a>00580 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0 ; j < m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() ; j++) { |
---|
498 | <a name="l00581"></a>00581 <span class="keyword">set</span>(r + i, c + j, m(i, j)); |
---|
499 | <a name="l00582"></a>00582 } |
---|
500 | <a name="l00583"></a>00583 } |
---|
501 | <a name="l00584"></a>00584 } |
---|
502 | <a name="l00585"></a>00585 |
---|
503 | <a name="l00586"></a>00586 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
504 | <a name="l00587"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#e969584f109b897c04fb85c71ab6fc9a">00587</a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#e969584f109b897c04fb85c71ab6fc9a" title="Returns the sub-matrix from rows r1 to r2 and columns c1 to c2.">Sparse_Mat<T>::get_submatrix</a>(<span class="keywordtype">int</span> r1, <span class="keywordtype">int</span> r2, <span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2)<span class="keyword"> const</span> |
---|
505 | <a name="l00588"></a>00588 <span class="keyword"></span>{ |
---|
506 | <a name="l00589"></a>00589 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(r1 <= r2 && r1 >= 0 && r1 < n_rows && c1 <= c2 && c1 >= 0 && c1 < n_cols, |
---|
507 | <a name="l00590"></a>00590 <span class="stringliteral">"Sparse_Mat<T>::get_submatrix(): illegal input variables"</span>); |
---|
508 | <a name="l00591"></a>00591 |
---|
509 | <a name="l00592"></a>00592 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> r(r2 - r1 + 1, c2 - c1 + 1); |
---|
510 | <a name="l00593"></a>00593 |
---|
511 | <a name="l00594"></a>00594 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = c1; c <= c2; c++) |
---|
512 | <a name="l00595"></a>00595 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c-c1] = col[c].get_subvector(r1, r2); |
---|
513 | <a name="l00596"></a>00596 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5" title="Set the maximum number of non-zero elements in each column equal to the actual number...">compact</a>(); |
---|
514 | <a name="l00597"></a>00597 |
---|
515 | <a name="l00598"></a>00598 <span class="keywordflow">return</span> r; |
---|
516 | <a name="l00599"></a>00599 } |
---|
517 | <a name="l00600"></a>00600 |
---|
518 | <a name="l00601"></a>00601 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
519 | <a name="l00602"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#aecf3287d3bb4192eb7555b93d5dfac1">00602</a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#aecf3287d3bb4192eb7555b93d5dfac1" title="Returns the sub-matrix from columns c1 to c2 (all rows).">Sparse_Mat<T>::get_submatrix_cols</a>(<span class="keywordtype">int</span> c1, <span class="keywordtype">int</span> c2)<span class="keyword"> const</span> |
---|
520 | <a name="l00603"></a>00603 <span class="keyword"></span>{ |
---|
521 | <a name="l00604"></a>00604 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(c1 <= c2 && c1 >= 0 && c1 < n_cols, <span class="stringliteral">"Sparse_Mat<T>::get_submatrix_cols()"</span>); |
---|
522 | <a name="l00605"></a>00605 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> r(n_rows, c2 - c1 + 1, 0); |
---|
523 | <a name="l00606"></a>00606 |
---|
524 | <a name="l00607"></a>00607 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = c1; c <= c2; c++) |
---|
525 | <a name="l00608"></a>00608 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c-c1] = col[c]; |
---|
526 | <a name="l00609"></a>00609 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#29bf2d6f6a05709a35c156c137226de5" title="Set the maximum number of non-zero elements in each column equal to the actual number...">compact</a>(); |
---|
527 | <a name="l00610"></a>00610 |
---|
528 | <a name="l00611"></a>00611 <span class="keywordflow">return</span> r; |
---|
529 | <a name="l00612"></a>00612 } |
---|
530 | <a name="l00613"></a>00613 |
---|
531 | <a name="l00614"></a>00614 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
532 | <a name="l00615"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca">00615</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">Sparse_Mat<T>::get_col</a>(<span class="keywordtype">int</span> c, <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> &v)<span class="keyword"> const</span> |
---|
533 | <a name="l00616"></a>00616 <span class="keyword"></span>{ |
---|
534 | <a name="l00617"></a>00617 <a class="code" href="group__errorhandlingfunc.html#gd5c34b291e5018534fd2344486e2b5a1" title="Abort if t is not true.">it_assert</a>(c >= 0 && c < n_cols, <span class="stringliteral">"Sparse_Mat<T>::get_col()"</span>); |
---|
535 | <a name="l00618"></a>00618 v = col[c]; |
---|
536 | <a name="l00619"></a>00619 } |
---|
537 | <a name="l00620"></a>00620 |
---|
538 | <a name="l00621"></a>00621 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
539 | <a name="l00622"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#422dbcfed4a9aaad5b4a590e4bd427ff">00622</a> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">Sparse_Mat<T>::get_col</a>(<span class="keywordtype">int</span> c)<span class="keyword"> const</span> |
---|
540 | <a name="l00623"></a>00623 <span class="keyword"></span>{ |
---|
541 | <a name="l00624"></a>00624 <a class="code" href="group__errorhandlingfunc.html#gd5c34b291e5018534fd2344486e2b5a1" title="Abort if t is not true.">it_assert</a>(c >= 0 && c < n_cols, <span class="stringliteral">"Sparse_Mat<T>::get_col()"</span>); |
---|
542 | <a name="l00625"></a>00625 <span class="keywordflow">return</span> col[c]; |
---|
543 | <a name="l00626"></a>00626 } |
---|
544 | <a name="l00627"></a>00627 |
---|
545 | <a name="l00628"></a>00628 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
546 | <a name="l00629"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#e15d124adfa11120960ecfd11ad90ef0">00629</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#e15d124adfa11120960ecfd11ad90ef0" title="Set column c of the Sparse_Mat.">Sparse_Mat<T>::set_col</a>(<span class="keywordtype">int</span> c, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> &v) |
---|
547 | <a name="l00630"></a>00630 { |
---|
548 | <a name="l00631"></a>00631 <a class="code" href="group__errorhandlingfunc.html#gd5c34b291e5018534fd2344486e2b5a1" title="Abort if t is not true.">it_assert</a>(c >= 0 && c < n_cols, <span class="stringliteral">"Sparse_Mat<T>::set_col()"</span>); |
---|
549 | <a name="l00632"></a>00632 col[c] = v; |
---|
550 | <a name="l00633"></a>00633 } |
---|
551 | <a name="l00634"></a>00634 |
---|
552 | <a name="l00635"></a>00635 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
553 | <a name="l00636"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#5b12be950cd135b8fb0f345a9d73348d">00636</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">Sparse_Mat<T>::transpose</a>(<a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m)<span class="keyword"> const</span> |
---|
554 | <a name="l00637"></a>00637 <span class="keyword"></span>{ |
---|
555 | <a name="l00638"></a>00638 m.<a class="code" href="classitpp_1_1Sparse__Mat.html#bede37fe2203b2bae86c7000c6fa78f4" title="Set the size of the sparse matrix.">set_size</a>(n_cols, n_rows); |
---|
556 | <a name="l00639"></a>00639 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
557 | <a name="l00640"></a>00640 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p = 0; p < col[c].nnz(); p++) |
---|
558 | <a name="l00641"></a>00641 m.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[col[c].get_nz_index(p)].set_new(c, col[c].get_nz_data(p)); |
---|
559 | <a name="l00642"></a>00642 } |
---|
560 | <a name="l00643"></a>00643 } |
---|
561 | <a name="l00644"></a>00644 |
---|
562 | <a name="l00645"></a>00645 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
563 | <a name="l00646"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">00646</a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">Sparse_Mat<T>::transpose</a>()<span class="keyword"> const</span> |
---|
564 | <a name="l00647"></a>00647 <span class="keyword"></span>{ |
---|
565 | <a name="l00648"></a>00648 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> m; |
---|
566 | <a name="l00649"></a>00649 <a class="code" href="classitpp_1_1Sparse__Mat.html#da0c107ad90b5445d8cb7c55b48ef8b3">transpose</a>(m); |
---|
567 | <a name="l00650"></a>00650 <span class="keywordflow">return</span> m; |
---|
568 | <a name="l00651"></a>00651 } |
---|
569 | <a name="l00652"></a>00652 |
---|
570 | <a name="l00653"></a>00653 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
571 | <a name="l00654"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#cf3ddc3a3af57157e51c00b3d6e423ce">00654</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#cf3ddc3a3af57157e51c00b3d6e423ce" title="Assign sparse matrix the value and dimensions of the sparse matrix m.">Sparse_Mat<T>::operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) |
---|
572 | <a name="l00655"></a>00655 { |
---|
573 | <a name="l00656"></a>00656 free(); |
---|
574 | <a name="l00657"></a>00657 n_rows = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a>; |
---|
575 | <a name="l00658"></a>00658 n_cols = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a>; |
---|
576 | <a name="l00659"></a>00659 alloc_empty(); |
---|
577 | <a name="l00660"></a>00660 |
---|
578 | <a name="l00661"></a>00661 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
579 | <a name="l00662"></a>00662 col[c] = m.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c]; |
---|
580 | <a name="l00663"></a>00663 } |
---|
581 | <a name="l00664"></a>00664 |
---|
582 | <a name="l00665"></a>00665 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
583 | <a name="l00666"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#0b32c38c1aa5ea999817190afc9f8858">00666</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#cf3ddc3a3af57157e51c00b3d6e423ce" title="Assign sparse matrix the value and dimensions of the sparse matrix m.">Sparse_Mat<T>::operator=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m) |
---|
584 | <a name="l00667"></a>00667 { |
---|
585 | <a name="l00668"></a>00668 free(); |
---|
586 | <a name="l00669"></a>00669 n_rows = m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>(); |
---|
587 | <a name="l00670"></a>00670 n_cols = m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>(); |
---|
588 | <a name="l00671"></a>00671 alloc(); |
---|
589 | <a name="l00672"></a>00672 |
---|
590 | <a name="l00673"></a>00673 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
591 | <a name="l00674"></a>00674 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < n_rows; r++) { |
---|
592 | <a name="l00675"></a>00675 <span class="keywordflow">if</span> (m(r, c) != T(0)) |
---|
593 | <a name="l00676"></a>00676 col[c].set_new(r, m(r, c)); |
---|
594 | <a name="l00677"></a>00677 } |
---|
595 | <a name="l00678"></a>00678 col[c].compact(); |
---|
596 | <a name="l00679"></a>00679 } |
---|
597 | <a name="l00680"></a>00680 } |
---|
598 | <a name="l00681"></a>00681 |
---|
599 | <a name="l00682"></a>00682 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
600 | <a name="l00683"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#1eb8891a51aa9c69fadcb8ab623c5d36">00683</a> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="classitpp_1_1Sparse__Mat.html#1eb8891a51aa9c69fadcb8ab623c5d36" title="Returns the sign inverse of all elements in the sparse matrix.">Sparse_Mat<T>::operator-</a>()<span class="keyword"> const</span> |
---|
601 | <a name="l00684"></a>00684 <span class="keyword"></span>{ |
---|
602 | <a name="l00685"></a>00685 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat</a> r(n_rows, n_cols, 0); |
---|
603 | <a name="l00686"></a>00686 |
---|
604 | <a name="l00687"></a>00687 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
605 | <a name="l00688"></a>00688 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c].resize_data(col[c].<a class="code" href="classitpp_1_1Sparse__Mat.html#28166b919565d9e50895569b7204c9c4" title="The number of non-zero elements in the sparse matrix.">nnz</a>()); |
---|
606 | <a name="l00689"></a>00689 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p = 0; p < col[c].nnz(); p++) |
---|
607 | <a name="l00690"></a>00690 r.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c].set_new(col[c].get_nz_index(p), -col[c].get_nz_data(p)); |
---|
608 | <a name="l00691"></a>00691 } |
---|
609 | <a name="l00692"></a>00692 |
---|
610 | <a name="l00693"></a>00693 <span class="keywordflow">return</span> r; |
---|
611 | <a name="l00694"></a>00694 } |
---|
612 | <a name="l00695"></a>00695 |
---|
613 | <a name="l00696"></a>00696 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
614 | <a name="l00697"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#ee53a24c0f6be2927b512b64fadd650b">00697</a> <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#ee53a24c0f6be2927b512b64fadd650b" title="Compare two sparse matricies. False if wrong sizes or different values.">Sparse_Mat<T>::operator==</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m)<span class="keyword"> const</span> |
---|
615 | <a name="l00698"></a>00698 <span class="keyword"></span>{ |
---|
616 | <a name="l00699"></a>00699 <span class="keywordflow">if</span> (n_rows != m.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a> || n_cols != m.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a>) |
---|
617 | <a name="l00700"></a>00700 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
---|
618 | <a name="l00701"></a>00701 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
619 | <a name="l00702"></a>00702 <span class="keywordflow">if</span> (!(col[c] == m.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c])) |
---|
620 | <a name="l00703"></a>00703 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
---|
621 | <a name="l00704"></a>00704 } |
---|
622 | <a name="l00705"></a>00705 <span class="comment">// If they passed all tests, they must be equal</span> |
---|
623 | <a name="l00706"></a>00706 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
---|
624 | <a name="l00707"></a>00707 } |
---|
625 | <a name="l00708"></a>00708 |
---|
626 | <a name="l00709"></a>00709 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
627 | <a name="l00710"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#901025d686820e6e2379701fcc4786fc">00710</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#901025d686820e6e2379701fcc4786fc" title="Add sparse matrix v to all non-zero elements of the sparse matrix.">Sparse_Mat<T>::operator+=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) |
---|
628 | <a name="l00711"></a>00711 { |
---|
629 | <a name="l00712"></a>00712 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.<a class="code" href="classitpp_1_1Sparse__Mat.html#98f82f4aca56a2b8083df057f0c5c359" title="Returns the number of rows of the sparse matrix.">rows</a>() == n_rows && m.<a class="code" href="classitpp_1_1Sparse__Mat.html#18ab90bb7cd0db31722374889e3d74c8" title="Returns the number of columns of the sparse matrix.">cols</a>() == n_cols, <span class="stringliteral">"Addition of unequal sized matrices is not allowed"</span>); |
---|
630 | <a name="l00713"></a>00713 |
---|
631 | <a name="l00714"></a>00714 <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> v; |
---|
632 | <a name="l00715"></a>00715 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
633 | <a name="l00716"></a>00716 m.<a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">get_col</a>(c, v); |
---|
634 | <a name="l00717"></a>00717 col[c] += v; |
---|
635 | <a name="l00718"></a>00718 } |
---|
636 | <a name="l00719"></a>00719 } |
---|
637 | <a name="l00720"></a>00720 |
---|
638 | <a name="l00721"></a>00721 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
639 | <a name="l00722"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#6ea4483a0a1077ee71ed24ed4bba7659">00722</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#901025d686820e6e2379701fcc4786fc" title="Add sparse matrix v to all non-zero elements of the sparse matrix.">Sparse_Mat<T>::operator+=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m) |
---|
640 | <a name="l00723"></a>00723 { |
---|
641 | <a name="l00724"></a>00724 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() == n_rows && m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() == n_cols, <span class="stringliteral">"Addition of unequal sized matrices is not allowed"</span>); |
---|
642 | <a name="l00725"></a>00725 |
---|
643 | <a name="l00726"></a>00726 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
644 | <a name="l00727"></a>00727 col[c] += (m.<a class="code" href="classitpp_1_1Mat.html#095a4e54f39932b62633f7f4f252ab46" title="Get column c.">get_col</a>(c)); |
---|
645 | <a name="l00728"></a>00728 } |
---|
646 | <a name="l00729"></a>00729 |
---|
647 | <a name="l00730"></a>00730 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
648 | <a name="l00731"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#9f42dce24f97723ed307eb2d2988de57">00731</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9f42dce24f97723ed307eb2d2988de57" title="Subtract sparse matrix v from all non-zero elements of the sparse matrix.">Sparse_Mat<T>::operator-=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m) |
---|
649 | <a name="l00732"></a>00732 { |
---|
650 | <a name="l00733"></a>00733 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.<a class="code" href="classitpp_1_1Sparse__Mat.html#98f82f4aca56a2b8083df057f0c5c359" title="Returns the number of rows of the sparse matrix.">rows</a>() == n_rows && m.<a class="code" href="classitpp_1_1Sparse__Mat.html#18ab90bb7cd0db31722374889e3d74c8" title="Returns the number of columns of the sparse matrix.">cols</a>() == n_cols, <span class="stringliteral">"Subtraction of unequal sized matrices is not allowed"</span>); |
---|
651 | <a name="l00734"></a>00734 |
---|
652 | <a name="l00735"></a>00735 <a class="code" href="classitpp_1_1Sparse__Vec.html" title="Templated sparse vector class.">Sparse_Vec<T></a> v; |
---|
653 | <a name="l00736"></a>00736 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) { |
---|
654 | <a name="l00737"></a>00737 m.<a class="code" href="classitpp_1_1Sparse__Mat.html#9b9759f1df3016d2004ee6a0d347d0ca" title="Returns column c of the Sparse_Mat in the Sparse_Vec v.">get_col</a>(c, v); |
---|
655 | <a name="l00738"></a>00738 col[c] -= v; |
---|
656 | <a name="l00739"></a>00739 } |
---|
657 | <a name="l00740"></a>00740 } |
---|
658 | <a name="l00741"></a>00741 |
---|
659 | <a name="l00742"></a>00742 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
660 | <a name="l00743"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#998709bb09b76a7502da3a67a4a3e1f1">00743</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#9f42dce24f97723ed307eb2d2988de57" title="Subtract sparse matrix v from all non-zero elements of the sparse matrix.">Sparse_Mat<T>::operator-=</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Mat.html">Mat<T></a> &m) |
---|
661 | <a name="l00744"></a>00744 { |
---|
662 | <a name="l00745"></a>00745 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.<a class="code" href="classitpp_1_1Mat.html#f3028609c01e08fb07c5bf0bcd4c4e03" title="The number of rows.">rows</a>() == n_rows && m.<a class="code" href="classitpp_1_1Mat.html#49680ef454d1d75b737e3ce157f1ac7b" title="The number of columns.">cols</a>() == n_cols, <span class="stringliteral">"Subtraction of unequal sized matrices is not allowed"</span>); |
---|
663 | <a name="l00746"></a>00746 |
---|
664 | <a name="l00747"></a>00747 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
665 | <a name="l00748"></a>00748 col[c] -= (m.<a class="code" href="classitpp_1_1Mat.html#095a4e54f39932b62633f7f4f252ab46" title="Get column c.">get_col</a>(c)); |
---|
666 | <a name="l00749"></a>00749 } |
---|
667 | <a name="l00750"></a>00750 |
---|
668 | <a name="l00751"></a>00751 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
669 | <a name="l00752"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#f209ca65dde352cc53fa7b0db747d698">00752</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#f209ca65dde352cc53fa7b0db747d698" title="Multiply all non-zero elements of the sparse matrix with the scalar v.">Sparse_Mat<T>::operator*=</a>(<span class="keyword">const</span> T &m) |
---|
670 | <a name="l00753"></a>00753 { |
---|
671 | <a name="l00754"></a>00754 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
672 | <a name="l00755"></a>00755 col[c] *= m; |
---|
673 | <a name="l00756"></a>00756 } |
---|
674 | <a name="l00757"></a>00757 |
---|
675 | <a name="l00758"></a>00758 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
676 | <a name="l00759"></a><a class="code" href="classitpp_1_1Sparse__Mat.html#5962d40e4865536207f2ae9c204d9796">00759</a> <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Sparse__Mat.html#5962d40e4865536207f2ae9c204d9796" title="Divide all non-zero elements of the sparse matrix with the scalar v.">Sparse_Mat<T>::operator/=</a>(<span class="keyword">const</span> T &m) |
---|
677 | <a name="l00760"></a>00760 { |
---|
678 | <a name="l00761"></a>00761 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < n_cols; c++) |
---|
679 | <a name="l00762"></a>00762 col[c] /= m; |
---|
680 | <a name="l00763"></a>00763 } |
---|
681 | <a name="l00764"></a>00764 |
---|
682 | <a name="l00765"></a>00765 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
683 | <a name="l00766"></a>00766 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> <a class="code" href="group__fixed.html#g683d6c037357e472e84756fe1b1faae8" title="Fix + cfixmat.">operator+</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m1, <span class="keyword">const</span> <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> &m2) |
---|
684 | <a name="l00767"></a>00767 { |
---|
685 | <a name="l00768"></a>00768 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m1.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a> == m2.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a> && m1.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a> == m2.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a> , <span class="stringliteral">"Sparse_Mat<T> + Sparse_Mat<T>"</span>); |
---|
686 | <a name="l00769"></a>00769 |
---|
687 | <a name="l00770"></a>00770 <a class="code" href="classitpp_1_1Sparse__Mat.html" title="Templated Sparse Matrix Class.">Sparse_Mat<T></a> m(m1.<a class="code" href="classitpp_1_1Sparse__Mat.html#fc7d597baedd923717429e33be26ff1c">n_rows</a>, m1.<a class="code" href="classitpp_1_1Sparse__Mat.html#4ad4ff37dc3c118af1882a76d0c472c3">n_cols</a>, 0); |
---|
688 | <a name="l00771"></a>00771 |
---|
689 | <a name="l00772"></a>00772 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < m.n_cols; c++) |
---|
690 | <a name="l00773"></a>00773 m.col[c] = m1.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c] + m2.<a class="code" href="classitpp_1_1Sparse__Mat.html#a083ae3ef8a3895e8da0a6e52418e982">col</a>[c]; |
---|
691 | <a name="l00774"></a>00774 |
---|
692 | <a name="l00775"></a>00775 <span class="keywordflow">return</span> m; |
---|
693 | <a name="l00776"></a>00776 } |
---|
694 | <a name="l00777"></a>00777 |
---|
695 | <a name="l00778"></a>00778 <span class="comment">// This function added by EGL, May'05</span> |
---|
696 | <a name="l00779"></a>00779 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
697 | <a name="l00780"></a>00780 Sparse_Mat<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> T &c, <span class="keyword">const</span> Sparse_Mat<T> &m) |
---|
698 | <a name="l00781"></a>00781 { |
---|
699 | <a name="l00782"></a>00782 <span class="keywordtype">int</span> i, j; |
---|
700 | <a name="l00783"></a>00783 Sparse_Mat<T> ret(m.n_rows, m.n_cols); |
---|
701 | <a name="l00784"></a>00784 <span class="keywordflow">for</span> (j = 0; j < m.n_cols; j++) { |
---|
702 | <a name="l00785"></a>00785 <span class="keywordflow">for</span> (i = 0; i < m.col[j].nnz(); i++) { |
---|
703 | <a name="l00786"></a>00786 T x = c * m.col[j].get_nz_data(i); |
---|
704 | <a name="l00787"></a>00787 <span class="keywordtype">int</span> k = m.col[j].get_nz_index(i); |
---|
705 | <a name="l00788"></a>00788 ret.set_new(k, j, x); |
---|
706 | <a name="l00789"></a>00789 } |
---|
707 | <a name="l00790"></a>00790 } |
---|
708 | <a name="l00791"></a>00791 <span class="keywordflow">return</span> ret; |
---|
709 | <a name="l00792"></a>00792 } |
---|
710 | <a name="l00793"></a>00793 |
---|
711 | <a name="l00794"></a>00794 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
712 | <a name="l00795"></a>00795 Sparse_Mat<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2) |
---|
713 | <a name="l00796"></a>00796 { |
---|
714 | <a name="l00797"></a>00797 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m1.n_cols == m2.n_rows, <span class="stringliteral">"Sparse_Mat<T> * Sparse_Mat<T>"</span>); |
---|
715 | <a name="l00798"></a>00798 |
---|
716 | <a name="l00799"></a>00799 Sparse_Mat<T> ret(m1.n_rows, m2.n_cols); |
---|
717 | <a name="l00800"></a>00800 |
---|
718 | <a name="l00801"></a>00801 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < m2.n_cols; c++) { |
---|
719 | <a name="l00802"></a>00802 Sparse_Vec<T> &m2colc = m2.col[c]; |
---|
720 | <a name="l00803"></a>00803 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p2 = 0; p2 < m2colc.nnz(); p2++) { |
---|
721 | <a name="l00804"></a>00804 Sparse_Vec<T> &mcol = m1.col[m2colc.get_nz_index(p2)]; |
---|
722 | <a name="l00805"></a>00805 T x = m2colc.get_nz_data(p2); |
---|
723 | <a name="l00806"></a>00806 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p1 = 0; p1 < mcol.nnz(); p1++) { |
---|
724 | <a name="l00807"></a>00807 <span class="keywordtype">int</span> r = mcol.get_nz_index(p1); |
---|
725 | <a name="l00808"></a>00808 T inc = mcol.get_nz_data(p1) * x; |
---|
726 | <a name="l00809"></a>00809 ret.col[c].add_elem(r, inc); |
---|
727 | <a name="l00810"></a>00810 } |
---|
728 | <a name="l00811"></a>00811 } |
---|
729 | <a name="l00812"></a>00812 } |
---|
730 | <a name="l00813"></a>00813 <span class="comment">// old code</span> |
---|
731 | <a name="l00814"></a>00814 <span class="comment">/* for (int c=0; c<m2.n_cols; c++) { */</span> |
---|
732 | <a name="l00815"></a>00815 <span class="comment">/* for (int p2=0; p2<m2.col[c].nnz(); p2++) { */</span> |
---|
733 | <a name="l00816"></a>00816 <span class="comment">/* Sparse_Vec<T> &mcol = m1.col[m2.col[c].get_nz_index(p2)]; */</span> |
---|
734 | <a name="l00817"></a>00817 <span class="comment">/* for (int p1=0; p1<mcol.nnz(); p1++) { */</span> |
---|
735 | <a name="l00818"></a>00818 <span class="comment">/* int r = mcol.get_nz_index(p1); */</span> |
---|
736 | <a name="l00819"></a>00819 <span class="comment">/* T inc = mcol.get_nz_data(p1) * m2.col[c].get_nz_data(p2); */</span> |
---|
737 | <a name="l00820"></a>00820 <span class="comment">/* ret.col[c].add_elem(r,inc); */</span> |
---|
738 | <a name="l00821"></a>00821 <span class="comment">/* } */</span> |
---|
739 | <a name="l00822"></a>00822 <span class="comment">/* } */</span> |
---|
740 | <a name="l00823"></a>00823 <span class="comment">/* } */</span> |
---|
741 | <a name="l00824"></a>00824 ret.compact(); |
---|
742 | <a name="l00825"></a>00825 <span class="keywordflow">return</span> ret; |
---|
743 | <a name="l00826"></a>00826 } |
---|
744 | <a name="l00827"></a>00827 |
---|
745 | <a name="l00828"></a>00828 |
---|
746 | <a name="l00829"></a>00829 <span class="comment">// This is apparently buggy.</span> |
---|
747 | <a name="l00830"></a>00830 <span class="comment">/* template <class T> */</span> |
---|
748 | <a name="l00831"></a>00831 <span class="comment">/* Sparse_Mat<T> operator*(const Sparse_Mat<T> &m1, const Sparse_Mat<T> &m2) */</span> |
---|
749 | <a name="l00832"></a>00832 <span class="comment">/* { */</span> |
---|
750 | <a name="l00833"></a>00833 <span class="comment">/* it_assert_debug(m1.n_cols == m2.n_rows, "Sparse_Mat<T> * Sparse_Mat<T>"); */</span> |
---|
751 | <a name="l00834"></a>00834 |
---|
752 | <a name="l00835"></a>00835 <span class="comment">/* Sparse_Mat<T> ret(m1.n_rows, m2.n_cols); */</span> |
---|
753 | <a name="l00836"></a>00836 <span class="comment">/* ivec occupied_by(ret.n_rows), pos(ret.n_rows); */</span> |
---|
754 | <a name="l00837"></a>00837 <span class="comment">/* for (int rp=0; rp<m1.n_rows; rp++) */</span> |
---|
755 | <a name="l00838"></a>00838 <span class="comment">/* occupied_by[rp] = -1; */</span> |
---|
756 | <a name="l00839"></a>00839 <span class="comment">/* for (int c=0; c<ret.n_cols; c++) { */</span> |
---|
757 | <a name="l00840"></a>00840 <span class="comment">/* Sparse_Vec<T> &m2col = m2.col[c]; */</span> |
---|
758 | <a name="l00841"></a>00841 <span class="comment">/* for (int p2=0; p2<m2col.nnz(); p2++) { */</span> |
---|
759 | <a name="l00842"></a>00842 <span class="comment">/* Sparse_Vec<T> &m1col = m1.col[m2col.get_nz_index(p2)]; */</span> |
---|
760 | <a name="l00843"></a>00843 <span class="comment">/* for (int p1=0; p1<m1col.nnz(); p1++) { */</span> |
---|
761 | <a name="l00844"></a>00844 <span class="comment">/* int r = m1col.get_nz_index(p1); */</span> |
---|
762 | <a name="l00845"></a>00845 <span class="comment">/* T inc = m1col.get_nz_data(p1) * m2col.get_nz_data(p2); */</span> |
---|
763 | <a name="l00846"></a>00846 <span class="comment">/* if (occupied_by[r] == c) { */</span> |
---|
764 | <a name="l00847"></a>00847 <span class="comment">/* int index=ret.col[c].get_nz_index(pos[r]); */</span> |
---|
765 | <a name="l00848"></a>00848 <span class="comment">/* ret.col[c].add_elem(index,inc); */</span> |
---|
766 | <a name="l00849"></a>00849 <span class="comment">/* } */</span> |
---|
767 | <a name="l00850"></a>00850 <span class="comment">/* else { */</span> |
---|
768 | <a name="l00851"></a>00851 <span class="comment">/* occupied_by[r] = c; */</span> |
---|
769 | <a name="l00852"></a>00852 <span class="comment">/* pos[r] = ret.col[c].nnz(); */</span> |
---|
770 | <a name="l00853"></a>00853 <span class="comment">/* ret.col[c].set_new(r, inc); */</span> |
---|
771 | <a name="l00854"></a>00854 <span class="comment">/* } */</span> |
---|
772 | <a name="l00855"></a>00855 <span class="comment">/* } */</span> |
---|
773 | <a name="l00856"></a>00856 <span class="comment">/* } */</span> |
---|
774 | <a name="l00857"></a>00857 <span class="comment">/* } */</span> |
---|
775 | <a name="l00858"></a>00858 <span class="comment">/* ret.compact(); */</span> |
---|
776 | <a name="l00859"></a>00859 |
---|
777 | <a name="l00860"></a>00860 <span class="comment">/* return ret; */</span> |
---|
778 | <a name="l00861"></a>00861 <span class="comment">/* } */</span> |
---|
779 | <a name="l00862"></a>00862 |
---|
780 | <a name="l00863"></a>00863 |
---|
781 | <a name="l00864"></a>00864 <span class="comment">// This function added by EGL, May'05</span> |
---|
782 | <a name="l00865"></a>00865 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
783 | <a name="l00866"></a>00866 Sparse_Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Sparse_Vec<T> &v) |
---|
784 | <a name="l00867"></a>00867 { |
---|
785 | <a name="l00868"></a>00868 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.n_cols == v.size(), <span class="stringliteral">"Sparse_Mat<T> * Sparse_Vec<T>"</span>); |
---|
786 | <a name="l00869"></a>00869 |
---|
787 | <a name="l00870"></a>00870 Sparse_Vec<T> ret(m.n_rows); |
---|
788 | <a name="l00871"></a>00871 |
---|
789 | <a name="l00872"></a>00872 <span class="comment">/* The two lines below added because the input parameter "v" is</span> |
---|
790 | <a name="l00873"></a>00873 <span class="comment"> declared const, but the some functions (e.g., nnz()) change</span> |
---|
791 | <a name="l00874"></a>00874 <span class="comment"> the vector... Is there a better workaround? */</span> |
---|
792 | <a name="l00875"></a>00875 Sparse_Vec<T> vv = v; |
---|
793 | <a name="l00876"></a>00876 |
---|
794 | <a name="l00877"></a>00877 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p2 = 0; p2 < vv.nnz(); p2++) { |
---|
795 | <a name="l00878"></a>00878 Sparse_Vec<T> &mcol = m.col[vv.get_nz_index(p2)]; |
---|
796 | <a name="l00879"></a>00879 T x = vv.get_nz_data(p2); |
---|
797 | <a name="l00880"></a>00880 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p1 = 0; p1 < mcol.nnz(); p1++) { |
---|
798 | <a name="l00881"></a>00881 <span class="keywordtype">int</span> r = mcol.get_nz_index(p1); |
---|
799 | <a name="l00882"></a>00882 T inc = mcol.get_nz_data(p1) * x; |
---|
800 | <a name="l00883"></a>00883 ret.add_elem(r, inc); |
---|
801 | <a name="l00884"></a>00884 } |
---|
802 | <a name="l00885"></a>00885 } |
---|
803 | <a name="l00886"></a>00886 ret.compact(); |
---|
804 | <a name="l00887"></a>00887 <span class="keywordflow">return</span> ret; |
---|
805 | <a name="l00888"></a>00888 } |
---|
806 | <a name="l00889"></a>00889 |
---|
807 | <a name="l00890"></a>00890 |
---|
808 | <a name="l00891"></a>00891 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
809 | <a name="l00892"></a>00892 Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Vec<T> &v) |
---|
810 | <a name="l00893"></a>00893 { |
---|
811 | <a name="l00894"></a>00894 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m.n_cols == v.size(), <span class="stringliteral">"Sparse_Mat<T> * Vec<T>"</span>); |
---|
812 | <a name="l00895"></a>00895 |
---|
813 | <a name="l00896"></a>00896 Vec<T> r(m.n_rows); |
---|
814 | <a name="l00897"></a>00897 r.clear(); |
---|
815 | <a name="l00898"></a>00898 |
---|
816 | <a name="l00899"></a>00899 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < m.n_cols; c++) { |
---|
817 | <a name="l00900"></a>00900 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> p = 0; p < m.col[c].nnz(); p++) |
---|
818 | <a name="l00901"></a>00901 r(m.col[c].get_nz_index(p)) += m.col[c].get_nz_data(p) * v(c); |
---|
819 | <a name="l00902"></a>00902 } |
---|
820 | <a name="l00903"></a>00903 |
---|
821 | <a name="l00904"></a>00904 <span class="keywordflow">return</span> r; |
---|
822 | <a name="l00905"></a>00905 } |
---|
823 | <a name="l00906"></a>00906 |
---|
824 | <a name="l00907"></a>00907 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
825 | <a name="l00908"></a>00908 Vec<T> <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> Vec<T> &v, <span class="keyword">const</span> Sparse_Mat<T> &m) |
---|
826 | <a name="l00909"></a>00909 { |
---|
827 | <a name="l00910"></a>00910 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(v.size() == m.n_rows, <span class="stringliteral">"Vec<T> * Sparse_Mat<T>"</span>); |
---|
828 | <a name="l00911"></a>00911 |
---|
829 | <a name="l00912"></a>00912 Vec<T> r(m.n_cols); |
---|
830 | <a name="l00913"></a>00913 r.clear(); |
---|
831 | <a name="l00914"></a>00914 |
---|
832 | <a name="l00915"></a>00915 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < m.n_cols; c++) |
---|
833 | <a name="l00916"></a>00916 r[c] = v * m.col[c]; |
---|
834 | <a name="l00917"></a>00917 |
---|
835 | <a name="l00918"></a>00918 <span class="keywordflow">return</span> r; |
---|
836 | <a name="l00919"></a>00919 } |
---|
837 | <a name="l00920"></a>00920 |
---|
838 | <a name="l00921"></a>00921 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
839 | <a name="l00922"></a>00922 Mat<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m) |
---|
840 | <a name="l00923"></a>00923 { |
---|
841 | <a name="l00924"></a>00924 Mat<T> ret(m.n_cols, m.n_cols); |
---|
842 | <a name="l00925"></a>00925 Vec<T> col; |
---|
843 | <a name="l00926"></a>00926 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < ret.cols(); c++) { |
---|
844 | <a name="l00927"></a>00927 m.col[c].full(col); |
---|
845 | <a name="l00928"></a>00928 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < c; r++) { |
---|
846 | <a name="l00929"></a>00929 T tmp = m.col[r] * col; |
---|
847 | <a name="l00930"></a>00930 ret(r, c) = tmp; |
---|
848 | <a name="l00931"></a>00931 ret(c, r) = tmp; |
---|
849 | <a name="l00932"></a>00932 } |
---|
850 | <a name="l00933"></a>00933 ret(c, c) = m.col[c].sqr(); |
---|
851 | <a name="l00934"></a>00934 } |
---|
852 | <a name="l00935"></a>00935 |
---|
853 | <a name="l00936"></a>00936 <span class="keywordflow">return</span> ret; |
---|
854 | <a name="l00937"></a>00937 } |
---|
855 | <a name="l00938"></a>00938 |
---|
856 | <a name="l00939"></a>00939 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
857 | <a name="l00940"></a>00940 Sparse_Mat<T> trans_mult_s(<span class="keyword">const</span> Sparse_Mat<T> &m) |
---|
858 | <a name="l00941"></a>00941 { |
---|
859 | <a name="l00942"></a>00942 Sparse_Mat<T> ret(m.n_cols, m.n_cols); |
---|
860 | <a name="l00943"></a>00943 Vec<T> col; |
---|
861 | <a name="l00944"></a>00944 T tmp; |
---|
862 | <a name="l00945"></a>00945 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < ret.n_cols; c++) { |
---|
863 | <a name="l00946"></a>00946 m.col[c].full(col); |
---|
864 | <a name="l00947"></a>00947 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < c; r++) { |
---|
865 | <a name="l00948"></a>00948 tmp = m.col[r] * col; |
---|
866 | <a name="l00949"></a>00949 <span class="keywordflow">if</span> (tmp != T(0)) { |
---|
867 | <a name="l00950"></a>00950 ret.col[c].set_new(r, tmp); |
---|
868 | <a name="l00951"></a>00951 ret.col[r].set_new(c, tmp); |
---|
869 | <a name="l00952"></a>00952 } |
---|
870 | <a name="l00953"></a>00953 } |
---|
871 | <a name="l00954"></a>00954 tmp = m.col[c].sqr(); |
---|
872 | <a name="l00955"></a>00955 <span class="keywordflow">if</span> (tmp != T(0)) |
---|
873 | <a name="l00956"></a>00956 ret.col[c].set_new(c, tmp); |
---|
874 | <a name="l00957"></a>00957 } |
---|
875 | <a name="l00958"></a>00958 |
---|
876 | <a name="l00959"></a>00959 <span class="keywordflow">return</span> ret; |
---|
877 | <a name="l00960"></a>00960 } |
---|
878 | <a name="l00961"></a>00961 |
---|
879 | <a name="l00962"></a>00962 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
880 | <a name="l00963"></a>00963 Sparse_Mat<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2) |
---|
881 | <a name="l00964"></a>00964 { |
---|
882 | <a name="l00965"></a>00965 <a class="code" href="group__errorhandlingfunc.html#gb319550e696ee9d824d23c2a176bc3a6" title="Abort if t is not true and NDEBUG is not defined.">it_assert_debug</a>(m1.n_rows == m2.n_rows, <span class="stringliteral">"trans_mult()"</span>); |
---|
883 | <a name="l00966"></a>00966 |
---|
884 | <a name="l00967"></a>00967 Sparse_Mat<T> ret(m1.n_cols, m2.n_cols); |
---|
885 | <a name="l00968"></a>00968 Vec<T> col; |
---|
886 | <a name="l00969"></a>00969 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < ret.n_cols; c++) { |
---|
887 | <a name="l00970"></a>00970 m2.col[c].full(col); |
---|
888 | <a name="l00971"></a>00971 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < ret.n_rows; r++) |
---|
889 | <a name="l00972"></a>00972 ret.col[c].set_new(r, m1.col[r] * col); |
---|
890 | <a name="l00973"></a>00973 } |
---|
891 | <a name="l00974"></a>00974 |
---|
892 | <a name="l00975"></a>00975 <span class="keywordflow">return</span> ret; |
---|
893 | <a name="l00976"></a>00976 } |
---|
894 | <a name="l00977"></a>00977 |
---|
895 | <a name="l00978"></a>00978 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
896 | <a name="l00979"></a>00979 Vec<T> trans_mult(<span class="keyword">const</span> Sparse_Mat<T> &m, <span class="keyword">const</span> Vec<T> &v) |
---|
897 | <a name="l00980"></a>00980 { |
---|
898 | <a name="l00981"></a>00981 Vec<T> r(m.n_cols); |
---|
899 | <a name="l00982"></a>00982 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = 0; c < m.n_cols; c++) |
---|
900 | <a name="l00983"></a>00983 r(c) = m.col[c] * v; |
---|
901 | <a name="l00984"></a>00984 |
---|
902 | <a name="l00985"></a>00985 <span class="keywordflow">return</span> r; |
---|
903 | <a name="l00986"></a>00986 } |
---|
904 | <a name="l00987"></a>00987 |
---|
905 | <a name="l00988"></a>00988 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
906 | <a name="l00989"></a>00989 Sparse_Mat<T> mult_trans(<span class="keyword">const</span> Sparse_Mat<T> &m1, <span class="keyword">const</span> Sparse_Mat<T> &m2) |
---|
907 | <a name="l00990"></a>00990 { |
---|
908 | <a name="l00991"></a>00991 <span class="keywordflow">return</span> trans_mult(m1.transpose(), m2.transpose()); |
---|
909 | <a name="l00992"></a>00992 } |
---|
910 | <a name="l00993"></a>00993 |
---|
911 | <a name="l00995"></a>00995 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
912 | <a name="l00996"></a>00996 <span class="keyword">inline</span> Sparse_Mat<T> sparse(<span class="keyword">const</span> Mat<T> &m, T epsilon) |
---|
913 | <a name="l00997"></a>00997 { |
---|
914 | <a name="l00998"></a>00998 Sparse_Mat<T> s(m, epsilon); |
---|
915 | <a name="l00999"></a>00999 <span class="keywordflow">return</span> s; |
---|
916 | <a name="l01000"></a>01000 } |
---|
917 | <a name="l01001"></a>01001 |
---|
918 | <a name="l01003"></a>01003 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
919 | <a name="l01004"></a>01004 <span class="keyword">inline</span> Mat<T> full(<span class="keyword">const</span> Sparse_Mat<T> &s) |
---|
920 | <a name="l01005"></a>01005 { |
---|
921 | <a name="l01006"></a>01006 Mat<T> m; |
---|
922 | <a name="l01007"></a>01007 s.full(m); |
---|
923 | <a name="l01008"></a>01008 <span class="keywordflow">return</span> m; |
---|
924 | <a name="l01009"></a>01009 } |
---|
925 | <a name="l01010"></a>01010 |
---|
926 | <a name="l01012"></a>01012 <span class="keyword">template</span> <<span class="keyword">class</span> T> |
---|
927 | <a name="l01013"></a>01013 <span class="keyword">inline</span> Sparse_Mat<T> <a class="code" href="group__matrix__functions.html#g22c587fbc615e295f2b881c2e5025006" title="Transposition of the matrix m returning the transposed matrix in out.">transpose</a>(<span class="keyword">const</span> Sparse_Mat<T> &s) |
---|
928 | <a name="l01014"></a>01014 { |
---|
929 | <a name="l01015"></a>01015 Sparse_Mat<T> m; |
---|
930 | <a name="l01016"></a>01016 s.transpose(m); |
---|
931 | <a name="l01017"></a>01017 <span class="keywordflow">return</span> m; |
---|
932 | <a name="l01018"></a>01018 } |
---|
933 | <a name="l01019"></a>01019 |
---|
934 | <a name="l01021"></a>01021 |
---|
935 | <a name="l01022"></a>01022 <span class="comment">// ---------------------------------------------------------------------</span> |
---|
936 | <a name="l01023"></a>01023 <span class="comment">// Instantiations</span> |
---|
937 | <a name="l01024"></a>01024 <span class="comment">// ---------------------------------------------------------------------</span> |
---|
938 | <a name="l01025"></a>01025 |
---|
939 | <a name="l01026"></a>01026 <span class="preprocessor">#ifdef HAVE_EXTERN_TEMPLATE</span> |
---|
940 | <a name="l01027"></a>01027 <span class="preprocessor"></span> |
---|
941 | <a name="l01028"></a>01028 <span class="keyword">extern</span> <span class="keyword">template</span> <span class="keyword">class </span>Sparse_Mat<int>; |
---|
942 | <a name="l01029"></a>01029 <span class="keyword">extern</span> <span class="keyword">template</span> <span class="keyword">class </span>Sparse_Mat<double>; |
---|
943 | <a name="l01030"></a>01030 <span class="keyword">extern</span> <span class="keyword">template</span> <span class="keyword">class </span>Sparse_Mat<std::complex<double> >; |
---|
944 | <a name="l01031"></a>01031 |
---|
945 | <a name="l01032"></a>01032 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_imat <a class="code" href="group__fixed.html#g683d6c037357e472e84756fe1b1faae8" title="Fix + cfixmat.">operator+</a>(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> sparse_imat &); |
---|
946 | <a name="l01033"></a>01033 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_mat <a class="code" href="group__fixed.html#g683d6c037357e472e84756fe1b1faae8" title="Fix + cfixmat.">operator+</a>(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> sparse_mat &); |
---|
947 | <a name="l01034"></a>01034 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_cmat <a class="code" href="group__fixed.html#g683d6c037357e472e84756fe1b1faae8" title="Fix + cfixmat.">operator+</a>(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> sparse_cmat &); |
---|
948 | <a name="l01035"></a>01035 |
---|
949 | <a name="l01036"></a>01036 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_imat <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> sparse_imat &); |
---|
950 | <a name="l01037"></a>01037 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_mat <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> sparse_mat &); |
---|
951 | <a name="l01038"></a>01038 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_cmat <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> sparse_cmat &); |
---|
952 | <a name="l01039"></a>01039 |
---|
953 | <a name="l01040"></a>01040 <span class="keyword">extern</span> <span class="keyword">template</span> ivec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> ivec &, <span class="keyword">const</span> sparse_imat &); |
---|
954 | <a name="l01041"></a>01041 <span class="keyword">extern</span> <span class="keyword">template</span> vec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> vec &, <span class="keyword">const</span> sparse_mat &); |
---|
955 | <a name="l01042"></a>01042 <span class="keyword">extern</span> <span class="keyword">template</span> cvec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> cvec &, <span class="keyword">const</span> sparse_cmat &); |
---|
956 | <a name="l01043"></a>01043 |
---|
957 | <a name="l01044"></a>01044 <span class="keyword">extern</span> <span class="keyword">template</span> ivec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> ivec &); |
---|
958 | <a name="l01045"></a>01045 <span class="keyword">extern</span> <span class="keyword">template</span> vec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> vec &); |
---|
959 | <a name="l01046"></a>01046 <span class="keyword">extern</span> <span class="keyword">template</span> cvec <a class="code" href="group__fixed.html#g8bb80689611f7b6b0e36f5507d990af7" title="Fix * cfixmat.">operator*</a>(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> cvec &); |
---|
960 | <a name="l01047"></a>01047 |
---|
961 | <a name="l01048"></a>01048 <span class="keyword">extern</span> <span class="keyword">template</span> imat trans_mult(<span class="keyword">const</span> sparse_imat &); |
---|
962 | <a name="l01049"></a>01049 <span class="keyword">extern</span> <span class="keyword">template</span> mat trans_mult(<span class="keyword">const</span> sparse_mat &); |
---|
963 | <a name="l01050"></a>01050 <span class="keyword">extern</span> <span class="keyword">template</span> cmat trans_mult(<span class="keyword">const</span> sparse_cmat &); |
---|
964 | <a name="l01051"></a>01051 |
---|
965 | <a name="l01052"></a>01052 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_imat trans_mult_s(<span class="keyword">const</span> sparse_imat &); |
---|
966 | <a name="l01053"></a>01053 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_mat trans_mult_s(<span class="keyword">const</span> sparse_mat &); |
---|
967 | <a name="l01054"></a>01054 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_cmat trans_mult_s(<span class="keyword">const</span> sparse_cmat &); |
---|
968 | <a name="l01055"></a>01055 |
---|
969 | <a name="l01056"></a>01056 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_imat trans_mult(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> sparse_imat &); |
---|
970 | <a name="l01057"></a>01057 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_mat trans_mult(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> sparse_mat &); |
---|
971 | <a name="l01058"></a>01058 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_cmat trans_mult(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> sparse_cmat &); |
---|
972 | <a name="l01059"></a>01059 |
---|
973 | <a name="l01060"></a>01060 <span class="keyword">extern</span> <span class="keyword">template</span> ivec trans_mult(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> ivec &); |
---|
974 | <a name="l01061"></a>01061 <span class="keyword">extern</span> <span class="keyword">template</span> vec trans_mult(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> vec &); |
---|
975 | <a name="l01062"></a>01062 <span class="keyword">extern</span> <span class="keyword">template</span> cvec trans_mult(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> cvec &); |
---|
976 | <a name="l01063"></a>01063 |
---|
977 | <a name="l01064"></a>01064 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_imat mult_trans(<span class="keyword">const</span> sparse_imat &, <span class="keyword">const</span> sparse_imat &); |
---|
978 | <a name="l01065"></a>01065 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_mat mult_trans(<span class="keyword">const</span> sparse_mat &, <span class="keyword">const</span> sparse_mat &); |
---|
979 | <a name="l01066"></a>01066 <span class="keyword">extern</span> <span class="keyword">template</span> sparse_cmat mult_trans(<span class="keyword">const</span> sparse_cmat &, <span class="keyword">const</span> sparse_cmat &); |
---|
980 | <a name="l01067"></a>01067 |
---|
981 | <a name="l01068"></a>01068 <span class="preprocessor">#endif // HAVE_EXTERN_TEMPLATE</span> |
---|
982 | <a name="l01069"></a>01069 <span class="preprocessor"></span> |
---|
983 | <a name="l01071"></a>01071 |
---|
984 | <a name="l01072"></a>01072 } <span class="comment">// namespace itpp</span> |
---|
985 | <a name="l01073"></a>01073 |
---|
986 | <a name="l01074"></a>01074 <span class="preprocessor">#endif // #ifndef SMAT_H</span> |
---|
987 | <a name="l01075"></a>01075 <span class="preprocessor"></span> |
---|
988 | </pre></div></div> |
---|
989 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:13 2009 for mixpp by |
---|
990 | <a href="http://www.doxygen.org/index.html"> |
---|
991 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
992 | </body> |
---|
993 | </html> |
---|