Login  Register

Re: Running into problem with R-Swig wrappers

Posted by Joseph Wang-2 on Jun 07, 2006; 5:17am
URL: http://quantlib.414.s1.nabble.com/Running-into-problem-with-R-Swig-wrappers-tp11141p11143.html

在 Tuesday 06 June 2006 22:48,您写道:
> Can you show us some of the overloaded functions, please?
> I don't know what you mean by a "large" number of arguments
> and why you are generating functions with a large number of
> parameters so it would be helpful to see what you are generating.
>

Sure thing the signature

        FixedCouponBondPtr(const Date& issueDate,
                           const Date& datedDate,
                           const Date& maturityDate,
                           Integer settlementDays,
                           const std::vector<Rate>& coupons,
                           Frequency couponFrequency,
                           const Calendar& calendar,
                           const DayCounter& dayCounter,
                           BusinessDayConvention accrualConvention
                                                       = QuantLib::Following,
                           BusinessDayConvention paymentConvention
                                                       = QuantLib::Following,
                           Real redemption = 100.0,
                           const Handle<YieldTermStructure>& discountCurve
                                              = Handle<YieldTermStructure>(),
                           const Date& stub = Date(),
                           bool fromEnd = true)

generates six separate wrappers for each possible number of optional argument.
(See below for the first few wrappers.)

Loading the wrappers into R seems to take about several meg of heap space.  
Loading in about a hundred of these sorts of functions, kills the machine.

If I change the signature to make the optional arguments required, then an
ordinary non-generic function gets generated, and I don't get the huge memory
bloat.



setGeneric('FixedCouponBond', function(s_arg1, s_arg2, s_arg3, s_arg4, s_arg5,
s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12, s_arg13, s_arg14,
s_arg15, ...) standardGeneric('FixedCouponBond'))
attr(FixedCouponBond, 'returnType') = '_p_FixedCouponBondPtr'
setMethod('FixedCouponBond',
c('_p_Date', '_p_Date', '_p_Date', 'numeric', '_p_std__vectorTdouble_std__allocatorTdouble_t_t', 'character', '_p_Calendar', '_p_DayCounter', 'character', 'character', 'numeric', '_p_HandleTYieldTermStructure_t', '_p_Date', 'logical',
s_arg15 = "missing"),
function(s_arg1, s_arg2, s_arg3, s_arg4, s_arg5, s_arg6, s_arg7, s_arg8,
s_arg9, s_arg10, s_arg11, s_arg12, s_arg13, s_arg14)
{
  s_arg1 = coerceIfNotSubclass(s_arg1, "_p_Date")
  s_arg2 = coerceIfNotSubclass(s_arg2, "_p_Date")
  s_arg3 = coerceIfNotSubclass(s_arg3, "_p_Date")
  s_arg4 = as.integer(s_arg4)
 
  if(length(s_arg4) > 1) {
    warning("using only the first element of s_arg4")
  }
 
  s_arg5 =
coerceIfNotSubclass(s_arg5, "_p_std__vectorTdouble_std__allocatorTdouble_t_t")
  s_arg6 = enumToInteger(s_arg6, "_Frequency")
 
  if(length(s_arg6) > 1) {
    warning("using only the first element of s_arg6")
  }
 
  s_arg7 = coerceIfNotSubclass(s_arg7, "_p_Calendar")
  s_arg8 = coerceIfNotSubclass(s_arg8, "_p_DayCounter")
  s_arg9 = enumToInteger(s_arg9, "_BusinessDayConvention")
 
  if(length(s_arg9) > 1) {
    warning("using only the first element of s_arg9")
  }
 
  s_arg10 = enumToInteger(s_arg10, "_BusinessDayConvention")
 
  if(length(s_arg10) > 1) {
    warning("using only the first element of s_arg10")
  }
 
  s_arg11 = as.numeric(s_arg11)
  s_arg12 = coerceIfNotSubclass(s_arg12, "_p_HandleTYieldTermStructure_t")
  s_arg13 = coerceIfNotSubclass(s_arg13, "_p_Date")
  s_arg14 = as.logical(s_arg14)
  ans = .Call('R_swig_new_FixedCouponBond__SWIG_0', s_arg1, s_arg2, s_arg3,
s_arg4, s_arg5, s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12,
s_arg13, s_arg14, PACKAGE='QuantLib_wrap')
  class(ans) <- "_p_FixedCouponBondPtr"
 
  ans
 
}

)
setMethod('FixedCouponBond',
c('_p_Date', '_p_Date', '_p_Date', 'numeric', '_p_std__vectorTdouble_std__allocatorTdouble_t_t', 'character', '_p_Calendar', '_p_DayCounter', 'character', 'character', 'numeric', '_p_HandleTYieldTermStructure_t', '_p_Date',
s_arg14 = "missing", s_arg15 = "missing"),
function(s_arg1, s_arg2, s_arg3, s_arg4, s_arg5, s_arg6, s_arg7, s_arg8,
s_arg9, s_arg10, s_arg11, s_arg12, s_arg13)
{
  s_arg1 = coerceIfNotSubclass(s_arg1, "_p_Date")
  s_arg2 = coerceIfNotSubclass(s_arg2, "_p_Date")
  s_arg3 = coerceIfNotSubclass(s_arg3, "_p_Date")
  s_arg4 = as.integer(s_arg4)
 
  if(length(s_arg4) > 1) {
    warning("using only the first element of s_arg4")
  }
 
  s_arg5 =
coerceIfNotSubclass(s_arg5, "_p_std__vectorTdouble_std__allocatorTdouble_t_t")
  s_arg6 = enumToInteger(s_arg6, "_Frequency")
 
  if(length(s_arg6) > 1) {
    warning("using only the first element of s_arg6")
  }
 
  s_arg7 = coerceIfNotSubclass(s_arg7, "_p_Calendar")
  s_arg8 = coerceIfNotSubclass(s_arg8, "_p_DayCounter")
  s_arg9 = enumToInteger(s_arg9, "_BusinessDayConvention")
 
  if(length(s_arg9) > 1) {
    warning("using only the first element of s_arg9")
  }
 
  s_arg10 = enumToInteger(s_arg10, "_BusinessDayConvention")
 
  if(length(s_arg10) > 1) {
    warning("using only the first element of s_arg10")
  }
 
  s_arg11 = as.numeric(s_arg11)
  s_arg12 = coerceIfNotSubclass(s_arg12, "_p_HandleTYieldTermStructure_t")
  s_arg13 = coerceIfNotSubclass(s_arg13, "_p_Date")
  ans = .Call('R_swig_new_FixedCouponBond__SWIG_1', s_arg1, s_arg2, s_arg3,
s_arg4, s_arg5, s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12,
s_arg13, PACKAGE='QuantLib_wrap')
  class(ans) <- "_p_FixedCouponBondPtr"
 
  ans
 
}

)