From: fred Date: Sun, 24 Mar 2002 19:52:39 +0000 (+0000) Subject: lilypond-0.1.1 X-Git-Tag: release/1.5.59~4185 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=94d9804991558c001b81600ab48f7b8d52a3f332;p=lilypond.git lilypond-0.1.1 --- diff --git a/flower/diagonal-storage.cc b/flower/diagonal-storage.cc index 3cf2f93d20..fc812423e5 100644 --- a/flower/diagonal-storage.cc +++ b/flower/diagonal-storage.cc @@ -9,6 +9,15 @@ #include "diagonal-storage.hh" + +#ifdef INLINE +#undef INLINE +#endif + +#define INLINE inline + +#include "full-storage.icc" + int Diagonal_storage::dim()const { @@ -40,6 +49,7 @@ Diagonal_storage::band_size_i()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; @@ -110,7 +120,7 @@ void 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); } @@ -134,9 +144,7 @@ Diagonal_storage::mult_next(int &i, int &j)const 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(); } } @@ -155,9 +163,7 @@ Diagonal_storage::trans_next(int &i, int& j)const 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(); } } @@ -178,8 +184,9 @@ Diagonal_storage::elem(int i, int j) /* 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()); @@ -196,8 +203,8 @@ Diagonal_storage::try_right_multiply(Matrix_storage*dest, 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. @@ -209,7 +216,7 @@ Diagonal_storage::try_right_multiply(Matrix_storage*dest, 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; } @@ -234,3 +241,5 @@ Diagonal_storage::OK() const { band_.OK(); } + +IMPLEMENT_VIRTUAL_COPY_CONS(Diagonal_storage, Matrix_storage); diff --git a/flower/full-storage.cc b/flower/full-storage.cc index 223796ba35..fd0d9f550b 100644 --- a/flower/full-storage.cc +++ b/flower/full-storage.cc @@ -8,6 +8,7 @@ #include "full-storage.hh" + void Full_storage::operator=(Full_storage const &fs) { @@ -19,6 +20,7 @@ Full_storage::operator=(Full_storage const &fs) els_p_p_[i][j]= fs.els_p_p_[i][j]; } + void Full_storage::OK() const { @@ -30,63 +32,18 @@ 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; imult_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(); @@ -95,12 +52,14 @@ Full_storage::resize(int rows, int cols) } + bool Full_storage::mult_ok(int i, int ) const { return i < height_i_; } + bool Full_storage::trans_ok(int , int j) const { @@ -108,6 +67,7 @@ Full_storage::trans_ok(int , int j) const } + void Full_storage::trans_next(int &i, int &j) const { @@ -119,6 +79,7 @@ Full_storage::trans_next(int &i, int &j) const } } + void Full_storage::mult_next(int &i, int &j) const { @@ -130,6 +91,7 @@ Full_storage::mult_next(int &i, int &j) const } } + void Full_storage::delete_column(int k) { @@ -139,6 +101,8 @@ 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) { @@ -150,6 +114,7 @@ Full_storage::delete_row(int k) } + void Full_storage::insert_row(int k) { @@ -161,19 +126,6 @@ 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 { @@ -198,3 +150,61 @@ Full_storage::try_right_multiply(Matrix_storage * dest, Matrix_storage const * r } 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; imult_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" diff --git a/flower/include/full-storage.hh b/flower/include/full-storage.hh index 78bafab43d..1dfb96e8fa 100644 --- a/flower/include/full-storage.hh +++ b/flower/include/full-storage.hh @@ -26,57 +26,28 @@ class Full_storage : public Matrix_storage 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 &); @@ -89,7 +60,7 @@ public: 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; }; diff --git a/flower/include/full-storage.icc b/flower/include/full-storage.icc new file mode 100644 index 0000000000..06bcc9d70c --- /dev/null +++ b/flower/include/full-storage.icc @@ -0,0 +1,94 @@ +/* + full-storage.icc -- implement Full_storage inline functions + + source file of the Flower Library + + (c) 1997 Han-Wen Nienhuys +*/ + + +#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 diff --git a/flower/include/virtual-methods.hh b/flower/include/virtual-methods.hh index 88dad44aeb..ceb12694e3 100644 --- a/flower/include/virtual-methods.hh +++ b/flower/include/virtual-methods.hh @@ -24,10 +24,18 @@ int a_stupid_nonexistent_function_to_allow_the_semicolon_come_out() #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) \