MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
repl.h
1//
2// repl.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_repl_h
29#define _math_scmat_repl_h
30
31#include <util/group/message.h>
32
33#include <math/scmat/block.h>
34#include <math/scmat/matrix.h>
35#include <math/scmat/abstract.h>
36
37namespace sc {
38
43 public:
48 SymmSCMatrix* symmmatrix(const RefSCDimension&);
49 DiagSCMatrix* diagmatrix(const RefSCDimension&);
50 SCVector* vector(const RefSCDimension&);
51};
52
53
55 protected:
56 Ref<MessageGrp> grp_;
57 double *data_;
58 int ndata_;
59 public:
61 const Ref<SCMatrixBlockList> &list,
62 const Ref<MessageGrp> &grp,
63 double *data, int ndata);
65};
66
67class ReplSCVector: public SCVector {
68 friend class ReplSCMatrix;
69 friend class ReplSymmSCMatrix;
70 friend class ReplDiagSCMatrix;
71 protected:
72 Ref<SCMatrixBlockList> blocklist;
73 double* vector;
74 void init_blocklist();
75 void before_elemop();
76 void after_elemop();
77 public:
80 void assign_val(double);
81 void assign_v(SCVector*);
82 void assign_p(const double*);
83
84 void set_element(int,double);
85 void accumulate_element(int,double);
86 double get_element(int) const;
87 void accumulate_product_sv(SymmSCMatrix*,SCVector*);
88 void accumulate_product_rv(SCMatrix*,SCVector*);
89 void accumulate(const SCVector*);
90 void accumulate(const SCMatrix*);
93 void element_op(const Ref<SCElementOp2>&,
94 SCVector*);
95 void element_op(const Ref<SCElementOp3>&,
97 void vprint(const char* title=0,
98 std::ostream& out=ExEnv::out0(), int =10) const;
99
100 // return a pointer to the data for fast access
101 double *get_data() { return vector; }
102
103 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
104 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
105
107};
108
109class ReplSCMatrix: public SCMatrix {
110 friend class ReplSymmSCMatrix;
111 friend class ReplDiagSCMatrix;
112 friend class ReplSCVector;
113 protected:
114 Ref<SCMatrixBlockList> blocklist;
115 double* matrix;
116 double** rows;
117 protected:
118 // utility functions
119 size_t compute_offset(int,int) const;
120 void init_blocklist();
121
122 void before_elemop();
123 void after_elemop();
124 public:
128
129 // implementations and overrides of virtual functions
130 void assign_val(double);
131 double get_element(int,int) const;
132 void set_element(int,int,double);
133 void accumulate_element(int,int,double);
134 SCMatrix * get_subblock(int,int,int,int);
135 void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
136 void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
138 SCVector * get_column(int i);
139 void assign_row(SCVector *v, int i);
140 void assign_column(SCVector *v, int i);
141 void accumulate_row(SCVector *v, int i);
142 void accumulate_column(SCVector *v, int i);
143 void assign_p(const double*);
144 void assign_pp(const double**);
145 void convert_p(double*) const;
146 void convert_pp(double**) const;
147
149 void accumulate_product_rr(SCMatrix*,SCMatrix*);
150 void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
151 void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
152 void accumulate(const SCMatrix*);
153 void accumulate(const SymmSCMatrix*);
154 void accumulate(const DiagSCMatrix*);
155 void accumulate(const SCVector*);
157 double invert_this();
159 double solve_this(SCVector*);
160 double determ_this();
161 double trace();
163 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
165 void element_op(const Ref<SCElementOp2>&,
166 SCMatrix*);
167 void element_op(const Ref<SCElementOp3>&,
169 void vprint(const char* title=0,
170 std::ostream& out=ExEnv::out0(), int =10) const;
171
172 // return a pointer to the data for fast access
173 double *get_data() { return matrix; }
174 double **get_rows() { return rows; }
175
176 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
177 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
178
180};
181
184 friend class ReplSCMatrix;
185 friend class ReplDiagSCMatrix;
186 friend class ReplSCVector;
187 protected:
188 Ref<SCMatrixBlockList> blocklist;
189 double* matrix;
190 double** rows;
191 protected:
192 // utility functions
193 size_t compute_offset(int,int) const;
194 void init_blocklist();
195
196 void before_elemop();
197 void after_elemop();
198 public:
201
202 // implementations and overrides of virtual functions
203 void assign_val(double);
204 void assign_s(SymmSCMatrix*);
205 void assign_p(const double*);
206 void assign_pp(const double**);
207 void convert_p(double*) const;
208 void convert_pp(double**) const;
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
214 SCMatrix * get_subblock(int,int,int,int);
215 SymmSCMatrix * get_subblock(int,int);
216 void assign_subblock(SCMatrix*, int,int,int,int);
217 void assign_subblock(SymmSCMatrix*, int,int);
218 void accumulate_subblock(SCMatrix*, int,int,int,int);
219 void accumulate_subblock(SymmSCMatrix*, int,int);
221 void assign_row(SCVector *v, int i);
222 void accumulate_row(SCVector *v, int i);
223
224 void accumulate_product_rr(SCMatrix*,SCMatrix*);
226 double invert_this();
227 double solve_this(SCVector*);
228 double trace();
229 double determ_this();
230 void gen_invert_this(double condition_number_threshold = 1e8);
231
235 void accumulate_symmetric_outer_product(SCVector*);
238 void accumulate_transform(SCMatrix*,SymmSCMatrix*,
239 SCMatrix::Transform = SCMatrix::NormalTransform);
240 void accumulate_transform(SCMatrix*,DiagSCMatrix*,
241 SCMatrix::Transform = SCMatrix::NormalTransform);
242 void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
244 void element_op(const Ref<SCElementOp2>&,
245 SymmSCMatrix*);
246 void element_op(const Ref<SCElementOp3>&,
248 void vprint(const char* title=0,
249 std::ostream& out=ExEnv::out0(), int =10) const;
250
251 // return a pointer to the data for fast access
252 double *get_data() { return matrix; }
253 double **get_rows() { return rows; }
254
255 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
256 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
257
259};
260
263 friend class ReplSCMatrix;
264 friend class ReplSymmSCMatrix;
265 friend class ReplSCVector;
266 protected:
267 Ref<SCMatrixBlockList> blocklist;
268 void init_blocklist();
269 double* matrix;
270
271 void before_elemop();
272 void after_elemop();
273 public:
276
277 // implementations and overrides of virtual functions
278 void assign_val(double);
279 double get_element(int) const;
280 void set_element(int,double);
281 void accumulate_element(int,double);
283 double invert_this();
284 double determ_this();
285 double trace();
286 void gen_invert_this(double condition_number_threshold = 1e8);
287
289 void element_op(const Ref<SCElementOp2>&,
290 DiagSCMatrix*);
291 void element_op(const Ref<SCElementOp3>&,
293 void vprint(const char* title=0,
294 std::ostream& out=ExEnv::out0(), int =10) const;
295
296 // return a pointer to the data for fast access
297 double *get_data() { return matrix; }
298
299 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
300 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
301
303};
304
305}
306
307#endif
308
309// Local Variables:
310// mode: c++
311// c-file-style: "CLJ"
312// End:
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition abstract.h:555
static std::ostream & out0()
Return an ostream that writes from node 0.
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition dim.h:152
A template class that maintains references counts.
Definition ref.h:361
Replicated DiagSCMatrix.
Definition repl.h:262
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
double get_element(int) const
Return or modify an element.
double determ_this()
Return the determinant of this. this is overwritten.
void accumulate(const DiagSCMatrix *)
Sum m into this.
void assign_val(double)
Overridden to implement the assign members.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
double trace()
Return the trace.
void gen_invert_this(double condition_number_threshold=1e8)
Return the generalized inverse of this using SVD decomposition.
double invert_this()
Invert this.
The ReplSCMatrixKit produces matrices that work in a many processor environment.
Definition repl.h:42
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
Definition repl.h:109
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
void accumulate(const SCMatrix *)
Sum m into this.
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
SCVector * get_row(int i)
Return a row or column of this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
double get_element(int, int) const
Return or modify an element.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void assign_val(double)
Overridden to implement to assign members.
double invert_this()
Invert this.
void transpose_this()
Transpose this.
double trace()
Return the trace.
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
double determ_this()
Return the determinant of this. this is overwritten.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
Definition repl.h:67
void accumulate(const SCVector *)
Sum v into this.
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.
double get_element(int) const
Return the value of element i.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
void accumulate(const SCMatrix *)
Sum m into this. One of m's dimensions must be 1.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void assign_val(double)
Overridden to implement the assign functions.
double scalar_product(SCVector *)
Return the dot product.
Replicated SymmSCMatrix.
Definition repl.h:183
void accumulate(const SymmSCMatrix *)
Sum m into this.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void accumulate_symmetric_sum(SCMatrix *)
Sum into a + a.t()
void assign_row(SCVector *v, int i)
Assign v to a row of this.
void gen_invert_this(double condition_number_threshold=1e8)
Return the generalized inverse of this using SVD decomposition.
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
void assign_val(double)
Overridden to implement the assign functions.
void element_op(const Ref< SCElementOp > &)
only applied to the unique elements of this.
SCMatrix * get_subblock(int, int, int, int)
Return 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 accumulate_symmetric_product(SCMatrix *)
Sum into this a * a.t()
double invert_this()
Invert this.
double trace()
Return the trace.
SCVector * get_row(int i)
Return a row of this.
void eigensystem(SymmSCMatrix *, DiagSCMatrix *, SCMatrix *)
Solve generalized eigensystem for this with metric s, placing the eigenvalues in d and the eigenvecto...
void scale(double)
Multiply all elements by val.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition abstract.h:57
Definition block.h:414
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition abstract.h:199
Transform
types of matrix transforms. Only real-valued matrices are assumed.
Definition abstract.h:205
The SCVector class is the abstract base class for double valued vectors.
Definition abstract.h:97
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition abstract.h:389
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.