Running on Windows. WOOHOO!
This commit is contained in:
parent
c1d8fe97d4
commit
92034d3d2f
@ -17,6 +17,17 @@
|
|||||||
#define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT32
|
#define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MS_WIN64
|
||||||
|
/**
|
||||||
|
* Function passed to Python to use for cleanup of
|
||||||
|
* foreignly obtained data.
|
||||||
|
**/
|
||||||
|
static inline void capsule_cleanup(void* capsule) {
|
||||||
|
void *memory = PyCapsule_GetPointer(capsule, NULL);
|
||||||
|
free(memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
/**
|
/**
|
||||||
* Create a numpy array from an existing dmat.
|
* Create a numpy array from an existing dmat.
|
||||||
*
|
*
|
||||||
@ -47,7 +58,18 @@ static inline PyObject* dmat_to_ndarray(dmat* mat,bool transfer_ownership) {
|
|||||||
|
|
||||||
if(transfer_ownership) {
|
if(transfer_ownership) {
|
||||||
mat->_foreign_data = true;
|
mat->_foreign_data = true;
|
||||||
|
#ifdef MS_WIN64
|
||||||
|
// The default destructor of Python cannot free the data, as it is allocated
|
||||||
|
// with malloc. Therefore, with this code, we tell Numpy/Python to use
|
||||||
|
// the capsule_cleanup constructor. See:
|
||||||
|
// https://stackoverflow.com/questions/54269956/crash-of-jupyter-due-to-the-use-of-pyarray-enableflags/54278170#54278170
|
||||||
|
// Note that in general it was disadvised to build all C code with MinGW on Windows.
|
||||||
|
// We do it anyway, see if we find any problems on the way.
|
||||||
|
void* capsule = PyCapsule_New(mat->_data, NULL, capsule_cleanup);
|
||||||
|
PyArray_SetBaseObject( arr_t, capsule);
|
||||||
|
#else
|
||||||
PyArray_ENABLEFLAGS(arr_t, NPY_OWNDATA);
|
PyArray_ENABLEFLAGS(arr_t, NPY_OWNDATA);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transpose the array
|
// Transpose the array
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
This file contains the Cython wrapper functions to C implementations.
|
This file contains the Cython wrapper functions to C implementations.
|
||||||
"""
|
"""
|
||||||
include "config.pxi"
|
include "config.pxi"
|
||||||
|
from libc.stdio cimport printf
|
||||||
|
from numpy cimport import_array
|
||||||
|
|
||||||
|
import_array()
|
||||||
|
|
||||||
|
|
||||||
IF LASP_FLOAT == "double":
|
IF LASP_FLOAT == "double":
|
||||||
ctypedef double d
|
ctypedef double d
|
||||||
ctypedef double complex c
|
ctypedef double complex c
|
||||||
@ -456,13 +462,13 @@ cdef class SosFilterBank:
|
|||||||
cdef dmat output
|
cdef dmat output
|
||||||
with nogil:
|
with nogil:
|
||||||
output = Sosfilterbank_filter(self.fb,&input_vd)
|
output = Sosfilterbank_filter(self.fb,&input_vd)
|
||||||
|
#printf('Came back from filter\n')
|
||||||
# Steal the pointer from output
|
# Steal the pointer from output
|
||||||
result = dmat_to_ndarray(&output,True)
|
result = dmat_to_ndarray(&output,True)
|
||||||
|
#printf('Converted to array\n')
|
||||||
dmat_free(&output)
|
dmat_free(&output)
|
||||||
vd_free(&input_vd)
|
vd_free(&input_vd)
|
||||||
|
#printf('Ready to return\n')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
cdef extern from "lasp_decimation.h":
|
cdef extern from "lasp_decimation.h":
|
||||||
|
Loading…
Reference in New Issue
Block a user