diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-22 16:38:02 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2017-02-22 16:38:02 -0500 |
| commit | 8baef999da28d8a51734994219514e20fe92a2d2 (patch) | |
| tree | c3a1be6900fbc1036a2a887d43f10e4279a0591a | |
| parent | c373a9512d9cecd9d94497f0637d763ce7cfe9e5 (diff) | |
| download | pyisda-8baef999da28d8a51734994219514e20fe92a2d2.tar.gz | |
switch to C++cpp
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | cpp_layer/curve.hpp | 42 | ||||
| -rw-r--r-- | setup.py | 9 |
3 files changed, 49 insertions, 4 deletions
@@ -2,7 +2,7 @@ build: python setup.py build_ext --inplace clean: - find pyisda \( -name *.c -o -name \*.h -o -name \*.so \) -exec rm {} \; + find pyisda \( -name *.c -o -name *.h -o -name *.so -o -name *.cpp -o -name *.html \) -exec rm {} \; rm -rf build install: diff --git a/cpp_layer/curve.hpp b/cpp_layer/curve.hpp new file mode 100644 index 0000000..8e54216 --- /dev/null +++ b/cpp_layer/curve.hpp @@ -0,0 +1,42 @@ +#include <vector> +typedef long TDate; + +class CurveObject { +public: + CurveObject(TDate baseDate, std::vector<TDate> dates, std::vector<double> rates, + double basis, long dayCountConv) { + _ptr = JpmcdsMakeTCurve(baseDate, dates.data(), rates.data(), dates.size(), + basis, dayCountConv); + } + CurveObject(TCurve* ptr) { + _ptr = ptr; + } + CurveObject(const CurveObject& other) { + _ptr = JpmcdsCopyCurve(other._ptr); + } + CurveObject(CurveObject&& other) : _ptr(other._ptr) { + other._ptr = nullptr; + } + CurveObject& operator=(const CurveObject& other) { + if( this != &other) { + JpmcdsFreeTCurve(_ptr); + _ptr = JpmcdsCopyCurve(other._ptr); + } + return *this; + } + CurveObject& operator=(CurveObject&& other) { + if( this != &other) { + JpmcdsFreeTCurve(_ptr); + _ptr = other._ptr; + other._ptr = nullptr; + } + return *this; + } + ~CurveObject() { + if(_ptr != nullptr) { + JpmcdsFreeTCurve(_ptr); + } + } +private: + TCurve* _ptr; +}; @@ -4,13 +4,16 @@ from Cython.Build import cythonize import numpy all_extensions = Extension("*", ["pyisda/*.pyx"], - include_dirs = ['c_layer', numpy.get_include()], - libraries = ["cds"]) + include_dirs = ['cpp_layer', 'c_layer', numpy.get_include()], + libraries = ["cds"], + language = 'c++') c_extension = Extension("pyisda.flat_hazard", include_dirs = ['c_layer', numpy.get_include()], sources = ['pyisda/flat_hazard.pyx', 'c_layer/cdsbootstrap.c'], - libraries = ['cds']) + libraries = ['cds'], + language = 'c++') + all_extensions = cythonize([c_extension, all_extensions], nthreads = 4, compiler_directives={'embedsignature':True}) |
