Commit 8825a87b by Laurent Belcour

### Merge

parents c836654a 03d5939d
 ... ... @@ -12,19 +12,16 @@ rational_function_1d::rational_function_1d() { } rational_function_1d::rational_function_1d(int np, int nq, bool separable) rational_function_1d::rational_function_1d(int nX, unsigned int np, unsigned int nq, bool separable) { setDimX(nX); setDimY(1); resize(np, nq); _separable = separable; } rational_function_1d::rational_function_1d(const vec& a, const vec& b) : a(a), b(b) { //update(a, b); _separable = false; } bool rational_function_1d::load(std::istream&) { return true; ... ... @@ -35,55 +32,54 @@ void rational_function_1d::save_body(std::ostream& out, const arguments& args) c bool is_matlab = args["export"] == "matlab"; bool is_alta = !args.is_defined("export") || args["export"] == "alta"; const unsigned int np = _p_coeffs.size(); const unsigned int nq = _q_coeffs.size(); if(is_alta) { for(int i=0; i index = this->index2degree(i) ; for(unsigned int j=0; j index = this->index2degree(i) ; for(unsigned int j=0; j indices = this->index2degree(i); out << _p_coeffs[i].a; for(int k=0; k indices = this->index2degree(i); out << _p_coeffs[i].a << "x.^" << i; for(int k=0; k deg = index2degree(k); _p_coeffs[k].deg = deg; } } // Set the new coeffs to zero for(int i=old_np; i deg = index2degree(k); _q_coeffs[k].deg = deg; } } } ... ... @@ -130,40 +150,26 @@ void rational_function_1d::resize(int np, int nq) // Get the p_i and q_j function vec rational_function_1d::p(const vec& x) const { vec res(_nY) ; unsigned int const np = a.size() / _nY ; for(int k=0; k<_nY; ++k) { double p = 0.0f ; vec res(1) ; const unsigned int np = _p_coeffs.size() ; for(unsigned int i=0; ip(x, i) ; res[0] += _p_coeffs[i].a * this->p(x, i) ; } res[k] = p ; } return res ; } vec rational_function_1d::q(const vec& x) const { vec res(_nY) ; unsigned int const nq = b.size() / _nY ; for(int k=0; k<_nY; ++k) { double q = 0.0f ; vec res(1) ; for(unsigned int i=0; iq(x, i) ; res[0] += _q_coeffs[i].a * this->p(x, i) ; } res[k] = q ; } return res ; } ... ... @@ -287,19 +293,25 @@ std::vector rational_function_1d::index2degree(int i) const // Get the p_i and q_j function double rational_function_1d::p(const vec& x, int i) const { std::vector deg = index2degree(i); double res = 1.0; for(int k=0; kp(x, i) ; p += _p_coeffs[i].a*this->p(x, i) ; } for(unsigned int i=0; iq(x, i) ; q += _q_coeffs[i].a*this->q(x, i) ; } res[0] = p/q ; ... ... @@ -330,25 +342,28 @@ vec rational_function_1d::value(const vec& x) const std::ostream& operator<< (std::ostream& out, const rational_function_1d& r) { const unsigned int np = r._p_coeffs.size(); const unsigned int nq = r._q_coeffs.size(); std::cout << "p = [" ; for(int i=0; isetDimX(dimX()); rs[i]->setDimY(dimY()); rs[i] = new rational_function_1d(dimX(), np, nq); // Test if the input domain is not empty. If one dimension of // the input domain is a point, I manually inflate this dimension ... ...
 ... ... @@ -21,18 +21,18 @@ class rational_function_1d : public function public: // methods rational_function_1d() ; rational_function_1d(int np, int nq, bool separable = false) ; rational_function_1d(const vec& a, const vec& b) ; rational_function_1d(int nX, unsigned int np, unsigned int nq, bool separable = false) ; virtual ~rational_function_1d() {} /* FUNCTION INHERITANCE */ // Overload the function operator //! Overload the function operator virtual vec value(const vec& x) const ; virtual vec operator()(const vec& x) const { return value(x) ; } // IO function to text files //! IO function to text files virtual bool load(std::istream& in); //! \brief Save the rational function expansion. It should ... ... @@ -50,6 +50,7 @@ class rational_function_1d : public function //! algorithm to efficiently evaluate recursively defined //! polynomials. virtual vec p(const vec& x) const ; //! Evaluate the denominator \f$q(\mathbf{x})\f$ of the rational //! function. This function is provided to allow fast //! implementation. For example one can use the Clenshaw ... ... @@ -64,19 +65,41 @@ class rational_function_1d : public function //! denominator of the rational function. virtual double q(const vec& x, int j) const ; // Update the function //! Update the coefficient vectors with new values. The new values //! are normalized by the first element of the denominator //! coefficients. virtual void update(const vec& in_a, const vec& in_b) ; // Resize the polynomial virtual void resize(int np, int nq); //! Resize the polynomial. virtual void resize(unsigned int np, unsigned int nq); //! Get the i-th coefficient of the numerator. virtual double getP(int i) const { return _p_coeffs[i].a; } // Get the coefficients virtual double getP(int i) const { return a[i]; } virtual double getQ(int i) const { return b[i]; } //! Get the i-th coefficient of the denominator. virtual double getQ(int i) const { return _q_coeffs[i].a; } //! Get the vector of coefficient for the numerator. virtual vec getP() const { const int np = _p_coeffs.size(); vec t(np); for(int i=0; i deg) : a(a), deg(deg) { } double a; std::vector deg; }; // Table of coefficients and indices, sorted with respect // to the indices. std::vector _p_coeffs; std::vector _q_coeffs; //! Is the function separable with respect to its input dimensions? //! \todo Make possible to have only part of the dimensions ... ...
 ... ... @@ -27,14 +27,8 @@ rational_function_chebychev_1d::rational_function_chebychev_1d() { } rational_function_chebychev_1d::rational_function_chebychev_1d(int np, int nq) : rational_function_1d(np, nq) { } rational_function_chebychev_1d::rational_function_chebychev_1d(const vec& a, const vec& b) : rational_function_1d(a, b) rational_function_chebychev_1d::rational_function_chebychev_1d(int nX, int np, int nq) : rational_function_1d(nX, np, nq) { } ... ... @@ -92,9 +86,7 @@ rational_function_1d* rational_function_chebychev::get(int i) { if(rs[i] == NULL) { rs[i] = new rational_function_chebychev_1d(np, nq); rs[i]->setDimX(dimX()); rs[i]->setDimY(dimY()); rs[i] = new rational_function_chebychev_1d(dimX(), np, nq); // Test if the input domain is not empty. If one dimension of // the input domain is a point, I manually inflate this dimension ... ...
 ... ... @@ -17,8 +17,7 @@ class rational_function_chebychev_1d : public rational_function_1d public: // methods rational_function_chebychev_1d() ; rational_function_chebychev_1d(int np, int nq) ; rational_function_chebychev_1d(const vec& a, const vec& b) ; rational_function_chebychev_1d(int nX, int np, int nq) ; virtual ~rational_function_chebychev_1d() {} // Get the p_i and q_j function ... ...
 ... ... @@ -29,41 +29,12 @@ rational_function_chebychev_1d::rational_function_chebychev_1d() setDimY(0); } rational_function_chebychev_1d::rational_function_chebychev_1d(int nX, int nY, int np, int nq) : rational_function_1d(np, nq) rational_function_chebychev_1d::rational_function_chebychev_1d(int nX, int np, int nq) : rational_function_1d(nX, np, nq) { setDimX(nX); setDimY(nY); this->resize(np, nq); } rational_function_chebychev_1d::rational_function_chebychev_1d(const vec& a, const vec& b) : rational_function_1d(a, b) { setDimX(0); setDimY(0); const int np = a.size(); const int nq = b.size(); this->resize(np, nq); // Update the numerator coefficient array for(int k=0; k
 ... ... @@ -17,8 +17,7 @@ class rational_function_chebychev_1d : public rational_function_1d public: // methods rational_function_chebychev_1d() ; rational_function_chebychev_1d(int nX, int nY, int np, int nq) ; rational_function_chebychev_1d(const vec& a, const vec& b) ; rational_function_chebychev_1d(int nX, int np, int nq) ; virtual ~rational_function_chebychev_1d() {} // Get the p_i and q_j function ... ... @@ -30,8 +29,8 @@ public: // methods { vec res(1) ; unsigned int const np = a.size() / _nY ; unsigned int const nq = b.size() / _nY ; unsigned int const np = _p_coeffs.size(); unsigned int const nq = _q_coeffs.size(); double p = 0.0f ; double q = 0.0f ; ... ... @@ -54,8 +53,6 @@ public: // methods virtual void update(const vec& in_a, const vec& in_b) { rational_function_1d::update(in_a, in_b); // Get the size of the input vector const int np = in_a.size(); const int nq = in_b.size(); ... ...
 ... ... @@ -12,18 +12,12 @@ rational_function_legendre_1d::rational_function_legendre_1d() { } rational_function_legendre_1d::rational_function_legendre_1d(int np, int nq, params::input param) : rational_function_1d(np, nq) rational_function_legendre_1d::rational_function_legendre_1d(int nX, int np, int nq, params::input param) : rational_function_1d(nX, np, nq) { setParametrization(param); } rational_function_legendre_1d::rational_function_legendre_1d(const vec& a, const vec& b) : rational_function_1d(a, b) { } double rational_function_legendre_1d::legendre(double x, int i) const { if(i == 0) ... ...
 ... ... @@ -17,8 +17,7 @@ class rational_function_legendre_1d : public rational_function_1d public: // methods rational_function_legendre_1d() ; rational_function_legendre_1d(int np, int nq, params::input params) ; rational_function_legendre_1d(const vec& a, const vec& b) ; rational_function_legendre_1d(int nX, int np, int nq, params::input params) ; virtual ~rational_function_legendre_1d() {} // Get the p_i and q_j function ... ... @@ -47,9 +46,7 @@ class rational_function_legendre : public rational_function { if(rs[i] == NULL) { rs[i] = new rational_function_legendre_1d(np, nq, input_parametrization()); rs[i]->setDimX(dimX()); rs[i]->setDimY(dimY()); rs[i] = new rational_function_legendre_1d(dimX(), np, nq, input_parametrization()); vec _min = min(); vec _max = max(); ... ...
 ... ... @@ -12,14 +12,8 @@ rational_function_legendre_1d::rational_function_legendre_1d() { }