comparison liboctave/sparse-dmsolve.cc @ 10350:12884915a8e4

merge MArray classes & improve Array interface
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 23 Jan 2010 21:41:03 +0100
parents 07ebe522dac2
children fd0a3ac60b0e
comparison
equal deleted inserted replaced
10349:d4d13389c957 10350:12884915a8e4
24 #include <config.h> 24 #include <config.h>
25 #endif 25 #endif
26 26
27 #include <vector> 27 #include <vector>
28 28
29 #include "MArray2.h" 29 #include "MArray.h"
30 #include "MSparse.h" 30 #include "MSparse.h"
31 #include "SparseQR.h" 31 #include "SparseQR.h"
32 #include "SparseCmplxQR.h" 32 #include "SparseCmplxQR.h"
33 #include "MatrixType.h" 33 #include "MatrixType.h"
34 #include "oct-sort.h" 34 #include "oct-sort.h"
114 octave_idx_type cend, octave_idx_type maxnz, 114 octave_idx_type cend, octave_idx_type maxnz,
115 bool lazy); 115 bool lazy);
116 #endif 116 #endif
117 117
118 template <class T> 118 template <class T>
119 static MArray2<T> 119 static MArray<T>
120 dmsolve_extract (const MArray2<T> &m, const octave_idx_type *, 120 dmsolve_extract (const MArray<T> &m, const octave_idx_type *,
121 const octave_idx_type *, octave_idx_type r1, 121 const octave_idx_type *, octave_idx_type r1,
122 octave_idx_type r2, octave_idx_type c1, 122 octave_idx_type r2, octave_idx_type c1,
123 octave_idx_type c2) 123 octave_idx_type c2)
124 { 124 {
125 r2 -= 1; 125 r2 -= 1;
128 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } 128 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; }
129 129
130 octave_idx_type new_r = r2 - r1 + 1; 130 octave_idx_type new_r = r2 - r1 + 1;
131 octave_idx_type new_c = c2 - c1 + 1; 131 octave_idx_type new_c = c2 - c1 + 1;
132 132
133 MArray2<T> result (new_r, new_c); 133 MArray<T> result (new_r, new_c);
134 134
135 for (octave_idx_type j = 0; j < new_c; j++) 135 for (octave_idx_type j = 0; j < new_c; j++)
136 for (octave_idx_type i = 0; i < new_r; i++) 136 for (octave_idx_type i = 0; i < new_r; i++)
137 result.xelem (i, j) = m.elem (r1+i, c1+j); 137 result.xelem (i, j) = m.elem (r1+i, c1+j);
138 138
139 return result; 139 return result;
140 } 140 }
141 141
142 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) 142 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
143 static MArray2<double> 143 static MArray<double>
144 dmsolve_extract (const MArray2<double> &m, const octave_idx_type *, 144 dmsolve_extract (const MArray<double> &m, const octave_idx_type *,
145 const octave_idx_type *, octave_idx_type r1, 145 const octave_idx_type *, octave_idx_type r1,
146 octave_idx_type r2, octave_idx_type c1, 146 octave_idx_type r2, octave_idx_type c1,
147 octave_idx_type c2) 147 octave_idx_type c2)
148 148
149 static MArray2<Complex> 149 static MArray<Complex>
150 dmsolve_extract (const MArray2<Complex> &m, const octave_idx_type *, 150 dmsolve_extract (const MArray<Complex> &m, const octave_idx_type *,
151 const octave_idx_type *, octave_idx_type r1, 151 const octave_idx_type *, octave_idx_type r1,
152 octave_idx_type r2, octave_idx_type c1, 152 octave_idx_type r2, octave_idx_type c1,
153 octave_idx_type c2) 153 octave_idx_type c2)
154 #endif 154 #endif
155 155
156 template <class T> 156 template <class T>
157 static void 157 static void
158 dmsolve_insert (MArray2<T> &a, const MArray2<T> &b, const octave_idx_type *Q, 158 dmsolve_insert (MArray<T> &a, const MArray<T> &b, const octave_idx_type *Q,
159 octave_idx_type r, octave_idx_type c) 159 octave_idx_type r, octave_idx_type c)
160 { 160 {
161 T *ax = a.fortran_vec(); 161 T *ax = a.fortran_vec();
162 const T *bx = b.fortran_vec(); 162 const T *bx = b.fortran_vec();
163 octave_idx_type anr = a.rows(); 163 octave_idx_type anr = a.rows();
175 } 175 }
176 } 176 }
177 177
178 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) 178 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
179 static void 179 static void
180 dmsolve_insert (MArray2<double> &a, const MArray2<double> &b, 180 dmsolve_insert (MArray<double> &a, const MArray<double> &b,
181 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); 181 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c);
182 182
183 static void 183 static void
184 dmsolve_insert (MArray2<Complex> &a, const MArray2<Complex> &b, 184 dmsolve_insert (MArray<Complex> &a, const MArray<Complex> &b,
185 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); 185 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c);
186 #endif 186 #endif
187 187
188 template <class T> 188 template <class T>
189 static void 189 static void
272 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); 272 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c);
273 #endif 273 #endif
274 274
275 template <class T, class RT> 275 template <class T, class RT>
276 static void 276 static void
277 dmsolve_permute (MArray2<RT> &a, const MArray2<T>& b, const octave_idx_type *p) 277 dmsolve_permute (MArray<RT> &a, const MArray<T>& b, const octave_idx_type *p)
278 { 278 {
279 octave_idx_type b_nr = b.rows (); 279 octave_idx_type b_nr = b.rows ();
280 octave_idx_type b_nc = b.cols (); 280 octave_idx_type b_nc = b.cols ();
281 const T *Bx = b.fortran_vec(); 281 const T *Bx = b.fortran_vec();
282 a.resize(b_nr, b_nc); 282 a.resize(b_nr, b_nc);
292 } 292 }
293 } 293 }
294 294
295 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) 295 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
296 static void 296 static void
297 dmsolve_permute (MArray2<double> &a, const MArray2<double>& b, 297 dmsolve_permute (MArray<double> &a, const MArray<double>& b,
298 const octave_idx_type *p); 298 const octave_idx_type *p);
299 299
300 static void 300 static void
301 dmsolve_permute (MArray2<Complex> &a, const MArray2<double>& b, 301 dmsolve_permute (MArray<Complex> &a, const MArray<double>& b,
302 const octave_idx_type *p); 302 const octave_idx_type *p);
303 303
304 static void 304 static void
305 dmsolve_permute (MArray2<Complex> &a, const MArray2<Complex>& b, 305 dmsolve_permute (MArray<Complex> &a, const MArray<Complex>& b,
306 const octave_idx_type *p); 306 const octave_idx_type *p);
307 #endif 307 #endif
308 308
309 template <class T, class RT> 309 template <class T, class RT>
310 static void 310 static void