From b1fac2a46ca7e16248d73934937f54f750eecdb4 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 17 Nov 2017 10:22:20 -0500 Subject: tie numpy array's life to the C++ vector life --- pyisda/credit_index.pyx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyisda/credit_index.pyx b/pyisda/credit_index.pyx index bc3ee8f..c93b177 100644 --- a/pyisda/credit_index.pyx +++ b/pyisda/credit_index.pyx @@ -3,6 +3,7 @@ from libc.stdlib cimport malloc, free from libc.math cimport nan from libcpp.pair cimport pair from cython.operator cimport dereference as deref +from cpython cimport PyObject, Py_INCREF cimport cython from legs cimport (JpmcdsCdsContingentLegMake, JpmcdsCdsFeeLegMake, @@ -88,6 +89,8 @@ cdef class CurveList: cdef np.npy_intp shape = self.weights.size() cdef np.ndarray[np.float64_t] out = \ np.PyArray_SimpleNewFromData(1, &shape, np.NPY_DOUBLE, self.weights.data()) + out.base = self + Py_INCREF(self) return out @property -- cgit v1.2.3-70-g09d2