MPQC  2.3.1
local.h
1 //
2 // local.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_local_h
33 #define _math_scmat_local_h
34 
35 #include <math/scmat/block.h>
36 #include <math/scmat/matrix.h>
37 #include <math/scmat/abstract.h>
38 
39 namespace sc {
40 
41 class LocalSCMatrixKit;
42 class LocalSCVector;
43 class LocalSCMatrix;
44 class LocalSymmSCMatrix;
45 class LocalDiagSCMatrix;
46 
50  public:
55  SymmSCMatrix* symmmatrix(const RefSCDimension&);
56  DiagSCMatrix* diagmatrix(const RefSCDimension&);
57  SCVector* vector(const RefSCDimension&);
58 };
59 
60 class LocalSCVector: public SCVector {
61  friend class LocalSCMatrix;
62  friend class LocalSymmSCMatrix;
63  friend class LocalDiagSCMatrix;
64  private:
66 
67  void resize(int);
68  public:
69  LocalSCVector();
71  ~LocalSCVector();
72  void assign_val(double);
73  void assign_v(SCVector*);
74  void assign_p(const double*);
75 
76  void set_element(int,double);
77  void accumulate_element(int,double);
78  double get_element(int) const;
79  void accumulate_product_sv(SymmSCMatrix*,SCVector*);
80  void accumulate_product_rv(SCMatrix*,SCVector*);
81  void accumulate(const SCVector*);
82  void accumulate(const SCMatrix*);
83  double scalar_product(SCVector*);
84  void element_op(const Ref<SCElementOp>&);
85  void element_op(const Ref<SCElementOp2>&,
86  SCVector*);
87  void element_op(const Ref<SCElementOp3>&,
88  SCVector*,SCVector*);
89  void vprint(const char* title=0,
90  std::ostream& out=ExEnv::out0(), int =10) const;
91 
92  // return a pointer to the data for fast access
93  double *get_data();
94 
95  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
96  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
97 };
98 
99 class LocalSCMatrix: public SCMatrix {
100  friend class LocalSymmSCMatrix;
101  friend class LocalDiagSCMatrix;
102  friend class LocalSCVector;
103  private:
105  double** rows;
106  private:
107  // utility functions
108  int compute_offset(int,int) const;
109  void resize(int,int);
110  public:
113  ~LocalSCMatrix();
114 
115  // implementations and overrides of virtual functions
116  void assign_val(double);
117  double get_element(int,int) const;
118  void set_element(int,int,double);
119  void accumulate_element(int,int,double);
120  SCMatrix * get_subblock(int,int,int,int);
121  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
122  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
123  SCVector * get_row(int i);
124  SCVector * get_column(int i);
125  void assign_row(SCVector *v, int i);
126  void assign_column(SCVector *v, int i);
127  void accumulate_row(SCVector *v, int i);
128  void accumulate_column(SCVector *v, int i);
130  void accumulate_product_rr(SCMatrix*,SCMatrix*);
131  void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
132  void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
133  void accumulate(const SCMatrix*);
134  void accumulate(const SymmSCMatrix*);
135  void accumulate(const DiagSCMatrix*);
136  void accumulate(const SCVector*);
137  void transpose_this();
138  double invert_this();
139  void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
140  double solve_this(SCVector*);
141  double determ_this();
142  double trace();
143  void schmidt_orthog(SymmSCMatrix*,int);
144  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
145  void element_op(const Ref<SCElementOp>&);
146  void element_op(const Ref<SCElementOp2>&,
147  SCMatrix*);
148  void element_op(const Ref<SCElementOp3>&,
149  SCMatrix*,SCMatrix*);
150  void vprint(const char* title=0,
151  std::ostream& out=ExEnv::out0(), int =10) const;
152 
153  // return a pointer to the data for fast access
154  double *get_data();
155  double **get_rows();
156 
157  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
158  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
159 };
160 
162  friend class LocalSCMatrix;
163  friend class LocalDiagSCMatrix;
164  friend class LocalSCVector;
165  private:
167  double** rows;
168  private:
169  // utility functions
170  int compute_offset(int,int) const;
171  void resize(int n);
172  public:
175 
176  // implementations and overrides of virtual functions
177  double get_element(int,int) const;
178  void set_element(int,int,double);
179  void accumulate_element(int,int,double);
180 
181  SCMatrix * get_subblock(int,int,int,int);
182  SymmSCMatrix * get_subblock(int,int);
183  void assign_subblock(SCMatrix*, int,int,int,int);
184  void assign_subblock(SymmSCMatrix*, int,int);
185  void accumulate_subblock(SCMatrix*, int,int,int,int);
186  void accumulate_subblock(SymmSCMatrix*, int,int);
187  SCVector * get_row(int i);
188  void assign_row(SCVector *v, int i);
189  void accumulate_row(SCVector *v, int i);
190 
191  void accumulate_product_rr(SCMatrix*,SCMatrix*);
192  void accumulate(const SymmSCMatrix*);
193  double invert_this();
194  double solve_this(SCVector*);
195  double trace();
196  double determ_this();
197  void gen_invert_this();
198 
199  double scalar_product(SCVector*);
201  void accumulate_symmetric_outer_product(SCVector*);
202  void accumulate_symmetric_product(SCMatrix*);
204  void accumulate_transform(SCMatrix*,SymmSCMatrix*,
205  SCMatrix::Transform = SCMatrix::NormalTransform);
206  void accumulate_transform(SCMatrix*,DiagSCMatrix*,
207  SCMatrix::Transform = SCMatrix::NormalTransform);
208  void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
209  void element_op(const Ref<SCElementOp>&);
210  void element_op(const Ref<SCElementOp2>&,
211  SymmSCMatrix*);
212  void element_op(const Ref<SCElementOp3>&,
214  void vprint(const char* title=0,
215  std::ostream& out=ExEnv::out0(), int =10) const;
216 
217  // return a pointer to the data for fast access
218  double *get_data();
219  double **get_rows();
220 
221  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
222  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
223 };
224 
226  friend class LocalSCMatrix;
227  friend class LocalSymmSCMatrix;
228  friend class LocalSCVector;
229  private:
231  void resize(int n);
232  public:
235 
236  // implementations and overrides of virtual functions
237  void save_data_state(StateOut&);
238  double get_element(int) const;
239  void set_element(int,double);
240  void accumulate_element(int,double);
241  void accumulate(const DiagSCMatrix*);
242  double invert_this();
243  double determ_this();
244  double trace();
245  void gen_invert_this();
246 
247  void element_op(const Ref<SCElementOp>&);
248  void element_op(const Ref<SCElementOp2>&,
249  DiagSCMatrix*);
250  void element_op(const Ref<SCElementOp3>&,
252  void vprint(const char* title=0,
253  std::ostream& out=ExEnv::out0(), int =10) const;
254 
255  // return a pointer to the data for fast access
256  double *get_data();
257 
258  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
259  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
260 };
261 
262 }
263 
264 #endif
265 
266 // Local Variables:
267 // mode: c++
268 // c-file-style: "CLJ"
269 // End:
sc::LocalSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
sc::LocalSymmSCMatrix::diagonalize
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
sc::LocalSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::LocalSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::LocalSymmSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::LocalSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
sc::SCVector
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
sc::LocalSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::LocalDiagSCMatrix::accumulate
void accumulate(const DiagSCMatrix *)
Sum m into this.
sc::LocalSymmSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::LocalSCMatrixKit::matrix
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
sc::LocalSymmSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row of this.
sc::LocalSymmSCMatrix::accumulate_symmetric_sum
void accumulate_symmetric_sum(SCMatrix *)
Sum into this the products of various vectors or matrices.
sc::LocalSymmSCMatrix::invert_this
double invert_this()
Invert this.
sc::LocalSCVector::get_element
double get_element(int) const
Return the value of element i.
sc::LocalSCMatrix::get_row
SCVector * get_row(int i)
Return a row or column of this.
sc::LocalSymmSCMatrix
Definition: local.h:161
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
sc::LocalSCVector::set_element
void set_element(int, double)
Set element i to val.
sc::LocalSCVector
Definition: local.h:60
sc::LocalSymmSCMatrix::get_row
SCVector * get_row(int i)
Return a row of this.
sc::SCMatrixKit
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:58
sc::LocalSCVector::assign_val
void assign_val(double)
Overridden to implement the assign functions.
sc::LocalSCVector::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
sc::LocalSymmSCMatrix::scalar_product
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
sc::LocalSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::LocalSCMatrix::invert_this
double invert_this()
Invert this.
sc::DiagSCMatrix
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:503
sc::LocalDiagSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::LocalDiagSCMatrix::invert_this
double invert_this()
Invert this.
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:156
sc::LocalSymmSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
sc::LocalSCVector::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
sc::LocalSCMatrix::trace
double trace()
Return the trace.
sc::LocalDiagSCMatrix::gen_invert_this
void gen_invert_this()
Do a generalized inversion of this.
sc::LocalSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
sc::LocalSCMatrix::assign_val
void assign_val(double)
Overridden to implement to assign members.
sc::LocalSymmSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::SymmSCMatrix::n
int n() const
Return the dimension.
Definition: abstract.h:412
sc::DiagSCMatrix::n
int n() const
Return the dimension.
Definition: abstract.h:542
sc::LocalSCMatrix::accumulate
void accumulate(const SCMatrix *)
Sum m into this.
sc::LocalSymmSCMatrix::accumulate
void accumulate(const SymmSCMatrix *)
Sum m into this.
sc::LocalSCMatrix
Definition: local.h:99
sc::LocalDiagSCMatrix
Definition: local.h:225
sc::LocalSCVector::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::LocalSymmSCMatrix::trace
double trace()
Return the trace.
sc::LocalSymmSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::LocalSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::StateOut
Serializes objects that derive from SavableState.
Definition: stateout.h:61
sc::LocalSCMatrix::schmidt_orthog_tol
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
sc::LocalDiagSCMatrix::trace
double trace()
Return the trace.
sc::LocalSymmSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::LocalSCVector::scalar_product
double scalar_product(SCVector *)
Return the dot product.
sc::LocalSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
sc::LocalSCMatrixKit
The LocalSCMatrixKit produces matrices that work in a single processor environment.
Definition: local.h:49
sc::SymmSCMatrix
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:364
sc::LocalSCMatrix::transpose_this
void transpose_this()
Transpose this.
sc::LocalDiagSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::LocalSCVector::accumulate_element
void accumulate_element(int, double)
Add val to element i.
sc::LocalSymmSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::LocalSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::SCMatrix
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
sc::LocalSCMatrix::schmidt_orthog
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
sc::LocalSymmSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
sc::LocalDiagSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::LocalSCMatrix::accumulate_outer_product
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
sc::LocalSymmSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
sc::LocalDiagSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::LocalDiagSCMatrix::get_element
double get_element(int) const
Return or modify an element.
sc::LocalSCMatrix::svd_this
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
sc::LocalSCVector::accumulate
void accumulate(const SCVector *)
Sum v into this.

Generated at Sun Jan 26 2020 23:33:04 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.