28 #ifndef _math_scmat_abstract_h
29 #define _math_scmat_abstract_h
31 #include <util/group/message.h>
33 #include <util/state/state.h>
34 #ifdef MPQC_NEW_FEATURES
35 # include <util/misc/xml.h>
37 #include <math/scmat/dim.h>
38 #include <math/scmat/block.h>
106 virtual void restore(
StateIn&);
119 int n()
const {
return d->n(); }
121 virtual double maxabs()
const;
129 void assign(
const double* v) { assign_p(v); }
135 virtual void assign_p(
const double* v);
138 void convert(
double* v)
const { convert_p(v); }
140 virtual void convert_p(
double* v)
const;
141 virtual void convert_v(SCVector*);
142 virtual void convert_accumulate(SCVector*);
144 virtual void scale(
double val);
156 { accumulate_product_sv(m,v); }
158 { accumulate_product_rv(m,v); }
159 virtual void accumulate_product_sv(SymmSCMatrix* m, SCVector* v);
160 virtual void accumulate_product_rv(SCMatrix* m, SCVector* v) = 0;
162 virtual void accumulate(
const SCVector*v) = 0;
164 virtual void accumulate(
const SCMatrix*m) = 0;
168 virtual void element_op(
const Ref<SCElementOp>&) = 0;
169 virtual void element_op(
const Ref<SCElementOp2>&,
171 virtual void element_op(
const Ref<SCElementOp3>&,
172 SCVector*,SCVector*) = 0;
175 void print(
const char* title=0,std::ostream&out=
ExEnv::out0(),
int=10)
const;
176 virtual void vprint(
const char*title=0,std::ostream&out=
ExEnv::out0(),
187 SCMatrixSubblockIter::Access) = 0;
189 virtual Ref<SCMatrixSubblockIter>
all_blocks(SCMatrixSubblockIter::Access) = 0;
196 #ifdef MPQC_NEW_FEATURES
205 enum Transform { NormalTransform = 0, TransposeTransform = 1 };
213 virtual void restore(
StateIn&);
215 #ifdef MPQC_NEW_FEATURES
216 virtual boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent,
const XMLWriter& writer);
223 int nrow()
const {
return d1->n(); }
225 int ncol()
const {
return d2->n(); }
227 virtual double maxabs()
const;
233 void assign(
const double* m) { assign_p(m); }
235 void assign(
const double** m) { assign_pp(m); }
240 virtual void assign_p(
const double* m);
241 virtual void assign_pp(
const double** m);
245 void convert(
double*a)
const { convert_p(a); }
246 void convert(
double**a)
const { convert_pp(a); }
247 void convert(SCMatrix*a) { convert_r(a); }
248 virtual void convert_p(
double*)
const;
249 virtual void convert_pp(
double**)
const;
250 virtual void convert_r(SCMatrix*a);
251 virtual void convert_accumulate(SCMatrix*);
253 virtual void scale(
double val);
261 virtual SCMatrix*
copy();
263 virtual SCMatrix*
clone();
271 virtual void set_element(
int,
int,
double) = 0;
272 virtual void accumulate_element(
int,
int,
double) = 0;
277 virtual SCMatrix *
get_subblock(
int br,
int er,
int bc,
int ec) =0;
280 virtual void assign_subblock(SCMatrix *m,
int,
int,
int,
int,
int=0,
int=0) =0;
284 int source_br = 0,
int source_bc = 0) =0;
287 virtual SCVector *
get_row(
int i) =0;
288 virtual SCVector * get_column(
int i) =0;
291 virtual void assign_row(SCVector *v,
int i) =0;
292 virtual void assign_column(SCVector *v,
int i) =0;
296 virtual void accumulate_column(SCVector *v,
int i) =0;
299 virtual void accumulate(
const SCMatrix* m) = 0;
300 virtual void accumulate(
const SymmSCMatrix* m) = 0;
301 virtual void accumulate(
const DiagSCMatrix* m) = 0;
305 void accumulate_product(SCMatrix*m1,SCMatrix*m2)
306 { accumulate_product_rr(m1,m2); }
307 void accumulate_product(SCMatrix*m1,SymmSCMatrix*m2)
308 { accumulate_product_rs(m1,m2); }
309 void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
310 { accumulate_product_rd(m1,m2); }
311 void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
312 { accumulate_product_sr(m1,m2); }
313 void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
314 { accumulate_product_dr(m1,m2); }
315 void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
316 { accumulate_product_ss(m1,m2); }
317 void accumulate_product(SymmSCMatrix*m1,DiagSCMatrix*m2)
318 { accumulate_product_sd(m1,m2); }
319 void accumulate_product(DiagSCMatrix*m1,SymmSCMatrix*m2)
320 { accumulate_product_ds(m1,m2); }
321 virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
322 virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
323 virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
324 virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
325 virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
326 virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
327 virtual void accumulate_product_sd(SymmSCMatrix*,DiagSCMatrix*);
328 virtual void accumulate_product_ds(DiagSCMatrix*,SymmSCMatrix*);
332 virtual double trace() =0;
340 virtual void svd_this(SCMatrix *U, DiagSCMatrix *
sigma, SCMatrix *V);
341 virtual double solve_this(SCVector*) = 0;
359 virtual void element_op(
const Ref<SCElementOp>&) = 0;
360 virtual void element_op(
const Ref<SCElementOp2>&,
362 virtual void element_op(
const Ref<SCElementOp3>&,
363 SCMatrix*,SCMatrix*) = 0;
368 virtual void vprint(
const char*title=0,
377 SCMatrixSubblockIter::Access) = 0;
380 SCMatrixSubblockIter::Access) = 0;
386 #ifdef MPQC_NEW_FEATURES
402 virtual void restore(
StateIn&);
404 #ifdef MPQC_NEW_FEATURES
405 virtual boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent,
const XMLWriter& writer);
409 virtual double maxabs()
const;
415 void assign(
const double* m) { assign_p(m); }
417 void assign(
const double** m) { assign_pp(m); }
423 virtual void assign_p(
const double* m);
424 virtual void assign_pp(
const double** m);
427 void convert(
double*a)
const { convert_p(a); }
428 void convert(
double**a)
const { convert_pp(a); }
429 void convert(SymmSCMatrix*a) { convert_s(a); }
430 virtual void convert_p(
double*)
const;
431 virtual void convert_pp(
double**)
const;
432 virtual void convert_s(SymmSCMatrix*);
433 virtual void convert_accumulate(SymmSCMatrix*);
435 virtual void scale(
double);
443 int n()
const {
return d->n(); }
454 virtual void set_element(
int,
int,
double) = 0;
455 virtual void accumulate_element(
int,
int,
double) = 0;
499 virtual void accumulate_symmetric_outer_product(
SCVector*);
504 virtual double trace() = 0;
510 virtual double solve_this(
SCVector*) = 0;
512 virtual void gen_invert_this(
double condition_number_threshold = 1e8) = 0;
534 virtual void vprint(
const char* title=0,
543 SCMatrixSubblockIter::Access) = 0;
546 SCMatrixSubblockIter::Access) = 0;
552 #ifdef MPQC_NEW_FEATURES
568 virtual void restore(
StateIn&);
570 #ifdef MPQC_NEW_FEATURES
571 virtual boost::property_tree::ptree& write_xml(boost::property_tree::ptree& parent,
const XMLWriter& writer);
575 virtual double maxabs()
const;
581 void assign(
const double*p) { assign_p(p); }
587 virtual void assign_p(
const double*);
590 void convert(
double*a)
const { convert_p(a); }
592 virtual void convert_p(
double*)
const;
593 virtual void convert_d(DiagSCMatrix*);
594 virtual void convert_accumulate(DiagSCMatrix*);
596 virtual void scale(
double);
598 int n()
const {
return d->n(); }
609 virtual void set_element(
int,
double) = 0;
610 virtual void accumulate_element(
int,
double) = 0;
614 virtual double trace() = 0;
620 virtual void gen_invert_this(
double condition_number_threshold = 1e8) = 0;
629 void print(
const char* title=0,
631 virtual void vprint(
const char* title=0,
640 SCMatrixSubblockIter::Access) = 0;
643 SCMatrixSubblockIter::Access) = 0;
virtual SCMatrix * copy()
Return a matrix with the same dimension and same elements.
virtual double determ_this()=0
Return the determinant of this. this is overwritten.
virtual double get_element(int, int) const =0
Return or modify an element.
void assign(const double *m)
Assign element i, j to m[i*(i+1)/2+j].
Definition: abstract.h:415
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:564
virtual void accumulate(const SCMatrix *m)=0
Sum m into this.
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual void scale_diagonal(double)
Scale the diagonal elements by val.
void assign(DiagSCMatrix *d_a)
Make this have the same elements as m.
Definition: abstract.h:584
virtual double maxabs() const
Return the maximum absolute value element of this vector.
void convert(double *a) const
Like the assign members, but these write values to the arguments.
Definition: abstract.h:427
virtual void transpose_this()=0
Transpose this.
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
virtual void assign_val(double val)
Overridden to implement the assign members.
virtual void accumulate_outer_product(SCVector *, SCVector *)=0
Sum into this the products of various vectors or matrices.
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
void assign(const double *m)
Assign element i, j to m[ir*nrow()+j].
Definition: abstract.h:233
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
RefSCDimension dim() const
Return the dimension.
Definition: abstract.h:606
virtual double get_element(int, int) const =0
Return or modify an element.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this vector.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this vector.
virtual void scale(double val)
Multiply each element by val.
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual double scalar_product(SCVector *v)
Return the scalar obtained by multiplying this on the left and right by v.
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)=0
Given the dimensions, create matrices or vectors.
A template class that maintains references counts.
Definition: ref.h:361
int ncol() const
Return the number of columns.
Definition: abstract.h:225
virtual double determ_this()=0
Return the determinant of this. this is overwritten.
void assign(SymmSCMatrix *m)
Make this have the same elements as m.
Definition: abstract.h:420
virtual void accumulate_row(SCVector *v, int i)=0
Sum v to a row of this.
virtual void diagonalize(DiagSCMatrix *d, SCMatrix *m)=0
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit object that created this object.
Definition: abstract.h:398
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual SCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
virtual void scale(double)
Multiply all elements by val.
virtual DiagSCMatrix * copy()
Return a matrix with the same dimension and same elements.
virtual void assign_val(double val)
Overridden to implement the assign functions.
virtual double invert_this()=0
Invert this.
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:57
virtual void gen_invert_this(double condition_number_threshold=1e8)
Return the generalized inverse of this using SVD decomposition.
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
virtual void assign_val(double val)
Overridden to implement the assign functions.
virtual void assign_val(double val)
Overridden to implement to assign members.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:220
virtual void schmidt_orthog(SymmSCMatrix *, int n)=0
Schmidt orthogonalize this.
virtual void gen_invert_this(double condition_number_threshold=1e8)=0
Return the generalized inverse of this using SVD decomposition.
void accumulate_product(SymmSCMatrix *m, SCVector *v)
Sum the result of m times v into this.
Definition: abstract.h:155
virtual SCMatrix * get_subblock(int br, int er, int bc, int ec)=0
Return a subblock of this.
virtual void element_op(const Ref< SCElementOp > &)=0
only applied to the unique elements of this.
RefSCDimension dim() const
Return the RefSCDimension corresponding to this vector.
Definition: abstract.h:147
virtual void accumulate(const SymmSCMatrix *m)=0
Sum m into this.
virtual void eigensystem(SymmSCMatrix *s, DiagSCMatrix *d, SCMatrix *m)=0
Solve generalized eigensystem for this with metric s, placing the eigenvalues in d and the eigenvecto...
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:551
virtual void set_element(int i, double val)=0
Set element i to val.
static void set_default_matrixkit(const Ref< SCMatrixKit > &)
change the default matrix kit
virtual double trace()=0
Return the trace.
virtual void scale_diagonal(double val)
Scale the diagonal elements by val.
void assign(const double *v)
Assign element i to v[i] for all i.
Definition: abstract.h:129
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
virtual void scale(double)
Multiply all elements by val.
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
virtual void accumulate_symmetric_product(SCMatrix *a)
Sum into this a * a.t()
virtual void accumulate_subblock(SCMatrix *m, int br, int er, int bc, int ec, int source_br=0, int source_bc=0)=0
Sum m into a subblock of this.
virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0)=0
Assign m to a subblock of this.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual void scale(double val)
Multiply all elements by val.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual void accumulate_subblock(SCMatrix *m, int, int, int, int)=0
Sum m into a subblock of this.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:109
virtual SymmSCMatrix * copy()
Return a matrix with the same dimension and same elements.
static SCMatrixKit * default_matrixkit()
This returns the default matrix kit.
void assign(SCMatrix *m)
Make this have the same elements as m. The dimensions must match.
Definition: abstract.h:237
void assign(const double *p)
Assign element i, i to m[i].
Definition: abstract.h:581
virtual double determ_this()=0
Return the determinant of this. this is overwritten.
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
int n() const
Return the dimension.
Definition: abstract.h:443
virtual void accumulate(const SCVector *v)=0
Sum v into this.
int n() const
Return the dimension.
Definition: abstract.h:598
virtual void unit()
Make this equal to the unit matrix.
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual void accumulate_element(int, double)=0
Add val to element i.
void assign(SCVector *v)
Make this have the same elements as v.
Definition: abstract.h:132
void assign(const double **m)
Assign element i, j to m[i][j].
Definition: abstract.h:235
virtual SCVector * copy()
Return a vector with the same dimension and same elements.
SCMatrix * restore_matrix(StateIn &, const RefSCDimension &, const RefSCDimension &)
Given the dimensions and a StateIn object, restore matrices or vectors.
RefSCDimension rowdim() const
Return the row or column dimension.
Definition: abstract.h:267
virtual SCVector * clone()
Return a vector with the same dimension but uninitialized memory.
virtual void assign_row(SCVector *v, int i)=0
Assign v to a row of this.
virtual void shift_diagonal(double)
Shift the diagonal elements by val.
virtual int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)=0
Schmidt orthogonalize this.
virtual SCMatrix * get_subblock(int br, int er, int bc, int ec)=0
Return a subblock of this.
virtual double invert_this()=0
Invert this.
Definition: stateout.h:71
void assign(double val)
Assign all elements of this to val.
Definition: abstract.h:127
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
Definition: xmlwriter.h:215
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
void convert(double *a) const
Like the assign member, but this writes values to the argument.
Definition: abstract.h:590
void assign(const double **m)
Assign element i, j to m[i][j].
Definition: abstract.h:417
virtual SCVector * get_row(int i)=0
Return a row of this.
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:385
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void convert(double *a) const
Like the assign members, but these write values to the arguments.
Definition: abstract.h:245
Transform
types of matrix transforms. Only real-valued matrices are assumed.
Definition: abstract.h:205
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition: class.h:233
virtual void normalize()
Normalize this.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
virtual void unit()
Make this equal to the unit matrix.
virtual double scalar_product(SCVector *)=0
Return the dot product.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual void assign_subblock(SCMatrix *m, int, int, int, int)=0
Assign m to a subblock of this.
static std::ostream & out0()
Return an ostream that writes from node 0.
void convert(double *v) const
Assign v[i] to element i for all i.
Definition: abstract.h:138
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
virtual double maxabs() const
Return the maximum absolute value element of this vector.
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
void assign(double val)
Set all elements to val.
Definition: abstract.h:413
virtual void accumulate_symmetric_sum(SCMatrix *a)=0
Sum into a + a.t()
virtual DiagSCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
void print(std::ostream &o=ExEnv::out0()) const
Print out the vector.
virtual double get_element(int) const =0
Return or modify an element.
virtual double get_element(int i) const =0
Return the value of element i.
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133
void assign(double val)
Set all elements to val.
Definition: abstract.h:231
virtual void accumulate_row(SCVector *v, int i)=0
Sum v to a row or column of this.
virtual double trace()=0
Return the trace.
virtual void assign_row(SCVector *v, int i)=0
Assign v to a row or column of this.
virtual void shift_diagonal(double val)
Shift the diagonal elements by val.
virtual void gen_invert_this(double condition_number_threshold=1e8)=0
Return the generalized inverse of this using SVD decomposition.
virtual double maxabs() const
Return the maximum absolute value element of this vector.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
int nrow() const
Return the number of rows.
Definition: abstract.h:223
RefSCDimension dim() const
Return the dimension.
Definition: abstract.h:451
virtual double maxabs() const
Return the maximum absolute value element.
virtual double trace()=0
Return the trace.
virtual SCVector * get_row(int i)=0
Return a row or column of this.
int n() const
Return the length of the vector.
Definition: abstract.h:119
virtual double invert_this()=0
Invert this.
virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
virtual SymmSCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
void assign(double val)
Set all elements to val.
Definition: abstract.h:579
virtual void accumulate(const DiagSCMatrix *m)=0
Sum m into this.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
Generated at Sun Jan 26 2020 23:24:00 for MPQC
3.0.0-alpha using the documentation package Doxygen
1.8.16.