summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2023-06-02 11:46:34 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2023-06-02 11:46:34 -0400
commit96352a2bb657815d42eb38b85d31f0bd9fc56a4a (patch)
treef3ab98d44c2d2a48c6ca5d2975f1141f0dec5f5e
parent8c8a4092458029b4c619eb0603ee21c639702a2b (diff)
downloadpyisda-96352a2bb657815d42eb38b85d31f0bd9fc56a4a.tar.gz
no need to manually expose these numpy functions
-rw-r--r--pyisda/curve.pyx24
1 files changed, 8 insertions, 16 deletions
diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx
index ccd83f7..312c7d6 100644
--- a/pyisda/curve.pyx
+++ b/pyisda/curve.pyx
@@ -1,6 +1,6 @@
from cython.operator import dereference as deref, preincrement as preinc
-from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AS_STRING
+from cpython.bytes cimport PyBytes_FromStringAndSize, PyBytes_AS_STRING, PyBytes_GET_SIZE
from libc.math cimport log1p, log, exp, isnan
from libc.string cimport strcpy, strncpy, strlen
from .date cimport (JpmcdsStringToDateInterval, pydate_to_TDate, dcc,
@@ -19,19 +19,11 @@ import numpy as np
np.import_array()
import pandas as pd
from cpython cimport Py_buffer
-from cpython.bytes cimport PyBytes_GET_SIZE
cdef extern from "Python.h":
int PyMemoryView_Check(object)
Py_buffer *PyMemoryView_GET_BUFFER(object)
-cdef extern from "numpy/arrayobject.h":
- void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
- int PyArray_CheckExact(object)
- void* PyArray_DATA(object)
- int PyArray_TYPE(object)
- np.npy_intp PyArray_Size(object)
-
cdef extern from "lz4.h" nogil:
int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity)
int LZ4_decompress_safe(const char* src, char* dst, int compressedSize, int dstCapacity)
@@ -303,7 +295,7 @@ cdef class Curve(object):
cdef np.ndarray[np.float64_t] out = \
np.PyArray_SimpleNewFromData(1, &shape, np.NPY_DOUBLE, data)
- PyArray_ENABLEFLAGS(out, np.NPY_OWNDATA)
+ np.PyArray_ENABLEFLAGS(out, np.NPY_OWNDATA)
return out
@property
@@ -841,13 +833,13 @@ cdef class SpreadCurve(Curve):
if not isnan(upfront_rates[i]) and not isnan(coupon_rates[i]):
includes |= 1 << i
i += 1
- elif PyArray_CheckExact(end_dates):
- n_dates = PyArray_Size(end_dates)
- if PyArray_TYPE(end_dates) == np.NPY_INT64:
- end_dates_c = <TDate*>PyArray_DATA(end_dates)
- elif PyArray_TYPE(end_dates) == np.NPY_DOUBLE:
+ elif np.PyArray_CheckExact(end_dates):
+ n_dates = np.PyArray_Size(end_dates)
+ if np.PyArray_TYPE(end_dates) == np.NPY_INT64:
+ end_dates_c = <TDate*>np.PyArray_DATA(end_dates)
+ elif np.PyArray_TYPE(end_dates) == np.NPY_DOUBLE:
end_dates_c = <TDate*>malloc(n_dates * sizeof(TDate))
- tenors_c = <double*>PyArray_DATA(end_dates)
+ tenors_c = <double*>np.PyArray_DATA(end_dates)
freeup = True
_roll_date(today_c, tenors_c, n_dates, end_dates_c)
for i in range(upfront_rates.shape[0]):