dimension to apply the offset, k (default = 1)
2-dimensional slice
offset from the main diagonal, k > 0 for diagonals above the main diagonal, and k < 0 for diagonals below the main diagonal
the extracted diagonal slice
import mir.ndslice.topology : iota; // ------- // | 0 1 2 | // | 3 4 5 | // ------- auto a = iota(2, 3); assert(a.diag == [0, 4]); assert(a.diag!1(1) == [1, 5]); assert(a.diag!0(1) == [3]);
import mir.ndslice : iota, map, alongDim; static immutable d33 = [[[1, 0, 0], [0, 2, 0], [0, 0, 3]], [[4, 0, 0], [0, 5, 0], [0, 0, 6]], [[7, 0, 0], [0, 8, 0], [0, 0, 9]]]; assert(iota([3, 3], 1).alongDim!(-1).map!diag == d33);
Extract the diagonal of a 2-dimensional slice.