Hi.
What is IndexList
meant to be?
Is it meant to be like Python’s list
type?
If so, why change the name?
Best regards.
Hi.
What is IndexList
meant to be?
Is it meant to be like Python’s list
type?
If so, why change the name?
Best regards.
Hi @monte, IndexList
is a type used by MAX. If you’re looking for a type like list
, just use List
.
As the docstring for the module says:
Implements
IndexList
which is commonly used to represent N-D indices.
To elaborate on this a bit more, say you have an array 20 elements long. You could index that with an integer between 0 and 19 inclusive. Say you have a two-dimensional array, 20x30. You can index that with two integers in the ranges [0, 19] and [0, 29]. Maybe you have a five-dimensional array. You’d need five integers to index that.
If you’re writing application code for a specific rank of multidimensional array, this is fine. But to write code that’s generic across ranks of multidimensional arrays, you’ll want to pack these into one value you can pass around. IndexList
does this. Think of it as a homogeneous tuple of integers used for indexing multidimensional arrays. For types that support IndexList
, this means you could use my_nd_arr[my_index_list]
instead of having to explicitly specify each dimension’s index as e.g. my_nd_arr[a, b, c]
.
As @sora says, we use this extensively in MAX, as ML applications often use multidimensional arrays heavily, but it’s not exclusive to MAX and you could use this in any other Mojo code interacting with multidimensional arrays as well.
Echoing @sora, if you’re looking for a type more like list
in Python, List
is the Mojo type you’d want.
Thank you for the detailed response.
It clears things up.
Much appreciated!
Thanks for the clarification!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.