Closed jlmaccal closed 8 years ago
Is this different from #6? It sounds like exactly the same problem.
I don't think so. Why would you say they are the same problem?
This is after setting a bunch of environment variables to make sure that everything is compiled with libc++. The link error goes away, but now errors like this pop up every time std::vector is used.
Oh, I see. Is the problem just with numpy arrays? Or does it also fail with regular Python lists?
I think what you need to do is add the following to exampleplugin.i:
namespace std {
%template(vectord) vector<double>;
};
That will tell it to generate a wrapper type of std::vector
The code works fine with a list, but it doesn't know what to do with a numpy array.
I have that line included. I also include std_vector.i. It doesn't seem to help.
OK,
So I need lines like:
namespace std {
%template(vectord) vector<double>;
};
Without those, it doesn't work with lists. But, I still don't know how to make it work with arrays.
OK, I think I'm starting to make progress...
In OpenMM, I think all arguments get passed through stripUnits
before being passed to the swig wrapper. Among the first lines of that function:
for arg in args:
if 'numpy' in sys.modules and isinstance(arg, numpy.ndarray):
arg = arg.tolist()
So, the unit handling code is implicitly converting all ndarray
objects into lists as a part of stripping off the units.
I hadn't even realized it did that. stripUnits() is called from pythonprepend_all.i:
%pythonprepend %{
try: args=stripUnits(args)
except UnboundLocalError: pass
%}
Perhaps we just need to include the same in the plugin?
Perhaps we just need to include the same in the plugin?
Yes, I think so. I'm going to look into this.
That would also provide the advantage that you could specify units on all your arguments and they would work automatically. stripUnits() is a public member of the simtk.openmm module, so there's no need to reimplement it.
I'm having a problem calling any routine that takes a std:vector as input or output. This code used to work fine when my plugin was part of the openmm tree. Now, it fails at runtime with errors like:
In this example, I am trying to pass a numpy array, which used to work fine. I'm sure this has something to do with type maps, but I have no idea where to even start.