Unfortunately I don’t think this is possible from the
nnls bindings that SciPy provides. Whilst the routine is Fortran, it’s wrapped in a C extension and the symbol to the Fortran routine is local:
$ nm `python -c 'import scipy.optimize.__nnls as x; print(x.__file__)'`|grep 't nnls_\|T nnls_'
00000000000057b0 t nnls_
as a result, there’s no reasonable way of calling that function directly.
Were SciPy to elect to make this symbol global or make it e.g. a Cython export then Numba could bind to it and this would be just a case of wiring data.
Assuming SciPy doesn’t make the symbol global, I think your options are:
- Compile and ship the Fortran and bind to it, or find another package which ships this routine in a library with the symbol exported and bind to that.
- Translate the Fortran to Python and let Numba compile it. Given the routine makes use of things that are available in BLAS/LAPACK (Givens rotations and Householder transforms) and Numba can bind to BLAS/LAPACK, this might be the way to go.
Hope this helps?
NNLS C extension import: https://github.com/scipy/scipy/blob/v1.5.4/scipy/optimize/_nnls.py#L1
NNLS Fortran routine: https://github.com/scipy/scipy/blob/v1.5.4/scipy/optimize/__nnls/nnls.f#L1