MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

block.h
1 //
2 // block.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_block_h
29 #define _math_scmat_block_h
30
31 #ifdef __GNUC__
32 #pragma interface
33 #endif
34
35 #include <util/state/state.h>
36
37 namespace sc {
38
39 class SCElementOp;
40 class SCElementOp2;
41 class SCElementOp3;
42
45 class SCMatrixBlock: public SavableState {
46 public:
47 int blocki, blockj;
48 public:
49 SCMatrixBlock();
50 SCMatrixBlock(StateIn&s);
51 virtual ~SCMatrixBlock();
52 void save_data_state(StateOut&s);
53
57 virtual SCMatrixBlock *deepcopy() const;
58
63 virtual double *dat();
64 virtual int ndat() const;
65
66 // These routines are obsolete.
67 virtual void process(SCElementOp*) = 0;
68 virtual void process(SCElementOp2*, SCMatrixBlock*) = 0;
69 virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0;
70 };
71
72
73 class SCMatrixBlockListLink {
74 private:
75 void operator = (const SCMatrixBlockListLink&) {} // disallowed
76 SCMatrixBlock* _block;
77 SCMatrixBlockListLink* _next;
78 public:
79 SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0);
80 ~SCMatrixBlockListLink();
81 void block(SCMatrixBlock*);
82 void next(SCMatrixBlockListLink* link) { _next = link; }
83 SCMatrixBlock* block() { return _block; }
84 SCMatrixBlockListLink* next() { return _next; }
85 };
86
87 class SCMatrixBlockListIter {
88 private:
89 SCMatrixBlockListLink* link;
90 public:
91 SCMatrixBlockListIter(): link(0) {}
92 SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {}
93 int operator !=(const SCMatrixBlockListIter p) const {
94 return link != p.link;
95 }
96 void operator ++() { link = link->next(); }
97 void operator ++(int) { link = link->next(); }
98 SCMatrixBlock* block() const { return link->block(); }
99 };
100
101 class SCMatrixBlockList: public SavableState {
102 private:
103 SCMatrixBlockListLink* _begin;
104 public:
105 SCMatrixBlockList();
106 SCMatrixBlockList(StateIn&);
107 ~SCMatrixBlockList();
108 void save_data_state(StateOut&);
109 void insert(SCMatrixBlock*);
110 void append(SCMatrixBlock*);
111 SCMatrixBlockListIter begin() { return _begin; }
112 SCMatrixBlockListIter end() { return 0; }
113 SCMatrixBlockList *deepcopy();
114 };
115
116
127 class SCVectorSimpleBlock: public SCMatrixBlock {
128 public:
129 SCVectorSimpleBlock(int istart,int iend);
130 SCVectorSimpleBlock(StateIn&);
131 virtual ~SCVectorSimpleBlock();
132 void save_data_state(StateOut&);
133 int istart;
134 int iend;
135 double* data;
136
137 SCMatrixBlock *deepcopy() const;
138
139 void process(SCElementOp*);
140 void process(SCElementOp2*, SCMatrixBlock*);
141 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
142
143 double *dat();
144 int ndat() const;
145 };
146
147
158 class SCVectorSimpleSubBlock: public SCMatrixBlock {
159 public:
160 SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
161 SCVectorSimpleSubBlock(StateIn&);
162 virtual ~SCVectorSimpleSubBlock();
163 void save_data_state(StateOut&);
164 int istart;
165 int iend;
166 int offset;
167 double* data;
168
169 void process(SCElementOp*);
170 void process(SCElementOp2*, SCMatrixBlock*);
171 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
172 };
173
174
187 class SCMatrixRectBlock: public SCMatrixBlock {
188 public:
189 SCMatrixRectBlock(int is, int ie, int js, int je);
190 SCMatrixRectBlock(StateIn&);
191 virtual ~SCMatrixRectBlock();
192 void save_data_state(StateOut&);
193 int istart;
194 int jstart;
195 int iend;
196 int jend;
197 double* data;
198
199 SCMatrixBlock *deepcopy() const;
200
201 void process(SCElementOp*);
202 void process(SCElementOp2*, SCMatrixBlock*);
203 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
204
205 double *dat();
206 int ndat() const;
207 };
208
209
223 class SCMatrixRectSubBlock: public SCMatrixBlock {
224 public:
225 SCMatrixRectSubBlock(int is, int ie, int istride, int js, int je,
226 double* data);
227 SCMatrixRectSubBlock(StateIn&);
228 // does not delete the data member
229 virtual ~SCMatrixRectSubBlock();
230 // does not save the data member
231 void save_data_state(StateOut&);
232 int istart;
233 int jstart;
234 int iend;
235 int jend;
236 int istride;
237 double* data;
238
239 void process(SCElementOp*);
240 void process(SCElementOp2*, SCMatrixBlock*);
241 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
242 };
243
244
257 class SCMatrixLTriBlock: public SCMatrixBlock {
258 public:
259 SCMatrixLTriBlock(int s,int e);
260 SCMatrixLTriBlock(StateIn&);
261 virtual ~SCMatrixLTriBlock();
262 void save_data_state(StateOut&);
263 int start;
264 int end;
265 double* data;
266
267 SCMatrixBlock *deepcopy() const;
268
269 void process(SCElementOp*);
270 void process(SCElementOp2*, SCMatrixBlock*);
271 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
272
273 double *dat();
274 int ndat() const;
275 };
276
277
292 class SCMatrixLTriSubBlock: public SCMatrixBlock {
293 public:
294 SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data);
295 SCMatrixLTriSubBlock(StateIn&);
296 // does not delete the data member
297 virtual ~SCMatrixLTriSubBlock();
298 // does not save the data member
299 void save_data_state(StateOut&);
300 int istart;
301 int iend;
302 int jstart;
303 int jend;
304 double* data;
305
306 void process(SCElementOp*);
307 void process(SCElementOp2*, SCMatrixBlock*);
308 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
309 };
310
311
322 class SCMatrixDiagBlock: public SCMatrixBlock {
323 public:
324 SCMatrixDiagBlock(int istart,int iend,int jstart);
325 SCMatrixDiagBlock(int istart,int iend);
326 SCMatrixDiagBlock(StateIn&);
327 virtual ~SCMatrixDiagBlock();
328 void save_data_state(StateOut&);
329 int istart;
330 int jstart;
331 int iend;
332 double* data;
333
334 SCMatrixBlock *deepcopy() const;
335
336 void process(SCElementOp*);
337 void process(SCElementOp2*, SCMatrixBlock*);
338 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
339
340 double *dat();
341 int ndat() const;
342 };
343
344
355 class SCMatrixDiagSubBlock: public SCMatrixBlock {
356 public:
357 SCMatrixDiagSubBlock(int istart,int iend,int jstart, int offset,
358 double*data);
359 SCMatrixDiagSubBlock(int istart,int iend, int offset, double*data);
360 SCMatrixDiagSubBlock(StateIn&);
361 // does not delete the data member
362 virtual ~SCMatrixDiagSubBlock();
363 // does not save the data member
364 void save_data_state(StateOut&);
365 int istart;
366 int jstart;
367 int iend;
368 int offset;
369 double* data;
370
371 void process(SCElementOp*);
372 void process(SCElementOp2*, SCMatrixBlock*);
373 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
374 };
375
376
377 // //////////////////////////////////////////////////////////////////
378 // Classes that iterate through the blocks of a matrix.
379
383 class SCMatrixSubblockIter: public RefCount {
384 public:
385 enum Access { Read, Write, Accum, None };
386 protected:
387 Access access_;
388 public:
391 SCMatrixSubblockIter(Access access): access_(access) {}
392 ~SCMatrixSubblockIter();
394 virtual void begin() = 0;
396 virtual int ready() = 0;
398 virtual void next() = 0;
400 virtual SCMatrixBlock *block() = 0;
402 Access access() const { return access_; }
403 };
404
405
406 class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
407 protected:
408 Ref<SCMatrixBlock> block_;
409 int ready_;
410 public:
411 SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
412 void begin();
413 int ready();
414 void next();
415 SCMatrixBlock *block();
416 };
417
418 class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
419 protected:
420 Ref<SCMatrixBlockList> list_;
421 SCMatrixBlockListIter iter_;
422 public:
423 SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
424 void begin();
425 int ready();
426 void next();
427 SCMatrixBlock *block();
428 };
429
430 class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
431 public:
432 SCMatrixNullSubblockIter();
433 SCMatrixNullSubblockIter(Access);
434 void begin();
435 int ready();
436 void next();
437 SCMatrixBlock *block();
438 };
439
440 class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
441 protected:
442 int niters_;
443 Ref<SCMatrixSubblockIter> *iters_;
444 int iiter_;
445 public:
446 SCMatrixCompositeSubblockIter(Access, int niter);
447 SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
448 Ref<SCMatrixSubblockIter>&);
449 ~SCMatrixCompositeSubblockIter();
450 void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
451 void begin();
452 int ready();
453 void next();
454 SCMatrixBlock *block();
455 int current_block() const { return iiter_; }
456 };
457
458
459 class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
460 protected:
461 int niters_;
462 Ref<SCMatrixSubblockIter> *iters_;
463 public:
464 SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
465 const Ref<SCMatrixSubblockIter>&,
466 const Ref<SCMatrixSubblockIter>& = 0,
467 const Ref<SCMatrixSubblockIter>& = 0,
468 const Ref<SCMatrixSubblockIter>& = 0);
469 ~SCMatrixJointSubblockIter();
470 void begin();
471 int ready();
472 void next();
473 SCMatrixBlock *block();
474 SCMatrixBlock *block(int i);
475 };
476
477 }
478
479 #endif
480
481 // Local Variables:
482 // mode: c++
483 // c-file-style: "CLJ"
484 // End: