Boost logo

Boost Users :

From: Hicham Mouline (hicham_at_[hidden])
Date: 2008-05-15 15:32:11


Hello,

I am modeling a 1-dim real numerical function f, not necessarily monotone,
described by :

x0 y0
x1 y1
.
xn-1 yn-1

by

template <typename InterpolationType,
          typename ExtrapolationType,
            typename IntegrationType>
class Curve : public std::map<double, double> {
protected:
        Curve();
        virtual ~Curve();

        const InterpolationType& interpolator() const;
        const ExtrapolationType& extrapolator() const;
        const IntegrationType& integrator() const;

        double operator()(double t) const; /**< read f(t) */
        double& operator()(double t); /**< write f(t)=ft */
        double inverse(double f) const; /**< read f-1(f) */
        double derivative(double t) const; /**< read f'(t) */
        
        /**
         * \brief Returns Integral over [tmin,tmax] of f(t) using
         * the template argument integration method
         */
        double integral(double tmax, double tmin =0.0) const;
        /**
         * \brief Returns Integral over [tmin,tmax] of f^n(t) using
         * the template argument integration method
         */
        double integral(int n, double tmax, double tmin =0.0) const;

      /**
         * \brief Applies operation Op on the f(t) curve, outputs in result
         */
      template<typename Op> void transform(Curve& result) const;

        /**
         * \brief Outputs tabulated data
         */
      friend std::ostream& operator<<(std::ostream& s, const Curve& rhs);

private:
        const InterpolationType& interpolator_;
        const ExtrapolationType& extrapolator_;
        const IntegrationType& integrator_;
};

There are different ways of interpolating f(x) for x0 <= x <= xn-1,
extrapolating f(x) for x<x0 or x>xn-1,
and integrating over some domain [tmin,tmax]

1- Each of InterpolationType, ExtrapolationType, IntegrationType arguments
expects
a type derived from BaseInterpolator, BaseExtrapolator, BaseIntegrator,
but I am not certain I need this inheritance.
What are the tradeoffs?

2- Curve is an internal implementation object of my library. However,
private derived classes
from Curve will be exposed to library users. So Curve's header will have to
be exposed too.
I guess public inheritance from map is fine? There are no public
constructors.

3- Constructing the curve is not performance-critical, but the operator(),
inverse,
derivative and integral are. I have played with native arrays, with map and
with
boost::multi_array with optimized macros, and it seems operator() when it is
a simple
linear interpolation is fastest with maps (because they are sorted). Any
comments?

Rds,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net