Skip to content

Commit

Permalink
Use std::function and std::tuple instead of the ones in the ext names…
Browse files Browse the repository at this point in the history
…pace (#664)
  • Loading branch information
lballabio committed Jul 26, 2024
2 parents 43a400b + 6f33138 commit d419466
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
28 changes: 17 additions & 11 deletions .github/workflows/namespaces.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Fix uses of boost namespace
name: Fix uses of boost and/or ext namespace
on:
push:
branches:
Expand All @@ -10,19 +10,25 @@ jobs:
- uses: actions/checkout@v4
- name: Check
run: |
sed -i -e 's/boost::shared_ptr/ext::shared_ptr/g' SWIG/*
sed -i -e 's/boost::make_shared/ext::make_shared/g' SWIG/*
sed -i -e 's/boost::dynamic_pointer_cast/ext::dynamic_pointer_cast/g' SWIG/*
sed -i -e 's/boost::tuple/ext::tuple/g' SWIG/*
sed -i -e 's/boost::get/ext::get/g' SWIG/*
sed -i -e 's/boost::function/ext::function/g' SWIG/*
sed -i -e 's/boost::optional/ext::optional/g' SWIG/*
sed -i -e 's/boost::none/ext::nullopt/g' SWIG/*
sed -i -e 's/boost::shared_ptr\b/ext::shared_ptr/g' SWIG/*
sed -i -e 's/boost::make_shared\b/ext::make_shared/g' SWIG/*
sed -i -e 's/boost::dynamic_pointer_cast\b/ext::dynamic_pointer_cast/g' SWIG/*
sed -i -e 's/ext::tuple\b/std::tuple/g' SWIG/*
sed -i -e 's/ext::make_tuple\b/std::make_tuple/g' SWIG/*
sed -i -e 's/ext::get\b/std::get/g' SWIG/*
sed -i -e 's/ext::tie\b/std::tie/g' SWIG/*
sed -i -e 's/ext::function\b/std::function/g' SWIG/*
sed -i -e 's/ext::bind\b/std::bind/g' SWIG/*
sed -i -e 's/ext::ref\b/std::ref/g' SWIG/*
sed -i -e 's/ext::cref\b/std::cref/g' SWIG/*
sed -i -e 's/ext::placeholders\b/std::placeholders/g' SWIG/*
sed -i -e 's/boost::optional\b/ext::optional/g' SWIG/*
sed -i -e 's/boost::none\b/ext::nullopt/g' SWIG/*
- uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: fix-boost-namespace-${{ github.ref_name }}
delete-branch: true
commit-message: 'Fix uses of boost namespace'
title: 'Fix uses of boost namespace'
commit-message: 'Fix uses of boost and/or ext namespace'
title: 'Fix uses of boost and/or ext namespace'
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
10 changes: 5 additions & 5 deletions SWIG/fdm.i
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class FdmBlackScholesMesher : public Fdm1dMesher {
Volatility vol);
};

%template(Concentrating1dMesherPoint) ext::tuple<Real, Real, bool>;
%template(Concentrating1dMesherPointVector) std::vector<ext::tuple<Real, Real, bool> >;
%template(Concentrating1dMesherPoint) std::tuple<Real, Real, bool>;
%template(Concentrating1dMesherPointVector) std::vector<std::tuple<Real, Real, bool> >;


%shared_ptr(Concentrating1dMesher)
Expand All @@ -113,7 +113,7 @@ class Concentrating1dMesher : public Fdm1dMesher {

Concentrating1dMesher(
Real start, Real end, Size size,
const std::vector<ext::tuple<Real, Real, bool> >& cPoints,
const std::vector<std::tuple<Real, Real, bool> >& cPoints,
Real tol = 1e-8);
};

Expand Down Expand Up @@ -686,7 +686,7 @@ class FdmTimeDepDirichletBoundary : public FdmBoundaryCondition {
PyObject* function,
Size direction, Side side) {

const ext::function<Real(Real)> f = UnaryFunction(function);
const std::function<Real(Real)> f = UnaryFunction(function);
return new FdmTimeDepDirichletBoundary(
mesher, f, direction, side);
}
Expand All @@ -696,7 +696,7 @@ class FdmTimeDepDirichletBoundary : public FdmBoundaryCondition {
UnaryFunctionDelegate* function,
Size direction, Side side) {

const ext::function<Real(Real)> f = UnaryFunction(function);
const std::function<Real(Real)> f = UnaryFunction(function);
return new FdmTimeDepDirichletBoundary(
mesher, f, direction, side);
}
Expand Down
10 changes: 2 additions & 8 deletions SWIG/stochasticprocess.i
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,8 @@ using QuantLib::ExtOUWithJumpsProcess;

%shared_ptr(ExtendedOrnsteinUhlenbeckProcess)
class ExtendedOrnsteinUhlenbeckProcess : public StochasticProcess1D {
public:
enum Discretization { MidPoint, Trapezodial, GaussLobatto };

ExtendedOrnsteinUhlenbeckProcess(
Real speed, Volatility sigma, Real x0,
const ext::function<Real (Real)>& b,
Discretization discretization = MidPoint,
Real intEps = 1e-4);
public:
enum Discretization { MidPoint, Trapezodial, GaussLobatto };
%extend{
#if defined(SWIGPYTHON)
ExtendedOrnsteinUhlenbeckProcess(
Expand Down
16 changes: 9 additions & 7 deletions SWIG/tuple.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

%include common.i

namespace ext {
namespace std {

template <typename T1=void, typename T2=void, typename T3=void>
struct tuple;

Expand All @@ -36,7 +37,7 @@ namespace ext {
tuple(T1);
%extend {
T1 first() const {
return ext::get<0>(*$self);
return std::get<0>(*$self);
}
}
};
Expand All @@ -46,10 +47,10 @@ namespace ext {
tuple(T1,T2);
%extend {
T1 first() const {
return ext::get<0>(*$self);
return std::get<0>(*$self);
}
T2 second() const {
return ext::get<1>(*$self);
return std::get<1>(*$self);
}
}
};
Expand All @@ -59,16 +60,17 @@ namespace ext {
tuple(T1,T2,T3);
%extend {
T1 first() const {
return ext::get<0>(*$self);
return std::get<0>(*$self);
}
T2 second() const {
return ext::get<1>(*$self);
return std::get<1>(*$self);
}
T3 third() const {
return ext::get<2>(*$self);
return std::get<2>(*$self);
}
}
};

}

#endif
4 changes: 2 additions & 2 deletions SWIG/volatilities.i
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ using QuantLib::AndreasenHugeLocalVolAdapter;
using QuantLib::HestonBlackVolSurface;
%}

%template(CalibrationErrorTuple) ext::tuple<Real, Real, Real>;
%template(CalibrationErrorTuple) std::tuple<Real, Real, Real>;

%shared_ptr(AndreasenHugeVolatilityInterpl)
class AndreasenHugeVolatilityInterpl : public Observable {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ class AndreasenHugeVolatilityInterpl : public Observable {
const Handle<YieldTermStructure>& riskFreeRate() const;

// returns min, max and average error in volatility units
ext::tuple<Real, Real, Real> calibrationError() const;
std::tuple<Real, Real, Real> calibrationError() const;

// returns the option price of the calibration type. In case
// of CallPut it return the call option price
Expand Down

0 comments on commit d419466

Please sign in to comment.