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

# blocked.h

    00001 //
    00002 // blocked.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 #ifdef __GNUC__
    00029 #pragma interface
    00030 #endif
    00031
    00032 #ifndef _math_scmat_blocked_h
    00033 #define _math_scmat_blocked_h
    00034
    00035 #include <math/scmat/block.h>
    00036 #include <math/scmat/elemop.h>
    00037 #include <math/scmat/matrix.h>
    00038 #include <math/scmat/abstract.h>
    00039
    00040 namespace sc {
    00041
    00042 class BlockedSCMatrixKit;
    00043 class BlockedSCVector;
    00044 class BlockedSCMatrix;
    00045 class BlockedSymmSCMatrix;
    00046 class BlockedDiagSCMatrix;
    00047
    00048 class BlockedSCMatrixKit: public SCMatrixKit {
    00049   private:
    00050     Ref<SCMatrixKit> subkit_;
    00051   public:
    00052     BlockedSCMatrixKit(const Ref<SCMatrixKit>& subkit);
    00053     BlockedSCMatrixKit(const Ref<KeyVal>&);
    00054     ~BlockedSCMatrixKit();
    00055     SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
    00056     SymmSCMatrix* symmmatrix(const RefSCDimension&);
    00057     DiagSCMatrix* diagmatrix(const RefSCDimension&);
    00058     SCVector* vector(const RefSCDimension&);
    00059
    00060     Ref<SCMatrixKit> subkit() { return subkit_; }
    00061 };
    00062
    00063
    00064 class BlockedSCVector: public SCVector {
    00065     friend class BlockedSCMatrix;
    00066     friend class BlockedSymmSCMatrix;
    00067     friend class BlockedDiagSCMatrix;
    00068   private:
    00069     Ref<SCMatrixKit> subkit;
    00070     RefSCVector *vecs_;
    00071
    00072     void resize(SCDimension*);
    00073
    00074   public:
    00075     BlockedSCVector(const RefSCDimension&, BlockedSCMatrixKit*);
    00076     ~BlockedSCVector();
    00077
    00078     // Save and restore this in an implementation independent way.
    00079     void save(StateOut&);
    00080     void restore(StateIn&);
    00081
    00082     void assign_val(double);
    00083     void assign_v(SCVector*);
    00084     void assign_p(const double*);
    00085
    00086     double get_element(int) const;
    00087     void set_element(int,double);
    00088     void accumulate_element(int,double);
    00089
    00090     void accumulate_product_rv(SCMatrix*,SCVector*);
    00091     void accumulate_product_sv(SymmSCMatrix*,SCVector*);
    00092
    00093     void accumulate(const SCVector*);
    00094     void accumulate(const SCMatrix*);
    00095     double scalar_product(SCVector*);
    00096
    00097     void element_op(const Ref<SCElementOp>&);
    00098     void element_op(const Ref<SCElementOp2>&,
    00099                     SCVector*);
    00100     void element_op(const Ref<SCElementOp3>&,
    00101                     SCVector*,SCVector*);
    00102     void vprint(const char* title=0,
    00103                 std::ostream& out=ExEnv::out0(), int =10) const;
    00104
    00105     // BlockedSCVector specific functions
    00106     RefSCDimension dim() const { return d; }
    00107     RefSCDimension dim(int) const;
    00108     int nblocks() const;
    00109     RefSCVector block(int);
    00110
    00111     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00112     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00113 };
    00114
    00115 class BlockedSCMatrix: public SCMatrix {
    00116     friend class BlockedSymmSCMatrix;
    00117     friend class BlockedDiagSCMatrix;
    00118     friend class BlockedSCVector;
    00119   private:
    00120     Ref<SCMatrixKit> subkit;
    00121     RefSCMatrix *mats_;
    00122     int nblocks_;
    00123
    00124     void resize(SCDimension*, SCDimension*);
    00125
    00126   public:
    00127     BlockedSCMatrix(const RefSCDimension&, const RefSCDimension&,
    00128                     BlockedSCMatrixKit*);
    00129     ~BlockedSCMatrix();
    00130
    00131     // Save and restore this in an implementation independent way.
    00132     void save(StateOut&);
    00133     void restore(StateIn&);
    00134
    00135     void assign_val(double);
    00136     double get_element(int,int) const;
    00137     void set_element(int,int,double);
    00138     void accumulate_element(int,int,double);
    00139
    00140     SCMatrix * get_subblock(int,int,int,int);
    00141     void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
    00142     void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
    00143
    00144     SCVector * get_row(int i);
    00145     SCVector * get_column(int i);
    00146     void assign_row(SCVector *v, int i);
    00147     void assign_column(SCVector *v, int i);
    00148     void accumulate_row(SCVector *v, int i);
    00149     void accumulate_column(SCVector *v, int i);
    00150
    00151     void accumulate_outer_product(SCVector*,SCVector*);
    00152     void accumulate_product_rr(SCMatrix*,SCMatrix*);
    00153     void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
    00154     void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
    00155     void accumulate(const SCMatrix*);
    00156     void accumulate(const SymmSCMatrix*);
    00157     void accumulate(const DiagSCMatrix*);
    00158     void accumulate(const SCVector*);
    00159
    00160     void transpose_this();
    00161     double invert_this();
    00162     void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
    00163     double solve_this(SCVector*);
    00164     double determ_this();
    00165     double trace();
    00166     void gen_invert_this();
    00167     void schmidt_orthog(SymmSCMatrix*,int);
    00168     int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
    00169
    00170     void element_op(const Ref<SCElementOp>&);
    00171     void element_op(const Ref<SCElementOp2>&,
    00172                     SCMatrix*);
    00173     void element_op(const Ref<SCElementOp3>&,
    00174                     SCMatrix*,SCMatrix*);
    00175
    00176     void vprint(const char* title=0,
    00177                 std::ostream& out=ExEnv::out0(), int =10) const;
    00178
    00179     // BlockedSCMatrix specific functions
    00180     RefSCDimension rowdim() const { return d1; }
    00181     RefSCDimension coldim() const { return d2; }
    00182     RefSCDimension rowdim(int) const;
    00183     RefSCDimension coldim(int) const;
    00184     int nblocks() const;
    00185     RefSCMatrix block(int);
    00186
    00187     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00188     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00189 };
    00190
    00191 class BlockedSymmSCMatrix: public SymmSCMatrix {
    00192     friend class BlockedSCMatrix;
    00193     friend class BlockedDiagSCMatrix;
    00194     friend class BlockedSCVector;
    00195   private:
    00196     Ref<SCMatrixKit> subkit;
    00197     RefSymmSCMatrix *mats_;
    00198
    00199     void resize(SCDimension*);
    00200
    00201   public:
    00202     BlockedSymmSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
    00203     ~BlockedSymmSCMatrix();
    00204
    00205     // Save and restore this in an implementation independent way.
    00206     void save(StateOut&);
    00207     void restore(StateIn&);
    00208
    00209     double get_element(int,int) const;
    00210     void set_element(int,int,double);
    00211     void accumulate_element(int,int,double);
    00212     void scale(double);
    00213     void assign_val(double);
    00214     void assign_s(SymmSCMatrix*m);
    00215
    00216     SCMatrix * get_subblock(int,int,int,int);
    00217     SymmSCMatrix * get_subblock(int,int);
    00218     void assign_subblock(SCMatrix*, int,int,int,int);
    00219     void assign_subblock(SymmSCMatrix*, int,int);
    00220     void accumulate_subblock(SCMatrix*, int,int,int,int);
    00221     void accumulate_subblock(SymmSCMatrix*, int,int);
    00222     SCVector * get_row(int i);
    00223     void assign_row(SCVector *v, int i);
    00224     void accumulate_row(SCVector *v, int i);
    00225
    00226     double invert_this();
    00227     double determ_this();
    00228     double trace();
    00229     double solve_this(SCVector*);
    00230     void gen_invert_this();
    00231
    00232     double scalar_product(SCVector*);
    00233     void diagonalize(DiagSCMatrix*,SCMatrix*);
    00234
    00235     void accumulate(const SymmSCMatrix*);
    00236     void accumulate_symmetric_outer_product(SCVector*);
    00237     void accumulate_symmetric_product(SCMatrix*);
    00238     void accumulate_symmetric_sum(SCMatrix*);
    00239     void accumulate_transform(SCMatrix*,SymmSCMatrix*,
    00240                               SCMatrix::Transform = SCMatrix::NormalTransform);
    00241     void accumulate_transform(SCMatrix*,DiagSCMatrix*,
    00242                               SCMatrix::Transform = SCMatrix::NormalTransform);
    00243     void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
    00244
    00245     void convert_accumulate(SymmSCMatrix*a);
    00246
    00247     void element_op(const Ref<SCElementOp>&);
    00248     void element_op(const Ref<SCElementOp2>&,
    00249                     SymmSCMatrix*);
    00250     void element_op(const Ref<SCElementOp3>&,
    00251                     SymmSCMatrix*,SymmSCMatrix*);
    00252
    00253     void vprint(const char* title=0,
    00254                 std::ostream& out=ExEnv::out0(), int =10) const;
    00255
    00256     // BlockedSymmSCMatrix specific functions
    00257     RefSCDimension dim() const { return d; }
    00258     RefSCDimension dim(int) const;
    00259     int nblocks() const;
    00260     RefSymmSCMatrix block(int);
    00261
    00262     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00263     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00264 };
    00265
    00266 class BlockedDiagSCMatrix: public DiagSCMatrix {
    00267     friend class BlockedSCMatrix;
    00268     friend class BlockedSymmSCMatrix;
    00269     friend class BlockedSCVector;
    00270   private:
    00271     Ref<SCMatrixKit> subkit;
    00272     RefDiagSCMatrix *mats_;
    00273
    00274     void resize(SCDimension*);
    00275
    00276   public:
    00277     BlockedDiagSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
    00278     ~BlockedDiagSCMatrix();
    00279
    00280     // Save and restore this in an implementation independent way.
    00281     void save(StateOut&);
    00282     void restore(StateIn&);
    00283
    00284     double get_element(int) const;
    00285     void set_element(int,double);
    00286     void accumulate_element(int,double);
    00287     void accumulate(const DiagSCMatrix*);
    00288
    00289     double invert_this();
    00290     double determ_this();
    00291     double trace();
    00292     void gen_invert_this();
    00293
    00294     void element_op(const Ref<SCElementOp>&);
    00295     void element_op(const Ref<SCElementOp2>&,
    00296                     DiagSCMatrix*);
    00297     void element_op(const Ref<SCElementOp3>&,
    00298                     DiagSCMatrix*,DiagSCMatrix*);
    00299     void vprint(const char* title=0,
    00300                 std::ostream& out=ExEnv::out0(), int =10) const;
    00301
    00302     // BlockedDiagSCMatrix specific functions
    00303     RefSCDimension dim() const { return d; }
    00304     RefSCDimension dim(int) const;
    00305     int nblocks() const;
    00306     RefDiagSCMatrix block(int);
    00307
    00308     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00309     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00310 };
    00311
    00312 class BlockedSCElementOp : public SCElementOp {
    00313   private:
    00314     int current_block_;
    00315
    00316   public:
    00317     BlockedSCElementOp();
    00318     void working_on(int);
    00319     int current_block() const;
    00320 };
    00321
    00322 class BlockedSCElementOp2 : public SCElementOp2 {
    00323   private:
    00324     int current_block_;
    00325
    00326   public:
    00327     BlockedSCElementOp2();
    00328     void working_on(int);
    00329     int current_block() const;
    00330 };
    00331
    00332 class BlockedSCElementOp3 : public SCElementOp3 {
    00333   private:
    00334     int current_block_;
    00335
    00336   public:
    00337     BlockedSCElementOp3();
    00338     void working_on(int);
    00339     int current_block() const;
    00340 };
    00341
    00342 }
    00343
    00344 #endif
    00345
    00346 // Local Variables:
    00347 // mode: c++
    00348 // c-file-style: "CLJ"
    00349 // End: