Hi, this might have been reported somewhere, but I don’t happen to find an answer.
I have the following code in test_fortran.f90
subroutine addstuff_wrap(a,b,c) bind(C,name=‘addstuff_wrap’)
use iso_c_binding
implicit none
real(c_double), intent(in) :: a, b
real(c_double), intent(out) :: c
c = a + b
end subroutine addstuff_wrap
and then i do to make an executable
gfortran test_fortran.f90 -shared -fPIC -o test_fortran90.so
then i write the following test_f90.py
import ctypes as ct
from numba import njit, jit
import numpy as np
mylib = ct.CDLL(‘./test_fortran90.so’)
mylib.addstuff_wrap.argtypes =[ct.c_void_p, ct.c_void_p, ct.c_void_p]
mylib.addstuff_wrap.restype = ct.c_double
@njit(‘float64(float64,float64)’)
def test(a,b):
aa = np.array(a)
bb = np.array(b)
c = np.array(0.0)
mylib.addstuff_wrap(aa.ctypes.c_double, bb.ctypes.c_double, c.ctypes.c_double)
return c.item()
fty = ct.CFUNCTYPE(ct.c_double,ct.c_double,ct.c_double)(test)
@njit
def fty_wrapping(a,b):
return fty
a = ct.c_double(1.0)
b = ct.c_double(2.0)
print(‘W/ numba’,fty_wrapping(a,b))
neither functions fty_wrapping nor test are working
i keep getting the following error
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘mylib’: Cannot determine Numba type of <class ‘ctypes.CDLL’>
File “test_f90.py”, line 21:
def test(a,b):
mylib.addstuff_wrap(aa.ctypes.c_double, bb.ctypes.c_double, c.ctypes.c_double)
^
This error may have been caused by the following argument(s):
- argument 0: Cannot determine Numba type of <class ‘ctypes.c_double’>
- argument 1: Cannot determine Numba type of <class ‘ctypes.c_double’>
any idea on what’s going on?