instant appears to incorrectly identify a function signature
Issue #23
invalid
I have a function
void snes_execute_linesearch(SNES snes, Vec X, Vec F, PetscReal *fnorm, Vec Y)
that I'd like to wrap with instant. I've had good success in using instant for similar tasks of wrapping PETSc before.
The code compiles successfully. But when I try to call it, it gives me
snes_execute_linesearch(snes, x, f, fnorm, y)
Traceback (most recent call last):
File "x.py", line 51, in <module>
snes_execute_linesearch(snes, x, f, fnorm, y)
TypeError: snes_execute_linesearch expected 4 arguments, got 5
Even though the function actually takes 5 arguments, instant seems to think that it should only take 4.
Full code to reproduce:
import instant
import petsc4py
from petsc4py import PETSc
import os
include_dirs = [os.path.join(os.getenv('PETSC_DIR'), 'include'),
os.path.join(os.getenv('PETSC_DIR'), os.getenv('PETSC_ARCH'), 'include'),
petsc4py.get_include(),
# May need to add extras here depending on your environment
'/usr/lib/openmpi/include', '/usr/lib/openmpi/include/openmpi',
]
swig_include_dirs = [petsc4py.get_include()]
library_dirs = [os.path.join(os.getenv('PETSC_DIR'), os.getenv('PETSC_ARCH'), 'lib')]
libraries = ['petsc']
snes_execute_linesearch_cpp_code = r"""
#ifdef SWIG
%include "petsc4py/petsc4py.i"
#endif
#include <petsc.h>
int snes_execute_linesearch(SNES snes, Vec X, Vec F, PetscReal *fnorm, Vec Y)
{
SNESLineSearch linesearch;
PetscErrorCode ierr;
ierr = SNESGetLineSearch(snes, &linesearch);CHKERRQ(ierr);
ierr = SNESLineSearchSetType(linesearch, SNESLINESEARCHBASIC);CHKERRQ(ierr);
ierr = SNESLineSearchSetFromOptions(linesearch);CHKERRQ(ierr);
ierr = SNESLineSearchSetUp(linesearch);CHKERRQ(ierr);
ierr = SNESLineSearchApply(linesearch, X, F, fnorm, Y);CHKERRQ(ierr);
return 0;
}
"""
snes_execute_linesearch = instant.build_module(code=snes_execute_linesearch_cpp_code,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
swig_include_dirs=swig_include_dirs).snes_execute_linesearch
del snes_execute_linesearch_cpp_code
snes = PETSc.SNES().create()
x = PETSc.Vec().createSeq(10)
y = x.duplicate()
f = x.duplicate()
fnorm = 0.0
snes_execute_linesearch(snes, x, f, fnorm, y)
Comments (2)
-
-
- changed status to invalid
Not an instant bug
- Log in to comment
This is not instant per se. Most probably does petsc4py.i provide an argout typemap for PetscReal*, which means it think it is a return argument. Try changing the interface to:
This will result in a segfault when run, but that happens inside SNESLineSearchSetUp and instant should not be blamed.