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

Accessing data in std::vector<double> #75

Open
ianhbell opened this issue Oct 17, 2016 · 5 comments
Open

Accessing data in std::vector<double> #75

ianhbell opened this issue Oct 17, 2016 · 5 comments

Comments

@ianhbell
Copy link

In my C++ code, I sometimes return std::vector. That end up getting wrapped in a DoubleVector from the swig typemap, but for the life of me, I can't figure out how to get access to the data being wrapped. I tried to pop(), but that only works once, and the second call crashes MATLAB. The at() function isn't wrapped, and neither is any other type of accessor. So, how do I get my data back out of a DoubleVector?

@jaeandersson
Copy link
Owner

Sounds like it's not implemented properly.
In CasADi we have a output typemap for it. So the user never works directly with it - it gets converted to a MATLAB row vector.

@ianhbell
Copy link
Author

Well, it does seem that you can index into the DoubleVector using x(3) for instance, but I keep getting random crashes that I can't debug. I return a struct that holds std::vector and that seems to add more wrinkles to the vector wrapping.

@jaeandersson
Copy link
Owner

OK, it's probably a reference counting thing. It needs to keep a reference to the original vector<double> in order to do things like mystruct.x(3) = 3.

@ianhbell
Copy link
Author

How fixable is this? At the moment I have a non-swig-based MATLAB wrapper working, so it's not the end of the world, but it is quite annoying that I can can't have vectors in returned structs.

@jaeandersson
Copy link
Owner

It's probably fixable with a moderate effort. But someone has to do it.

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

2 participants