MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

blocked.h
1 //
2 // blocked.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 #ifdef __GNUC__
29 #pragma interface
30 #endif
31
32 #ifndef _math_scmat_blocked_h
33 #define _math_scmat_blocked_h
34
35 #include <math/scmat/block.h>
36 #include <math/scmat/elemop.h>
37 #include <math/scmat/matrix.h>
38 #include <math/scmat/abstract.h>
39
40 namespace sc {
41
42 class BlockedSCMatrixKit;
43 class BlockedSCVector;
44 class BlockedSCMatrix;
45 class BlockedSymmSCMatrix;
46 class BlockedDiagSCMatrix;
47
48 class BlockedSCMatrixKit: public SCMatrixKit {
49 private:
50 Ref<SCMatrixKit> subkit_;
51 public:
52 BlockedSCMatrixKit(const Ref<SCMatrixKit>& subkit);
53 BlockedSCMatrixKit(const Ref<KeyVal>&);
54 ~BlockedSCMatrixKit();
55 SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
56 SymmSCMatrix* symmmatrix(const RefSCDimension&);
57 DiagSCMatrix* diagmatrix(const RefSCDimension&);
58 SCVector* vector(const RefSCDimension&);
59
60 Ref<SCMatrixKit> subkit() { return subkit_; }
61 };
62
63
64 class BlockedSCVector: public SCVector {
65 friend class BlockedSCMatrix;
66 friend class BlockedSymmSCMatrix;
67 friend class BlockedDiagSCMatrix;
68 private:
69 Ref<SCMatrixKit> subkit;
70 RefSCVector *vecs_;
71
72 void resize(SCDimension*);
73
74 public:
75 BlockedSCVector(const RefSCDimension&, BlockedSCMatrixKit*);
76 ~BlockedSCVector();
77
78 // Save and restore this in an implementation independent way.
79 void save(StateOut&);
80 void restore(StateIn&);
81
82 void assign_val(double);
83 void assign_v(SCVector*);
84 void assign_p(const double*);
85
86 double get_element(int) const;
87 void set_element(int,double);
88 void accumulate_element(int,double);
89
90 void accumulate_product_rv(SCMatrix*,SCVector*);
91 void accumulate_product_sv(SymmSCMatrix*,SCVector*);
92
93 void accumulate(const SCVector*);
94 void accumulate(const SCMatrix*);
95 double scalar_product(SCVector*);
96
97 void element_op(const Ref<SCElementOp>&);
98 void element_op(const Ref<SCElementOp2>&,
99 SCVector*);
100 void element_op(const Ref<SCElementOp3>&,
101 SCVector*,SCVector*);
102 void vprint(const char* title=0,
103 std::ostream& out=ExEnv::out0(), int =10) const;
104
105 // BlockedSCVector specific functions
106 RefSCDimension dim() const { return d; }
107 RefSCDimension dim(int) const;
108 int nblocks() const;
109 RefSCVector block(int);
110
111 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
112 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
113 };
114
115 class BlockedSCMatrix: public SCMatrix {
116 friend class BlockedSymmSCMatrix;
117 friend class BlockedDiagSCMatrix;
118 friend class BlockedSCVector;
119 private:
120 Ref<SCMatrixKit> subkit;
121 RefSCMatrix *mats_;
122 int nblocks_;
123
124 void resize(SCDimension*, SCDimension*);
125
126 public:
127 BlockedSCMatrix(const RefSCDimension&, const RefSCDimension&,
128 BlockedSCMatrixKit*);
129 ~BlockedSCMatrix();
130
131 // Save and restore this in an implementation independent way.
132 void save(StateOut&);
133 void restore(StateIn&);
134
135 void assign_val(double);
136 double get_element(int,int) const;
137 void set_element(int,int,double);
138 void accumulate_element(int,int,double);
139
140 SCMatrix * get_subblock(int,int,int,int);
141 void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
142 void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
143
144 SCVector * get_row(int i);
145 SCVector * get_column(int i);
146 void assign_row(SCVector *v, int i);
147 void assign_column(SCVector *v, int i);
148 void accumulate_row(SCVector *v, int i);
149 void accumulate_column(SCVector *v, int i);
150
151 void accumulate_outer_product(SCVector*,SCVector*);
152 void accumulate_product_rr(SCMatrix*,SCMatrix*);
153 void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
154 void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
155 void accumulate(const SCMatrix*);
156 void accumulate(const SymmSCMatrix*);
157 void accumulate(const DiagSCMatrix*);
158 void accumulate(const SCVector*);
159
160 void transpose_this();
161 double invert_this();
162 void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
163 double solve_this(SCVector*);
164 double determ_this();
165 double trace();
166 void gen_invert_this();
167 void schmidt_orthog(SymmSCMatrix*,int);
168 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
169
170 void element_op(const Ref<SCElementOp>&);
171 void element_op(const Ref<SCElementOp2>&,
172 SCMatrix*);
173 void element_op(const Ref<SCElementOp3>&,
174 SCMatrix*,SCMatrix*);
175
176 void vprint(const char* title=0,
177 std::ostream& out=ExEnv::out0(), int =10) const;
178
179 // BlockedSCMatrix specific functions
180 RefSCDimension rowdim() const { return d1; }
181 RefSCDimension coldim() const { return d2; }
182 RefSCDimension rowdim(int) const;
183 RefSCDimension coldim(int) const;
184 int nblocks() const;
185 RefSCMatrix block(int);
186
187 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
188 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
189 };
190
191 class BlockedSymmSCMatrix: public SymmSCMatrix {
192 friend class BlockedSCMatrix;
193 friend class BlockedDiagSCMatrix;
194 friend class BlockedSCVector;
195 private:
196 Ref<SCMatrixKit> subkit;
197 RefSymmSCMatrix *mats_;
198
199 void resize(SCDimension*);
200
201 public:
202 BlockedSymmSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
203 ~BlockedSymmSCMatrix();
204
205 // Save and restore this in an implementation independent way.
206 void save(StateOut&);
207 void restore(StateIn&);
208
209 double get_element(int,int) const;
210 void set_element(int,int,double);
211 void accumulate_element(int,int,double);
212 void scale(double);
213 void assign_val(double);
214 void assign_s(SymmSCMatrix*m);
215
216 SCMatrix * get_subblock(int,int,int,int);
217 SymmSCMatrix * get_subblock(int,int);
218 void assign_subblock(SCMatrix*, int,int,int,int);
219 void assign_subblock(SymmSCMatrix*, int,int);
220 void accumulate_subblock(SCMatrix*, int,int,int,int);
221 void accumulate_subblock(SymmSCMatrix*, int,int);
222 SCVector * get_row(int i);
223 void assign_row(SCVector *v, int i);
224 void accumulate_row(SCVector *v, int i);
225
226 double invert_this();
227 double determ_this();
228 double trace();
229 double solve_this(SCVector*);
230 void gen_invert_this();
231
232 double scalar_product(SCVector*);
233 void diagonalize(DiagSCMatrix*,SCMatrix*);
234
235 void accumulate(const SymmSCMatrix*);
236 void accumulate_symmetric_outer_product(SCVector*);
237 void accumulate_symmetric_product(SCMatrix*);
238 void accumulate_symmetric_sum(SCMatrix*);
239 void accumulate_transform(SCMatrix*,SymmSCMatrix*,
240 SCMatrix::Transform = SCMatrix::NormalTransform);
241 void accumulate_transform(SCMatrix*,DiagSCMatrix*,
242 SCMatrix::Transform = SCMatrix::NormalTransform);
243 void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
244
245 void convert_accumulate(SymmSCMatrix*a);
246
247 void element_op(const Ref<SCElementOp>&);
248 void element_op(const Ref<SCElementOp2>&,
249 SymmSCMatrix*);
250 void element_op(const Ref<SCElementOp3>&,
251 SymmSCMatrix*,SymmSCMatrix*);
252
253 void vprint(const char* title=0,
254 std::ostream& out=ExEnv::out0(), int =10) const;
255
256 // BlockedSymmSCMatrix specific functions
257 RefSCDimension dim() const { return d; }
258 RefSCDimension dim(int) const;
259 int nblocks() const;
260 RefSymmSCMatrix block(int);
261
262 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
263 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
264 };
265
266 class BlockedDiagSCMatrix: public DiagSCMatrix {
267 friend class BlockedSCMatrix;
268 friend class BlockedSymmSCMatrix;
269 friend class BlockedSCVector;
270 private:
271 Ref<SCMatrixKit> subkit;
272 RefDiagSCMatrix *mats_;
273
274 void resize(SCDimension*);
275
276 public:
277 BlockedDiagSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
278 ~BlockedDiagSCMatrix();
279
280 // Save and restore this in an implementation independent way.
281 void save(StateOut&);
282 void restore(StateIn&);
283
284 double get_element(int) const;
285 void set_element(int,double);
286 void accumulate_element(int,double);
287 void accumulate(const DiagSCMatrix*);
288
289 double invert_this();
290 double determ_this();
291 double trace();
292 void gen_invert_this();
293
294 void element_op(const Ref<SCElementOp>&);
295 void element_op(const Ref<SCElementOp2>&,
296 DiagSCMatrix*);
297 void element_op(const Ref<SCElementOp3>&,
298 DiagSCMatrix*,DiagSCMatrix*);
299 void vprint(const char* title=0,
300 std::ostream& out=ExEnv::out0(), int =10) const;
301
302 // BlockedDiagSCMatrix specific functions
303 RefSCDimension dim() const { return d; }
304 RefSCDimension dim(int) const;
305 int nblocks() const;
306 RefDiagSCMatrix block(int);
307
308 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
309 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
310 };
311
312 class BlockedSCElementOp : public SCElementOp {
313 private:
314 int current_block_;
315
316 public:
317 BlockedSCElementOp();
318 void working_on(int);
319 int current_block() const;
320 };
321
322 class BlockedSCElementOp2 : public SCElementOp2 {
323 private:
324 int current_block_;
325
326 public:
327 BlockedSCElementOp2();
328 void working_on(int);
329 int current_block() const;
330 };
331
332 class BlockedSCElementOp3 : public SCElementOp3 {
333 private:
334 int current_block_;
335
336 public:
337 BlockedSCElementOp3();
338 void working_on(int);
339 int current_block() const;
340 };
341
342 }
343
344 #endif
345
346 // Local Variables:
347 // mode: c++
348 // c-file-style: "CLJ"
349 // End: