Interfacing a dynamic shared library gives me different results in 2.7 versus 3.5

Siyi Deng mr.siyi.deng at gmail.com
Tue May 24 13:38:36 EDT 2016


The c function has a signature as follows:

int cfun(int len_data, float* data, int* a, int num_a,
        int flag1, int flag2, int flag3, float* param,
        float* out1, float* out2, float* out3)


and in python:

import numpy as np
import ctypes as ct

    data = np.atleast_2d(np.float32(data))
    a = np.atleast_2d(np.int32(a)) if a else np.zeros((2, 1), dtype=np.int32)
    param = np.atleast_2d(np.float32(param))

    num_a = activity.shape[1]
    len_data = data.shape[1]
    num_inc = len_data//256
    cf = ct.POINTER(ct.c_float)
    
hr = np.zeros((2, num_inc), dtype=np.float32)
    of = np.zeros((num_inc, 207), dtype=np.float32)
    gait = np.zeros((num_inc, 14), dtype=np.float32)
    pt_of = of.ctypes.data_as(cf) if do_of else None
    pt_gait = gait.ctypes.data_as(cf) if do_gait else None
    pt_param = param.ctypes.data_as(cf) if param else None
    dl.run_plt_hrm(len_data, data.ctypes.data_as(cf),
            activity.ctypes.data_as(ct.POINTER(ct.c_int)),
            num_act, do_long_fft+0, do_cls_mitigate+0, do_weighted_average+0,
            pt_param, hr.ctypes.data_as(cf), pt_of, pt_gait)




More information about the Python-list mailing list