Does anybody know how to convert a 1D array to a std::vector in the most optimal way? #773
-
I know we can do this?
But I am wondering if anybody has had any success doing something faster? Maybe with the array data method? I want to essentially want to extract all non-zero elements from the array and this is an intermediate step to do it |
Beta Was this translation helpful? Give feedback.
Answered by
angeloskath
Mar 3, 2024
Replies: 1 comment 1 reply
-
This is all about memory management. Since the vector manages its own memory then we can't just create a normal vector from an MLX array. If you just want to access the underlying elements though then it is as simple as auto data = snake.data<int>();
for (int el = 0; el < snake.size(); el++) {
// you can use elem_to_loc here or just el depending
// on whether the data is contiguous or not
//
// do something with data[el]
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cemlyn007
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is all about memory management. Since the vector manages its own memory then we can't just create a normal vector from an MLX array. If you just want to access the underlying elements though then it is as simple as