Skip to content

Commit 2c5406b

Browse files
authored
Simplify the docstring for Diagonal (#51097)
1 parent 0ba5dc5 commit 2c5406b

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/diagonal.jl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ julia> I(2)
5353
⋅ 1
5454
```
5555
56-
Note that a one-column matrix is not treated like a vector, but instead calls the
57-
method `Diagonal(A::AbstractMatrix)` which extracts 1-element `diag(A)`:
56+
!!! note
57+
A one-column matrix is not treated like a vector, but instead calls the
58+
method `Diagonal(A::AbstractMatrix)` which extracts 1-element `diag(A)`:
5859
5960
```jldoctest
6061
julia> A = transpose([7.0 13.0])
@@ -72,27 +73,31 @@ Diagonal(V::AbstractVector)
7273
"""
7374
Diagonal(A::AbstractMatrix)
7475
75-
Construct a matrix from the diagonal of `A`.
76+
Construct a matrix from the principal diagonal of `A`.
77+
The input matrix `A` may be rectangular, but the output will
78+
be square.
7679
7780
# Examples
7881
```jldoctest
79-
julia> A = permutedims(reshape(1:15, 5, 3))
80-
3×5 Matrix{Int64}:
81-
1 2 3 4 5
82-
6 7 8 9 10
83-
11 12 13 14 15
82+
julia> A = [1 2; 3 4]
83+
2×2 Matrix{Int64}:
84+
1 2
85+
3 4
86+
87+
julia> D = Diagonal(A)
88+
2×2 Diagonal{Int64, Vector{Int64}}:
89+
1 ⋅
90+
⋅ 4
91+
92+
julia> A = [1 2 3; 4 5 6]
93+
2×3 Matrix{Int64}:
94+
1 2 3
95+
4 5 6
8496
8597
julia> Diagonal(A)
86-
3×3 Diagonal{$Int, Vector{$Int}}:
87-
1 ⋅ ⋅
88-
⋅ 7 ⋅
89-
⋅ ⋅ 13
90-
91-
julia> diag(A, 2)
92-
3-element Vector{$Int}:
93-
3
94-
9
95-
15
98+
2×2 Diagonal{Int64, Vector{Int64}}:
99+
1 ⋅
100+
⋅ 5
96101
```
97102
"""
98103
Diagonal(A::AbstractMatrix) = Diagonal(diag(A))

0 commit comments

Comments
 (0)