diag

Create a diagonal 2-dimensional slice from a 1-dimensional slice.

  1. template diag(size_t dimension = 1)
  2. auto diag(S s)
    pure
    diag
    (
    S
    )
    (
    S s
    )
    if (
    isVector!S
    )

Parameters

s S

1-dimensional slice

Return Value

Type: auto

diagonal 2-dimensional slice

Examples

import mir.ndslice.topology : iota;
import mir.ndslice.slice : sliced;

//  -------
// | 0 1 2 |
//  -------
auto a = iota(3).diag;
auto result = [[0, 0, 0],
               [0, 1, 0],
               [0, 0, 2]].sliced;
assert(a[0] == result[0]);
assert(a[1] == result[1]);
assert(a[2] == result[2]);

Meta