Skip to content

Commit 0b1587c

Browse files
authored
Add an IndexStyle example to the diagind docstring (#53757)
Also, simplifies the docstring by splitting the usage into two lines.
1 parent 912460b commit 0b1587c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

stdlib/LinearAlgebra/src/dense.jl

+11-2
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,16 @@ function diagind(::IndexCartesian, m::Integer, n::Integer, k::Integer=0)
216216
end
217217

218218
"""
219-
diagind(M::AbstractMatrix, [k::Integer=0,] indstyle::IndexStyle = IndexLinear())
219+
diagind(M::AbstractMatrix, k::Integer = 0, indstyle::IndexStyle = IndexLinear())
220+
diagind(M::AbstractMatrix, indstyle::IndexStyle = IndexLinear())
220221
221222
An `AbstractRange` giving the indices of the `k`th diagonal of the matrix `M`.
222223
Optionally, an index style may be specified which determines the type of the range returned.
223224
If `indstyle isa IndexLinear` (default), this returns an `AbstractRange{Integer}`.
224225
On the other hand, if `indstyle isa IndexCartesian`, this returns an `AbstractRange{CartesianIndex{2}}`.
225226
227+
If `k` is not provided, it is assumed to be `0` (corresponding to the main diagonal).
228+
226229
See also: [`diag`](@ref), [`diagm`](@ref), [`Diagonal`](@ref).
227230
228231
# Examples
@@ -233,9 +236,15 @@ julia> A = [1 2 3; 4 5 6; 7 8 9]
233236
4 5 6
234237
7 8 9
235238
236-
julia> diagind(A,-1)
239+
julia> diagind(A, -1)
237240
2:4:6
241+
242+
julia> diagind(A, IndexCartesian())
243+
StepRangeLen(CartesianIndex(1, 1), CartesianIndex(1, 1), 3)
238244
```
245+
246+
!!! compat "Julia 1.11"
247+
Specifying an `IndexStyle` requires at least Julia 1.11.
239248
"""
240249
function diagind(A::AbstractMatrix, k::Integer=0, indexstyle::IndexStyle = IndexLinear())
241250
require_one_based_indexing(A)

0 commit comments

Comments
 (0)