Google

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

block.h

00001 //
00002 // block.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_block_h
00029 #define _math_scmat_block_h
00030 
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034 
00035 #include <util/state/state.h>
00036 
00037 namespace sc {
00038 
00039 class SCElementOp;
00040 class SCElementOp2;
00041 class SCElementOp3;
00042 
00045 class SCMatrixBlock: public SavableState {
00046   public:
00047     int blocki, blockj;
00048   public:
00049     SCMatrixBlock();
00050     SCMatrixBlock(StateIn&s);
00051     virtual ~SCMatrixBlock();
00052     void save_data_state(StateOut&s);
00053 
00057     virtual SCMatrixBlock *deepcopy() const;
00058 
00063     virtual double *dat();
00064     virtual int ndat() const;
00065 
00066     // These routines are obsolete.
00067     virtual void process(SCElementOp*) = 0;
00068     virtual void process(SCElementOp2*, SCMatrixBlock*) = 0;
00069     virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0;
00070 };
00071 
00072 
00073 class SCMatrixBlockListLink {
00074   private:
00075     void operator = (const SCMatrixBlockListLink&) {}  // disallowed
00076     SCMatrixBlock* _block;
00077     SCMatrixBlockListLink* _next;
00078   public:
00079     SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0);
00080     ~SCMatrixBlockListLink();
00081     void block(SCMatrixBlock*);
00082     void next(SCMatrixBlockListLink* link) { _next = link; }
00083     SCMatrixBlock* block() { return _block; }
00084     SCMatrixBlockListLink* next() { return _next; }
00085 };
00086 
00087 class SCMatrixBlockListIter {
00088   private:
00089     SCMatrixBlockListLink* link;
00090   public:
00091     SCMatrixBlockListIter(): link(0) {}
00092     SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {}
00093     int operator !=(const SCMatrixBlockListIter p) const {
00094         return link != p.link;
00095       }
00096     void operator ++() { link = link->next(); }
00097     void operator ++(int) { link = link->next(); }
00098     SCMatrixBlock* block() const { return link->block(); }
00099 };
00100 
00101 class SCMatrixBlockList: public SavableState {
00102   private:
00103     SCMatrixBlockListLink* _begin;
00104   public:
00105     SCMatrixBlockList();
00106     SCMatrixBlockList(StateIn&);
00107     ~SCMatrixBlockList();
00108     void save_data_state(StateOut&);
00109     void insert(SCMatrixBlock*);
00110     void append(SCMatrixBlock*);
00111     SCMatrixBlockListIter begin() { return _begin; }
00112     SCMatrixBlockListIter end() { return 0; }
00113     SCMatrixBlockList *deepcopy();
00114 };
00115 
00116 
00127 class SCVectorSimpleBlock: public SCMatrixBlock {
00128   public:
00129     SCVectorSimpleBlock(int istart,int iend);
00130     SCVectorSimpleBlock(StateIn&);
00131     virtual ~SCVectorSimpleBlock();
00132     void save_data_state(StateOut&);
00133     int istart;
00134     int iend;
00135     double* data;
00136 
00137     SCMatrixBlock *deepcopy() const;
00138 
00139     void process(SCElementOp*);
00140     void process(SCElementOp2*, SCMatrixBlock*);
00141     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00142 
00143     double *dat();
00144     int ndat() const;
00145 };
00146 
00147 
00158 class SCVectorSimpleSubBlock: public SCMatrixBlock {
00159   public:
00160     SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
00161     SCVectorSimpleSubBlock(StateIn&);
00162     virtual ~SCVectorSimpleSubBlock();
00163     void save_data_state(StateOut&);
00164     int istart;
00165     int iend;
00166     int offset;
00167     double* data;
00168 
00169     void process(SCElementOp*);
00170     void process(SCElementOp2*, SCMatrixBlock*);
00171     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00172 };
00173 
00174 
00187 class SCMatrixRectBlock: public SCMatrixBlock {
00188   public:
00189     SCMatrixRectBlock(int is, int ie, int js, int je);
00190     SCMatrixRectBlock(StateIn&);
00191     virtual ~SCMatrixRectBlock();
00192     void save_data_state(StateOut&);
00193     int istart;
00194     int jstart;
00195     int iend;
00196     int jend;
00197     double* data;
00198 
00199     SCMatrixBlock *deepcopy() const;
00200 
00201     void process(SCElementOp*);
00202     void process(SCElementOp2*, SCMatrixBlock*);
00203     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00204 
00205     double *dat();
00206     int ndat() const;
00207 };
00208 
00209 
00223 class SCMatrixRectSubBlock: public SCMatrixBlock {
00224   public:
00225     SCMatrixRectSubBlock(int is, int ie, int istride, int js, int je,
00226                          double* data);
00227     SCMatrixRectSubBlock(StateIn&);
00228     // does not delete the data member
00229     virtual ~SCMatrixRectSubBlock();
00230     // does not save the data member
00231     void save_data_state(StateOut&);
00232     int istart;
00233     int jstart;
00234     int iend;
00235     int jend;
00236     int istride;
00237     double* data;
00238 
00239     void process(SCElementOp*);
00240     void process(SCElementOp2*, SCMatrixBlock*);
00241     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00242 };
00243 
00244 
00257 class SCMatrixLTriBlock: public SCMatrixBlock {
00258   public:
00259     SCMatrixLTriBlock(int s,int e);
00260     SCMatrixLTriBlock(StateIn&);
00261     virtual ~SCMatrixLTriBlock();
00262     void save_data_state(StateOut&);
00263     int start;
00264     int end;
00265     double* data;
00266 
00267     SCMatrixBlock *deepcopy() const;
00268 
00269     void process(SCElementOp*);
00270     void process(SCElementOp2*, SCMatrixBlock*);
00271     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00272 
00273     double *dat();
00274     int ndat() const;
00275 };
00276 
00277 
00292 class SCMatrixLTriSubBlock: public SCMatrixBlock {
00293   public:
00294     SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data);
00295     SCMatrixLTriSubBlock(StateIn&);
00296     // does not delete the data member
00297     virtual ~SCMatrixLTriSubBlock();
00298     // does not save the data member
00299     void save_data_state(StateOut&);
00300     int istart;
00301     int iend;
00302     int jstart;
00303     int jend;
00304     double* data;
00305 
00306     void process(SCElementOp*);
00307     void process(SCElementOp2*, SCMatrixBlock*);
00308     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00309 };
00310 
00311 
00322 class SCMatrixDiagBlock: public SCMatrixBlock {
00323   public:
00324     SCMatrixDiagBlock(int istart,int iend,int jstart);
00325     SCMatrixDiagBlock(int istart,int iend);
00326     SCMatrixDiagBlock(StateIn&);
00327     virtual ~SCMatrixDiagBlock();
00328     void save_data_state(StateOut&);
00329     int istart;
00330     int jstart;
00331     int iend;
00332     double* data;
00333 
00334     SCMatrixBlock *deepcopy() const;
00335 
00336     void process(SCElementOp*);
00337     void process(SCElementOp2*, SCMatrixBlock*);
00338     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00339 
00340     double *dat();
00341     int ndat() const;
00342 };
00343 
00344 
00355 class SCMatrixDiagSubBlock: public SCMatrixBlock {
00356   public:
00357     SCMatrixDiagSubBlock(int istart,int iend,int jstart, int offset,
00358                          double*data);
00359     SCMatrixDiagSubBlock(int istart,int iend, int offset, double*data);
00360     SCMatrixDiagSubBlock(StateIn&);
00361     // does not delete the data member
00362     virtual ~SCMatrixDiagSubBlock();
00363     // does not save the data member
00364     void save_data_state(StateOut&);
00365     int istart;
00366     int jstart;
00367     int iend;
00368     int offset;
00369     double* data;
00370 
00371     void process(SCElementOp*);
00372     void process(SCElementOp2*, SCMatrixBlock*);
00373     void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00374 };
00375 
00376 
00377 // //////////////////////////////////////////////////////////////////
00378 // Classes that iterate through the blocks of a matrix.
00379 
00383 class SCMatrixSubblockIter: public RefCount {
00384   public:
00385     enum Access { Read, Write, Accum, None };
00386   protected:
00387     Access access_;
00388   public:
00391     SCMatrixSubblockIter(Access access): access_(access) {}
00393     virtual void begin() = 0;
00395     virtual int ready() = 0;
00397     virtual void next() = 0;
00399     virtual SCMatrixBlock *block() = 0;
00401     Access access() const { return access_; }
00402 };
00403 
00404 
00405 class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
00406   protected:
00407     Ref<SCMatrixBlock> block_;
00408     int ready_;
00409   public:
00410     SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
00411     void begin();
00412     int ready();
00413     void next();
00414     SCMatrixBlock *block();
00415 };
00416 
00417 class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
00418   protected:
00419     Ref<SCMatrixBlockList> list_;
00420     SCMatrixBlockListIter iter_;
00421   public:
00422     SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
00423     void begin();
00424     int ready();
00425     void next();
00426     SCMatrixBlock *block();
00427 };
00428 
00429 class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
00430   public:
00431     SCMatrixNullSubblockIter();
00432     SCMatrixNullSubblockIter(Access);
00433     void begin();
00434     int ready();
00435     void next();
00436     SCMatrixBlock *block();
00437 };
00438 
00439 class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
00440   protected:
00441     int niters_;
00442     Ref<SCMatrixSubblockIter> *iters_;
00443     int iiter_;
00444   public:
00445     SCMatrixCompositeSubblockIter(Access, int niter);
00446     SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
00447                                   Ref<SCMatrixSubblockIter>&);
00448     ~SCMatrixCompositeSubblockIter();
00449     void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
00450     void begin();
00451     int ready();
00452     void next();
00453     SCMatrixBlock *block();
00454     int current_block() const { return iiter_; }
00455 };
00456 
00457 
00458 class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
00459   protected:
00460     int niters_;
00461     Ref<SCMatrixSubblockIter> *iters_;
00462   public:
00463     SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
00464                               const Ref<SCMatrixSubblockIter>&,
00465                               const Ref<SCMatrixSubblockIter>& = 0,
00466                               const Ref<SCMatrixSubblockIter>& = 0,
00467                               const Ref<SCMatrixSubblockIter>& = 0);
00468     ~SCMatrixJointSubblockIter();
00469     void begin();
00470     int ready();
00471     void next();
00472     SCMatrixBlock *block();
00473     SCMatrixBlock *block(int i);
00474 };
00475 
00476 }
00477 
00478 #endif
00479 
00480 // Local Variables:
00481 // mode: c++
00482 // c-file-style: "CLJ"
00483 // End:

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