Skip to content

Commit

Permalink
Preserve axes in Diagonal
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jul 11, 2023
1 parent 2d4d096 commit 8caf51b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ end
r
end

function axes(D::Diagonal)
ax = axes(D.diag,1)
(ax, ax)
end

@inline function Base.isstored(D::Diagonal, i::Int, j::Int)
@boundscheck checkbounds(D, i, j)
if i == j
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ Random.seed!(1)
end
end

@testset "axes" begin
v = OffsetArray(1:3)
D = Diagonal(v)
@test axes(D) isa NTuple{2,typeof(axes(v,1))}
end

@testset "rdiv! (#40887)" begin
@test rdiv!(Matrix(Diagonal([2.0, 3.0])), Diagonal(2:3)) == Diagonal([1.0, 1.0])
@test rdiv!(fill(3.0, 3, 3), 3.0I(3)) == ones(3,3)
Expand Down

0 comments on commit 8caf51b

Please sign in to comment.