How to define nested dict function
(This is a shortened cross post of my stackoverflow question).
How do I define a function in Mojo where the argument or return value is a nested structure, like a dictionary. But where the exact structure is not known at compile time because, for example, it is read from disk.
For example, how do I type annotate
params
in the function neural_network
to represent a nested dict to keep the model parameters (i.e., a pytree).
Thanks so much!Stack Overflow
How to define a nested dictionary argument of arbitrary depth
How do I define a function in Mojo where the argument is a nested structure, like a dictionary. But where the exact structure is not known at compile time because, for example, it is read from disk...
3 Replies
Probably not the best way to do what you're looking for but see the 2 examples below. From example you have though, makes me wonder if you want to use a nested dict or just store each type in its own array.
Also if you are looking at parsing (or better more fleshed out code) I recommend checking out https://www.modular.com/modverse/modverse-42
specifically Pholmola's project
Modverse #42: Magic is the best way to build with MAX and Mojo
Welcome to Modverse #42, covering blogs, videos, tutorials, community projects, MAX, and Mojo!
Thanks for the pointers, that's a big help!