-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Getting the flows #2
Comments
So it seems that this is a bit tricky to do with the current C++ implementation, since we'd have to pass a pointer to a std::vectorstd::vector, and I haven't found anything encouraging on the web that would imply Cython can do that. I suggest writing a wrapping function in the C++ code that creates a nested vector, passes it to the original function and returns it. I think Cython can deal with simple vector outputs. Unless you have any better idea? |
I'm fine with that approach—I'm afraid that since our application doesn't require the flows, I can't really spend too much time on this feature. Happy to look over a PR though! |
NP - I need it, an I think it might be useful to someone else, so I might On 28 May 2015 at 18:48, Will Mayner notifications@github.com wrote:
Rémi "We asked the captain what course www.notonebitsimpler.com Institut de Physique Théorique, CEA Saclay remi.louf@cea.fr |
@rlouf – any luck with the flows? If not, I may be able to help. (And, am I correct in understanding that once one has the flows, you can also deduce where any 'remainder' unmoved/unmatched mass remains?) |
@gojomo Not so far, I had to focus on my thesis writing for a while. But I will need this feature soon for my research. My C++ is a bit rusty, so I would definitely appreciate some help with this! |
@gojomo I will start working on this relatively soon, actually (maybe a couple of weeks). The C++ function takes a pointer as an input for the flows, and I am not sure how/if you can deal with this with Cython. The other idea I had was to wrap the original function with another function than initialises the flow matrices, passes a pointer to the original function, and outputs the matrix. Any thoughts? |
I had to deal with a similar problem in one of my other projects; I managed to get Cython to pass a reference to an array to a C++ function that filled the referenced array with values, and then to turn that into a NumPy array (without copying any data) to expose to Python. Perhaps some of that code might be useful. I got the idea from a helpful person in this Google groups discussion, and I used it in this file. |
Thanks, that's really helpful! If I understand well that is for simple vectors, correct? Any idea for a vector of vectors (this is out of my league too :) )? |
Yes, I believe it is much simpler to interpret the vector as multidimensional in Python rather than treating it as such in C++. In fact, that is exactly what's happening in the code I linked—the C++ has two indices which are used to fill the linear vector, and then corresponding NumPy array is reshaped to the proper dimensions afterwards. |
Hello, I've been using Fast-EMD code (the C++ routine and the Matlab wrapper) for a Data assimilation application (ETPF: ensemble transform particle filter) where the important output is precisely the flow. Now, I am extending a Python data assimilation code to ETPF, so I wonder if there is currently a simple way to obtain the flow via pyemd? |
@walteracevedo, glad to hear you're finding the wrapper useful. @rlouf, did you have any luck with getting the flows? |
@rlouf, did you have any luck with getting the flows?
Not yet. The project I needed it for has been delayed for several months. Not
sure when I will be come back to it.
|
That's a pity. I have no idea about Cython, otherwise I would gladly help in the development. |
The C++ code can output the flows if you pass a parameter, but there is On Fri, 3 Jun 2016, 13:14 Walter Acevedo, notifications@github.com wrote:
|
@walteracevedo, I can't do much on this at the moment, but this may be useful in getting started: The interface to the underlying C++ implementation is described here. We would need to provide a pointer to an array that “has enough space and is initialized to zeros.” Such an array can be declared and initialized in Cython, i.e. in emd.pyx. I used a similar strategy in another one of my projects, on this line. There, I'm making a call to this function, supplying it with references to the first elements of the various Int32Wrappers, which it then fills with data. Note that the EMD code requires a pointer, rather than a reference, but you can probably adapt the above approach to work that way. |
Hey again, I just got from my boss a bit of time to work on getting the flows via pyemd :D One question: Could that be a problem? |
Yes, it may be a problem—it's written assuming Python 3. There are no plans to implement Python 2 support at present, since the wrapper was developed to be used as a dependency of another project, PyPhi, which is a Python 3 library. However, if you need Python 2.7 support, it shouldn't be too difficult to develop a fork that's compatible, since there's not that much code. Also, this shouldn't affect the strategy for getting the flows. |
@walteracevedo, just FYI, I recently tried installing |
I finally found a way to get the flows. I am now working on finding a way to get both flows and emd value while not breaking the current api. Will add a PR when I'm done. |
That's very good to hear! In any case in the meantime I came up with another solution. I took an interface to C/Fortran that I have developed before and added an extra layer of ctypes code. It was a rather ad-hoc solution but so far it has worked well for me. In case anyone is interested the code can be found here https://github.com/walteracevedo/fastEMD_python_fortran_wrapper |
Great! I'll try your solution at some point. I have issues with my implementation; I developed it over an old fork of pyemd, it worked well, and now it won't compile (see PR #14)... Any help on the PR appreciated! |
Solved by PR #15 |
@walteracevedo, @gojomo, thanks to @rlouf's efforts the flow can now be obtained in the latest version (v0.4.0): from pyemd import emd_with_flow
emd, flow = emd_with_flow(first_signature, second_signature, distance_matrix) Enjoy! |
Thanks for the wrapper, it has been very useful to me! For my application, I would like to get the flows as well, and I was wondering whether it would be possible?
I read over the original C++ code, and if I understood well you can pass a pointer to a
std::vector<std::vector<NUM_T>>
initialised with 0, and it will modify the container in place, giving you the flows. Am I right?I am a complete beginners with Cython. Would you have any pointer to some useful tutorials (besides the doc) to get me started? Since python functions do not modify objects in place, I am a bit confused.
I'll see what I can do, and file a PR once/if I ever managed to include this function!
The text was updated successfully, but these errors were encountered: