MPQC  3.0.0-alpha
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 #ifndef _math_scmat_blocked_h
29 #define _math_scmat_blocked_h
30 
31 #include <math/scmat/block.h>
32 #include <math/scmat/elemop.h>
33 #include <math/scmat/matrix.h>
34 #include <math/scmat/abstract.h>
35 
36 namespace sc {
37 
38 class BlockedSCMatrixKit;
39 class BlockedSCVector;
40 class BlockedSCMatrix;
41 class BlockedSymmSCMatrix;
42 class BlockedDiagSCMatrix;
43 
46  private:
47  Ref<SCMatrixKit> subkit_;
48  public:
53  SymmSCMatrix* symmmatrix(const RefSCDimension&);
54  DiagSCMatrix* diagmatrix(const RefSCDimension&);
56 
58  Ref<SCMatrixKit> subkit() { return subkit_; }
59 
62  SCMatrixKit* subkit = subkit_.pointer();
63  BlockedSCMatrixKit* bsubkit = dynamic_cast<BlockedSCMatrixKit*>(subkit);
64  while (bsubkit) {
65  subkit = bsubkit->subkit().pointer();
66  bsubkit = dynamic_cast<BlockedSCMatrixKit*>(subkit);
67  }
68  return subkit;
69  }
70 
71 };
72 
73 
74 class BlockedSCVector: public SCVector {
75  friend class BlockedSCMatrix;
76  friend class BlockedSymmSCMatrix;
77  friend class BlockedDiagSCMatrix;
78  private:
79  Ref<SCMatrixKit> subkit;
80  RefSCVector *vecs_;
81 
82  void resize(SCDimension*);
83 
84  public:
86  ~BlockedSCVector();
87 
88  // Save and restore this in an implementation independent way.
89  void save(StateOut&);
90  void restore(StateIn&);
91 
92  void assign_val(double);
93  void assign_v(SCVector*);
94  void assign_p(const double*);
95 
96  double get_element(int) const;
97  void set_element(int,double);
98  void accumulate_element(int,double);
99 
100  void accumulate_product_rv(SCMatrix*,SCVector*);
101  void accumulate_product_sv(SymmSCMatrix*,SCVector*);
102 
103  void accumulate(const SCVector*);
104  void accumulate(const SCMatrix*);
105  double scalar_product(SCVector*);
106 
107  void element_op(const Ref<SCElementOp>&);
108  void element_op(const Ref<SCElementOp2>&,
109  SCVector*);
110  void element_op(const Ref<SCElementOp3>&,
111  SCVector*,SCVector*);
112  void vprint(const char* title=0,
113  std::ostream& out=ExEnv::out0(), int =10) const;
114 
115  // BlockedSCVector specific functions
116  RefSCDimension dim() const { return d; }
117  RefSCDimension dim(int) const;
118  int nblocks() const;
119  RefSCVector block(int);
120 
121  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
122  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
123 };
124 
126 class BlockedSCMatrix: public SCMatrix {
127  friend class BlockedSymmSCMatrix;
128  friend class BlockedDiagSCMatrix;
129  friend class BlockedSCVector;
130  private:
131  Ref<SCMatrixKit> subkit;
132  RefSCMatrix *mats_;
133  int nblocks_;
134 
135  void resize(SCDimension*, SCDimension*);
136 
137  public:
140  ~BlockedSCMatrix();
141 
142  // Save and restore this in an implementation independent way.
143  void save(StateOut&);
144  void restore(StateIn&);
145 
146  void assign_val(double);
147  double get_element(int,int) const;
148  void set_element(int,int,double);
149  void accumulate_element(int,int,double);
150 
151  void assign_p(const double*);
152  void assign_pp(const double**);
153  void convert_p(double*) const;
154  void convert_pp(double**) const;
155 
156  SCMatrix * get_subblock(int,int,int,int);
157  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
158  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
159 
160  SCVector * get_row(int i);
161  SCVector * get_column(int i);
162  void assign_row(SCVector *v, int i);
163  void assign_column(SCVector *v, int i);
164  void accumulate_row(SCVector *v, int i);
165  void accumulate_column(SCVector *v, int i);
166 
168  void accumulate_product_rr(SCMatrix*,SCMatrix*);
169  void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
170  void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
171  void accumulate(const SCMatrix*);
172  void accumulate(const SymmSCMatrix*);
173  void accumulate(const DiagSCMatrix*);
174  void accumulate(const SCVector*);
175 
176  void transpose_this();
177  double invert_this();
179  double solve_this(SCVector*);
180  double determ_this();
181  double trace();
183  void gen_invert_this(double condition_number_threshold = 1e8);
184  void schmidt_orthog(SymmSCMatrix*,int);
185  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
186 
187  void convert_accumulate(SCMatrix*a);
188 
189  void element_op(const Ref<SCElementOp>&);
190  void element_op(const Ref<SCElementOp2>&,
191  SCMatrix*);
192  void element_op(const Ref<SCElementOp3>&,
193  SCMatrix*,SCMatrix*);
194 
195  void vprint(const char* title=0,
196  std::ostream& out=ExEnv::out0(), int =10) const;
197 
198  // BlockedSCMatrix specific functions
199  RefSCDimension rowdim() const { return d1; }
200  RefSCDimension coldim() const { return d2; }
201  RefSCDimension rowdim(int) const;
202  RefSCDimension coldim(int) const;
203  int nblocks() const;
204  RefSCMatrix block(int);
205 
206  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
207  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
208 };
209 
212  friend class BlockedSCMatrix;
213  friend class BlockedDiagSCMatrix;
214  friend class BlockedSCVector;
215  private:
216  Ref<SCMatrixKit> subkit;
217  RefSymmSCMatrix *mats_;
218 
219  void resize(SCDimension*);
220 
221  public:
224 
225  // Save and restore this in an implementation independent way.
226  void save(StateOut&);
227  void restore(StateIn&);
228 
229  double get_element(int,int) const;
230  void set_element(int,int,double);
231  void accumulate_element(int,int,double);
232  void scale(double);
233  void assign_val(double);
234  void assign_s(SymmSCMatrix*m);
235 
236  void assign_p(const double*);
237  void assign_pp(const double**);
238  void convert_p(double*) const;
239  void convert_pp(double**) const;
240 
241  SCMatrix * get_subblock(int,int,int,int);
242  SymmSCMatrix * get_subblock(int,int);
243  void assign_subblock(SCMatrix*, int,int,int,int);
244  void assign_subblock(SymmSCMatrix*, int,int);
245  void accumulate_subblock(SCMatrix*, int,int,int,int);
246  void accumulate_subblock(SymmSCMatrix*, int,int);
247  SCVector * get_row(int i);
248  void assign_row(SCVector *v, int i);
249  void accumulate_row(SCVector *v, int i);
250 
251  double invert_this();
252  double determ_this();
253  double trace();
254  double solve_this(SCVector*);
256  void gen_invert_this(double condition_number_threshold = 1e8);
257 
258  double scalar_product(SCVector*);
262 
263  void accumulate(const SymmSCMatrix*);
264  void accumulate_symmetric_outer_product(SCVector*);
267  void accumulate_transform(SCMatrix*,SymmSCMatrix*,
268  SCMatrix::Transform = SCMatrix::NormalTransform);
269  void accumulate_transform(SCMatrix*,DiagSCMatrix*,
270  SCMatrix::Transform = SCMatrix::NormalTransform);
271  void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
272 
273  void convert_accumulate(SymmSCMatrix*a);
274 
275  void element_op(const Ref<SCElementOp>&);
276  void element_op(const Ref<SCElementOp2>&,
277  SymmSCMatrix*);
278  void element_op(const Ref<SCElementOp3>&,
280 
281  void vprint(const char* title=0,
282  std::ostream& out=ExEnv::out0(), int =10) const;
283 
284  // BlockedSymmSCMatrix specific functions
285  RefSCDimension dim() const { return d; }
286  RefSCDimension dim(int) const;
287  int nblocks() const;
288  RefSymmSCMatrix block(int);
289 
290  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
291  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
292 };
293 
296  friend class BlockedSCMatrix;
297  friend class BlockedSymmSCMatrix;
298  friend class BlockedSCVector;
299  private:
300  Ref<SCMatrixKit> subkit;
301  RefDiagSCMatrix *mats_;
302 
303  void resize(SCDimension*);
304 
305  public:
308 
309  // Save and restore this in an implementation independent way.
310  void save(StateOut&);
311  void restore(StateIn&);
312 
313  double get_element(int) const;
314  void set_element(int,double);
315  void accumulate_element(int,double);
316  void accumulate(const DiagSCMatrix*);
317 
318  double invert_this();
319  double determ_this();
320  double trace();
322  void gen_invert_this(double condition_number_threshold = 1e8);
323 
324  void convert_accumulate(DiagSCMatrix*a);
325 
326  void element_op(const Ref<SCElementOp>&);
327  void element_op(const Ref<SCElementOp2>&,
328  DiagSCMatrix*);
329  void element_op(const Ref<SCElementOp3>&,
331  void vprint(const char* title=0,
332  std::ostream& out=ExEnv::out0(), int =10) const;
333 
334  // BlockedDiagSCMatrix specific functions
335  RefSCDimension dim() const { return d; }
336  RefSCDimension dim(int) const;
337  int nblocks() const;
338  RefDiagSCMatrix block(int);
339 
340  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
341  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
342 };
343 
345  private:
346  int current_block_;
347 
348  public:
350  void working_on(int);
351  int current_block() const;
352 };
353 
355  private:
356  int current_block_;
357 
358  public:
360  void working_on(int);
361  int current_block() const;
362 };
363 
365  private:
366  int current_block_;
367 
368  public:
370  void working_on(int);
371  int current_block() const;
372 };
373 
374 }
375 
376 #endif
377 
378 // Local Variables:
379 // mode: c++
380 // c-file-style: "CLJ"
381 // End:
sc::BlockedSymmSCMatrix::get_row
SCVector * get_row(int i)
Return a row of this.
sc::BlockedSCMatrix::svd_this
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
sc::BlockedDiagSCMatrix::get_element
double get_element(int) const
Return or modify an element.
sc::SCElementOp2
The SCElementOp2 class is very similar to the SCElementOp class except that pairs of blocks are treat...
Definition: elemop.h:159
sc::BlockedSymmSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
sc::BlockedSCVector::set_element
void set_element(int, double)
Set element i to val.
sc::BlockedDiagSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::BlockedSCVector::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::BlockedSCMatrixKit::subkit_lowest
Ref< SCMatrixKit > subkit_lowest()
same as subkit, but recursive
Definition: blocked.h:61
sc::BlockedSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::BlockedSymmSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row of this.
mpqc::ci::sigma
void sigma(const CI< Type, Index > &ci, const mpqc::Vector &h, const Matrix &V, ci::Vector &C, ci::Vector &S)
Computes sigma 1,2,3 contributions.
Definition: sigma.hpp:30
sc::SCDimension
The SCDimension class is used to determine the size and blocking of matrices.
Definition: dim.h:105
sc::BlockedDiagSCMatrix::trace
double trace()
Return the trace.
sc::SCVector
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
sc::BlockedSCVector::accumulate
void accumulate(const SCVector *)
Sum v into this.
sc::BlockedSCMatrixKit::matrix
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
sc::BlockedSymmSCMatrix::accumulate_symmetric_product
void accumulate_symmetric_product(SCMatrix *)
Sum into this a * a.t()
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::BlockedSCMatrix::accumulate_outer_product
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
sc::BlockedSymmSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
sc::BlockedSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
generalized-invert this.
sc::RefSCMatrix
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition: matrix.h:135
sc::BlockedSymmSCMatrix::eigensystem
void eigensystem(SymmSCMatrix *S, DiagSCMatrix *e, SCMatrix *V)
like diagonalize(), but with general metric S
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::BlockedSCVector::scalar_product
double scalar_product(SCVector *)
Return the dot product.
sc::BlockedSymmSCMatrix::save
void save(StateOut &)
Save and restore this in an implementation independent way.
sc::BlockedSCMatrix::schmidt_orthog_tol
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
sc::SCMatrixKit
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:57
sc::BlockedSymmSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
sc::Ref::pointer
T * pointer() const
Returns a pointer the reference counted object.
Definition: ref.h:413
sc::BlockedSCVector::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
sc::RefDiagSCMatrix
The RefDiagSCMatrix class is a smart pointer to an DiagSCMatrix specialization.
Definition: matrix.h:389
sc::BlockedSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::BlockedSCVector
Definition: blocked.h:74
sc::DiagSCMatrix
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:551
sc::BlockedSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::BlockedSCMatrixKit
BlockedSCMatrixKit is a SCMatrixKit that produces blocked matrices.
Definition: blocked.h:45
sc::SCElementOp
Objects of class SCElementOp are used to perform operations on the elements of matrices.
Definition: elemop.h:94
sc::BlockedSymmSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::StateIn
Definition: statein.h:79
sc::BlockedSCElementOp
Definition: blocked.h:344
sc::BlockedSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
sc::BlockedSCVector::get_element
double get_element(int) const
Return the value of element i.
sc::BlockedSCMatrix::assign_val
void assign_val(double)
Overridden to implement to assign members.
sc::BlockedSCMatrix::schmidt_orthog
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
sc::BlockedDiagSCMatrix::accumulate
void accumulate(const DiagSCMatrix *)
Sum m into this.
sc::BlockedDiagSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::BlockedSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::BlockedDiagSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::BlockedSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
sc::BlockedSCVector::accumulate_element
void accumulate_element(int, double)
Add val to element i.
sc::BlockedSCVector::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
sc::BlockedSymmSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::BlockedSymmSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::BlockedSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
sc::BlockedSCMatrix::save
void save(StateOut &)
Save and restore this in an implementation independent way.
sc::BlockedSCMatrix::get_row
SCVector * get_row(int i)
Return a row or column of this.
sc::BlockedSymmSCMatrix::trace
double trace()
Return the trace.
sc::BlockedSymmSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
only applied to the unique elements of this.
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::BlockedDiagSCMatrix::invert_this
double invert_this()
Invert this.
sc::StateOut
Definition: stateout.h:71
sc::BlockedSymmSCMatrix::scale
void scale(double)
Multiply all elements by val.
sc::BlockedSCElementOp2
Definition: blocked.h:354
sc::BlockedSCMatrix::invert_this
double invert_this()
Invert this.
sc::BlockedSCMatrix::accumulate
void accumulate(const SCMatrix *)
Sum m into this.
sc::SymmSCMatrix
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:385
sc::BlockedSymmSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::BlockedDiagSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::BlockedDiagSCMatrix
Blocked DiagSCMatrix.
Definition: blocked.h:295
sc::SCMatrix::Transform
Transform
types of matrix transforms. Only real-valued matrices are assumed.
Definition: abstract.h:205
sc::BlockedSymmSCMatrix
Blocked SymmSCMatrix.
Definition: blocked.h:211
sc::BlockedSCElementOp3
Definition: blocked.h:364
sc::BlockedSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::BlockedSCMatrixKit::subkit
Ref< SCMatrixKit > subkit()
the kit used to implement blocks of the matrices
Definition: blocked.h:58
sc::SCMatrix
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
sc::BlockedDiagSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
generalized-invert this.
sc::BlockedSymmSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
generalized-invert this.
sc::BlockedSCMatrix::trace
double trace()
Return the trace.
sc::BlockedSymmSCMatrix::invert_this
double invert_this()
Invert this.
sc::SCElementOp3
The SCElementOp3 class is very similar to the SCElementOp class except that a triplet of blocks is tr...
Definition: elemop.h:181
mpqc::vector
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133
sc::BlockedSCMatrix
Blocked SCMatrix.
Definition: blocked.h:126
sc::BlockedSymmSCMatrix::assign_val
void assign_val(double)
Overridden to implement the assign functions.
sc::BlockedSymmSCMatrix::scalar_product
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
sc::BlockedSCVector::save
void save(StateOut &)
Save and restore this in an implementation independent way.
sc::BlockedSCMatrix::transpose_this
void transpose_this()
Transpose this.
sc::BlockedSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::BlockedDiagSCMatrix::save
void save(StateOut &)
Save and restore this in an implementation independent way.
sc::BlockedSymmSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::BlockedSymmSCMatrix::diagonalize
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
sc::BlockedSymmSCMatrix::accumulate
void accumulate(const SymmSCMatrix *)
Sum m into this.
sc::BlockedSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::BlockedSymmSCMatrix::accumulate_symmetric_sum
void accumulate_symmetric_sum(SCMatrix *)
Sum into a + a.t()
sc::BlockedSCVector::assign_val
void assign_val(double)
Overridden to implement the assign functions.

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.