Skip to content

Commit 2d4d65e

Browse files
Automatic Runic.jl run (#73)
Co-authored-by: mtfishman <[email protected]>
1 parent 38fdcd9 commit 2d4d65e

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseArraysBase"
22
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.7.5"
4+
version = "0.7.6"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

test/test_dense.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ using Test: @test, @testset
66
elts = (Float32, ComplexF64)
77
arrayts = (Array, JLArray)
88
@testset "dense (arraytype=$arrayt, eltype=$elt)" for arrayt in arrayts, elt in elts
9-
dev(x) = adapt(arrayt, x)
9+
dev(x) = adapt(arrayt, x)
1010

11-
@testset "SparseArrayDOK" begin
12-
s = sparsezeros(elt, 3, 4)
13-
s[1, 2] = 2
14-
d = dense(s)
15-
@test d isa Matrix{elt}
16-
@test d == [0 2 0 0; 0 0 0 0; 0 0 0 0]
17-
end
18-
19-
@testset "Custom sparse array" begin
20-
struct MySparseArrayDOK{T,N,S<:AbstractVector{T}} <: AbstractArray{T,N}
21-
storedvalues::S
22-
storedindices::Dict{CartesianIndex{N},Int}
23-
size::NTuple{N,Int}
24-
end
25-
Base.size(a::MySparseArrayDOK) = a.size
26-
function Base.getindex(a::MySparseArrayDOK{<:Any,N}, I::Vararg{Int,N}) where {N}
27-
storageindex = get(a.storedindices, CartesianIndex(I), nothing)
28-
isnothing(storageindex) && return zero(eltype(a))
29-
return a.storedvalues[storageindex]
11+
@testset "SparseArrayDOK" begin
12+
s = sparsezeros(elt, 3, 4)
13+
s[1, 2] = 2
14+
d = dense(s)
15+
@test d isa Matrix{elt}
16+
@test d == [0 2 0 0; 0 0 0 0; 0 0 0 0]
3017
end
31-
Base.parent(a::MySparseArrayDOK) = a.storedvalues
3218

33-
s = MySparseArrayDOK(
34-
dev(elt[2, 4]), Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4)
35-
)
36-
d = dense(s)
37-
@show typeof(d)
38-
@test d isa arrayt{elt,2}
39-
@test d == dev(elt[0 2 0 0; 0 0 0 0; 0 0 0 4])
40-
end
19+
@testset "Custom sparse array" begin
20+
struct MySparseArrayDOK{T, N, S <: AbstractVector{T}} <: AbstractArray{T, N}
21+
storedvalues::S
22+
storedindices::Dict{CartesianIndex{N}, Int}
23+
size::NTuple{N, Int}
24+
end
25+
Base.size(a::MySparseArrayDOK) = a.size
26+
function Base.getindex(a::MySparseArrayDOK{<:Any, N}, I::Vararg{Int, N}) where {N}
27+
storageindex = get(a.storedindices, CartesianIndex(I), nothing)
28+
isnothing(storageindex) && return zero(eltype(a))
29+
return a.storedvalues[storageindex]
30+
end
31+
Base.parent(a::MySparseArrayDOK) = a.storedvalues
32+
33+
s = MySparseArrayDOK(
34+
dev(elt[2, 4]), Dict([CartesianIndex(1, 2) => 1, CartesianIndex(3, 4) => 2]), (3, 4)
35+
)
36+
d = dense(s)
37+
@show typeof(d)
38+
@test d isa arrayt{elt, 2}
39+
@test d == dev(elt[0 2 0 0; 0 0 0 0; 0 0 0 4])
40+
end
4141
end

0 commit comments

Comments
 (0)