Matrix.diag

Makes a diagonal matrix from a vector.

struct Matrix(T, ubyte R, ubyte C = R)
static
static if(isSquare && R > 2)
diag
(
Vector!(T, R) v
)
if (
R >= 2 &&
R <= 4
&&
C >= 2
&&
C <= 4
)

Examples

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

Meta