Is possible to decorate a f2py-compiled function with numba.jit?
<p>Say I have this function that works on 1-d arrays:</p>

<pre><code>def opfunc(a, b):
    if len(a.shape) != 1 and len(b.shape) != 1:
        raise ValueError('opfunc: both inputs must be 1-d arrays.')
    return 2 * b + 2 * (a[0] - a[-1])
</code></pre>

<p>and I want to use it repeatedly in loops or nested loops like this</p>

<pre><code>nx1, nx2, nx3 = a.shape
c = np.zeros(a.shape)
for ix1 in range(nx1):
    for ix2 in range(nx2):
        avec = a[ix1, ix2, :]
        bvec = b[ix1, ix2, :]
        cvec = opfunc(avec, bvec)
            c[ix1, ix2, :] = cvec
</code></pre>

<p>I can speed this up by putting these statements in a function and decorating it and <code>opfunc</code> with <code>numba.jit</code>:</p>

<pre><code>@numba.jit(nopython=True)
def opfunc(a, b):
    if len(a.shape) != 1 and len(b.shape) != 1:
        raise ValueError('opfunc: both inputs must be 1-d arrays.')
    return 2 * b + 2 * (a[0] - a[-1])

@numba.jit(nopython=True)
def opfunc1(a, b):
    nx1, nx2, nx3 = a.shape
    c = np.zeros(a.shape)
    for ix1 in range(nx1):
        for ix2 in range(nx2):
            avec = a[ix1, ix2, :]
            bvec = b[ix1, ix2, :]
            cvec = opfunc(avec, bvec)
            c[ix1, ix2, :] = cvec
    return c
</code></pre>

<p>Definite speed-up here.  </p>

<p>Is it possible to do a similar thing if <code>opfunc</code> is written in Fortran </p>

<pre><code>$ !cat fortran_test.f90

module test_fortran

  implicit none

contains

  subroutine opfunc(a, b, c)
    implicit none

    real (kind=8), dimension(6), intent(in) :: a, b
    real (kind=8), dimension(6), intent(out) :: c

    c = 2 * b + 2 !* (a(1) - a(ubound(a)))
  end subroutine opfunc

end module test_fortran
</code></pre>

<p>and has been imported into Python with f2py?</p>

<pre><code>import fortran_test

opfuncx = fortran_test.test_fortran.opfunc

@numba.jit(nopython=True)
def opfunc1x(a, b):
    nx1, nx2, nx3 = a.shape
    c = np.zeros(a.shape)
    for ix1 in range(nx1):
        for ix2 in range(nx2):
            avec = a[ix1, ix2, :]
            bvec = b[ix1, ix2, :]
            cvec = opfuncx(avec, bvec)
            c[ix1, ix2, :] = cvec
    return c
</code></pre>

<p>As it is, I'm getting </p>

<pre><code>TypingError: Failed at nopython (nopython frontend)
Untyped global name 'opfuncx'
File "&lt;ipython-input-48-c51d5b4fdad5&gt;", line 13
</code></pre>

<p>when running the function.  I am guessing that it is because <code>opfuncx</code> has not been decorated with <code>numba.jit</code>.  Is it possible to do this?</p>