Implementing a simple lookup matrix
I have a precomputed (=handwritten) simple matrix that I want to use in my code. I have currently written it as follows (without a type):
The envisioned example use of this would be something like this:
The original
conversion_matrices
becomes a ListLiteral
, which seems clearly unusable for this usecase given its lack of getitem implementation.
I believe using a StaticTuple
should probably work, but would require explicitly initializing the tuple for each nested tuple, explicitly listing the nested types repeatedly for every individual tuple. This is probably what I will fall back on if I find nothing else, but I wonder if there is a proper way to do this that doesn't lead to huge chunks of nested and repeated type definitions.
I don't have a lot of experience writing python code, so this might not even be a mojo specific question. In any case, I would be very thankful for a pointer in the right direction.4 Replies
if you are looking for pure efficiency, although it isn’t fun, you could hard code all of these in
you could also flatten this to a one dimensional list and just loop over row+col for index
otherwise you’d have to implement a custom struct, there are some examples you can find on github, and even some on the mojo docs specifically for matrices (see the example of matmul)
Congrats @benny, you just advanced to level 1!
Alright, I guess I'll do that, thank you. Just wanted to check if there was some "proper" way to do this that I was missing
Modular Docs - Matrix multiplication in Mojo
Learn how to leverage Mojo's various functions to write a high-performance matmul.