From f1cc8f8ee759743982988b9ec6dc406c8a96c4e2 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Mon, 10 Sep 2007 21:09:45 +0000 Subject: [PATCH] Small bug fix in TransFarToFar: the order of the approximation was set to 0, but it really should have been set to the order of the translated expansion --- .../series_expansion/series_expansion.h | 30 +++++++++++++++++-- .../series_expansion/series_expansion_aux.h | 21 ------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/fastlib/u/dongryel/series_expansion/series_expansion.h b/fastlib/u/dongryel/series_expansion/series_expansion.h index b7356df73f..a0a7d4fc7d 100644 --- a/fastlib/u/dongryel/series_expansion/series_expansion.h +++ b/fastlib/u/dongryel/series_expansion/series_expansion.h @@ -445,6 +445,9 @@ template void SeriesExpansion::PrintDebug(const char *name, FILE *stream) const { + int dim = sea_->get_dimension(); + int total_num_coeffs = sea_->get_total_num_coeffs(order_); + fprintf(stream, "----- SERIESEXPANSION %s ------\n", name); fprintf(stream, "Expansion type: %s\n", (expansion_type_ == FARFIELD) ? "FARFIELD":"LOCAL"); @@ -455,8 +458,29 @@ void SeriesExpansion::PrintDebug(const char *name, } fprintf(stream, "\n"); - for (index_t i = 0; i < coeffs_.length(); i++) { - fprintf(stream, "%g ", coeffs_[i]); + fprintf(stream, "f("); + for(index_t d = 0; d < dim; d++) { + fprintf(stream, "x_%d", d); + if(d < dim - 1) + fprintf(stream, ","); + } + fprintf(stream, ") = "); + + for (index_t i = 0; i < total_num_coeffs; i++) { + ArrayList mapping = sea_->get_multiindex(i); + if(expansion_type_ == FARFIELD) { + fprintf(stream, "%g", coeffs_[i]); + + for(index_t d = 0; d < dim; d++) { + fprintf(stream, "(x_%d - (%g))^%d", d, center_[d], mapping[d]); + } + } + else { + fprintf(stream, "%g ", coeffs_[i]); + } + if(i < total_num_coeffs - 1) { + fprintf(stream, " + "); + } } fprintf(stream, "\n"); } @@ -486,6 +510,8 @@ void SeriesExpansion::TransFarToFar(const SeriesExpansion &se) { // no coefficients can be translated if(order == 0) return; + else + order_ = order; // the first order (the sum of the weights) stays constant regardless // of the location of the center. diff --git a/fastlib/u/dongryel/series_expansion/series_expansion_aux.h b/fastlib/u/dongryel/series_expansion/series_expansion_aux.h index 7733904126..86c6706634 100644 --- a/fastlib/u/dongryel/series_expansion/series_expansion_aux.h +++ b/fastlib/u/dongryel/series_expansion/series_expansion_aux.h @@ -31,27 +31,6 @@ class SeriesExpansionAux { /** row index is for n, column index is for k */ Matrix n_choose_k_; - /** compute n choose k: this might be moved later to FastLib core... */ - int nchoosek(int n, int k) { - int n_k = n - k; - int nchsk = 1; - int i; - - if(k > n) - return 0; - - if(k < n_k) { - k = n_k; - n_k = n - k; - } - - for(i = 1; i <= n_k; i++) { - nchsk *= (++k); - nchsk /= i; - } - return nchsk; - } - public: // construtor/destructor