-
Notifications
You must be signed in to change notification settings - Fork 19
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
JSD() stack overflow with many rows #7
Comments
Dear @wkc1986, Thank you very much for finding this issue. I will have a look, it might be a problem with the internal Rcpp loop e.g. But I will keep you posted. Many thanks and kind regards, |
I'm seeing something that I suspect is related. I run |
Dear @elbamos Thank you very very much for making me aware of this. I am very sorry for the inconvenience it might have caused. Kind regards, |
No problem :) BTW - you know in C you can refer to a function by a pointer. If you did that with |
Dear all, as I predicted the issue was in the Rcpp functions The problem was that Rcpp doesn't allow efficiently passing functions as an argument of another function. You can find a detailed discussion here: https://stackoverflow.com/questions/27391472/passing-r-function-as-parameter-to-rcpp-function @elbamos: You are absolutely correct and I am aware that it is possible to define C functions as pointers. But when writing @wkc1986 When I now run your example code: m <- matrix(runif(1500 * 10), nrow = 1500)
dist_mat <- JSD(m)
str(dist_mat) I don't get a segfault anymore.
@elbamos Could you please let me know if your example also works now with the newest developer version of In the future, I will also add the option to run matrix computations in parallel (multicore computations) to further speed up the process. Thank you both once again very very much for making me aware of this issue and I hope that you won't have problems now. Kind regards, |
Confirm dev version working for my (actual) application. Thanks so much as always for your responsiveness @HajkD ! |
@HajkD I can take a look this weekend. I can also tell you that, to solve my issue, I cut-and-pasted the JS function and DistMatrixWithUnitMAT() into another file and took out the function pointer, and that solved it. (That was my guess about what was causing it.) Regarding function pointers, I actually wasn't referring to the passing of Rcpp functions, which always seemed like voodoo to me. I was referring to structures like this: https://github.com/HajkD/philentropy/blob/9ca1b4c503ae61ab223d892840a13adeb92cc414/src/distances.h#L1288, which could be made more maintainable and simpler, and probably considerably faster, by passing the relevant |
Hi @elbamos, This is a great suggestion. I would truly appreciate it if you could look into this and whatever makes it easier for me to maintain the code the happier I am of course :) Many thanks for helping me on this one! Cheers, |
Sorry I haven't had a chance to test the new code yet; I had extracted the relevant code into a separate file and I've been using that. In terms of using a function pointer:
Not fully tested, but you get the idea. |
Also, you can buy a performance improvement in the loops with:
|
The function pointer idea works even better if you do the if..then in the exported function and pass the function pointer as a parameter to all of your distance functions. Also you don't need to check that the columns are the same size each time the distance function is called -- they come from a matrix, so they have to be the same size. (Actually it would be better to map2 them using C++11, but that's another story.) |
Dear @elbamos, These are absolutely amazing suggestions!!! I will start working on incorporating your approaches and am more than happy for any further improvements :) Many many thanks, |
BTW - it shouldn't be terribly hard to get this working with OpenMP. I put an hour or two into it but kept getting seg faults and don't have the time to track them down. But its "embarassingly parallel", as they say. |
I'm trying to figure this out myself, but no luck yet.
The text was updated successfully, but these errors were encountered: