You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below is my solution for Advent Of Code 2020 Day 17. The problem involves running Conway's Game of Life in both 3 and 4 dimensions. I want to use slice_mut to create a mutable slice for Dimension D. The only way I could figure out how to do it was to convert the array to IxDyn using into_dimensionality, slice the array using a Vec I created, and then convert the array back to dimension D.
To solve a similar problem, I was able to call raw_dim on my existing array, and then iterate over it and modify it. My initial proposal would be to have a similar method (raw_slice?) that would return a SliceArg that I could then iterate over and modify in place.
I think the simplest way to implement the slicing in the example would be like this:
letmut v = x.view_mut();
field
.axes().for_each(|ax| v.slice_axis_inplace(ax.axis(),Slice::from(2..2 + ax.len())));
v.assign(field);
This doesn't require x to be dynamic-dimensional.
Usually, the simplest way to perform slicing in a function which is generic over dimensionality is to use the methods which slice individual axes, like .slice_axis_inplace() and .collapse_axis(). I've created #912 to improve the documentation in this area.
The code below is my solution for Advent Of Code 2020 Day 17. The problem involves running Conway's Game of Life in both 3 and 4 dimensions. I want to use slice_mut to create a mutable slice for Dimension D. The only way I could figure out how to do it was to convert the array to IxDyn using into_dimensionality, slice the array using a Vec I created, and then convert the array back to dimension D.
To solve a similar problem, I was able to call raw_dim on my existing array, and then iterate over it and modify it. My initial proposal would be to have a similar method (raw_slice?) that would return a SliceArg that I could then iterate over and modify in place.
https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=4a028d474bec27d8f32f938ece81b0e4
The text was updated successfully, but these errors were encountered: