#include "diagonal-storage.hh"
+
+#ifdef INLINE
+#undef INLINE
+#endif
+
+#define INLINE inline
+
+#include "full-storage.icc"
+
int
Diagonal_storage::dim()const
{
void
Diagonal_storage::set_band_size(int s)
{
+ assert( s>=0);
Full_storage f(dim(), 2*s+1);
for (int i=0; i < dim(); i++) {
int k=-s;
Diagonal_storage::resize_dim(int d)
{
Full_storage f(d, 2*band_size_i()+1);
- for (int i=0; i < d&& i < dim(); i++) {
+ for (int i=0; i < d && i < dim(); i++) {
for ( int k=0; k < 2*band_size_i(); k++)
f.elem(i,k) = elem(i,k);
}
j = i- band_size_i();
if ( j > i + band_size_i() || j >= dim() ) {
i++;
- j = i - band_size_i();
- if (j < 0)
- j=0;
+ j = 0 >? i - band_size_i();
}
}
if ( i >= dim() || i > j + band_size_i() ) {
j++;
- i = j - band_size_i();
- if (i < 0)
- i=0;
+ i = 0 >? j - band_size_i();
}
}
/*
if this fails, the previous call fucked up
*/
- assert(nul_entry);
- if (abs ( i-j ) > band_size_i())
+ assert(!nul_entry);
+
+ if (abs ( i-j ) > band_size_i())
return nul_entry;
else
return band_.elem(i, j - i + band_size_i());
if ( right->name() != Diagonal_storage::static_name() )
return false;
- const Diagonal_storage* diag = (Diagonal_storage const*)right;
- int band2 = diag->band_size_i();
+ const Diagonal_storage* right_diag = (Diagonal_storage const*)right;
+ int band2 = right_diag->band_size_i();
int n = dim();
/*
should check if dest is a Diagonal_storage of sufficient size too.
int relk = startk + band_size_i() -i;
Real sum =0.0;
for ( int k = startk; k <= stopk; k++)
- sum += band_.elem(i, relk) * diag->elem(relk, j);
+ sum += band_.elem(i, relk++) * right_diag->elem(k, j);
dest->elem(i, j) = sum;
}
{
band_.OK();
}
+
+IMPLEMENT_VIRTUAL_COPY_CONS(Diagonal_storage, Matrix_storage);
#include "full-storage.hh"
+
void
Full_storage::operator=(Full_storage const &fs)
{
els_p_p_[i][j]= fs.els_p_p_[i][j];
}
+
void
Full_storage::OK() const
{
#endif
}
-void
-Full_storage::resize_cols(int newh)
-{
- if (newh <= max_height_i_) {
- height_i_=newh;
- return;
- }
-
- Real ** newa=new Real*[newh];
- int j=0;
- for (; j < height_i_; j++)
- newa[j] = els_p_p_[j];
- for (; j < newh; j++)
- newa[j] = new Real[max_width_i_];
- delete[] els_p_p_;
- els_p_p_=newa;
- height_i_ = max_height_i_ = newh;
-}
-Full_storage::Full_storage(Matrix_storage*m)
+Full_storage::~Full_storage()
{
- set_size(m->rows(), m->cols());
- if ( !m->is_type_b ( Full_storage::static_name()))
- for (int i=0; i<height_i_; i++)
- for (int j=0; j<width_i_; j++)
- els_p_p_[i][j]=0.0;
- for (int i,j=0; m->mult_ok(i,j); m->mult_next(i,j))
- els_p_p_[i][j] = m->elem(i,j);
-}
-
-void
-Full_storage::resize_rows(int neww)
-{
- if (neww <= max_width_i_) {
- width_i_=neww;
- return;
- }
- for (int i=0; i < max_height_i_ ; i++) {
- Real* newa = new Real[neww];
- for (int k=0; k < width_i_; k++)
- newa[k] = els_p_p_[i][k];
-
- delete[] els_p_p_[i];
- els_p_p_[i] = newa;
- }
- width_i_ = max_width_i_ = neww;
-}
-
-Full_storage::~Full_storage() {
for (int i=0; i < max_height_i_; i++)
delete [] els_p_p_[i];
delete[] els_p_p_;
}
void
+
Full_storage::resize(int rows, int cols)
{
OK();
}
+
bool
Full_storage::mult_ok(int i, int ) const
{
return i < height_i_;
}
+
bool
Full_storage::trans_ok(int , int j) const
{
}
+
void
Full_storage::trans_next(int &i, int &j) const
{
}
}
+
void
Full_storage::mult_next(int &i, int &j) const
{
}
}
+
void
Full_storage::delete_column(int k)
{
els_p_p_[i][j-1]=els_p_p_[i][j];
width_i_--;
}
+
+
void
Full_storage::delete_row(int k)
{
}
+
void
Full_storage::insert_row(int k)
{
}
-int
-Full_storage::dim()const
-{
- assert (rows()==cols());
- return rows();
-}
-
-Full_storage::Full_storage(Full_storage const&s)
-{
- init();
- (*this) = s;
-}
-
bool
Full_storage::try_right_multiply(Matrix_storage * dest, Matrix_storage const * right)const
{
}
IMPLEMENT_IS_TYPE_B1(Full_storage,Matrix_storage);
+void
+Full_storage::resize_cols(int newh)
+{
+ if (newh <= max_height_i_) {
+ height_i_=newh;
+ return;
+ }
+
+ Real ** newa=new Real*[newh];
+ int j=0;
+ for (; j < height_i_; j++)
+ newa[j] = els_p_p_[j];
+ for (; j < newh; j++)
+ newa[j] = new Real[max_width_i_];
+ delete[] els_p_p_;
+ els_p_p_=newa;
+
+ height_i_ = max_height_i_ = newh;
+}
+
+
+
+Full_storage::Full_storage(Matrix_storage*m)
+{
+ set_size(m->rows(), m->cols());
+ if ( !m->is_type_b ( Full_storage::static_name()))
+ for (int i=0; i<height_i_; i++)
+ for (int j=0; j<width_i_; j++)
+ els_p_p_[i][j]=0.0;
+ for (int i,j=0; m->mult_ok(i,j); m->mult_next(i,j))
+ els_p_p_[i][j] = m->elem(i,j);
+}
+
+
+void
+Full_storage::resize_rows(int neww)
+{
+ if (neww <= max_width_i_) {
+ width_i_=neww;
+ return;
+ }
+ for (int i=0; i < max_height_i_ ; i++) {
+ Real* newa = new Real[neww];
+ for (int k=0; k < width_i_; k++)
+ newa[k] = els_p_p_[i][k];
+
+ delete[] els_p_p_[i];
+ els_p_p_[i] = newa;
+ }
+ width_i_ = max_width_i_ = neww;
+}
+
+#ifdef INLINE
+#undef INLINE
+#endif
+#define INLINE
+
+#include "full-storage.icc"
Real** els_p_p_;
void
- init() {
- els_p_p_=0;
- height_i_=width_i_=max_height_i_=max_width_i_=0;
-
- }
-
- bool valid(int i, int j) const {
- return (i>=0 && i < height_i_)
- && (j < width_i_ && j >=0);
- }
-
+ init() ;
+
+ bool valid(int i, int j) const ;
void resize_rows(int);
void resize_cols(int);
public:
- virtual int rows() const {
- return height_i_;
- }
- virtual int cols() const {
- return width_i_;
- }
+ virtual int rows() const;
+ virtual int cols() const ;
virtual void resize(int i, int j);
- virtual void resize(int i) {
- resize(i,i);
- }
-
- virtual Real& elem(int i,int j) {
- assert(valid(i,j));
- return els_p_p_[i][j];
- }
- virtual Real elem(int i, int j) const {
- assert(valid(i,j));
- return els_p_p_[i][j];
- }
+ virtual void resize(int i);
+ virtual Real& elem(int i,int j);
+ virtual Real elem(int i, int j)const ;
int dim()const;
Full_storage(Matrix_storage*);
- Full_storage() {
- init();
- }
- Full_storage(int i, int j) {
- init();
- set_size(i,j);
- }
+ Full_storage();
+ Full_storage(int i, int j);
Full_storage(Full_storage const&);
- Full_storage(int i) {
- init();
- set_size(i);
- }
+ Full_storage(int i);
void OK() const;
void operator=(Full_storage 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;
- VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
+ DECLARE_VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
DECLARE_MY_RUNTIME_TYPEINFO;
virtual bool try_right_multiply(Matrix_storage * dest, Matrix_storage const * )const;
};
--- /dev/null
+/*
+ full-storage.icc -- implement Full_storage inline functions
+
+ source file of the Flower Library
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef FULL_STORAGE_ICC
+#define FULL_STORAGE_ICC
+
+
+INLINE void
+Full_storage::init()
+{
+ els_p_p_=0;
+ height_i_=width_i_=max_height_i_=max_width_i_=0;
+}
+INLINE bool
+Full_storage::valid(int i, int j)const
+{
+ return (i>=0 && i < height_i_)
+ && (j < width_i_ && j >=0);
+}
+
+
+INLINE
+Full_storage::Full_storage(Full_storage const&s)
+{
+ init();
+ (*this) = s;
+}
+
+INLINE Real&
+Full_storage::elem(int i,int j)
+{
+ assert(valid(i,j));
+ return els_p_p_[i][j];
+}
+
+INLINE Real
+Full_storage::elem(int i, int j) const {
+ assert(valid(i,j));
+ return els_p_p_[i][j];
+}
+
+INLINE
+Full_storage::Full_storage() {
+ init();
+}
+
+
+INLINE int
+Full_storage::rows() const
+{
+ return height_i_;
+}
+INLINE int
+Full_storage::cols() const
+{
+ return width_i_;
+}
+INLINE int
+Full_storage::dim()const
+{
+ assert (rows()==cols());
+ return rows();
+}
+
+INLINE void
+Full_storage::resize(int i)
+{
+ resize(i,i);
+}
+
+INLINE
+Full_storage::Full_storage(int i,int j)
+{
+ init();
+ set_size(i,j);
+}
+
+INLINE
+Full_storage::Full_storage(int i)
+{
+ init();
+ set_size(i);
+}
+
+INLINE
+IMPLEMENT_VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
+
+#endif // FULL_STORAGE_ICC
#define IMPLEMENT_STATIC_NAME(c)\
char const *c::static_name() { return #c; }
+
+
#define VIRTUAL_COPY_CONS(T, R)\
virtual R *clone() const { return new T(*this); } \
int yet_another_stupid_function_to_allow_semicolon()
+
+#define DECLARE_VIRTUAL_COPY_CONS(T,R)\
+ virtual R *clone() const
+#define IMPLEMENT_VIRTUAL_COPY_CONS(T,R)\
+ R *T::clone() const { return new T(*this); } \
+
#define IMPLEMENT_IS_TYPE_B(D) \
IMPLEMENT_STATIC_NAME(D)\
bool D::static_is_type_b(const char *s) \