Efficient Mojo Tensor To Numpy Array Conversion
Hello,
I am attempting to convert a Mojo Tensor to a Numpy array without looping or at least with sub-polynomial time.
My approach is to get the pointer to the Tensor and use Python's ctypes.from_address()
But it doesn't work - the output np_array is not the same as the tensor...maybe Tensor has some header bytes? Or the pointer does not point to a contiguous memory block?
I would like to understand the issue with this code and get some inputs on how to achieve fast conversions for potentially large Mojo Tensors.
Here is the code:
Thank you.
I am attempting to convert a Mojo Tensor to a Numpy array without looping or at least with sub-polynomial time.
My approach is to get the pointer to the Tensor and use Python's ctypes.from_address()
But it doesn't work - the output np_array is not the same as the tensor...maybe Tensor has some header bytes? Or the pointer does not point to a contiguous memory block?
I would like to understand the issue with this code and get some inputs on how to achieve fast conversions for potentially large Mojo Tensors.
Here is the code:
Thank you.
