MPQC  2.3.1
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 #ifdef __GNUC__
29 #pragma interface
30 #endif
31 
32 #ifndef _math_scmat_repl_h
33 #define _math_scmat_repl_h
34 
35 #include <util/group/message.h>
36 
37 #include <math/scmat/block.h>
38 #include <math/scmat/matrix.h>
39 #include <math/scmat/abstract.h>
40 
41 namespace sc {
42 
47  public:
50  ~ReplSCMatrixKit();
52  SymmSCMatrix* symmmatrix(const RefSCDimension&);
53  DiagSCMatrix* diagmatrix(const RefSCDimension&);
54  SCVector* vector(const RefSCDimension&);
55 };
56 
57 
59  protected:
60  Ref<MessageGrp> grp_;
61  double *data_;
62  int ndata_;
63  public:
65  const Ref<SCMatrixBlockList> &list,
66  const Ref<MessageGrp> &grp,
67  double *data, int ndata);
69 };
70 
71 class ReplSCVector: public SCVector {
72  friend class ReplSCMatrix;
73  friend class ReplSymmSCMatrix;
74  friend class ReplDiagSCMatrix;
75  protected:
76  Ref<SCMatrixBlockList> blocklist;
77  double* vector;
78  void init_blocklist();
79  void before_elemop();
80  void after_elemop();
81  public:
83  ~ReplSCVector();
84  void assign_val(double);
85  void assign_v(SCVector*);
86  void assign_p(const double*);
87 
88  void set_element(int,double);
89  void accumulate_element(int,double);
90  double get_element(int) const;
91  void accumulate_product_sv(SymmSCMatrix*,SCVector*);
92  void accumulate_product_rv(SCMatrix*,SCVector*);
93  void accumulate(const SCVector*);
94  void accumulate(const SCMatrix*);
95  double scalar_product(SCVector*);
96  void element_op(const Ref<SCElementOp>&);
97  void element_op(const Ref<SCElementOp2>&,
98  SCVector*);
99  void element_op(const Ref<SCElementOp3>&,
100  SCVector*,SCVector*);
101  void vprint(const char* title=0,
102  std::ostream& out=ExEnv::out0(), int =10) const;
103 
104  // return a pointer to the data for fast access
105  double *get_data() { return vector; }
106 
107  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
108  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
109 
110  Ref<ReplSCMatrixKit> skit();
111 };
112 
113 class ReplSCMatrix: public SCMatrix {
114  friend class ReplSymmSCMatrix;
115  friend class ReplDiagSCMatrix;
116  friend class ReplSCVector;
117  protected:
118  Ref<SCMatrixBlockList> blocklist;
119  double* matrix;
120  double** rows;
121  protected:
122  // utility functions
123  int compute_offset(int,int) const;
124  void init_blocklist();
125 
126  void before_elemop();
127  void after_elemop();
128  public:
130  ReplSCMatrixKit*);
131  ~ReplSCMatrix();
132 
133  // implementations and overrides of virtual functions
134  void assign_val(double);
135  double get_element(int,int) const;
136  void set_element(int,int,double);
137  void accumulate_element(int,int,double);
138  SCMatrix * get_subblock(int,int,int,int);
139  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
140  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
141  SCVector * get_row(int i);
142  SCVector * get_column(int i);
143  void assign_row(SCVector *v, int i);
144  void assign_column(SCVector *v, int i);
145  void accumulate_row(SCVector *v, int i);
146  void accumulate_column(SCVector *v, int i);
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*);
156  void transpose_this();
157  double invert_this();
158  void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
159  double solve_this(SCVector*);
160  double determ_this();
161  double trace();
162  void schmidt_orthog(SymmSCMatrix*,int);
163  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
164  void element_op(const Ref<SCElementOp>&);
165  void element_op(const Ref<SCElementOp2>&,
166  SCMatrix*);
167  void element_op(const Ref<SCElementOp3>&,
168  SCMatrix*,SCMatrix*);
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 
179  Ref<ReplSCMatrixKit> skit();
180 };
181 
183  friend class ReplSCMatrix;
184  friend class ReplDiagSCMatrix;
185  friend class ReplSCVector;
186  protected:
187  Ref<SCMatrixBlockList> blocklist;
188  double* matrix;
189  double** rows;
190  protected:
191  // utility functions
192  int compute_offset(int,int) const;
193  void init_blocklist();
194 
195  void before_elemop();
196  void after_elemop();
197  public:
199  ~ReplSymmSCMatrix();
200 
201  // implementations and overrides of virtual functions
202  void assign_val(double);
203  void assign_s(SymmSCMatrix*);
204  void assign_p(const double*);
205  void assign_pp(const double**);
206  double get_element(int,int) const;
207  void set_element(int,int,double);
208  void accumulate_element(int,int,double);
209  void scale(double);
210 
211  SCMatrix * get_subblock(int,int,int,int);
212  SymmSCMatrix * get_subblock(int,int);
213  void assign_subblock(SCMatrix*, int,int,int,int);
214  void assign_subblock(SymmSCMatrix*, int,int);
215  void accumulate_subblock(SCMatrix*, int,int,int,int);
216  void accumulate_subblock(SymmSCMatrix*, int,int);
217  SCVector * get_row(int i);
218  void assign_row(SCVector *v, int i);
219  void accumulate_row(SCVector *v, int i);
220 
221  void accumulate_product_rr(SCMatrix*,SCMatrix*);
222  void accumulate(const SymmSCMatrix*);
223  double invert_this();
224  double solve_this(SCVector*);
225  double trace();
226  double determ_this();
227  void gen_invert_this();
228 
229  double scalar_product(SCVector*);
231  void accumulate_symmetric_outer_product(SCVector*);
232  void accumulate_symmetric_product(SCMatrix*);
234  void accumulate_transform(SCMatrix*,SymmSCMatrix*,
235  SCMatrix::Transform = SCMatrix::NormalTransform);
236  void accumulate_transform(SCMatrix*,DiagSCMatrix*,
237  SCMatrix::Transform = SCMatrix::NormalTransform);
238  void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
239  void element_op(const Ref<SCElementOp>&);
240  void element_op(const Ref<SCElementOp2>&,
241  SymmSCMatrix*);
242  void element_op(const Ref<SCElementOp3>&,
244  void vprint(const char* title=0,
245  std::ostream& out=ExEnv::out0(), int =10) const;
246 
247  // return a pointer to the data for fast access
248  double *get_data() { return matrix; }
249  double **get_rows() { return rows; }
250 
251  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
252  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
253 
254  Ref<ReplSCMatrixKit> skit();
255 };
256 
258  friend class ReplSCMatrix;
259  friend class ReplSymmSCMatrix;
260  friend class ReplSCVector;
261  protected:
262  Ref<SCMatrixBlockList> blocklist;
263  void init_blocklist();
264  double* matrix;
265 
266  void before_elemop();
267  void after_elemop();
268  public:
270  ~ReplDiagSCMatrix();
271 
272  // implementations and overrides of virtual functions
273  void assign_val(double);
274  double get_element(int) const;
275  void set_element(int,double);
276  void accumulate_element(int,double);
277  void accumulate(const DiagSCMatrix*);
278  double invert_this();
279  double determ_this();
280  double trace();
281  void gen_invert_this();
282 
283  void element_op(const Ref<SCElementOp>&);
284  void element_op(const Ref<SCElementOp2>&,
285  DiagSCMatrix*);
286  void element_op(const Ref<SCElementOp3>&,
288  void vprint(const char* title=0,
289  std::ostream& out=ExEnv::out0(), int =10) const;
290 
291  // return a pointer to the data for fast access
292  double *get_data() { return matrix; }
293 
294  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
295  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
296 
297  Ref<ReplSCMatrixKit> skit();
298 };
299 
300 }
301 
302 #endif
303 
304 // Local Variables:
305 // mode: c++
306 // c-file-style: "CLJ"
307 // End:
double get_element(int) const
Return or modify an element.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void gen_invert_this()
Do a generalized inversion of this.
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
double get_element(int, int) const
Return or modify an element.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
void assign_val(double)
Overridden to implement the assign functions.
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
void transpose_this()
Transpose this.
void assign_val(double)
Overridden to implement the assign members.
double invert_this()
Invert this.
double determ_this()
Return the determinant of this. this is overwritten.
void assign_row(SCVector *v, int i)
Assign v to a row of this.
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
void accumulate_element(int, double)
Add val to element i.
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
double trace()
Return the trace.
double invert_this()
Invert this.
void set_element(int, double)
Set element i to val.
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
A template class that maintains references counts.
Definition: ref.h:332
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:58
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
void accumulate_symmetric_sum(SCMatrix *)
Sum into this the products of various vectors or matrices.
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
Definition: repl.h:71
SCVector * get_row(int i)
Return a row or column of this.
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:503
void accumulate(const DiagSCMatrix *)
Sum m into this.
void assign_val(double)
Overridden to implement to assign members.
Definition: block.h:418
Definition: mpqcin.h:13
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:156
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void accumulate(const SCVector *)
Sum v into this.
double invert_this()
Invert this.
static std::ostream & out0()
Return an ostream that writes from node 0.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:364
double scalar_product(SCVector *)
Return the dot product.
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 accumulate(const SymmSCMatrix *)
Sum m into this.
double determ_this()
Return the determinant of this. this is overwritten.
SCVector * get_row(int i)
Return a row of this.
void accumulate(const SCMatrix *)
Sum m into this.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
Definition: repl.h:113
Definition: repl.h:257
void scale(double)
Multiply all elements by val.
Definition: repl.h:182
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
double trace()
Return the trace.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
double get_element(int, int) const
Return or modify an element.
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
The ReplSCMatrixKit produces matrices that work in a many processor environment.
Definition: repl.h:46
double trace()
Return the trace.
double determ_this()
Return the determinant of this. this is overwritten.
void assign_val(double)
Overridden to implement the assign functions.

Generated at Fri Feb 16 2018 01:48:56 for MPQC 2.3.1 using the documentation package Doxygen 1.8.14.