|
From: Joseph W. <jo...@gn...> - 2006-06-07 04:17:16
|
=E5=9C=A8 Tuesday 06 June 2006 22:48=EF=BC=8C=E6=82=A8=E5=86=99=E9=81=93=EF=
=BC=9A
> 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
=3D QuantLib::Follow=
ing,
BusinessDayConvention paymentConvention
=3D QuantLib::Follow=
ing,
Real redemption =3D 100.0,
const Handle<YieldTermStructure>& discountCurve
=3D Handle<YieldTermStructure=
>(),
const Date& stub =3D Date(),
bool fromEnd =3D true)=20
generates six separate wrappers for each possible number of optional argume=
nt.
(See below for the first few wrappers.)
Loading the wrappers into R seems to take about several meg of heap space. =
=20
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=
=20
ordinary non-generic function gets generated, and I don't get the huge memo=
ry=20
bloat.
setGeneric('FixedCouponBond', function(s_arg1, s_arg2, s_arg3, s_arg4, s_ar=
g5,=20
s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12, s_arg13, s_arg14=
,=20
s_arg15, ...) standardGeneric('FixedCouponBond'))
attr(FixedCouponBond, 'returnType') =3D '_p_FixedCouponBondPtr'
setMethod('FixedCouponBond',=20
c('_p_Date', '_p_Date', '_p_Date', 'numeric', '_p_std__vectorTdouble_std__a=
llocatorTdouble_t_t', 'character', '_p_Calendar', '_p_DayCounter', 'charact=
er', 'character', 'numeric', '_p_HandleTYieldTermStructure_t', '_p_Date', '=
logical',=20
s_arg15 =3D "missing"),=20
function(s_arg1, s_arg2, s_arg3, s_arg4, s_arg5, s_arg6, s_arg7, s_arg8,=20
s_arg9, s_arg10, s_arg11, s_arg12, s_arg13, s_arg14)
{
s_arg1 =3D coerceIfNotSubclass(s_arg1, "_p_Date")=20
s_arg2 =3D coerceIfNotSubclass(s_arg2, "_p_Date")=20
s_arg3 =3D coerceIfNotSubclass(s_arg3, "_p_Date")=20
s_arg4 =3D as.integer(s_arg4)=20
=20
if(length(s_arg4) > 1) {
warning("using only the first element of s_arg4")
}
=20
s_arg5 =3D=20
coerceIfNotSubclass(s_arg5, "_p_std__vectorTdouble_std__allocatorTdouble_t_=
t")=20
s_arg6 =3D enumToInteger(s_arg6, "_Frequency")=20
=20
if(length(s_arg6) > 1) {
warning("using only the first element of s_arg6")
}
=20
s_arg7 =3D coerceIfNotSubclass(s_arg7, "_p_Calendar")=20
s_arg8 =3D coerceIfNotSubclass(s_arg8, "_p_DayCounter")=20
s_arg9 =3D enumToInteger(s_arg9, "_BusinessDayConvention")=20
=20
if(length(s_arg9) > 1) {
warning("using only the first element of s_arg9")
}
=20
s_arg10 =3D enumToInteger(s_arg10, "_BusinessDayConvention")=20
=20
if(length(s_arg10) > 1) {
warning("using only the first element of s_arg10")
}
=20
s_arg11 =3D as.numeric(s_arg11)=20
s_arg12 =3D coerceIfNotSubclass(s_arg12, "_p_HandleTYieldTermStructure_t"=
)=20
s_arg13 =3D coerceIfNotSubclass(s_arg13, "_p_Date")=20
s_arg14 =3D as.logical(s_arg14)=20
ans =3D .Call('R_swig_new_FixedCouponBond__SWIG_0', s_arg1, s_arg2, s_arg=
3,=20
s_arg4, s_arg5, s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12,=
=20
s_arg13, s_arg14, PACKAGE=3D'QuantLib_wrap')
class(ans) <- "_p_FixedCouponBondPtr"
=20
ans
=20
}
)
setMethod('FixedCouponBond',=20
c('_p_Date', '_p_Date', '_p_Date', 'numeric', '_p_std__vectorTdouble_std__a=
llocatorTdouble_t_t', 'character', '_p_Calendar', '_p_DayCounter', 'charact=
er', 'character', 'numeric', '_p_HandleTYieldTermStructure_t', '_p_Date',=20
s_arg14 =3D "missing", s_arg15 =3D "missing"),=20
function(s_arg1, s_arg2, s_arg3, s_arg4, s_arg5, s_arg6, s_arg7, s_arg8,=20
s_arg9, s_arg10, s_arg11, s_arg12, s_arg13)
{
s_arg1 =3D coerceIfNotSubclass(s_arg1, "_p_Date")=20
s_arg2 =3D coerceIfNotSubclass(s_arg2, "_p_Date")=20
s_arg3 =3D coerceIfNotSubclass(s_arg3, "_p_Date")=20
s_arg4 =3D as.integer(s_arg4)=20
=20
if(length(s_arg4) > 1) {
warning("using only the first element of s_arg4")
}
=20
s_arg5 =3D=20
coerceIfNotSubclass(s_arg5, "_p_std__vectorTdouble_std__allocatorTdouble_t_=
t")=20
s_arg6 =3D enumToInteger(s_arg6, "_Frequency")=20
=20
if(length(s_arg6) > 1) {
warning("using only the first element of s_arg6")
}
=20
s_arg7 =3D coerceIfNotSubclass(s_arg7, "_p_Calendar")=20
s_arg8 =3D coerceIfNotSubclass(s_arg8, "_p_DayCounter")=20
s_arg9 =3D enumToInteger(s_arg9, "_BusinessDayConvention")=20
=20
if(length(s_arg9) > 1) {
warning("using only the first element of s_arg9")
}
=20
s_arg10 =3D enumToInteger(s_arg10, "_BusinessDayConvention")=20
=20
if(length(s_arg10) > 1) {
warning("using only the first element of s_arg10")
}
=20
s_arg11 =3D as.numeric(s_arg11)=20
s_arg12 =3D coerceIfNotSubclass(s_arg12, "_p_HandleTYieldTermStructure_t"=
)=20
s_arg13 =3D coerceIfNotSubclass(s_arg13, "_p_Date")=20
ans =3D .Call('R_swig_new_FixedCouponBond__SWIG_1', s_arg1, s_arg2, s_arg=
3,=20
s_arg4, s_arg5, s_arg6, s_arg7, s_arg8, s_arg9, s_arg10, s_arg11, s_arg12,=
=20
s_arg13, PACKAGE=3D'QuantLib_wrap')
class(ans) <- "_p_FixedCouponBondPtr"
=20
ans
=20
}
)
|