28 #ifndef _math_scmat_abstract_h
29 #define _math_scmat_abstract_h
35 #include <util/group/message.h>
37 #include <util/state/state.h>
38 #include <math/scmat/dim.h>
39 #include <math/scmat/block.h>
106 virtual void restore(
StateIn&);
119 int n()
const {
return d->n(); }
129 void assign(
const double* v) { assign_p(v); }
135 virtual void assign_p(
const double* v);
142 virtual void convert_accumulate(
SCVector*);
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;
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;
201 enum Transform { NormalTransform = 0, TransposeTransform = 1 };
209 virtual void restore(
StateIn&);
215 int nrow()
const {
return d1->n(); }
217 int ncol()
const {
return d2->n(); }
225 void assign(
const double* m) { assign_p(m); }
227 void assign(
const double** m) { assign_pp(m); }
232 virtual void assign_p(
const double* m);
233 virtual void assign_pp(
const double** m);
238 virtual void convert(
double**)
const;
242 virtual void convert_accumulate(
SCMatrix*);
262 virtual void set_element(
int,
int,
double) = 0;
263 virtual void accumulate_element(
int,
int,
double) = 0;
278 virtual SCVector * get_column(
int i) =0;
282 virtual void assign_column(
SCVector *v,
int i) =0;
286 virtual void accumulate_column(
SCVector *v,
int i) =0;
296 { accumulate_product_rr(m1,m2); }
298 { accumulate_product_rs(m1,m2); }
299 void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
300 { accumulate_product_rd(m1,m2); }
301 void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
302 { accumulate_product_sr(m1,m2); }
303 void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
304 { accumulate_product_dr(m1,m2); }
305 void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
306 { accumulate_product_ss(m1,m2); }
307 virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
308 virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
309 virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
310 virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
311 virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
312 virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
325 virtual double solve_this(
SCVector*) = 0;
326 virtual void gen_invert_this();
347 virtual void vprint(
const char*title=0,
356 SCMatrixSubblockIter::Access) = 0;
359 SCMatrixSubblockIter::Access) = 0;
377 virtual void restore(
StateIn&);
385 void assign(
const double* m) { assign_p(m); }
387 void assign(
const double** m) { assign_pp(m); }
393 virtual void assign_p(
const double* m);
394 virtual void assign_pp(
const double** m);
398 virtual void convert(
double**)
const;
412 int n()
const {
return d->n(); }
423 virtual void set_element(
int,
int,
double) = 0;
424 virtual void accumulate_element(
int,
int,
double) = 0;
456 virtual void accumulate_symmetric_product(
SCMatrix*);
458 SCMatrix::Transform = SCMatrix::NormalTransform);
460 SCMatrix::Transform = SCMatrix::NormalTransform);
462 virtual void accumulate_symmetric_outer_product(
SCVector*);
473 virtual double solve_this(
SCVector*) = 0;
474 virtual void gen_invert_this() = 0;
486 virtual void vprint(
const char* title=0,
495 SCMatrixSubblockIter::Access) = 0;
498 SCMatrixSubblockIter::Access) = 0;
516 virtual void restore(
StateIn&);
525 void assign(
const double*p) { assign_p(p); }
531 virtual void assign_p(
const double*);
542 int n()
const {
return d->n(); }
553 virtual void set_element(
int,
double) = 0;
554 virtual void accumulate_element(
int,
double) = 0;
573 void print(
const char* title=0,
575 virtual void vprint(
const char* title=0,
584 SCMatrixSubblockIter::Access) = 0;
587 SCMatrixSubblockIter::Access) = 0;
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition: class.h:244
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:503
virtual void convert(double *) const
Like the assign member, but this writes values to the argument.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual double invert_this()=0
Invert this.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual DiagSCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
virtual double trace()=0
Return the trace.
RefSCDimension dim() const
Return the dimension.
Definition: abstract.h:550
virtual DiagSCMatrix * copy()
Return a matrix with the same dimension and same elements.
virtual void scale(double)
Multiply all elements by val.
virtual void gen_invert_this()=0
Do a generalized inversion of this.
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
virtual double maxabs() const
Return the maximum absolute value element of this vector.
void assign(DiagSCMatrix *d_a)
Make this have the same elements as m.
Definition: abstract.h:528
void assign(double val)
Set all elements to val.
Definition: abstract.h:523
virtual void convert(DiagSCMatrix *)
Convert an SCDiagSCMatrix of a different specialization to this specialization and possibly accumulat...
virtual double get_element(int) const =0
Return or modify an element.
void assign(const double *p)
Assign element i, i to m[i].
Definition: abstract.h:525
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual void accumulate(const DiagSCMatrix *m)=0
Sum m into this.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:512
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.
virtual void assign_val(double val)
Overridden to implement the assign members.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
int n() const
Return the dimension.
Definition: abstract.h:542
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:156
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
static SCMatrixKit * default_matrixkit()
This returns a LocalSCMatrixKit, unless the default has been changed with set_default_matrixkit.
SCMatrix * restore_matrix(StateIn &, const RefSCDimension &, const RefSCDimension &)
Given the dimensions and a StateIn object, restore matrices or vectors.
virtual SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)=0
Given the dimensions, create matrices or vectors.
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
virtual double invert_this()=0
Invert this.
virtual void randomize()
Assign each element to a random number between -1 and 1.
virtual SCMatrix * copy()
Return a matrix with the same dimension and same elements.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
virtual void accumulate_subblock(SCMatrix *m, int, int, int, int, int=0, int=0)=0
Sum m into a subblock of this.
virtual void convert(double *) const
Like the assign members, but these write values to the arguments.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:212
virtual void accumulate_outer_product(SCVector *, SCVector *)=0
Sum into this the products of various vectors or matrices.
RefSCDimension rowdim() const
Return the row or column dimension.
Definition: abstract.h:258
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 Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
virtual void schmidt_orthog(SymmSCMatrix *, int n)=0
Schmidt orthogonalize this.
virtual double determ_this()=0
Return the determinant of this. this is overwritten.
virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0)=0
Assign m to a subblock of this.
virtual void scale_diagonal(double val)
Scale the diagonal elements by val.
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
virtual void assign_val(double val)
Overridden to implement to assign members.
void assign(const double *m)
Assign element i, j to m[ir*nrow()+j].
Definition: abstract.h:225
virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
void assign(double val)
Set all elements to val.
Definition: abstract.h:223
virtual void accumulate_row(SCVector *v, int i)=0
Sum v to a row or column of this.
virtual void unit()
Make this equal to the unit matrix.
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][j].
Definition: abstract.h:227
virtual double maxabs() const
Return the maximum absolute value element.
virtual void convert(SCMatrix *)
Convert an SCMatrix of a different specialization to this specialization and possibly accumulate the ...
virtual double trace()=0
Return the trace.
void assign(SCMatrix *m)
Make this have the same elements as m. The dimensions must match.
Definition: abstract.h:229
int nrow() const
Return the number of rows.
Definition: abstract.h:215
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
virtual void shift_diagonal(double val)
Shift the diagonal elements by val.
int ncol() const
Return the number of columns.
Definition: abstract.h:217
virtual SCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
virtual void transpose_this()=0
Transpose this.
virtual SCVector * get_row(int i)=0
Return a row or column of this.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
virtual void accumulate(const SCMatrix *m)=0
Sum m into this.
virtual void scale(double val)
Multiply all elements by val.
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual void assign_row(SCVector *v, int i)=0
Assign v to a row or column of this.
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
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.
virtual void normalize()
Normalize this.
virtual double maxabs() const
Return the maximum absolute value element of this vector.
RefSCDimension dim() const
Return the RefSCDimension corresponding to this vector.
Definition: abstract.h:147
virtual void scale(double val)
Multiply each element by val.
virtual void accumulate(const SCVector *v)=0
Sum v into this.
virtual void assign_val(double val)
Overridden to implement the assign functions.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this vector.
virtual double get_element(int i) const =0
Return the value of element i.
void assign(const double *v)
Assign element i to v[i] for all i.
Definition: abstract.h:129
virtual void accumulate(const SCMatrix *m)=0
Sum m into this. One of m's dimensions must be 1.
virtual void convert(SCVector *)
Convert an SCVector of a different specialization to this specialization and possibly accumulate the ...
void print(std::ostream &o=ExEnv::out0()) const
Print out the vector.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this vector.
Ref< MessageGrp > messagegrp() const
Returns the message group used by the matrix kit.
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit used to create this object.
Definition: abstract.h:109
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual void set_element(int i, double val)=0
Set element i to val.
virtual void convert(double *v) const
Assign v[i] to element i for all i.
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
virtual double scalar_product(SCVector *)=0
Return the dot product.
void accumulate_product(SymmSCMatrix *m, SCVector *v)
Sum the result of m times v into this.
Definition: abstract.h:155
virtual SCVector * clone()
Return a vector with the same dimension but uninitialized memory.
int n() const
Return the length of the vector.
Definition: abstract.h:119
void assign(SCVector *v)
Make this have the same elements as v.
Definition: abstract.h:132
void assign(double val)
Assign all elements of this to val.
Definition: abstract.h:127
virtual SCVector * copy()
Return a vector with the same dimension and same elements.
Restores objects that derive from SavableState.
Definition: statein.h:70
Serializes objects that derive from SavableState.
Definition: stateout.h:61
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:364
virtual void unit()
Make this equal to the unit matrix.
virtual double determ_this()=0
Return the determinant of this. this is overwritten.
virtual void scale(double)
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.
void assign(SymmSCMatrix *m)
Make this have the same elements as m.
Definition: abstract.h:390
int n() const
Return the dimension.
Definition: abstract.h:412
virtual void randomize()
Assign each element to a random number between -1 and 1.
void assign(double val)
Set all elements to val.
Definition: abstract.h:383
Ref< SCMatrixKit > kit() const
Return the SCMatrixKit object that created this object.
Definition: abstract.h:373
virtual void convert(SymmSCMatrix *)
Convert an SCSymmSCMatrix of a different specialization to this specialization and possibly accumulat...
virtual void accumulate_symmetric_sum(SCMatrix *)=0
Sum into this the products of various vectors or matrices.
virtual double maxabs() const
Return the maximum absolute value element of this vector.
void print(std::ostream &o=ExEnv::out0()) const
Print out the matrix.
virtual void element_op(const Ref< SCElementOp > &)=0
Perform the element operation op on each element of this.
virtual void scale_diagonal(double)
Scale the diagonal elements by val.
virtual Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the all blocks used in this matrix.
virtual Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)=0
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
virtual void accumulate(const SymmSCMatrix *m)=0
Sum m into this.
virtual void assign_val(double val)
Overridden to implement the assign functions.
virtual SymmSCMatrix * clone()
Return a matrix with the same dimension but uninitialized memory.
void assign(const double *m)
Assign element i, j to m[i*(i+1)/2+j].
Definition: abstract.h:385
virtual SymmSCMatrix * copy()
Return a matrix with the same dimension and same elements.
virtual SCMatrix * get_subblock(int br, int er, int bc, int ec)=0
Return a subblock of this.
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.
virtual void assign_subblock(SCMatrix *m, int, int, int, int)=0
Assign m to a subblock of this.
virtual double scalar_product(SCVector *v)
Return the scalar obtained by multiplying this on the left and right by v.
virtual void convert(double *) const
Like the assign members, but these write values to the arguments.
RefSCDimension dim() const
Return the dimension.
Definition: abstract.h:420
virtual void save(StateOut &)
Save and restore this in an implementation independent way.
virtual double invert_this()=0
Invert this.
virtual double trace()=0
Return the trace.
virtual SCVector * get_row(int i)=0
Return a row of this.
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][j].
Definition: abstract.h:387
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.