From 14ac1f7c0dd77287d66e1c99905c29ddcbb419c3 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 22 Apr 2025 17:46:29 +0530 Subject: [PATCH 1/2] Add `diagm` example --- src/dense.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dense.jl b/src/dense.jl index 0656a24a..58a71480 100644 --- a/src/dense.jl +++ b/src/dense.jl @@ -399,6 +399,8 @@ Construct a matrix with elements of the vector as diagonal elements. By default, the matrix is square and its size is given by `length(v)`, but a non-square size `m`×`n` can be specified by passing `m,n` as the first arguments. +If the diagonal of the matrix contains more elements than `v`, +the trailing elements will be zeros. # Examples ```jldoctest @@ -407,6 +409,13 @@ julia> diagm([1,2,3]) 1 0 0 0 2 0 0 0 3 + +julia> diagm(4, 5, [1,2,3]) +4×5 Matrix{Int64}: + 1 0 0 0 0 + 0 2 0 0 0 + 0 0 3 0 0 + 0 0 0 0 0 ``` """ diagm(v::AbstractVector) = diagm(0 => v) From 537ee46e04a295b64db39645cfef974caf9ed4a9 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 22 Apr 2025 17:48:24 +0530 Subject: [PATCH 2/2] Zero padding --- src/dense.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dense.jl b/src/dense.jl index 58a71480..9e7eff4f 100644 --- a/src/dense.jl +++ b/src/dense.jl @@ -399,8 +399,7 @@ Construct a matrix with elements of the vector as diagonal elements. By default, the matrix is square and its size is given by `length(v)`, but a non-square size `m`×`n` can be specified by passing `m,n` as the first arguments. -If the diagonal of the matrix contains more elements than `v`, -the trailing elements will be zeros. +The diagonal will be zero-padded if necessary. # Examples ```jldoctest