4

I am considering porting scientific code from Python to Jython and I am interested, whether there exist math libraries for Jython, which are:

  1. free for commercial use
  2. have convenient matrix syntax designed for Jython - i.e. permit slicing, binary and integer indexing, +-*/ operations like matlab and numpy.

Additional availability of machine learning and statistical routes would be a plus (or easy convertibility of data to some common data format, understood by major Java machine learning libraries).

Thanks in advance for any information about such libraries.

Apogentus
  • 6,371
  • 6
  • 32
  • 33

1 Answers1

5

I took on the role of maintaining such a package a while back. It's called jnumeric (available on github and installable via maven).

JNumeric kind of has a weird history though, dating back to the early 2000s. It's never really been functionally equivalent to NumPy (or even numeric, which is what it's actually trying to emulate), and while it was "good enough" for what we were using it for, to use it as the primary number-cruncher in a Java program is probably not a good idea. It was a bad enough idea that we rewrote our application from scratch in Python so that we could use NumPy instead of trying to do vector math in Java. For that reason, jnumeric is undermaintained, and should probably silently fade into non-existence.

I recently noticed a new project pop up on Github, Numpy4J, which may have a brighter future.

While I know it doesn't quite address your question, I am curious why you would want to move to Jython for scientific code. Java does not have the nice number crunching and plotting libraries that Python has. ML libraries like Weka have Python equivalents in scikit-learn. Imaging stuff like ImageJ has an equivalent in scikit-image. Statistical packages exist in pandas and statsmodels. What is your scientific itch that Python does not scratch?

If you want to move to Jython in order to interface with an existing Java library that cannot be easily ported to Python, I would consider JPype rather than Jython.

tbekolay
  • 17,201
  • 3
  • 40
  • 38
  • I need to make multiple arithmetic calculations on matrices as fast as possible. Firstly, I got to know that multithreading in Python cannot utilize all CPU's because of GIL limitation and multiprocessing might not solve the problem, because I will need to pass extremly large matrix to each process which may undermine parallelization (I try workarounds - not yet successfully: http://stackoverflow.com/questions/18831525/building-python-modules-failure). Jython, as I heard, does not have this issue. – Apogentus Sep 17 '13 at 08:40
  • Secondly, refactoring critical parts of code from Jython to Jave seems promising for efficiency reasons. However, I'm not sure that Java performs matrix calculations faster than Numpy. – Apogentus Sep 17 '13 at 08:45
  • The GIL is for sure an issue, this is true. And it definitely depends on your particular problem, but I don't believe that Java/Jython has proven itself to be a good solution to the kind of problem you're facing. Working on Windows makes things quite a bit more difficult, but I think your best bet is the numeric [Python compilers](https://github.com/IgnitionProject/ignition/wiki/CodeGenComposability_Scipy2013#projects-represented). Alternatively, consider writing your own multithreaded C code for critical sections (or see [Cython](http://cython.org/)). – tbekolay Sep 17 '13 at 13:07