numericalEFT / GreenFunc.jl

Toolbox to study quantum many-body problem at the treelevel
https://numericaleft.github.io/GreenFunc.jl/
MIT License
11 stars 1 forks source link

SparseMeshArray #60

Open kunyuan opened 1 year ago

kunyuan commented 1 year ago

Implement SparseMeshArray, which generalizes BlockGf in Triqs. Example from https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array

julia> struct SparseArray{T,N} <: AbstractArray{T,N}
           data::Dict{NTuple{N,Int}, T}
           dims::NTuple{N,Int}
       end

julia> SparseArray(::Type{T}, dims::Int...) where {T} = SparseArray(T, dims);

julia> SparseArray(::Type{T}, dims::NTuple{N,Int}) where {T,N} = SparseArray{T,N}(Dict{NTuple{N,Int}, T}(), dims);

julia> Base.size(A::SparseArray) = A.dims

julia> Base.similar(A::SparseArray, ::Type{T}, dims::Dims) where {T} = SparseArray(T, dims)

julia> Base.getindex(A::SparseArray{T,N}, I::Vararg{Int,N}) where {T,N} = get(A.data, I, zero(T))

julia> Base.setindex!(A::SparseArray{T,N}, v, I::Vararg{Int,N}) where {T,N} = (A.data[I] = v)
kunyuan commented 1 year ago

Some example: https://github.com/KristofferC/BlockSparseMatrices.jl