diag

Extract the diagonal of a 2-dimensional slice.

  1. auto diag(S s, size_t k)
    template diag(size_t dimension = 1)
    pure
    diag
    (
    S
    )
    (
    S s
    ,
    size_t k = 0
    )
    if (
    isMatrix!S
    )
  2. auto diag(S s)

Members

Functions

diag
auto diag(S s, size_t k)
Undocumented in source. Be warned that the author may not have intended to support it.

Parameters

dimension

dimension to apply the offset, k (default = 1)

s

2-dimensional slice

k

offset from the main diagonal, k > 0 for diagonals above the main diagonal, and k < 0 for diagonals below the main diagonal

Return Value

the extracted diagonal slice

Examples

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);

Meta