M
Modular6mo ago
Cdjones

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)
---------------------
Benchmark Report (s)
---------------------
Mean: 0.25936431399999998
Total: 2.0749145119999999
Iters: 8
Warmup Mean: 0.27413139349999999
Warmup Total: 0.54826278699999997
Warmup Iters: 2
Fastest Mean: 0.25936431399999998
Slowest Mean: 0.25936431399999998
---------------------
Benchmark Report (s)
---------------------
Mean: 0.25936431399999998
Total: 2.0749145119999999
Iters: 8
Warmup Mean: 0.27413139349999999
Warmup Total: 0.54826278699999997
Warmup Iters: 2
Fastest Mean: 0.25936431399999998
Slowest Mean: 0.25936431399999998
GitHub
Tensor-Transpose/transpose.mojo at main · mehta302/Tensor-Transpose
Contribute to mehta302/Tensor-Transpose development by creating an account on GitHub.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server