import mir.ndslice.allocation: slice; auto sli = slice!int(4, 3); auto idx = slice!(size_t[2])(3); idx[] = [ cast(size_t[2])[0, 2], cast(size_t[2])[3, 1], cast(size_t[2])[2, 0]]; // equivalent to: // import mir.ndslice.topology: indexed; // sli.indexed(indx)[] = 1; sli[idx] = 1; assert(sli == [ [0, 0, 1], [0, 0, 0], [1, 0, 0], [0, 1, 0], ]); foreach (row; sli[[1, 3].sliced]) row[] += 2; assert(sli == [ [0, 0, 1], [2, 2, 2], // <-- += 2 [1, 0, 0], [2, 3, 2], // <-- += 2 ]);
import mir.ndslice.topology: iota; import mir.ndslice.allocation: slice; auto sli = slice!int(5, 6); // equivalent to // import mir.ndslice.topology: indexed, cartesian; // auto a = [0, sli.length!0 / 2, sli.length!0 - 1].sliced; // auto b = [0, sli.length!1 / 2, sli.length!1 - 1].sliced; // auto c = cartesian(a, b); // auto minor = sli.indexed(c); auto minor = sli[[0, $ / 2, $ - 1].sliced, [0, $ / 2, $ - 1].sliced]; minor[] = iota!int([3, 3], 1); assert(sli == [ // ↓ ↓ ↓︎ [1, 0, 0, 2, 0, 3], // <--- [0, 0, 0, 0, 0, 0], [4, 0, 0, 5, 0, 6], // <--- [0, 0, 0, 0, 0, 0], [7, 0, 0, 8, 0, 9], // <--- ]);
$(BOLD Indexed slice.)