new view of a slice with the same data
import std.string : split; import mir.ndslice.topology : universal, iota; import mir.ndslice.allocation : slice; import mir.ndslice.dynamic : transposed; assert(iota(3, 4).slice.view(-1, 1).shape == [12, 1]); assert(iota(3, 4).slice.universal.transposed.view(-1, 6).shape == [2, 6]);
Invalid views generate ReshapeError
import std.string : split; import mir.ndslice.topology : iota; import mir.ndslice.allocation : slice; try { iota(3, 4).slice.view(2, 1); } catch (Exception e) { assert(e.msg.split(":")[0] == "ReshapeError"); } try { iota(0).slice.view(2, 1); } catch (Exception e) { assert(e.msg.split(":")[0] == "ReshapeError"); }
Returns a new view of a slice with the same data, but reshaped to have shape equal to lengths.