I'm trying to do numpy
view-casting (which I believe in C/C++
land would be called reinterpret-casting) in pythran:
The following silly made-up example takes an array of unsigned 8-byte integers, reinterprets them as twice as many unsigned 4-byte integers, slices off the first and last (this also does not touch the actual data; it only changes the "base pointer") and reinterprets as unsigned 8-byte again, the total effect being a frame shift. (We'll worry about endianness some other time.)
import numpy as np
A = np.arange(5,dtype="u8")
a = A.view("u4")
B = a[1:9].view("u8")
A
# array([0, 1, 2, 3, 4], dtype=uint64)
B
# array([ 4294967296, 8589934592, 12884901888, 17179869184], dtype=uint64)
np.shares_memory(A,B)
# True
I cannot have pythran translate this directly because it doesn't know the .view
attribute.
Is there a way to reinterpret cast arrays in pythran?