- Main Page
- Related Pages
- Classes
- Files

- File List

# 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) {}
    00392     ~SCMatrixSubblockIter();
    00394     virtual void begin() = 0;
    00396     virtual int ready() = 0;
    00398     virtual void next() = 0;
    00400     virtual SCMatrixBlock *block() = 0;
    00402     Access access() const { return access_; }
    00403 };
    00404
    00405
    00406 class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
    00407   protected:
    00408     Ref<SCMatrixBlock> block_;
    00409     int ready_;
    00410   public:
    00411     SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
    00412     void begin();
    00413     int ready();
    00414     void next();
    00415     SCMatrixBlock *block();
    00416 };
    00417
    00418 class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
    00419   protected:
    00420     Ref<SCMatrixBlockList> list_;
    00421     SCMatrixBlockListIter iter_;
    00422   public:
    00423     SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
    00424     void begin();
    00425     int ready();
    00426     void next();
    00427     SCMatrixBlock *block();
    00428 };
    00429
    00430 class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
    00431   public:
    00432     SCMatrixNullSubblockIter();
    00433     SCMatrixNullSubblockIter(Access);
    00434     void begin();
    00435     int ready();
    00436     void next();
    00437     SCMatrixBlock *block();
    00438 };
    00439
    00440 class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
    00441   protected:
    00442     int niters_;
    00443     Ref<SCMatrixSubblockIter> *iters_;
    00444     int iiter_;
    00445   public:
    00446     SCMatrixCompositeSubblockIter(Access, int niter);
    00447     SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
    00448                                   Ref<SCMatrixSubblockIter>&);
    00449     ~SCMatrixCompositeSubblockIter();
    00450     void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
    00451     void begin();
    00452     int ready();
    00453     void next();
    00454     SCMatrixBlock *block();
    00455     int current_block() const { return iiter_; }
    00456 };
    00457
    00458
    00459 class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
    00460   protected:
    00461     int niters_;
    00462     Ref<SCMatrixSubblockIter> *iters_;
    00463   public:
    00464     SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
    00465                               const Ref<SCMatrixSubblockIter>&,
    00466                               const Ref<SCMatrixSubblockIter>& = 0,
    00467                               const Ref<SCMatrixSubblockIter>& = 0,
    00468                               const Ref<SCMatrixSubblockIter>& = 0);
    00469     ~SCMatrixJointSubblockIter();
    00470     void begin();
    00471     int ready();
    00472     void next();
    00473     SCMatrixBlock *block();
    00474     SCMatrixBlock *block(int i);
    00475 };
    00476
    00477 }
    00478
    00479 #endif
    00480
    00481 // Local Variables:
    00482 // mode: c++
    00483 // c-file-style: "CLJ"
    00484 // End: