UltraScan III
us_matrix.h
Go to the documentation of this file.
1 #ifndef US_MATRIX_H
3 #define US_MATRIX_H
4 
5 #include <QtCore>
6 #include "us_extern.h"
7 
15 {
16 public:
17 
25  static bool lsfit( double*, double*, double*, int, int );
26 
36  static bool Cholesky_Decomposition( double**, int );
37 
47  static bool Cholesky_SolveSystem( double**, double*, int );
48 
59  static bool Cholesky_Invert ( double**, double**, int );
60 
69  static void LU_SolveSystem ( double**, double*&, int );
70 
81  static void LU_Decomposition ( double**, int*, bool, int );
82 
94  static void LU_BackSubstitute( double**, double*&, int*, int );
95 
106  static double** construct( QVector< double* >&, QVector< double >&,
107  int, int );
108 
117  static void tmm( double**, double**, int, int );
118 
128  static void tmm( double**, double**, int, int, bool );
129 
139  static void mvv( double**, double*, double*, int, int );
140 
150  static void tvv( double**, double*, double*, int, int );
151 
162  static void mmm( double**, double**, double**, int, int, int );
163 
172  static void msum( double**, double**, double**, int, int );
173 
182  static void vsum( double*, double*, double*, int );
183 
189  static void mident( double**, int );
190 
198  static void mcopy( double**, double**, int, int );
199 
206  static void vcopy( double*, double*, int );
207 
214  static void add_diag( double**, double, int );
215 
223  static void add( double**, double, int, int );
224 
232  static void scale( double**, double, int, int );
233 
241  static double dotproduct( double*, double*, int );
242 
249  static double dotproduct( double*, int );
250 
251 private:
252  static void print_matrix( double**, int, int );
253  static void print_vector( double* , int );
254 };
255 
256 
257 #endif
258 
259 #ifdef NEVER
260 
261 /*
262 #include <iostream>
263 #include <math.h>
264 #include <qstring.h>
265 #include <qmessagebox.h>
266 #include "us_math.h"
267 #include "us_thread.h"
268 */
269 struct fpairs
270 {
271  int columnlocation;
272  float locationvalue;
273 };
274 
275 struct dpairs
276 {
277  int columnlocation;
278  double locationvalue;
279 };
280 
281 
282 
283 // multiply tri-diagonal matrix with vector
284 void m3vm(double ***, double **, unsigned int);
285 void m3vm(float ***, float **, unsigned int);
286 void m3vm(float ***, double **, unsigned int);
287 
288 #ifdef ADOLC
289 void m3vm(float ***, adouble **, unsigned int);
290 void m3vm(double ***, adouble **, unsigned int);
291 void m3vm(adouble ***, adouble **, unsigned int);
292 void m3vm_a(adouble ***, adouble **, unsigned int, float);
293 void m3vm_b(float ***, adouble ***, adouble **, unsigned int, float);
294 #endif
295 void m3vm_b(float ***, float ***, float **, unsigned int, float);
296 void m3vm_b(double ***, double ***, double **, unsigned int, double);
297 void m2vm(double ***, double **, int);
298 void m2vm(float ***, float **, int);
299 
300 #ifdef ADOLC
301 void m2vm(float ***, adouble **, int);
302 void m2vm(double ***, adouble **, int);
303 #endif
304 // multiply matrix with vector
305 
306 void mmv(float **, double **, float ***, int, int);
307 void mmv(float **, float **, float ***, int, int);
308 void mmv(float **, float **, double ***, int, int);
309 void mmv(float **, double **, double ***, int, int);
310 
311 void ldu(double ***, double **, unsigned int, unsigned int, bool);
312 void ldu(float ***, float **, unsigned int, unsigned int, bool);
313 
314 #ifdef ADOLC
315 void ldu(adouble ***, adouble **, unsigned int, unsigned int, bool);
316 void ldu(float ***, adouble **, unsigned int, unsigned int, bool);
317 #endif
318 
319 float dotproduct(float **, float **, int);
320 void vvt(float ***, float **, float **, int);
321 void LU_Decomposition(double **, int *, bool, int);
322 void LU_SolveSystem(double **, double **, int);
323 void LU_Invert(double **, double **, int);
324 void LU_BackSubstitute(double **, double **, int *, int);
325 bool Cholesky_Decomposition(double **, int);
326 bool Cholesky_SolveSystem(double **, double *, int);
327 bool Cholesky_Invert(double **, double **, int);
328 void generalLeastSquares(float **, unsigned int, unsigned int, float *, float **);
329 void print_matrix( double **, int, int);
330 void print_vector( double **, unsigned int, const char *);
331 void calc_A_transpose_A(double*** /*original matrix*/, double*** /*product matrix*/,
332  unsigned int /*rows*/, unsigned int /*columns*/, unsigned int /*threads*/);
333 void calc_A_transpose_A(float*** /*original matrix*/, float*** /*product matrix*/,
334 unsigned int /*rows*/, unsigned int /*columns*/);
335 void calc_matrix_times_matrix(double ***, double ***, double ***, unsigned int, unsigned int);
336 void calc_matrix_times_matrix(float ***, float ***, float ***, unsigned int, unsigned int);
337 void calc_matrix_times_vector(double ***, double **, double **, unsigned int, unsigned int);
338 void calc_matrix_times_vector(float ***, float **, float **, unsigned int, unsigned int);
339 double calc_vector_transpose_times_vector(unsigned int /*rows*/, double ** /*vector1*/, double ** /*vector2*/);
340 float calc_vector_transpose_times_vector(unsigned int /*rows*/, float ** /*vector1*/, float ** /*vector2*/);
341 
342 class US_lsfit
343 {
344 //
345 // Class to solve general linear least squares problem:
346 //
347 // MIN chi-square
348 //
349 public:
350 
351  US_lsfit(double *coeff, double *x, double *y, int n, int ord, bool mesg);
352 
353 //
354 // coeff returns the coefficients for best least-squares fit
355 // x contains the x values of the raw data
356 // y contains the y values of the raw data
357 // n contains the dimension of x and y
358 // ord is the order of the function to be fitted
359 //
360  ~US_lsfit();
361 
362 private:
363 
364  double **A, *b, *c, *xval, *yval;
365  int order, numpoints, i, j, k;
366  void calc_coeff_polynomial();
367 };
368 
369 
370 void conc_dep_s(float, double **, double **, double ***, float temp1, unsigned int points);
371 void conc_dep_s(float, float **, float **, float ***, float temp1, unsigned int points);
372 #ifdef ADOLC
373 void conc_dep_s(adouble, adouble **, adouble **, double ***, adouble, unsigned int points);
374 void conc_dep_s(adouble, adouble **, adouble **, float ***, adouble, unsigned int points);
375 #endif
376 void conc_dep_d(float, double **, double **, double ***, double ***, double ***,
377  float, unsigned int, double **, double **, double **);
378 void conc_dep_d(float, float **, float **, float ***, float ***, float ***,
379  float, unsigned int, float **, float **, float **);
380 #ifdef ADOLC
381 void conc_dep_d(adouble, adouble **, adouble **, float ***, float ***, float ***,
382  adouble, unsigned int, adouble **, adouble **, adouble **);
383 void conc_dep_d(adouble, adouble **, adouble **, double ***, double ***, double ***,
384  adouble, unsigned int, adouble **, adouble **, adouble **);
385 #endif
386 
387 #include <qthread.h>
388 #include <qwaitcondition.h>
389 #include <qmutex.h>
390 
391 class ata_d_thr_t : public QThread
392 {
393  public:
394  ata_d_thr_t(int);
395  void ata_d_thr_setup(unsigned int,
396  unsigned int,
397  unsigned int,
398  double ***,
399  vector <vector <dpairs> > *);
400 
401  void ata_d_thr_shutdown();
402  void ata_d_thr_wait();
403  virtual void run();
404 
405  private:
406  unsigned int columns;
407  unsigned int c_start;
408  unsigned int c_end;
409  double ***product;
410  vector <vector <dpairs> > *dataarray;
411 
412  int thread;
413  unsigned int i;
414  unsigned int j;
415  QMutex work_mutex;
416  int work_to_do;
417  QWaitCondition cond_work_to_do;
418  int work_done;
419  QWaitCondition cond_work_done;
420  int work_to_do_waiters;
421  int work_done_waiters;
422 };
423 
424 #endif
425