Olha, tem coisas que não tem jeito… são conceitos muito complexos, e não tem como você dizer em “partes” devido a interdependência de regras, por exemplo:
Eu tenho um código Python que necessita rodar um modelo matemático em Fortran, como posso receber uma matriz bidimensional que seria o resultado do modelo Fortran, com ajuda de ISO_C_BIND, cuja as dimensões são apenas conhecidas do lado do modelo Fortran, em tempo de execução. De um resultado em cython pyrex sem usar ctypes.
A partir dai sai groselha… Mas quase tudo envolvendo Fortran ou cython sai groselha pelo que tenho visto, não é um assunto simples e ainda por cima é um nicho.
O jeito é ir para o Google e ficar alguns minutos na documentação do Cython e do numpy.
update: se alguém tem interesse em saber como seria uma possível solução para isso usando fortran2003:
blabla.f90
module api_wrappers
use iso_c_binding, only: c_float, c_int, c_bool, c_char, c_ptr, c_f_pointer
...
implicit none
private :: real (c_float), allocatable :: result_aux(:, :)
private :: integer (c_int) :: result_shape_aux(2) = [0, 0]
public :: wrapper_run
public :: wrapper_get_result
...
subroutine wrapper_run (..., result_shape) bind (c)
...
integer (c_int), intent(out) :: result_shape(2)
call run(..., result_aux, result_shape_aux)
result_shape = [size(result_shape_aux, 1), size(result_shape_aux, 2)]
result_shape_aux = result_shape
end subroutine
subroutine wrapper_get_result (result_table) bind (c)
real (c_float), intent (out) :: result_table(result_shape_aux(1), result_shape_aux(2))
result_table = result_aux
end subroutine
...
end module
blabla.pyx
from libcpp cimport bool
from libc.stdlib cimport malloc
import numpy as np
cdef extern from "stdbool.h":
pass
cdef extern void wrapper_run(
...,
int[2] result_shape
);
cdef extern void wrapper_get_result(
float* result_table
);
def run(...):
...
cdef int[2] rt_shape = [0, 0]
wrapper_run(..., rt_shape)
cdef float[:, :] result_table = np.zeros(rt_shape, dtype=np.float32, order='F')
wrapper_get_result(&result_table[0, 0])
result_table = np.asarray(result_table)
...