From 9c8383082fb2d09348104a5786e9f9fb8af9f679 Mon Sep 17 00:00:00 2001 From: fred Date: Sat, 31 Aug 1996 13:44:24 +0000 Subject: [PATCH] flower-1.0.2 --- flower/tsmat.cc | 151 +++++++++++++++++++++++++++++++++++++++++++++++ flower/tsmat.hh | 92 +++++++++++++++++++++++++++++ flower/tvsmat.hh | 140 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 383 insertions(+) create mode 100644 flower/tsmat.cc create mode 100644 flower/tsmat.hh create mode 100644 flower/tvsmat.hh diff --git a/flower/tsmat.cc b/flower/tsmat.cc new file mode 100644 index 0000000000..0e5407ae70 --- /dev/null +++ b/flower/tsmat.cc @@ -0,0 +1,151 @@ +#include "smat.hh" + +template +void +Full_storage::operator=(Full_storage const &fs) +{ + resize(fs.h, fs.w); + for (int i=0; i +void +Full_storage::OK() const +{ + assert(maxh >= h && maxw >= w); + assert(h >= 0 && w >= 0); +} +template +void +Full_storage::resize_cols(int newh) +{ + if (newh <= maxh) { + h=newh; + return; + } + + T** newa=new T*[newh]; + int j=0; + for (; j < h; j++) + newa[j] = els[j]; + for (; j < newh; j++) + newa[j] = new T[w]; + delete[] els; + els=newa; + maxh = newh; +} + +template +void +Full_storage::resize_rows(int neww) +{ + if (neww <= maxw) { + w=neww; + return; + } + for (int i=0; i < h ; i++) { + T* newa=new T[neww]; + for (int k=0; k < w; k++) + newa[k] = els[i][k]; + + delete[] els[i]; + els[i] = newa; + maxw = neww; + } +} + +template +Full_storage::~Full_storage() { + for (int i=0; i < maxh; i++) + delete [] els[i]; + delete[] els; +} + +template +void +Full_storage::resize(int i, int j) +{ + resize_cols(i); + resize_rows(j); +} + +template +void +Full_storage::set_size(int i, int j) +{ + resize(i,j) +} + +template +bool +Full_storage::mult_ok(int i, int j) const +{ + return valid(i,j); +} + +template +bool +Full_storage::trans_ok(int i, int j) const +{ + return valid(i,j); +} + + +template +void +Full_storage::trans_next(int &i, int &j) const +{ + assert(trans_ok(i,j)); + i++; + if (i >= h) { + i=0; + j ++; + } +} + +template +void +Full_storage::mult_next(int &i, int &j) const +{ + assert(mult_ok(i,j)); + j++; + if (j >= w) { + j=0; + i++; + } +} + +template +void +Full_storage::delete_row(int k) +{ + assert(0 <= k k ; i++) + for (int j=0; j < w; j++) + els[i-1][j]=els[i][j]; +} + +template +void +Full_storage::insert_row(int k) +{ + assert(0 <= k <=h); + resize_cols(h+1); + for (int i=h-1; i > k ; i++) + for (int j=0; j +virtual_smat * +virtual_smat::get_full(int n, int m) +{ + return new Full_storage(n,m); +} +#include "real.hh" + +template Full_storage; diff --git a/flower/tsmat.hh b/flower/tsmat.hh new file mode 100644 index 0000000000..0fe3f7af79 --- /dev/null +++ b/flower/tsmat.hh @@ -0,0 +1,92 @@ +#ifndef SMAT_HH +#define SMAT_HH +#include "vray.hh" +#include "vsmat.hh" + +/// simplest matrix storage. refer to its baseclass for the doco. +template +class Full_storage : public virtual_smat +{ + /// height, width + int h,w; + /// maxima. + int maxh, maxw; + + /// the storage + T** els; + void + init() { + els=0; + h=w=maxh=maxw=0; + + } + + bool valid(int i, int j) const { + return (i>=0 && i < h) + && (j < w && j >=0); + } + + + void resize_rows(int); + void resize_cols(int); + +public: + virtual int rows() const { + return h; + } + virtual int cols() const { + return w; + } + + + virtual void set_size(int i, int j) + { + resize(i,j); //this could be more efficient. + } + + virtual void set_size(int i) { + set_size(i,i); + } + virtual void resize(int i, int j); + virtual void resize(int i) { + resize(i,i); + } + + virtual T& elem(int i,int j) { + assert(valid(i,j)); + return els[i][j]; + } + virtual const T& elem(int i, int j) const { + assert(valid(i,j)); + return els[i][j]; + } + virtual svec row(int i) const; + virtual svec column(int j) const; + + Full_storage() { + init(); + } + Full_storage(int i, int j) { + init(); + set_size(i,j); + } + Full_storage(int i) { + init(); + set_size(i); + } + void OK() const; + void operator=(Full_storage const &); + + virtual void insert_row(int k); + virtual void delete_row(int k); + + + ~Full_storage(); + virtual bool mult_ok(int i, int j)const; + virtual void mult_next(int &i, int &j) const ; + virtual bool trans_ok(int i, int j) const; + virtual void trans_next(int &i, int &j) const; + +}; + +#endif diff --git a/flower/tvsmat.hh b/flower/tvsmat.hh new file mode 100644 index 0000000000..5e79634b55 --- /dev/null +++ b/flower/tvsmat.hh @@ -0,0 +1,140 @@ +#ifndef VSMAT_HH +#define VSMAT_HH +#include "vray.hh" + +/// a matrix storage baseclass. +class virtual_smat { + + +public: + /// check invariants + virtual void OK() const=0; + + /// height of matrix + virtual int rows() const = 0; + + /// width of matrix + virtual int cols() const = 0; + + /// set the size. contents lost + virtual void set_size(int i, int j) = 0; + /** + PRE + i >=0, j>=0 + */ + + /// set the size to square dimen. contents lost + virtual void set_size(int i) = 0; + /** + PRE + i>=0 + */ + /// set the size to i + virtual void resize(int i, int j) = 0; + /** + + keep contents. If enlarged contents unspecified + + PRE + i>=0, j>=0 + + */ + + /// set the size to square dimen. contents kept + virtual void resize(int i) = 0; + /** + Keep contents. If enlarged contents are unspecified + + PRE + i>=0 + */ + + /// access an element + virtual Real& elem(int i,int j) = 0; + /** + access an element. + + Generate an errormessage, if this happens + in the 0-part of a sparse matrix. + */ + + /// access a element, no modify + virtual const Real& elem(int i, int j) const = 0; + +#if 1 + virtual svec row(int i) const = 0; + virtual svec column(int j) const = 0; +#endif + + /// add a row + virtual void insert_row(int k)=0; + /** + add a row to the matrix before row k. Contents + of added row are unspecified + + 0 <= k <= rows() + */ + + /// delete a row + virtual void delete_row(int k)=0; + /** + delete a row from this matrix. + + PRE + 0 <= k < rows(); + */ + virtual ~virtual_smat() { } + virtual virtual_smat *clone()=0; + + + /// is there a next? + virtual bool mult_ok(int i, int j) const=0; + /** + at end of matrix? when doing loop + + for(i=0; i *get_full(int n, int m); + +}; + +/** base class for interface with matrix storageclasses. There are no + iterators for matrixclasses, since matrices are (like arrays) + explicitly int-indexed. + + Iteration is provided by *_next, *_ok, which update and check both + index variables simultaneously. + + TODO + determine type of product matrix. + +*/ + +#endif -- 2.39.5