Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

abstract.h

00001 //
00002 // abstract.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _math_scmat_abstract_h
00029 #define _math_scmat_abstract_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <util/group/message.h>
00036 
00037 #include <util/state/state.h>
00038 #include <math/scmat/dim.h>
00039 #include <math/scmat/block.h>
00040 #include <iostream>
00041 
00042 namespace sc {
00043 
00044 class SCMatrix;
00045 class SymmSCMatrix;
00046 class DiagSCMatrix;
00047 class SCVector;
00048 
00049 class SCElementOp;
00050 class SCElementOp2;
00051 class SCElementOp3;
00052 
00053 class RefSCDimension;
00054 
00058 class SCMatrixKit: public DescribedClass {
00059   protected:
00060     Ref<MessageGrp> grp_;
00061     
00062   public:
00063     SCMatrixKit();
00064     SCMatrixKit(const Ref<KeyVal>&);
00065     ~SCMatrixKit();
00066 
00067     // these members are default in local.cc
00070     static SCMatrixKit* default_matrixkit();
00071     static void set_default_matrixkit(const Ref<SCMatrixKit> &);
00072 
00073     Ref<MessageGrp> messagegrp() const;
00074 
00076     virtual SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&) = 0;
00077     virtual SymmSCMatrix* symmmatrix(const RefSCDimension&) = 0;
00078     virtual DiagSCMatrix* diagmatrix(const RefSCDimension&) = 0;
00079     virtual SCVector* vector(const RefSCDimension&) = 0;
00080 
00083     SCMatrix* restore_matrix(StateIn&,
00084                              const RefSCDimension&,
00085                              const RefSCDimension&);
00086     SymmSCMatrix* restore_symmmatrix(StateIn&,
00087                                      const RefSCDimension&);
00088     DiagSCMatrix* restore_diagmatrix(StateIn&,             
00089                                      const RefSCDimension&);
00090     SCVector* restore_vector(StateIn&,
00091                              const RefSCDimension&);
00092 };
00093 
00094 
00097 class SCVector: public DescribedClass {
00098   protected:
00099     RefSCDimension d;
00100     Ref<SCMatrixKit> kit_;
00101   public:
00102     SCVector(const RefSCDimension&, SCMatrixKit *);
00103 
00105     virtual void save(StateOut&);
00106     virtual void restore(StateIn&);
00107 
00109     Ref<SCMatrixKit> kit() const { return kit_; }
00110 
00111     // concrete functions (some can be overridden)
00113     virtual SCVector* copy();
00115     virtual SCVector* clone();
00116 
00117     virtual ~SCVector();
00119     int n() const { return d->n(); }
00121     virtual double maxabs() const;
00123     virtual void normalize();
00125     virtual void randomize();
00127     void assign(double val) { assign_val(val); }
00129     void assign(const double* v) { assign_p(v); }
00132     void assign(SCVector* v) { assign_v(v); }
00134     virtual void assign_val(double val);
00135     virtual void assign_p(const double* v);
00136     virtual void assign_v(SCVector *v);
00138     virtual void convert(double* v) const;
00141     virtual void convert(SCVector*);
00142     virtual void convert_accumulate(SCVector*);
00144     virtual void scale(double val);
00145 
00147     RefSCDimension dim() const { return d; }
00149     virtual void set_element(int i,double val) = 0;
00151     virtual void accumulate_element(int,double) = 0;
00153     virtual double get_element(int i) const = 0;
00155     void accumulate_product(SymmSCMatrix* m, SCVector* v)
00156         { accumulate_product_sv(m,v); }
00157     void accumulate_product(SCMatrix* m, SCVector* v)
00158         {  accumulate_product_rv(m,v); }
00159     virtual void accumulate_product_sv(SymmSCMatrix* m, SCVector* v);
00160     virtual void accumulate_product_rv(SCMatrix* m, SCVector* v) = 0;
00162     virtual void accumulate(const SCVector*v) = 0;
00164     virtual void accumulate(const SCMatrix*m) = 0;
00166     virtual double scalar_product(SCVector*) = 0;
00168     virtual void element_op(const Ref<SCElementOp>&) = 0;
00169     virtual void element_op(const Ref<SCElementOp2>&,
00170                             SCVector*) = 0;
00171     virtual void element_op(const Ref<SCElementOp3>&,
00172                             SCVector*,SCVector*) = 0;
00174     void print(std::ostream&o=ExEnv::out0()) const;
00175     void print(const char* title=0,std::ostream&out=ExEnv::out0(),int=10) const;
00176     virtual void vprint(const char*title=0,std::ostream&out=ExEnv::out0(),
00177                         int=10) const = 0;
00178 
00180     Ref<MessageGrp> messagegrp() const;
00181     
00186     virtual Ref<SCMatrixSubblockIter> local_blocks(
00187         SCMatrixSubblockIter::Access) = 0;
00189     virtual Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access) = 0;
00190 };
00191 
00195 class SCMatrix: public DescribedClass {
00196   protected:
00197     RefSCDimension d1,d2;
00198     Ref<SCMatrixKit> kit_;
00199   public:
00200     // used to control transformations
00201     enum Transform { NormalTransform = 0, TransposeTransform = 1 };
00202     
00203     // concrete functions (some can be overridden)
00204     SCMatrix(const RefSCDimension&, const RefSCDimension&, SCMatrixKit *);
00205     virtual ~SCMatrix();
00206 
00208     virtual void save(StateOut&);
00209     virtual void restore(StateIn&);
00210 
00212     Ref<SCMatrixKit> kit() const { return kit_; }
00213 
00215     int nrow() const { return d1->n(); }
00217     int ncol() const { return d2->n(); }
00219     virtual double maxabs() const;
00221     virtual void randomize();
00223     void assign(double val) { assign_val(val); }
00225     void assign(const double* m) { assign_p(m); }
00227     void assign(const double** m) { assign_pp(m); }
00229     void assign(SCMatrix* m) { assign_r(m); }
00231     virtual void assign_val(double val);
00232     virtual void assign_p(const double* m);
00233     virtual void assign_pp(const double** m);
00234     virtual void assign_r(SCMatrix* m);
00237     virtual void convert(double*) const;
00238     virtual void convert(double**) const;
00241     virtual void convert(SCMatrix*);
00242     virtual void convert_accumulate(SCMatrix*);
00244     virtual void scale(double val);
00246     virtual void scale_diagonal(double val);
00248     virtual void shift_diagonal(double val);
00250     virtual void unit();
00252     virtual SCMatrix* copy();
00254     virtual SCMatrix* clone();
00255 
00256     // pure virtual functions
00258     RefSCDimension rowdim() const { return d1; }
00259     RefSCDimension coldim() const { return d2; }
00261     virtual double get_element(int,int) const = 0;
00262     virtual void set_element(int,int,double) = 0;
00263     virtual void accumulate_element(int,int,double) = 0;
00264     
00268     virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
00269 
00271     virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0) =0;
00272 
00274     virtual void accumulate_subblock(SCMatrix *m, int, int, int, int, int=0,int=0) =0;
00275     
00277     virtual SCVector * get_row(int i) =0;
00278     virtual SCVector * get_column(int i) =0;
00279 
00281     virtual void assign_row(SCVector *v, int i) =0;
00282     virtual void assign_column(SCVector *v, int i) =0;
00283     
00285     virtual void accumulate_row(SCVector *v, int i) =0;
00286     virtual void accumulate_column(SCVector *v, int i) =0;
00287     
00289     virtual void accumulate(const SCMatrix* m) = 0;
00290     virtual void accumulate(const SymmSCMatrix* m) = 0;
00291     virtual void accumulate(const DiagSCMatrix* m) = 0;
00292     virtual void accumulate(const SCVector*) = 0;
00294     virtual void accumulate_outer_product(SCVector*,SCVector*) = 0;
00295     void accumulate_product(SCMatrix*m1,SCMatrix*m2)
00296         { accumulate_product_rr(m1,m2); }
00297     void accumulate_product(SCMatrix*m1,SymmSCMatrix*m2)
00298         { accumulate_product_rs(m1,m2); }
00299     void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
00300         { accumulate_product_rd(m1,m2); }
00301     void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
00302         { accumulate_product_sr(m1,m2); }
00303     void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
00304         { accumulate_product_dr(m1,m2); }
00305     void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
00306         { accumulate_product_ss(m1,m2); }
00307     virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
00308     virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
00309     virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
00310     virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
00311     virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
00312     virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
00314     virtual void transpose_this() = 0;
00316     virtual double trace() =0;
00318     virtual double invert_this() = 0;
00320     virtual double determ_this() = 0;
00321 
00324     virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
00325     virtual double solve_this(SCVector*) = 0;
00326     virtual void gen_invert_this();
00327 
00330     virtual void schmidt_orthog(SymmSCMatrix*, int n) =0;
00331 
00335     virtual int schmidt_orthog_tol(SymmSCMatrix*, double tol, double*res=0)=0;
00336     
00338     virtual void element_op(const Ref<SCElementOp>&) = 0;
00339     virtual void element_op(const Ref<SCElementOp2>&,
00340                             SCMatrix*) = 0;
00341     virtual void element_op(const Ref<SCElementOp3>&,
00342                             SCMatrix*,SCMatrix*) = 0;
00344     void print(std::ostream&o=ExEnv::out0()) const;
00345     void print(const char* title=0,std::ostream& out=ExEnv::out0(),
00346                int =10) const;
00347     virtual void vprint(const char*title=0,
00348                         std::ostream&out=ExEnv::out0(),int =10) const = 0;
00349 
00351     Ref<MessageGrp> messagegrp() const;
00352     
00355     virtual Ref<SCMatrixSubblockIter> local_blocks(
00356         SCMatrixSubblockIter::Access) = 0;
00358     virtual Ref<SCMatrixSubblockIter> all_blocks(
00359         SCMatrixSubblockIter::Access) = 0;
00360 };
00361 
00364 class SymmSCMatrix: public DescribedClass {
00365   protected:
00366     RefSCDimension d;
00367     Ref<SCMatrixKit> kit_;
00368   public:
00369     SymmSCMatrix(const RefSCDimension&, SCMatrixKit *);
00370 
00372     Ref<SCMatrixKit> kit() const { return kit_; }
00373 
00375     virtual void save(StateOut&);
00376     virtual void restore(StateIn&);
00378     virtual double maxabs() const;
00380     virtual void randomize();
00382     void assign(double val) { assign_val(val); }
00384     void assign(const double* m) { assign_p(m); }
00386     void assign(const double** m) { assign_pp(m); }
00389     void assign(SymmSCMatrix* m) { assign_s(m); }
00391     virtual void assign_val(double val);
00392     virtual void assign_p(const double* m);
00393     virtual void assign_pp(const double** m);
00394     virtual void assign_s(SymmSCMatrix* m);
00396     virtual void convert(double*) const;
00397     virtual void convert(double**) const;
00400     virtual void convert(SymmSCMatrix*);
00401     virtual void convert_accumulate(SymmSCMatrix*);
00403     virtual void scale(double);
00405     virtual void scale_diagonal(double);
00407     virtual void shift_diagonal(double);
00409     virtual void unit();
00411     int n() const { return d->n(); }
00413     virtual SymmSCMatrix* copy();
00415     virtual SymmSCMatrix* clone();
00416 
00417     // pure virtual functions
00419     RefSCDimension dim() const { return d; }
00421     virtual double get_element(int,int) const = 0;
00422     virtual void set_element(int,int,double) = 0;
00423     virtual void accumulate_element(int,int,double) = 0;
00424 
00428     virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
00429     virtual SymmSCMatrix * get_subblock(int br, int er) =0;
00430 
00432     virtual void assign_subblock(SCMatrix *m, int, int, int, int) =0;
00433     virtual void assign_subblock(SymmSCMatrix *m, int, int) =0;
00434 
00436     virtual void accumulate_subblock(SCMatrix *m, int, int, int, int) =0;
00437     virtual void accumulate_subblock(SymmSCMatrix *m, int, int) =0;
00438 
00440     virtual SCVector * get_row(int i) =0;
00441 
00443     virtual void assign_row(SCVector *v, int i) =0;
00444     
00446     virtual void accumulate_row(SCVector *v, int i) =0;
00447 
00450     virtual void diagonalize(DiagSCMatrix*d,SCMatrix*m) = 0;
00452     virtual void accumulate(const SymmSCMatrix* m) = 0;
00454     virtual void accumulate_symmetric_sum(SCMatrix*) = 0;
00455     virtual void accumulate_symmetric_product(SCMatrix*);
00456     virtual void accumulate_transform(SCMatrix*,SymmSCMatrix*,
00457                             SCMatrix::Transform = SCMatrix::NormalTransform);
00458     virtual void accumulate_transform(SCMatrix*,DiagSCMatrix*, 
00459                             SCMatrix::Transform = SCMatrix::NormalTransform);
00460     virtual void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
00461     virtual void accumulate_symmetric_outer_product(SCVector*);
00464     virtual double scalar_product(SCVector* v);
00466     virtual double trace() = 0;
00468     virtual double invert_this() = 0;
00470     virtual double determ_this() = 0;
00471 
00472     virtual double solve_this(SCVector*) = 0;
00473     virtual void gen_invert_this() = 0;
00474 
00476     virtual void element_op(const Ref<SCElementOp>&) = 0;
00477     virtual void element_op(const Ref<SCElementOp2>&,
00478                             SymmSCMatrix*) = 0;
00479     virtual void element_op(const Ref<SCElementOp3>&,
00480                             SymmSCMatrix*,SymmSCMatrix*) = 0;
00482     void print(std::ostream&o=ExEnv::out0()) const;
00483     void print(const char* title=0,std::ostream& out=ExEnv::out0(),
00484                int =10) const;
00485     virtual void vprint(const char* title=0,
00486                         std::ostream& out=ExEnv::out0(), int =10) const;
00487 
00489     Ref<MessageGrp> messagegrp() const;
00490     
00493     virtual Ref<SCMatrixSubblockIter> local_blocks(
00494         SCMatrixSubblockIter::Access) = 0;
00496     virtual Ref<SCMatrixSubblockIter> all_blocks(
00497         SCMatrixSubblockIter::Access) = 0;
00498 };
00499 
00502 class DiagSCMatrix: public DescribedClass {
00503   protected:
00504     RefSCDimension d;
00505     Ref<SCMatrixKit> kit_;
00506   public:
00507     DiagSCMatrix(const RefSCDimension&, SCMatrixKit *);
00508 
00510     Ref<SCMatrixKit> kit() const { return kit_; }
00511 
00513     virtual void save(StateOut&);
00514     virtual void restore(StateIn&);
00515 
00517     virtual double maxabs() const;
00519     virtual void randomize();
00521     void assign(double val) { assign_val(val); }
00523     void assign(const double*p) { assign_p(p); }
00526     void assign(DiagSCMatrix*d_a) { assign_d(d_a); }
00528     virtual void assign_val(double val);
00529     virtual void assign_p(const double*);
00530     virtual void assign_d(DiagSCMatrix*);
00532     virtual void convert(double*) const;
00535     virtual void convert(DiagSCMatrix*);
00536     virtual void convert_accumulate(DiagSCMatrix*);
00538     virtual void scale(double);
00540     int n() const { return d->n(); }
00542     virtual DiagSCMatrix* copy();
00544     virtual DiagSCMatrix* clone();
00545 
00546     // pure virtual functions
00548     RefSCDimension dim() const { return d; }
00550     virtual double get_element(int) const = 0;
00551     virtual void set_element(int,double) = 0;
00552     virtual void accumulate_element(int,double) = 0;
00554     virtual void accumulate(const DiagSCMatrix* m) = 0;
00556     virtual double trace() = 0;
00558     virtual double determ_this() = 0;
00560     virtual double invert_this() = 0;
00562     virtual void gen_invert_this() = 0;
00564     virtual void element_op(const Ref<SCElementOp>&) = 0;
00565     virtual void element_op(const Ref<SCElementOp2>&,
00566                             DiagSCMatrix*) = 0;
00567     virtual void element_op(const Ref<SCElementOp3>&,
00568                             DiagSCMatrix*,DiagSCMatrix*) = 0;
00570     void print(std::ostream&o=ExEnv::out0()) const;
00571     void print(const char* title=0,
00572                std::ostream& out=ExEnv::out0(), int =10) const;
00573     virtual void vprint(const char* title=0,
00574                         std::ostream& out=ExEnv::out0(), int =10) const;
00575 
00577     Ref<MessageGrp> messagegrp() const;
00578     
00581     virtual Ref<SCMatrixSubblockIter> local_blocks(
00582         SCMatrixSubblockIter::Access) = 0;
00584     virtual Ref<SCMatrixSubblockIter> all_blocks(
00585         SCMatrixSubblockIter::Access) = 0;
00586 };
00587 
00588 }
00589 
00590 #endif
00591 
00592 // Local Variables:
00593 // mode: c++
00594 // c-file-style: "CLJ"
00595 // End:

Generated at Fri Jan 10 08:14:08 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14.