Re: Convex Monotone Interpolation - SWIG - exposed to Python
Posted by Ioan F. on Jun 05, 2014; 9:16pm
URL: http://quantlib.414.s1.nabble.com/Convex-Monotone-Interpolation-SWIG-exposed-to-Python-tp15327p15400.html
Hi Luigi,
Pretty sad state of affairs with my SWIG code, but I guess you're right, it's better to start from somewhere rather than from scratch.
The code below should be placed within interpolation.i interface file.
Regards,
Ioan
%{
// safe versions which copy their arguments
template <class I1, class I2>
class SafeInterpolationConvex {
public:
SafeInterpolationConvex(const Array& x, const Array& y, Real quadraticity,
Real monotonicity, bool forcePositive)
: x_(x), y_(y),
quadraticity_(quadraticity), monotonicity_(monotonicity),
forcePositive_(forcePositive),
f_(x_.begin(), x_.end(), y_.begin(), quadraticity_,
monotonicity_, forcePositive_) {}
Real operator()(Real x, bool allowExtrapolation=false) {
return f_(x, allowExtrapolation);
}
protected:
Array x_, y_;
Real quadraticity_;
Real monotonicity_;
bool forcePositive_;
I1 f_;
};
%}
%define make_safe_interpolationConvex(T, Alias)
%{
typedef SafeInterpolationConvex(QuantLib::T) Safe##T;
%}
%rename(Alias) Safe##T;
class Safe##T {
#if defined(SWIGMZSCHEME) || defined(SWIGGUILE) \
|| defined(SWIGCSHARP) || defined(SWIGPERL)
%rename(call) operator();
#endif
public:
Safe##T(const Array& x, const Array& y, Real quadraticity,
Real monotonicity, bool forcePositive);
Real operator()(Real x, bool allowExtrapolation=false);
};
%enddef
//make_safe_interpolationConvex(ConvexMonotoneInterpolation,ConvexMonotoneInterpolation);
%{
using QuantLib::ConvexMonotone;
%}
struct ConvexMonotone{};