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

Is it possible to get active python session when running jvm started from a python sesson #115

Open
ZJinQES opened this Issue Jun 29, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@ZJinQES

ZJinQES commented Jun 29, 2017

I know my question is a bit weird. not sure if that's possible.

We are running some python code as user interface, from there call java which is logic layer to operate database. We don't want to get data in JVM and copy it to python.
what we have done using R is from R call java, and pass r session (.jengine) to jvm, and using this engine the java can operate the active R session object directly, like pull data from db and write it to R matrix.
Do you think it's possible that we can do similar thing based on python-javabridge?

Thanks

@LeeKamentsky

This comment has been minimized.

Owner

LeeKamentsky commented Jun 30, 2017

There's a pretty efficient transfer between a Java array and a Numpy array. The low-level env.get_<boolean, byte, short... etc>_array_elements() calls do a memory copy between the Java array memory into a Python Numpy array. You can either use Javascript or manipulate Java objects via the JWrapper / JClassWrapper to run Java from Python. However, if you're looking to use Scipy or Scikits, you will probably have to copy your data. I have a feeling that R jengine's jarray function does the same and there is a memory copy from R to Java.

For Javabridge's use in CellProfiler, megabyte-size images are loaded in Java and then transferred over the Javabridge to be processed in Python. In my experience, the momentary duplication of memory and the time of transfer have been a small fraction of the overall processing time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment