Skip to content

Commit

Permalink
Add an IndexStyle example to the diagind docstring (#53757)
Browse files Browse the repository at this point in the history
Also, simplifies the docstring by splitting the usage into two lines.

(cherry picked from commit 0b1587c)
  • Loading branch information
jishnub authored and KristofferC committed Mar 20, 2024
1 parent 7580c4f commit 9b14cc4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,16 @@ function diagind(::IndexCartesian, m::Integer, n::Integer, k::Integer=0)
end

"""
diagind(M::AbstractMatrix, [k::Integer=0,] indstyle::IndexStyle = IndexLinear())
diagind(M::AbstractMatrix, k::Integer = 0, indstyle::IndexStyle = IndexLinear())
diagind(M::AbstractMatrix, indstyle::IndexStyle = IndexLinear())
An `AbstractRange` giving the indices of the `k`th diagonal of the matrix `M`.
Optionally, an index style may be specified which determines the type of the range returned.
If `indstyle isa IndexLinear` (default), this returns an `AbstractRange{Integer}`.
On the other hand, if `indstyle isa IndexCartesian`, this returns an `AbstractRange{CartesianIndex{2}}`.
If `k` is not provided, it is assumed to be `0` (corresponding to the main diagonal).
See also: [`diag`](@ref), [`diagm`](@ref), [`Diagonal`](@ref).
# Examples
Expand All @@ -233,9 +236,15 @@ julia> A = [1 2 3; 4 5 6; 7 8 9]
4 5 6
7 8 9
julia> diagind(A,-1)
julia> diagind(A, -1)
2:4:6
julia> diagind(A, IndexCartesian())
StepRangeLen(CartesianIndex(1, 1), CartesianIndex(1, 1), 3)
```
!!! compat "Julia 1.11"
Specifying an `IndexStyle` requires at least Julia 1.11.
"""
function diagind(A::AbstractMatrix, k::Integer=0, indexstyle::IndexStyle = IndexLinear())
require_one_based_indexing(A)
Expand Down

0 comments on commit 9b14cc4

Please sign in to comment.