diff --git a/Project.toml b/Project.toml index ab15cdb..191b7cb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" authors = ["ITensor developers and contributors"] -version = "0.7.5" +version = "0.7.6" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" diff --git a/test/test_dense.jl b/test/test_dense.jl index 6211cb5..3acc147 100644 --- a/test/test_dense.jl +++ b/test/test_dense.jl @@ -6,36 +6,36 @@ using Test: @test, @testset elts = (Float32, ComplexF64) arrayts = (Array, JLArray) @testset "dense (arraytype=$arrayt, eltype=$elt)" for arrayt in arrayts, elt in elts - dev(x) = adapt(arrayt, x) + dev(x) = adapt(arrayt, x) - @testset "SparseArrayDOK" begin - s = sparsezeros(elt, 3, 4) - s[1, 2] = 2 - d = dense(s) - @test d isa Matrix{elt} - @test d == [0 2 0 0; 0 0 0 0; 0 0 0 0] - end - - @testset "Custom sparse array" begin - struct MySparseArrayDOK{T,N,S<:AbstractVector{T}} <: AbstractArray{T,N} - storedvalues::S - storedindices::Dict{CartesianIndex{N},Int} - size::NTuple{N,Int} - end - Base.size(a::MySparseArrayDOK) = a.size - function Base.getindex(a::MySparseArrayDOK{<:Any,N}, I::Vararg{Int,N}) where {N} - storageindex = get(a.storedindices, CartesianIndex(I), nothing) - isnothing(storageindex) && return zero(eltype(a)) - return a.storedvalues[storageindex] + @testset "SparseArrayDOK" begin + s = sparsezeros(elt, 3, 4) + s[1, 2] = 2 + d = dense(s) + @test d isa Matrix{elt} + @test d == [0 2 0 0; 0 0 0 0; 0 0 0 0] end - Base.parent(a::MySparseArrayDOK) = a.storedvalues - s = MySparseArrayDOK( - dev(elt[2, 4]), Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4) - ) - d = dense(s) - @show typeof(d) - @test d isa arrayt{elt,2} - @test d == dev(elt[0 2 0 0; 0 0 0 0; 0 0 0 4]) - end + @testset "Custom sparse array" begin + struct MySparseArrayDOK{T, N, S <: AbstractVector{T}} <: AbstractArray{T, N} + storedvalues::S + storedindices::Dict{CartesianIndex{N}, Int} + size::NTuple{N, Int} + end + Base.size(a::MySparseArrayDOK) = a.size + function Base.getindex(a::MySparseArrayDOK{<:Any, N}, I::Vararg{Int, N}) where {N} + storageindex = get(a.storedindices, CartesianIndex(I), nothing) + isnothing(storageindex) && return zero(eltype(a)) + return a.storedvalues[storageindex] + end + Base.parent(a::MySparseArrayDOK) = a.storedvalues + + s = MySparseArrayDOK( + dev(elt[2, 4]), Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4) + ) + d = dense(s) + @show typeof(d) + @test d isa arrayt{elt, 2} + @test d == dev(elt[0 2 0 0; 0 0 0 0; 0 0 0 4]) + end end