-
Notifications
You must be signed in to change notification settings - Fork 150
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
ndarray conversion fails after updating jep, scipy, numpy #560
Comments
Could it be that Jep 4.2.0 was not built with numpy support? How to get a numpy supported version? |
That is likely the cause. Jep will automatically include numpy support if numpy is present when you build jep so you need to install numpy before jep. You can check if numpy support is enabled by doing something like |
Numpy support is not enabled (the above command prints 0), so that is the issue.
But my Java program still seems to show that I'm missing numpy support in jep. Edit: uninstalled everything, reinstalled Python 3.12.6, numpy 2.1.1 and tried building Jep. Building works, still no numpy support... I'm baffled... Edit: building with the --verbose option shows that numpy is not found... everything tells me it is there... what am I missing? |
How to get Jep to find numpy?
And then: Numpy config shows the paths: The include files are not in numpy\core\include, but in numpy_core\include\numpy. I tried with a lower version of numpy (1.26.4), which does put the include files in numpy\core\include, but jep is still not finding numpy... I'm at a complete loss... |
I managed to build using numpy 1.26.4, and using " python setup.py build" and "python setup.py install". For some reason, when ran from pip, the test for the installation of numpy fails. |
I close this issue as it is resolved for me. |
Reopening the issue as installing via python rather than pip will be deprecated, so the issue of building with numpy will be an issue. |
Thanks for sharing what you found. We had not tried building Jep with numpy 2 yet. @bsteffensmeier opened pull request #562 to get the build to properly detect numpy 2. |
No problem. I hope it helps. Weird thing is that with numpy 1.26.4 (with the include files in the expected locations), pip install . fails to detect numpy, but python setup.py build works. |
Hello,
I recently needed to update some packages (pdfo and then numpy and scipy) and also updated jep to version 4.2.0 (not sure what the previous version was, but it was at least a year old. Since then, I cannot seem to import ndarrays to java.
The line in Java that used to work was:
NDArray<double[]> resultVector = (NDArray<double[]>) jep.getValue("get_result_x()");
But now this throws a
Exception in thread "main" java.lang.ClassCastException: class [D cannot be cast to class jep.NDArray ([D is in module java.base of loader 'bootstrap'; jep.NDArray is in unnamed module of loader 'app') at ds.python.PythonSciPy.test(PythonSciPy.java:119) ...
The above get_result_x is a getter applied on a SciPy OptimimizeResult to return the x:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.OptimizeResult.html#scipy.optimize.OptimizeResult
Jep is a new SharedInterpreter().
No changes were made to the Java code, I just updated the above packages and changed the referenced jar file to use jep-4.2.0.jar. It worked just prior to these updates.
Can anyone help?
The text was updated successfully, but these errors were encountered: