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

Proposal: sparse overlay #13

Open
putianyi889 opened this issue Mar 2, 2024 · 0 comments
Open

Proposal: sparse overlay #13

putianyi889 opened this issue Mar 2, 2024 · 0 comments

Comments

@putianyi889
Copy link

putianyi889 commented Mar 2, 2024

Motivation: JuliaSparse/SparseArrays.jl#512

Solution (just a brief sketch):

struct SparseOverlay{T,N,D<:AbstractArray{T,N}} <: AbstractArray{T,N}
    data::Dict{CartesianIndex{N},T}
    base::D
end
const SparseArray{T,N} = SparseOverlay{T,N,FillArrays.Zeros{T,N}}

@inline function Base.getindex(a::SparseOverlay{T,N}, I::CartesianIndex{N}) where {T,N}
    @boundscheck checkbounds(a, I)
    return get(a.data, I, a.base[I])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant