From 925a3a4ddeede65ce8cd5e9e8f505a9b048c4c97 Mon Sep 17 00:00:00 2001 From: Joseph Capriotti Date: Thu, 26 Oct 2023 17:14:15 -0600 Subject: [PATCH] add optionally handles to the underlying c functions for prism kernels --- geoana/kernels/__init__.py | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/geoana/kernels/__init__.py b/geoana/kernels/__init__.py index 55cc5e2a..6208470a 100644 --- a/geoana/kernels/__init__.py +++ b/geoana/kernels/__init__.py @@ -12,3 +12,61 @@ prism_fxxz, prism_fxyz, ) + +try: + from numba.extending import get_cython_function_address + import ctypes + + def __as_ctypes_func(module, function, argument_types): + func_address = get_cython_function_address(module, function) + func_type = ctypes.CFUNCTYPE(*argument_types) + return func_type(func_address) + + c_prism = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_f', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fz = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fz', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fzz = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fzz', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fzx = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fzx', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fzy = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fzy', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fzzz = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fzzz', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fxxy = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fxxy', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fxxz = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fxxz', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + c_prism_fxyz = __as_ctypes_func( + 'geoana.kernels._extensions.potential_field_prism', + 'prism_fxyz', + (ctypes.c_double, ctypes.c_double, ctypes.c_double, ctypes.c_double) + ) + +except ImportError: + pass