Tensor Transposition
After looking through the mojo documentation for the standard library as well as external code repositories, I was unable to find functionality to transpose 2 specified dimensions of a Tensor struct, similar to what's available in libraries such as Pytorch and Numpy. I implemented my own basic function as a brute force approach that iterates through every index, switches the specified dimensions and stores it in a separate Tensor struct. Is there any better way to go about doing this?
I've been trying to look for a way to vectorize this process using SIMD as well as trying to find a way to directly mutate the tensor but can't think of any better approach. I've also tried searching for the source code that Numpy or Pytorch uses for these functions but couldn't seem to find it.
My Current Approach:
https://github.com/mehta302/Tensor-Transpose/blob/main/transpose.mojo
Benchmark:
(with 100x100x100 float32 randomized tensor switching first 2 dimensions)
GitHub
Tensor-Transpose/transpose.mojo at main · mehta302/Tensor-Transpose
Contribute to mehta302/Tensor-Transpose development by creating an account on GitHub.
0 Replies