Open
Description
I'm trying to rewrite simple console python\numpy app to Qt app with UI, and xtensor seems to be the right choice to replace numpy. However, I'm unable to understand how to replace some parts of python-numpy with it.
Here is full code I'm trying to rewrite: https://pastebin.com/BUYZwCsn
And here is first section that stopped me:
image: : ndarray[uint16]
...
r1 = image[::2].reshape((-1))
r2 = image[1::2].reshape((-1))
channels = np.empty((4, image.size // 4), dtype = uint16)
channels[0] = r1[0::2]
channels[1] = r1[1::2]
channels[2] = r2[0::2]
channels[3] = r2[1::2]
It transformed to
...
auto activeAreaImageR1 = xt::view(activeAreaImage, xt::all(), 2);
xt::reshape_view(activeAreaImageR1, { -1 });
xt::xarray<uint16_t> activeAreaImageR2 = xt::view(activeAreaImage, xt::range(1, 2));
xt::reshape_view(activeAreaImageR2, { -1 });
auto channels = xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 });
... and what's next? How to implement assigning channels[0] = ...
?
Another question is: how can I pass\return xtensor arrays to\from functions? I.e. how to implement something like this without overhead?
def getActiveAreaPixels(image: ndarray[uint16], height: int, width: int, activeArea: [int]) -> ndarray[uint16]:
return image.reshape(height, width)[activeArea[0]:activeArea[2], activeArea[1]:activeArea[3]]
Thank you in advance.
BTW, maybe there is discord or any other chat for such questions? I believe creating issues is not the best way..