Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,20 @@
end
end
end

using LinearAlgebra: Diagonal
@interface ::AbstractArrayInterface storedvalues(D::Diagonal) = LinearAlgebra.diag(D)
@interface ::AbstractArrayInterface eachstoredindex(D::Diagonal) =

Check warning on line 167 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L166-L167

Added lines #L166 - L167 were not covered by tests
LinearAlgebra.diagind(D, IndexCartesian())
@interface ::AbstractArrayInterface isstored(D::Diagonal, i::Int, j::Int) =

Check warning on line 169 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L169

Added line #L169 was not covered by tests
i == j && Base.checkbounds(Bool, D, i, j)
@interface ::AbstractArrayInterface function getstoredindex(D::Diagonal, i::Int, j::Int)
return D.diag[i]

Check warning on line 172 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L171-L172

Added lines #L171 - L172 were not covered by tests
end
@interface ::AbstractArrayInterface function getunstoredindex(D::Diagonal, i::Int, j::Int)
return zero(eltype(D))

Check warning on line 175 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L174-L175

Added lines #L174 - L175 were not covered by tests
end
@interface ::AbstractArrayInterface function setstoredindex!(D::Diagonal, v, i::Int, j::Int)
D.diag[i] = v
return D

Check warning on line 179 in src/wrappers.jl

View check run for this annotation

Codecov / codecov/patch

src/wrappers.jl#L177-L179

Added lines #L177 - L179 were not covered by tests
end
25 changes: 25 additions & 0 deletions test/basics/test_diagonal.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using LinearAlgebra: Diagonal, diagind
using SparseArraysBase:
eachstoredindex,
getstoredindex,
getunstoredindex,
setstoredindex!,
isstored,
storedlength,
storedpairs,
storedvalues

using Test: @test, @testset

elts = (Float32, Float64, Complex{Float32}, Complex{Float64})

@testset "Diagonal{$T}" for T in elts
L = 4
D = Diagonal(rand(T, 4))
@test storedlength(D) == 4
@test eachstoredindex(D) == diagind(D, IndexCartesian())
@test isstored(D, 2, 2)
@test getstoredindex(D, 2, 2) == D[2, 2]
@test !isstored(D, 2, 1)
@test getunstoredindex(D, 2, 2) == zero(T)
end
Loading