The Setup :
I have two arrays from shared memory reals and imags :
#/usr/bin/env python2
reals = multiprocessing.RawArray('d', 10000000)
imags = multiprocessing.RawArray('d', 10000000)
then I make them numpy-arrays, named reals2 and imags2, without any copy :
import numpy as np
reals2 = np.frombuffer(reals)
imags2 = np.frombuffer(imags)
# check if the objects did a copy
assert reals2.flags['OWNDATA'] is False
assert imags2.flags['OWNDATA'] is False
I would like to then make a np.complex128 1D-array data, again without copying the data, but I don't know how to.
The Questions :
Can you make a np.complex128 1D-array data from a pair of float arrays, without copying, yes/no?
If yes, how?
Short answer: no. But if you control the sender then there is a solution that does not require copying.
Longer answer:
numpycomplex array from two separate arrays without copying the datanumpycompiled c code assumes interleaved real, imag dataif you control the sender, you can get your data without any copy operations. here's how!
hat tip to: https://stackoverflow.com/a/32877245/52074 as a great starting point.
here's how to do the same processing but with multiple processes being started and getting the data back from each process and verifying the returned data