Matrix.diag

Makes a diagonal matrix from a vector.

struct Matrix(T, ubyte R, ubyte C = R, MatrixOrder O = CurrentMatrixOrder)
static pure nothrow @safe @nogc
static if(O == MatrixOrder.RowMajor)
static if(isSquare && R > 2)
diag
(
Vector!(T, R) v
)
if (
R >= 2 &&
R <= 4
&&
C >= 2
&&
C <= 4
)

Examples

auto v1 = Vector!(int, 3)(4, 5, -1);
auto m1 = Matrix!(int, 3).diag(v1);
assert (m1.v == [4, 0, 0, /**/ 0, 5, 0, /**/ 0, 0, -1]);

Meta