I'm using py4j to send a byte array (Array[Byte]) from Scala to python. On the python side I wish to create a numpy array (preferably immutable) that is just a view of these bytes but interpreted as np.complex128. Disregarding byte order, the bytes are ordered as follows: real1, imag1, real2, imag2, ...
.
According to py4j documentation for python 3.5 and py4j 0.10.3, it seems like I'm should get a bytes object on the python side but I'm actually getting a JavaArray which as I understand it has a reference back to the array on the jvm side which I think makes this pretty slow. I'm guessing this is due to Scala's "autoboxing" of byte to Byte (the class) but I'm not sure.
Py4j question: Is it possible to force py4j to return a copy of the bytes?
Scala question: Maybe my guess is wrong and it actually compiles down to primitive byte array in this case? If not, is it possible to make sure it does in anyway besides writing that part in Java instead.