-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnttv_cwrapper.py
48 lines (32 loc) · 1.24 KB
/
nttv_cwrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import numpy as np
import ctypes
import os
fullpath = '/home/gjgilbert/projects/koi564/markov/'
lib = ctypes.CDLL(fullpath + 'nttv.so')
def free(pointer):
lib.myfree.argtype = ctypes.POINTER(6*ctypes.c_double)
lib.myfree(pointer)
return None
def integrator(state, mu, tbounds):
# sizes of arrays
Nstate = len(state)
Nmu = len(mu)
Ntbounds = 3
# set up conversion to c-readable arrays
state_array_type = Nstate*ctypes.c_double
mu_array_type = Nmu*ctypes.c_double
tbounds_array_type = Ntbounds*ctypes.c_double
state_array = state_array_type(*state)
mu_array = mu_array_type(*mu)
tbounds_array = tbounds_array_type(*tbounds)
# arguments to integrator
lib.dummy.argtypes = (ctypes.POINTER(state_array_type), \
ctypes.POINTER(mu_array_type), \
ctypes.POINTER(tbounds_array_type))
# returns from integrator
lib.dummy.restype = ctypes.POINTER(6*ctypes.c_double)
integrator_ptr = lib.dummy(state_array, mu_array, tbounds_array)
print integrator_ptr[0]
#R = [x for x in integrator_ptr.contents]
free(integrator_ptr)
return 0