Hello.
Thanks for your reply. Now, I have an issue with struct.unpack in Cython. The general scenario is I have a very large binary dataset and need to break them into small chunks through multiprocessing and do some calculations. The program works fine in Python but I have an issue with unpack function in Cython:
This is the Python version:
fid = open(rawfile, 'rb')
fid.seek(0, os.SEEK_END)
nFileLen = fid.tell()
fid.seek(0, 0).
............
with Pool(max_number_of_process, maxtasksperchild=1) as pool:
for i in tqdm.tqdm(range(0, Nt)):
nLenVals_i = round(chunk_size / 4)
# On each step we load a new chunk of the file and pass it to a new process.
nVals_i = struct.unpack('I' * nLenVals_i, fid.read(chunk_size))
.....
and, this is my code in Cython:
ff = rawfile.encode('utf-8')
cdef float *buf
fid = fopen(ff, 'rb')
if (fid == NULL):
return
else:
fseek(fid, 0, SEEK_END)
nFileLen = ftell(fid)
fseek(fid, 0, SEEK_SET)
...........
with Pool(max_number_of_process, maxtasksperchild=1) as pool:
for i in tqdm.tqdm(range(0, Nt)):
nLenVals_i = round(chunk_size / 4)
buf = malloc(10 * sizeof(float))
result = fread(buf, sizeof(float), chunk_size, fid)
nVals_i = struct.unpack('I' * nLenVals_i, buf) .
...
free(buf)
I get this error: "Cannot convert 'float *' to Python object".
Thanks for any suggestions.
Best,
Amir