MPQC 2.3.1
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
40namespace sc {
41
42class BlockedSCMatrixKit;
43class BlockedSCVector;
44class BlockedSCMatrix;
45class BlockedSymmSCMatrix;
46class BlockedDiagSCMatrix;
47
49 private:
50 Ref<SCMatrixKit> subkit_;
51 public:
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
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:
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*);
96
98 void element_op(const Ref<SCElementOp2>&,
99 SCVector*);
100 void element_op(const Ref<SCElementOp3>&,
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
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:
130
131 // Save and restore this in an implementation independent way.
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
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
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
161 double invert_this();
163 double solve_this(SCVector*);
164 double determ_this();
165 double trace();
166 void gen_invert_this();
168 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
169
171 void element_op(const Ref<SCElementOp2>&,
172 SCMatrix*);
173 void element_op(const Ref<SCElementOp3>&,
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
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:
204
205 // Save and restore this in an implementation independent way.
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);
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
234
236 void accumulate_symmetric_outer_product(SCVector*);
237 void accumulate_symmetric_product(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
248 void element_op(const Ref<SCElementOp2>&,
249 SymmSCMatrix*);
250 void element_op(const Ref<SCElementOp3>&,
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
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:
279
280 // Save and restore this in an implementation independent way.
282 void restore(StateIn&);
283
284 double get_element(int) const;
285 void set_element(int,double);
286 void accumulate_element(int,double);
288
289 double invert_this();
290 double determ_this();
291 double trace();
293
295 void element_op(const Ref<SCElementOp2>&,
296 DiagSCMatrix*);
297 void element_op(const Ref<SCElementOp3>&,
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
313 private:
314 int current_block_;
315
316 public:
318 void working_on(int);
319 int current_block() const;
320};
321
323 private:
324 int current_block_;
325
326 public:
328 void working_on(int);
329 int current_block() const;
330};
331
333 private:
334 int current_block_;
335
336 public:
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:
Definition blocked.h:266
double get_element(int) const
Return or modify an element.
double invert_this()
Invert this.
void gen_invert_this()
Do a generalized inversion of this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void save(StateOut &)
Save and restore this in an implementation independent way.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
double trace()
Return the trace.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void accumulate(const DiagSCMatrix *)
Sum m into this.
double determ_this()
Return the determinant of this. this is overwritten.
Definition blocked.h:322
Definition blocked.h:332
Definition blocked.h:312
Definition blocked.h:48
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
Definition blocked.h:115
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
double get_element(int, int) const
Return or modify an element.
double determ_this()
Return the determinant of this. this is overwritten.
void assign_val(double)
Overridden to implement to assign members.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
SCVector * get_row(int i)
Return a row or column of this.
double invert_this()
Invert this.
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
void transpose_this()
Transpose this.
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
double trace()
Return the trace.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void accumulate(const SCMatrix *)
Sum m into this.
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
void save(StateOut &)
Save and restore this in an implementation independent way.
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
Definition blocked.h:64
double scalar_product(SCVector *)
Return the dot product.
void accumulate(const SCMatrix *)
Sum m into this. One of m's dimensions must be 1.
void assign_val(double)
Overridden to implement the assign functions.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
double get_element(int) const
Return the value of element i.
void set_element(int, double)
Set element i to val.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
void accumulate_element(int, double)
Add val to element i.
void accumulate(const SCVector *)
Sum v into this.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
void save(StateOut &)
Save and restore this in an implementation independent way.
Definition blocked.h:191
double determ_this()
Return the determinant of this. this is overwritten.
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
void accumulate_symmetric_sum(SCMatrix *)
Sum into this the products of various vectors or matrices.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void scale(double)
Multiply all elements by val.
void accumulate(const SymmSCMatrix *)
Sum m into this.
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
void assign_val(double)
Overridden to implement the assign functions.
void save(StateOut &)
Save and restore this in an implementation independent way.
double invert_this()
Invert this.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
double get_element(int, int) const
Return or modify an element.
SCVector * get_row(int i)
Return a row of this.
void assign_row(SCVector *v, int i)
Assign v to a row of this.
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
double trace()
Return the trace.
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition abstract.h:503
static std::ostream & out0()
Return an ostream that writes from node 0.
The RefDiagSCMatrix class is a smart pointer to an DiagSCMatrix specialization.
Definition matrix.h:380
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition dim.h:156
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition matrix.h:135
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition matrix.h:55
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition matrix.h:261
A template class that maintains references counts.
Definition ref.h:332
The SCDimension class is used to determine the size and blocking of matrices.
Definition dim.h:109
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
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition abstract.h:58
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition abstract.h:195
The SCVector class is the abstract base class for double valued vectors.
Definition abstract.h:97
Restores objects that derive from SavableState.
Definition statein.h:70
Serializes objects that derive from SavableState.
Definition stateout.h:61
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition abstract.h:364

Generated at Fri Jan 31 2025 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.12.0.