-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Raw JNI arrays #144
Raw JNI arrays #144
Conversation
This is a very neat. As we build this out, let's make sure to build out tests to make sure that we are maintaining the old functionality while also demonstrating the new capabilities Also make sure to implement as much of the |
Hi @ahnlabb , what is the status of this PR? |
Hi @mkitti, this has been sitting on the shelf for a while partly because I've had to prioritize other things and partly to allow me (and anyone else) to think about the API. In its current state, it fulfills the basic AbstractArray interface. The arrays are static (I don't implement I've written some basic tests for the new functionality today but still not expanded on the old tests. Do you have any thoughts on the API or how to improve testing? I'm going to try using it in BioformatsLoader tomorrow to get a feel for the ergonomics. |
I looked through this and if possible, I would like to work through this in three phases:
|
Co-authored-by: João David <[email protected]>
Thank you @mkitti, this makes sense to me. I have created #149 for phases 1 and 2. I think proceeding with the JNIArrays without doing something like #149 risks convoluting the codebase and might hamper future development. However, I fully agree that it warrants its own extensive discussion and (like you say) a close inspection. I hope my arguments in #149 for the need for some kind of consolidation are convincing. |
Now that we have #149 merged, I think the Also, is there a reason it is called |
After the discussion in #134 I've experimented with approaches to exposing more of the JNI array functionality. Here is the draft for one such approach so that we can discuss whether this direction is of interest for JavaCall.
This would be a very lightweight approach to exposing the JNI array functionality where the user can choose to keep a returned array as a pointer and get and set elements directly through an
unsafe_wrap
array.There are also some parts of JProxies that point in this direction but they are less lightweight with a different interface from the rest of JavaCall. I couldn't get them to do exactly what I want. However, if you think the JProxies approach is a better direction I'd be glad to help to surface this functionality through documentation and/or changes to JProxies.
My own immediate use for this is in BioformatsLoader where it would allow me to use the pre-allocated versions of the reader and perform the reinterpretation and reshaping of the array simultaneously as the copy from java. In general, I believe it could expand what is possible without java adapters. @mkitti has already done a lot of work in this general direction and may have ideas for alternative approaches.
One alternative to this approach would be to only wrap the array ref without actually getting the elements. This would be simpler, safer, and even more lightweight. "Direct" access to the array from Julia is pretty convenient though.
Here is an example of how the proposed functionality can be used:
I'm sorry if the diff is a bit noisy, I tried to consolidate some things to make it easier for the "raw" arrays to plug in. In the process, I found that the "Attempt to call method on Java NULL" error is sometimes thrown as an
ErrorException
that should probably be fixed independent of whether this gets merged in some form.