MPQC 2.3.1
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
37namespace sc {
38
39class SCElementOp;
40class SCElementOp2;
41class SCElementOp3;
42
45class SCMatrixBlock: public SavableState {
46 public:
47 int blocki, blockj;
48 public:
49 SCMatrixBlock();
50 SCMatrixBlock(StateIn&s);
51 virtual ~SCMatrixBlock();
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
73class 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
87class SCMatrixBlockListIter {
88 private:
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
101class SCMatrixBlockList: public SavableState {
102 private:
103 SCMatrixBlockListLink* _begin;
104 public:
105 SCMatrixBlockList();
106 SCMatrixBlockList(StateIn&);
107 ~SCMatrixBlockList();
109 void insert(SCMatrixBlock*);
110 void append(SCMatrixBlock*);
111 SCMatrixBlockListIter begin() { return _begin; }
112 SCMatrixBlockListIter end() { return 0; }
113 SCMatrixBlockList *deepcopy();
114};
115
116
127class SCVectorSimpleBlock: public SCMatrixBlock {
128 public:
129 SCVectorSimpleBlock(int istart,int iend);
130 SCVectorSimpleBlock(StateIn&);
131 virtual ~SCVectorSimpleBlock();
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
158class SCVectorSimpleSubBlock: public SCMatrixBlock {
159 public:
160 SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
161 SCVectorSimpleSubBlock(StateIn&);
162 virtual ~SCVectorSimpleSubBlock();
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
187class SCMatrixRectBlock: public SCMatrixBlock {
188 public:
189 SCMatrixRectBlock(int is, int ie, int js, int je);
190 SCMatrixRectBlock(StateIn&);
191 virtual ~SCMatrixRectBlock();
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
223class 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
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
257class SCMatrixLTriBlock: public SCMatrixBlock {
258 public:
259 SCMatrixLTriBlock(int s,int e);
260 SCMatrixLTriBlock(StateIn&);
261 virtual ~SCMatrixLTriBlock();
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
292class 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
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
322class 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();
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
355class 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
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
383class 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) {}
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
406class 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();
416};
417
418class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
419 protected:
422 public:
423 SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
424 void begin();
425 int ready();
426 void next();
428};
429
430class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
431 public:
432 SCMatrixNullSubblockIter();
433 SCMatrixNullSubblockIter(Access);
434 void begin();
435 int ready();
436 void next();
438};
439
440class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
441 protected:
442 int niters_;
444 int iiter_;
445 public:
446 SCMatrixCompositeSubblockIter(Access, int niter);
447 SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
449 ~SCMatrixCompositeSubblockIter();
450 void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
451 void begin();
452 int ready();
453 void next();
455 int current_block() const { return iiter_; }
456};
457
458
459class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
460 protected:
461 int niters_;
463 public:
464 SCMatrixJointSubblockIter(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();
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:
A template class that maintains references counts.
Definition ref.h:332
The SCElementOp2 class is very similar to the SCElementOp class except that pairs of blocks are treat...
Definition elemop.h:125
The SCElementOp3 class is very similar to the SCElementOp class except that a triplet of blocks is tr...
Definition elemop.h:147
Objects of class SCElementOp are used to perform operations on the elements of matrices.
Definition elemop.h:60
Definition block.h:87
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
SCMatrixBlock is the base clase for all types of blocks that comprise matrices and vectors.
Definition block.h:45
virtual double * dat()
Return a pointer to the block's data and the number of elements in the block.
virtual SCMatrixBlock * deepcopy() const
Return of copy of this.
void save_data_state(StateOut &s)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
int ready()
Returns nonzero if there is another block.
void next()
Proceed to the next block.
SCMatrixBlock * block()
Return the current block.
void begin()
Start at the beginning.
double * dat()
Return a pointer to the block's data and the number of elements in the block.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
SCMatrixBlock * deepcopy() const
Return of copy of this.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
void begin()
Start at the beginning.
void next()
Proceed to the next block.
int ready()
Returns nonzero if there is another block.
SCMatrixBlock * block()
Return the current block.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
double * dat()
Return a pointer to the block's data and the number of elements in the block.
SCMatrixBlock * deepcopy() const
Return of copy of this.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
int ready()
Returns nonzero if there is another block.
void begin()
Start at the beginning.
void next()
Proceed to the next block.
SCMatrixBlock * block()
Return the current block.
int ready()
Returns nonzero if there is another block.
SCMatrixBlock * block()
Return the current block.
void begin()
Start at the beginning.
void next()
Proceed to the next block.
double * dat()
Return a pointer to the block's data and the number of elements in the block.
SCMatrixBlock * deepcopy() const
Return of copy of this.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
int ready()
Returns nonzero if there is another block.
void begin()
Start at the beginning.
SCMatrixBlock * block()
Return the current block.
void next()
Proceed to the next block.
Objects of class SCMatrixSubblockIter are used to iterate through the blocks of a matrix.
Definition block.h:383
Access access() const
Return the type of Access allowed for these blocks.
Definition block.h:402
virtual void next()=0
Proceed to the next block.
virtual SCMatrixBlock * block()=0
Return the current block.
virtual int ready()=0
Returns nonzero if there is another block.
virtual void begin()=0
Start at the beginning.
SCMatrixSubblockIter(Access access)
The access variable should be one of Read, Write, Accum, and None, with the SCMatrixSubblockIter:: sc...
Definition block.h:391
SCMatrixBlock * deepcopy() const
Return of copy of this.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
double * dat()
Return a pointer to the block's data and the number of elements in the block.
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Restores objects that derive from SavableState.
Definition statein.h:70
Serializes objects that derive from SavableState.
Definition stateout.h:61

Generated at Thu Jul 18 2024 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.13.1.