abstract.h
//
// abstract.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifndef _math_scmat_abstract_h
#define _math_scmat_abstract_h
#ifdef __GNUC__
#pragma interface
#endif
#include <util/group/message.h>
#include <util/state/state.h>
#include <math/scmat/dim.h>
#include <math/scmat/block.h>
#include <iostream>
namespace sc {
class SCMatrix;
class SymmSCMatrix;
class DiagSCMatrix;
class SCVector;
class SCElementOp;
class SCElementOp2;
class SCElementOp3;
class RefSCDimension;
class SCMatrixKit: public DescribedClass {
protected:
Ref<MessageGrp> grp_;
public:
SCMatrixKit();
SCMatrixKit(const Ref<KeyVal>&);
~SCMatrixKit();
// these members are default in local.cc
static SCMatrixKit* default_matrixkit();
static void set_default_matrixkit(const Ref<SCMatrixKit> &);
Ref<MessageGrp> messagegrp() const;
virtual SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&) = 0;
virtual SymmSCMatrix* symmmatrix(const RefSCDimension&) = 0;
virtual DiagSCMatrix* diagmatrix(const RefSCDimension&) = 0;
virtual SCVector* vector(const RefSCDimension&) = 0;
SCMatrix* restore_matrix(StateIn&,
const RefSCDimension&,
const RefSCDimension&);
SymmSCMatrix* restore_symmmatrix(StateIn&,
const RefSCDimension&);
DiagSCMatrix* restore_diagmatrix(StateIn&,
const RefSCDimension&);
SCVector* restore_vector(StateIn&,
const RefSCDimension&);
};
class SCVector: public DescribedClass {
protected:
RefSCDimension d;
Ref<SCMatrixKit> kit_;
public:
SCVector(const RefSCDimension&, SCMatrixKit *);
virtual void save(StateOut&);
virtual void restore(StateIn&);
Ref<SCMatrixKit> kit() const { return kit_; }
// concrete functions (some can be overridden)
virtual SCVector* copy();
virtual SCVector* clone();
virtual ~SCVector();
int n() const { return d->n(); }
virtual double maxabs() const;
virtual void normalize();
virtual void randomize();
void assign(double val) { assign_val(val); }
void assign(const double* v) { assign_p(v); }
void assign(SCVector* v) { assign_v(v); }
virtual void assign_val(double val);
virtual void assign_p(const double* v);
virtual void assign_v(SCVector *v);
virtual void convert(double* v) const;
virtual void convert(SCVector*);
virtual void convert_accumulate(SCVector*);
virtual void scale(double val);
RefSCDimension dim() const { return d; }
virtual void set_element(int i,double val) = 0;
virtual void accumulate_element(int,double) = 0;
virtual double get_element(int i) const = 0;
void accumulate_product(SymmSCMatrix* m, SCVector* v)
{ accumulate_product_sv(m,v); }
void accumulate_product(SCMatrix* m, SCVector* v)
{ accumulate_product_rv(m,v); }
virtual void accumulate_product_sv(SymmSCMatrix* m, SCVector* v);
virtual void accumulate_product_rv(SCMatrix* m, SCVector* v) = 0;
virtual void accumulate(const SCVector*v) = 0;
virtual void accumulate(const SCMatrix*m) = 0;
virtual double scalar_product(SCVector*) = 0;
virtual void element_op(const Ref<SCElementOp>&) = 0;
virtual void element_op(const Ref<SCElementOp2>&,
SCVector*) = 0;
virtual void element_op(const Ref<SCElementOp3>&,
SCVector*,SCVector*) = 0;
void print(std::ostream&o=ExEnv::out0()) const;
void print(const char* title=0,std::ostream&out=ExEnv::out0(),int=10) const;
virtual void vprint(const char*title=0,std::ostream&out=ExEnv::out0(),
int=10) const = 0;
Ref<MessageGrp> messagegrp() const;
virtual Ref<SCMatrixSubblockIter> local_blocks(
SCMatrixSubblockIter::Access) = 0;
virtual Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access) = 0;
};
class SCMatrix: public DescribedClass {
protected:
RefSCDimension d1,d2;
Ref<SCMatrixKit> kit_;
public:
// used to control transformations
enum Transform { NormalTransform = 0, TransposeTransform = 1 };
// concrete functions (some can be overridden)
SCMatrix(const RefSCDimension&, const RefSCDimension&, SCMatrixKit *);
virtual ~SCMatrix();
virtual void save(StateOut&);
virtual void restore(StateIn&);
Ref<SCMatrixKit> kit() const { return kit_; }
int nrow() const { return d1->n(); }
int ncol() const { return d2->n(); }
virtual double maxabs() const;
virtual void randomize();
void assign(double val) { assign_val(val); }
void assign(const double* m) { assign_p(m); }
void assign(const double** m) { assign_pp(m); }
void assign(SCMatrix* m) { assign_r(m); }
virtual void assign_val(double val);
virtual void assign_p(const double* m);
virtual void assign_pp(const double** m);
virtual void assign_r(SCMatrix* m);
virtual void convert(double*) const;
virtual void convert(double**) const;
virtual void convert(SCMatrix*);
virtual void convert_accumulate(SCMatrix*);
virtual void scale(double val);
virtual void scale_diagonal(double val);
virtual void shift_diagonal(double val);
virtual void unit();
virtual SCMatrix* copy();
virtual SCMatrix* clone();
// pure virtual functions
RefSCDimension rowdim() const { return d1; }
RefSCDimension coldim() const { return d2; }
virtual double get_element(int,int) const = 0;
virtual void set_element(int,int,double) = 0;
virtual void accumulate_element(int,int,double) = 0;
virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0) =0;
virtual void accumulate_subblock(SCMatrix *m, int, int, int, int, int=0,int=0) =0;
virtual SCVector * get_row(int i) =0;
virtual SCVector * get_column(int i) =0;
virtual void assign_row(SCVector *v, int i) =0;
virtual void assign_column(SCVector *v, int i) =0;
virtual void accumulate_row(SCVector *v, int i) =0;
virtual void accumulate_column(SCVector *v, int i) =0;
virtual void accumulate(const SCMatrix* m) = 0;
virtual void accumulate(const SymmSCMatrix* m) = 0;
virtual void accumulate(const DiagSCMatrix* m) = 0;
virtual void accumulate(const SCVector*) = 0;
virtual void accumulate_outer_product(SCVector*,SCVector*) = 0;
void accumulate_product(SCMatrix*m1,SCMatrix*m2)
{ accumulate_product_rr(m1,m2); }
void accumulate_product(SCMatrix*m1,SymmSCMatrix*m2)
{ accumulate_product_rs(m1,m2); }
void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
{ accumulate_product_rd(m1,m2); }
void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
{ accumulate_product_sr(m1,m2); }
void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
{ accumulate_product_dr(m1,m2); }
void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
{ accumulate_product_ss(m1,m2); }
virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
virtual void transpose_this() = 0;
virtual double trace() =0;
virtual double invert_this() = 0;
virtual double determ_this() = 0;
virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
virtual double solve_this(SCVector*) = 0;
virtual void gen_invert_this();
virtual void schmidt_orthog(SymmSCMatrix*, int n) =0;
virtual int schmidt_orthog_tol(SymmSCMatrix*, double tol, double*res=0)=0;
virtual void element_op(const Ref<SCElementOp>&) = 0;
virtual void element_op(const Ref<SCElementOp2>&,
SCMatrix*) = 0;
virtual void element_op(const Ref<SCElementOp3>&,
SCMatrix*,SCMatrix*) = 0;
void print(std::ostream&o=ExEnv::out0()) const;
void print(const char* title=0,std::ostream& out=ExEnv::out0(),
int =10) const;
virtual void vprint(const char*title=0,
std::ostream&out=ExEnv::out0(),int =10) const = 0;
Ref<MessageGrp> messagegrp() const;
virtual Ref<SCMatrixSubblockIter> local_blocks(
SCMatrixSubblockIter::Access) = 0;
virtual Ref<SCMatrixSubblockIter> all_blocks(
SCMatrixSubblockIter::Access) = 0;
};
class SymmSCMatrix: public DescribedClass {
protected:
RefSCDimension d;
Ref<SCMatrixKit> kit_;
public:
SymmSCMatrix(const RefSCDimension&, SCMatrixKit *);
~SymmSCMatrix();
Ref<SCMatrixKit> kit() const { return kit_; }
virtual void save(StateOut&);
virtual void restore(StateIn&);
virtual double maxabs() const;
virtual void randomize();
void assign(double val) { assign_val(val); }
void assign(const double* m) { assign_p(m); }
void assign(const double** m) { assign_pp(m); }
void assign(SymmSCMatrix* m) { assign_s(m); }
virtual void assign_val(double val);
virtual void assign_p(const double* m);
virtual void assign_pp(const double** m);
virtual void assign_s(SymmSCMatrix* m);
virtual void convert(double*) const;
virtual void convert(double**) const;
virtual void convert(SymmSCMatrix*);
virtual void convert_accumulate(SymmSCMatrix*);
virtual void scale(double);
virtual void scale_diagonal(double);
virtual void shift_diagonal(double);
virtual void unit();
int n() const { return d->n(); }
virtual SymmSCMatrix* copy();
virtual SymmSCMatrix* clone();
// pure virtual functions
RefSCDimension dim() const { return d; }
virtual double get_element(int,int) const = 0;
virtual void set_element(int,int,double) = 0;
virtual void accumulate_element(int,int,double) = 0;
virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
virtual SymmSCMatrix * get_subblock(int br, int er) =0;
virtual void assign_subblock(SCMatrix *m, int, int, int, int) =0;
virtual void assign_subblock(SymmSCMatrix *m, int, int) =0;
virtual void accumulate_subblock(SCMatrix *m, int, int, int, int) =0;
virtual void accumulate_subblock(SymmSCMatrix *m, int, int) =0;
virtual SCVector * get_row(int i) =0;
virtual void assign_row(SCVector *v, int i) =0;
virtual void accumulate_row(SCVector *v, int i) =0;
virtual void diagonalize(DiagSCMatrix*d,SCMatrix*m) = 0;
virtual void accumulate(const SymmSCMatrix* m) = 0;
virtual void accumulate_symmetric_sum(SCMatrix*) = 0;
virtual void accumulate_symmetric_product(SCMatrix*);
virtual void accumulate_transform(SCMatrix*,SymmSCMatrix*,
SCMatrix::Transform = SCMatrix::NormalTransform);
virtual void accumulate_transform(SCMatrix*,DiagSCMatrix*,
SCMatrix::Transform = SCMatrix::NormalTransform);
virtual void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
virtual void accumulate_symmetric_outer_product(SCVector*);
virtual double scalar_product(SCVector* v);
virtual double trace() = 0;
virtual double invert_this() = 0;
virtual double determ_this() = 0;
virtual double solve_this(SCVector*) = 0;
virtual void gen_invert_this() = 0;
virtual void element_op(const Ref<SCElementOp>&) = 0;
virtual void element_op(const Ref<SCElementOp2>&,
SymmSCMatrix*) = 0;
virtual void element_op(const Ref<SCElementOp3>&,
SymmSCMatrix*,SymmSCMatrix*) = 0;
void print(std::ostream&o=ExEnv::out0()) const;
void print(const char* title=0,std::ostream& out=ExEnv::out0(),
int =10) const;
virtual void vprint(const char* title=0,
std::ostream& out=ExEnv::out0(), int =10) const;
Ref<MessageGrp> messagegrp() const;
virtual Ref<SCMatrixSubblockIter> local_blocks(
SCMatrixSubblockIter::Access) = 0;
virtual Ref<SCMatrixSubblockIter> all_blocks(
SCMatrixSubblockIter::Access) = 0;
};
class DiagSCMatrix: public DescribedClass {
protected:
RefSCDimension d;
Ref<SCMatrixKit> kit_;
public:
DiagSCMatrix(const RefSCDimension&, SCMatrixKit *);
~DiagSCMatrix();
Ref<SCMatrixKit> kit() const { return kit_; }
virtual void save(StateOut&);
virtual void restore(StateIn&);
virtual double maxabs() const;
virtual void randomize();
void assign(double val) { assign_val(val); }
void assign(const double*p) { assign_p(p); }
void assign(DiagSCMatrix*d_a) { assign_d(d_a); }
virtual void assign_val(double val);
virtual void assign_p(const double*);
virtual void assign_d(DiagSCMatrix*);
virtual void convert(double*) const;
virtual void convert(DiagSCMatrix*);
virtual void convert_accumulate(DiagSCMatrix*);
virtual void scale(double);
int n() const { return d->n(); }
virtual DiagSCMatrix* copy();
virtual DiagSCMatrix* clone();
// pure virtual functions
RefSCDimension dim() const { return d; }
virtual double get_element(int) const = 0;
virtual void set_element(int,double) = 0;
virtual void accumulate_element(int,double) = 0;
virtual void accumulate(const DiagSCMatrix* m) = 0;
virtual double trace() = 0;
virtual double determ_this() = 0;
virtual double invert_this() = 0;
virtual void gen_invert_this() = 0;
virtual void element_op(const Ref<SCElementOp>&) = 0;
virtual void element_op(const Ref<SCElementOp2>&,
DiagSCMatrix*) = 0;
virtual void element_op(const Ref<SCElementOp3>&,
DiagSCMatrix*,DiagSCMatrix*) = 0;
void print(std::ostream&o=ExEnv::out0()) const;
void print(const char* title=0,
std::ostream& out=ExEnv::out0(), int =10) const;
virtual void vprint(const char* title=0,
std::ostream& out=ExEnv::out0(), int =10) const;
Ref<MessageGrp> messagegrp() const;
virtual Ref<SCMatrixSubblockIter> local_blocks(
SCMatrixSubblockIter::Access) = 0;
virtual Ref<SCMatrixSubblockIter> all_blocks(
SCMatrixSubblockIter::Access) = 0;
};
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End: