Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typemap not matching in overloaded methods #1193

Closed
karlnapf opened this issue Feb 7, 2018 · 1 comment
Closed

typemap not matching in overloaded methods #1193

karlnapf opened this issue Feb 7, 2018 · 1 comment

Comments

@karlnapf
Copy link

karlnapf commented Feb 7, 2018

I have a set of methods of the form

class Foo
{
Foo(SGMatrix<float64_t> value);

void bar(const std::string& name, float64_t const & value);
void bar(const std::string& name, SGVector<float64_t> const & value);
void bar(const std::string& name, SGMatrix<float64_t> const & value); // the method I care about here
}

There are (say Python) typemaps for all of the SG*.

Now in Python I do

mat = np.zeros( (2,2), dtype=np.float64)
foo = Foo(mat) # works, i.e. typemap is matched
foo.bar("mat", mat) # does not work

The error message I get for the second call is in the lines of

417:     foo.put("mat", mat)
417: NotImplementedError: Wrong number or type of arguments for overloaded function 'SGObject_put'.
417:   Possible C/C++ prototypes are:
417:     shogun::Foo::bar(std::string const &, float64_t const &)
417:     shogun::Foo::bar(std::string const &, SGVector< float64_t > const &)
417:     shogun::Foo::bar(std::string const &, SGMatrix< float64_t > const &)

Indeed, checking the generated c++ interface code, I see that for the constructor, the typemap is used, in the lines of

SWIGINTERN int _wrap_new_Foo__SWIG_0(PyObject *self, PyObject *args) {
......
    matrix_from_numpy<float64_t>(arg3, obj2, NPY_FLOAT64)

but for the method, this is not the case

SWIGINTERN PyObject *_wrap_Foo_bar__SWIG_5(PyObject *self, PyObject *args) {
......
    arg3 = reinterpret_cast< SGMatrix< float64_t > * >(argp3);

I tried playing around with removing the const references and changing the order of the arguments, but I could not get swig to match the typemap. Is there anything obvious I am doing wrong?

Many thanks!

@karlnapf karlnapf closed this as completed Feb 7, 2018
@karlnapf
Copy link
Author

karlnapf commented Feb 7, 2018

There is some other issue going on, I need to dig a bit before I can pin things down. Sorry

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

No branches or pull requests

1 participant