Skip to content

numbl interface#842

Draft
magland wants to merge 6 commits into
flatironinstitute:masterfrom
magland:master
Draft

numbl interface#842
magland wants to merge 6 commits into
flatironinstitute:masterfrom
magland:master

Conversation

@magland

@magland magland commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

This shows what needs to be added to support finufft in numbl.

@magland

magland commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator Author

Replace the per-function .js / wrapper.cpp pair with a single finufft.js
builtin backed by a minimal mex C API shim, so the upstream finufft.cpp
(the mwrap-generated MEX source) can be compiled unmodified into both
finufft.wasm and finufft.so.  The unmodified upstream finufft_plan.m and
finufftNd? simple-interface m-files now run through this builtin without
any numbl-specific overrides.

Subtle: finufft_setpts stores xj/yj/zj pointers without copying them, so
finufft.js retains the input mxArrays per-plan and frees them on destroy.
@magland

magland commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

Reworked the numbl interface to be a drop-in replacement for the MEX file rather than a parallel set of overrides.

  • Upstream finufft_plan.m, finufft1d1.m, etc. are now used unmodified — the previously-shadowed finufft_plan.m and the per-function .js files are gone.
  • matlab/finufft.cpp (the mwrap-generated MEX source) is compiled directly, against a minimal mex.h shim in matlab/numbl/mex_shim/ (mxArray as a tagged struct, ~25 mx/mex functions, MX_HAS_INTERLEAVED_COMPLEX on, no R2008OO). mexErrMsgTxt longjmps out to a mex_dispatch entry point.
  • matlab/numbl/finufft.js is a single builtin that marshals each runtime arg into a shim mxArray (numbers/tensors/structs; classdef instances unwrapped via their mwptr field), calls mex_dispatch, and decodes plhs[] back. Native (koffi) and wasm bridges share the marshalling code.
  • One subtlety: finufft_setpts stores xj/yj/zj pointers without copying. Real MATLAB keeps them alive because it owns prhs[]; finufft.js keys input mxArrays under the plan's mwptr string after a setpts call and frees them on destroy.

All 6 scripts in matlab/numbl/tests/ pass on both backends.

magland added 2 commits April 9, 2026 12:23
…rnings

Refactor mexPrintf / mexErrMsgIdAndTxt to early-return / call the
noreturn mexErrMsgTxt directly when fmt is null, instead of passing an
empty literal as the format string.  Cosmetic; no behavior change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant