Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an IndexStyle example to the diagind docstring #53757

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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