MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

abstract.h
1 //
2 // abstract.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27
28 #ifndef _math_scmat_abstract_h
29 #define _math_scmat_abstract_h
30
31 #ifdef __GNUC__
32 #pragma interface
33 #endif
34
35 #include <util/group/message.h>
36
37 #include <util/state/state.h>
38 #include <math/scmat/dim.h>
39 #include <math/scmat/block.h>
40 #include <iostream>
41
42 namespace sc {
43
44 class SCMatrix;
45 class SymmSCMatrix;
46 class DiagSCMatrix;
47 class SCVector;
48
49 class SCElementOp;
50 class SCElementOp2;
51 class SCElementOp3;
52
53 class RefSCDimension;
54
58 class SCMatrixKit: public DescribedClass {
59 protected:
60 Ref<MessageGrp> grp_;
61
62 public:
63 SCMatrixKit();
64 SCMatrixKit(const Ref<KeyVal>&);
65 ~SCMatrixKit();
66
67 // these members are default in local.cc
70 static SCMatrixKit* default_matrixkit();
71 static void set_default_matrixkit(const Ref<SCMatrixKit> &);
72
73 Ref<MessageGrp> messagegrp() const;
74
76 virtual SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&) = 0;
77 virtual SymmSCMatrix* symmmatrix(const RefSCDimension&) = 0;
78 virtual DiagSCMatrix* diagmatrix(const RefSCDimension&) = 0;
79 virtual SCVector* vector(const RefSCDimension&) = 0;
80
83 SCMatrix* restore_matrix(StateIn&,
84 const RefSCDimension&,
85 const RefSCDimension&);
86 SymmSCMatrix* restore_symmmatrix(StateIn&,
87 const RefSCDimension&);
88 DiagSCMatrix* restore_diagmatrix(StateIn&,
89 const RefSCDimension&);
90 SCVector* restore_vector(StateIn&,
91 const RefSCDimension&);
92 };
93
94
97 class SCVector: public DescribedClass {
98 protected:
99 RefSCDimension d;
100 Ref<SCMatrixKit> kit_;
101 public:
102 SCVector(const RefSCDimension&, SCMatrixKit *);
103
105 virtual void save(StateOut&);
106 virtual void restore(StateIn&);
107
109 Ref<SCMatrixKit> kit() const { return kit_; }
110
111 // concrete functions (some can be overridden)
113 virtual SCVector* copy();
115 virtual SCVector* clone();
116
117 virtual ~SCVector();
119 int n() const { return d->n(); }
121 virtual double maxabs() const;
123 virtual void normalize();
125 virtual void randomize();
127 void assign(double val) { assign_val(val); }
129 void assign(const double* v) { assign_p(v); }
132 void assign(SCVector* v) { assign_v(v); }
134 virtual void assign_val(double val);
135 virtual void assign_p(const double* v);
136 virtual void assign_v(SCVector *v);
138 virtual void convert(double* v) const;
141 virtual void convert(SCVector*);
142 virtual void convert_accumulate(SCVector*);
144 virtual void scale(double val);
145
147 RefSCDimension dim() const { return d; }
149 virtual void set_element(int i,double val) = 0;
151 virtual void accumulate_element(int,double) = 0;
153 virtual double get_element(int i) const = 0;
155 void accumulate_product(SymmSCMatrix* m, SCVector* v)
156 { accumulate_product_sv(m,v); }
157 void accumulate_product(SCMatrix* m, SCVector* v)
158 { accumulate_product_rv(m,v); }
159 virtual void accumulate_product_sv(SymmSCMatrix* m, SCVector* v);
160 virtual void accumulate_product_rv(SCMatrix* m, SCVector* v) = 0;
162 virtual void accumulate(const SCVector*v) = 0;
164 virtual void accumulate(const SCMatrix*m) = 0;
166 virtual double scalar_product(SCVector*) = 0;
168 virtual void element_op(const Ref<SCElementOp>&) = 0;
169 virtual void element_op(const Ref<SCElementOp2>&,
170 SCVector*) = 0;
171 virtual void element_op(const Ref<SCElementOp3>&,
172 SCVector*,SCVector*) = 0;
174 void print(std::ostream&o=ExEnv::out0()) const;
175 void print(const char* title=0,std::ostream&out=ExEnv::out0(),int=10) const;
176 virtual void vprint(const char*title=0,std::ostream&out=ExEnv::out0(),
177 int=10) const = 0;
178
180 Ref<MessageGrp> messagegrp() const;
181
186 virtual Ref<SCMatrixSubblockIter> local_blocks(
187 SCMatrixSubblockIter::Access) = 0;
189 virtual Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access) = 0;
190 };
191
195 class SCMatrix: public DescribedClass {
196 protected:
197 RefSCDimension d1,d2;
198 Ref<SCMatrixKit> kit_;
199 public:
200 // used to control transformations
201 enum Transform { NormalTransform = 0, TransposeTransform = 1 };
202
203 // concrete functions (some can be overridden)
204 SCMatrix(const RefSCDimension&, const RefSCDimension&, SCMatrixKit *);
205 virtual ~SCMatrix();
206
208 virtual void save(StateOut&);
209 virtual void restore(StateIn&);
210
212 Ref<SCMatrixKit> kit() const { return kit_; }
213
215 int nrow() const { return d1->n(); }
217 int ncol() const { return d2->n(); }
219 virtual double maxabs() const;
221 virtual void randomize();
223 void assign(double val) { assign_val(val); }
225 void assign(const double* m) { assign_p(m); }
227 void assign(const double** m) { assign_pp(m); }
229 void assign(SCMatrix* m) { assign_r(m); }
231 virtual void assign_val(double val);
232 virtual void assign_p(const double* m);
233 virtual void assign_pp(const double** m);
234 virtual void assign_r(SCMatrix* m);
237 virtual void convert(double*) const;
238 virtual void convert(double**) const;
241 virtual void convert(SCMatrix*);
242 virtual void convert_accumulate(SCMatrix*);
244 virtual void scale(double val);
246 virtual void scale_diagonal(double val);
248 virtual void shift_diagonal(double val);
250 virtual void unit();
252 virtual SCMatrix* copy();
254 virtual SCMatrix* clone();
255
256 // pure virtual functions
258 RefSCDimension rowdim() const { return d1; }
259 RefSCDimension coldim() const { return d2; }
261 virtual double get_element(int,int) const = 0;
262 virtual void set_element(int,int,double) = 0;
263 virtual void accumulate_element(int,int,double) = 0;
264
268 virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
269
271 virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0) =0;
272
274 virtual void accumulate_subblock(SCMatrix *m, int, int, int, int, int=0,int=0) =0;
275
277 virtual SCVector * get_row(int i) =0;
278 virtual SCVector * get_column(int i) =0;
279
281 virtual void assign_row(SCVector *v, int i) =0;
282 virtual void assign_column(SCVector *v, int i) =0;
283
285 virtual void accumulate_row(SCVector *v, int i) =0;
286 virtual void accumulate_column(SCVector *v, int i) =0;
287
289 virtual void accumulate(const SCMatrix* m) = 0;
290 virtual void accumulate(const SymmSCMatrix* m) = 0;
291 virtual void accumulate(const DiagSCMatrix* m) = 0;
292 virtual void accumulate(const SCVector*) = 0;
294 virtual void accumulate_outer_product(SCVector*,SCVector*) = 0;
295 void accumulate_product(SCMatrix*m1,SCMatrix*m2)
296 { accumulate_product_rr(m1,m2); }
297 void accumulate_product(SCMatrix*m1,SymmSCMatrix*m2)
298 { accumulate_product_rs(m1,m2); }
299 void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
300 { accumulate_product_rd(m1,m2); }
301 void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
302 { accumulate_product_sr(m1,m2); }
303 void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
304 { accumulate_product_dr(m1,m2); }
305 void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
306 { accumulate_product_ss(m1,m2); }
307 virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
308 virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
309 virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
310 virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
311 virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
312 virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
314 virtual void transpose_this() = 0;
316 virtual double trace() =0;
318 virtual double invert_this() = 0;
320 virtual double determ_this() = 0;
321
324 virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
325 virtual double solve_this(SCVector*) = 0;
326 virtual void gen_invert_this();
327
330 virtual void schmidt_orthog(SymmSCMatrix*, int n) =0;
331
335 virtual int schmidt_orthog_tol(SymmSCMatrix*, double tol, double*res=0)=0;
336
338 virtual void element_op(const Ref<SCElementOp>&) = 0;
339 virtual void element_op(const Ref<SCElementOp2>&,
340 SCMatrix*) = 0;
341 virtual void element_op(const Ref<SCElementOp3>&,
342 SCMatrix*,SCMatrix*) = 0;
344 void print(std::ostream&o=ExEnv::out0()) const;
345 void print(const char* title=0,std::ostream& out=ExEnv::out0(),
346 int =10) const;
347 virtual void vprint(const char*title=0,
348 std::ostream&out=ExEnv::out0(),int =10) const = 0;
349
351 Ref<MessageGrp> messagegrp() const;
352
355 virtual Ref<SCMatrixSubblockIter> local_blocks(
356 SCMatrixSubblockIter::Access) = 0;
358 virtual Ref<SCMatrixSubblockIter> all_blocks(
359 SCMatrixSubblockIter::Access) = 0;
360 };
361
364 class SymmSCMatrix: public DescribedClass {
365 protected:
366 RefSCDimension d;
367 Ref<SCMatrixKit> kit_;
368 public:
369 SymmSCMatrix(const RefSCDimension&, SCMatrixKit *);
370 ~SymmSCMatrix();
371
373 Ref<SCMatrixKit> kit() const { return kit_; }
374
376 virtual void save(StateOut&);
377 virtual void restore(StateIn&);
379 virtual double maxabs() const;
381 virtual void randomize();
383 void assign(double val) { assign_val(val); }
385 void assign(const double* m) { assign_p(m); }
387 void assign(const double** m) { assign_pp(m); }
390 void assign(SymmSCMatrix* m) { assign_s(m); }
392 virtual void assign_val(double val);
393 virtual void assign_p(const double* m);
394 virtual void assign_pp(const double** m);
395 virtual void assign_s(SymmSCMatrix* m);
397 virtual void convert(double*) const;
398 virtual void convert(double**) const;
401 virtual void convert(SymmSCMatrix*);
402 virtual void convert_accumulate(SymmSCMatrix*);
404 virtual void scale(double);
406 virtual void scale_diagonal(double);
408 virtual void shift_diagonal(double);
410 virtual void unit();
412 int n() const { return d->n(); }
414 virtual SymmSCMatrix* copy();
416 virtual SymmSCMatrix* clone();
417
418 // pure virtual functions
420 RefSCDimension dim() const { return d; }
422 virtual double get_element(int,int) const = 0;
423 virtual void set_element(int,int,double) = 0;
424 virtual void accumulate_element(int,int,double) = 0;
425
429 virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
430 virtual SymmSCMatrix * get_subblock(int br, int er) =0;
431
433 virtual void assign_subblock(SCMatrix *m, int, int, int, int) =0;
434 virtual void assign_subblock(SymmSCMatrix *m, int, int) =0;
435
437 virtual void accumulate_subblock(SCMatrix *m, int, int, int, int) =0;
438 virtual void accumulate_subblock(SymmSCMatrix *m, int, int) =0;
439
441 virtual SCVector * get_row(int i) =0;
442
444 virtual void assign_row(SCVector *v, int i) =0;
445
447 virtual void accumulate_row(SCVector *v, int i) =0;
448
451 virtual void diagonalize(DiagSCMatrix*d,SCMatrix*m) = 0;
453 virtual void accumulate(const SymmSCMatrix* m) = 0;
455 virtual void accumulate_symmetric_sum(SCMatrix*) = 0;
456 virtual void accumulate_symmetric_product(SCMatrix*);
457 virtual void accumulate_transform(SCMatrix*,SymmSCMatrix*,
458 SCMatrix::Transform = SCMatrix::NormalTransform);
459 virtual void accumulate_transform(SCMatrix*,DiagSCMatrix*,
460 SCMatrix::Transform = SCMatrix::NormalTransform);
461 virtual void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
462 virtual void accumulate_symmetric_outer_product(SCVector*);
465 virtual double scalar_product(SCVector* v);
467 virtual double trace() = 0;
469 virtual double invert_this() = 0;
471 virtual double determ_this() = 0;
472
473 virtual double solve_this(SCVector*) = 0;
474 virtual void gen_invert_this() = 0;
475
477 virtual void element_op(const Ref<SCElementOp>&) = 0;
478 virtual void element_op(const Ref<SCElementOp2>&,
479 SymmSCMatrix*) = 0;
480 virtual void element_op(const Ref<SCElementOp3>&,
481 SymmSCMatrix*,SymmSCMatrix*) = 0;
483 void print(std::ostream&o=ExEnv::out0()) const;
484 void print(const char* title=0,std::ostream& out=ExEnv::out0(),
485 int =10) const;
486 virtual void vprint(const char* title=0,
487 std::ostream& out=ExEnv::out0(), int =10) const;
488
490 Ref<MessageGrp> messagegrp() const;
491
494 virtual Ref<SCMatrixSubblockIter> local_blocks(
495 SCMatrixSubblockIter::Access) = 0;
497 virtual Ref<SCMatrixSubblockIter> all_blocks(
498 SCMatrixSubblockIter::Access) = 0;
499 };
500
503 class DiagSCMatrix: public DescribedClass {
504 protected:
505 RefSCDimension d;
506 Ref<SCMatrixKit> kit_;
507 public:
508 DiagSCMatrix(const RefSCDimension&, SCMatrixKit *);
509 ~DiagSCMatrix();
510
512 Ref<SCMatrixKit> kit() const { return kit_; }
513
515 virtual void save(StateOut&);
516 virtual void restore(StateIn&);
517
519 virtual double maxabs() const;
521 virtual void randomize();
523 void assign(double val) { assign_val(val); }
525 void assign(const double*p) { assign_p(p); }
528 void assign(DiagSCMatrix*d_a) { assign_d(d_a); }
530 virtual void assign_val(double val);
531 virtual void assign_p(const double*);
532 virtual void assign_d(DiagSCMatrix*);
534 virtual void convert(double*) const;
537 virtual void convert(DiagSCMatrix*);
538 virtual void convert_accumulate(DiagSCMatrix*);
540 virtual void scale(double);
542 int n() const { return d->n(); }
544 virtual DiagSCMatrix* copy();
546 virtual DiagSCMatrix* clone();
547
548 // pure virtual functions
550 RefSCDimension dim() const { return d; }
552 virtual double get_element(int) const = 0;
553 virtual void set_element(int,double) = 0;
554 virtual void accumulate_element(int,double) = 0;
556 virtual void accumulate(const DiagSCMatrix* m) = 0;
558 virtual double trace() = 0;
560 virtual double determ_this() = 0;
562 virtual double invert_this() = 0;
564 virtual void gen_invert_this() = 0;
566 virtual void element_op(const Ref<SCElementOp>&) = 0;
567 virtual void element_op(const Ref<SCElementOp2>&,
568 DiagSCMatrix*) = 0;
569 virtual void element_op(const Ref<SCElementOp3>&,
570 DiagSCMatrix*,DiagSCMatrix*) = 0;
572 void print(std::ostream&o=ExEnv::out0()) const;
573 void print(const char* title=0,
574 std::ostream& out=ExEnv::out0(), int =10) const;
575 virtual void vprint(const char* title=0,
576 std::ostream& out=ExEnv::out0(), int =10) const;
577
579 Ref<MessageGrp> messagegrp() const;
580
583 virtual Ref<SCMatrixSubblockIter> local_blocks(
584 SCMatrixSubblockIter::Access) = 0;
586 virtual Ref<SCMatrixSubblockIter> all_blocks(
587 SCMatrixSubblockIter::Access) = 0;
588 };
589
590 }
591
592 #endif
593
594 // Local Variables:
595 // mode: c++
596 // c-file-style: "CLJ"
597 // End: