ninia / jep

Embed Python in Java
Other
1.31k stars 149 forks source link

NDArrays are now returned as java primitive arrays instead of jep.NDArray #453

Closed ptrxwsmitt closed 9 months ago

ptrxwsmitt commented 1 year ago

Describe the bug NDArrays are now returned as java primitive arrays instead of jep.NDArray We were upgrading from 4.0 to 4.1 via ubuntu package manager and recognized that we get a lot of casting errors, because interpreter.getValue("someNumpyNdArray") now returns e.g. double[] instead of NDArray<double[]>. Is that intended?

To Reproduce Java: var ndarray = (jep.NDArray<double[]>) interpreter.getValue("someNumpyFloat64NdArray") or: var ndarray = (jep.NDArray<double[]>) interpreter.getValue("someNumpyFloat64NdArray", jep.NDArray.class)

Expected behavior No implicit type conversions.

Environment (please complete the following information):

Additional context

bsteffensmeier commented 1 year ago

It sounds like your jep library was built without support for numpy. Numpy is an optional dependency for jep and if it is not present when the jep library is built then the native code needed to support that automatic conversion cannot be included. You can check if numpy is supported in your jep library by checking the value of jep.JEP_NUMPY_ENABLED in a jep interpreter:

$ jep 
>>> import jep
>>> jep.JEP_NUMPY_ENABLED
1
>>>

If that is your problem you should be able to solve it by reinstalling jep with numpy installed

bsteffensmeier commented 9 months ago

Closing due to inactivity