bindings

Overview

Both surfaces call the same Fortran kernels through libgjp_cinterp and the preferred dispatch entry gauss_jacobi_rule_c (optional method, status codes).

Multi-image CAF is not exposed on C/Python (single-image only).

Build the C library (meson)

meson setup bbdir -Dfcoarray=single
meson compile -C bbdir
# products: bbdir/libgjp_cinterp.so  bbdir/c_cli_gjpq  bbdir/test_c_rule
meson test -C bbdir c_rule

OpenBLAS/LAPACK must be visible to the linker (LIBRARY_PATH / pkg-config).

C CLI

./bbdir/c_cli_gjpq 32 0 0 auto
./bbdir/c_cli_gjpq 40 0.5 0.5 glr
./bbdir/c_cli_gjpq 32 0 0 bogaert
# omit method → auto
./bbdir/c_cli_gjpq 16 0.5 12

Decimals are optional on the C CLI. Policy failures print gjp_status_string and exit nonzero (no process abort from Fortran error stop for bogaert policy).

C API (preferred)

Header: interfaces/CInterface/GaussJacobiQuadCInterp.h

#include "GaussJacobiQuadCInterp.h"

double x[64], w[64];
int st = gauss_jacobi_rule_c(64, 0.5, 0.5, x, w, "auto"); /* NULL or "" also auto */
if (st != GJP_OK) {
    fprintf(stderr, "%s\n", gjp_status_string(st));
}
/* forced methods: "rec", "gw", "algo665", "algo665_dc", "sturm", "glr", "bogaert" */
st = gauss_jacobi_rule_c(40, 0.5, 0.5, x, w, "glr");

C++ convenience (default method = auto):

#include "GaussJacobiQuadCInterp.h"
double x[32], w[32];
int st = gauss_jacobi_rule(32, 0.0, 0.0, x, w); // method defaults to nullptr → auto

Status codes: GJP_OK, GJP_ERR_NPTS, GJP_ERR_ALPHA, GJP_ERR_BETA, GJP_ERR_METHOD, GJP_ERR_BOGAERT_AB, GJP_ERR_BOGAERT_N.

Legacy named wrappers (gauss_jacobi_rec_c, gauss_jacobi_gw_c, gauss_jacobi_algo665_c) remain for ABI stability.

Full reference: Reference · C API.

Python (CPython extension — preferred)

The PyPI package gauss-jacobi-quad is a real CPython extension (not pure ctypes). It multi-phase-inits (PEP 489), uses a heap GaussJacobiError, and links the ISOCBINDING entry gauss_jacobi_rule_c into the extension (no GJP_CINTERP).

Wheels (v0.2.3+):

C/Python surfaces are single-image only; multi-image CAF is Fortran + cafrun.

Build from the repository root (meson-python + gfortran + OpenBLAS):

pip install .          # or: python -m build
pytest python/tests -q
from gauss_jacobi_quad import gauss_jacobi, GaussJacobiError

x, w = gauss_jacobi(32, 0.0, 0.0)                 # auto
x, w = gauss_jacobi(40, 0.5, 0.5, method="glr")
try:
    gauss_jacobi(32, 0.5, 0.0, method="bogaert")  # non-Legendre
except GaussJacobiError as e:
    print(e)  # message includes status=5 = GJP_ERR_BOGAERT_AB

Python (ctypes development path)

In-tree ctypes loader still works for local libgjp_cinterp development:

export GJP_CINTERP=$(find bbdir -name 'libgjp_cinterp.so' | head -1)
export PYTHONPATH=$PWD/interfaces/PyInterface:$PYTHONPATH
export LD_LIBRARY_PATH=$(dirname "$GJP_CINTERP"):$LD_LIBRARY_PATH
pytest pytests/test_c_py_bindings.py

Full reference: Reference · Python API.