Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.3.1"
version = "0.3.2"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
8 changes: 8 additions & 0 deletions src/abstractsparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ end
return error("Not implemented.")
end

@interface ::AbstractArrayInterface function isstored(a::SubArray, I::Int...)
return isstored(parent(a), Base.reindex(parentindices(a), I)...)
end

# TODO: Use `Base.to_indices`?
isstored(a::AbstractArray, I::CartesianIndex) = isstored(a, Tuple(I)...)
# TODO: Use `Base.to_indices`?
Expand Down Expand Up @@ -102,6 +106,10 @@ end
SparseArraysBase.storedvalues(::T)
end

@derive (T=SubArray,) begin
SparseArraysBase.isstored(::T, ::Int...)
end

# TODO: Add `ndims` type parameter, like `Base.Broadcast.AbstractArrayStyle`.
# TODO: This isn't used to define interface functions right now.
# Currently, `@interface` expects an instance, probably it should take a
Expand Down
11 changes: 10 additions & 1 deletion test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using SparseArraysBase:
storedlength,
storedpairs,
storedvalues
using Test: @test, @testset
using Test: @test, @test_throws, @testset

elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
arrayts = (Array, JLArray)
Expand Down Expand Up @@ -43,6 +43,15 @@ arrayts = (Array, JLArray)
@test iszero(getunstoredindex(a, I))
end

n = 2
a = @view dev(randn(elt, n, n))[1:2, 1]
@test storedlength(a) == length(a)
for indexstyle in (IndexLinear(), IndexCartesian())
for I in eachindex(indexstyle, a)
@test isstored(a, I)
end
end

a = dev(randn(elt, n, n))
for I in ((1, 2), (CartesianIndex(1, 2),))
b = copy(a)
Expand Down
27 changes: 27 additions & 0 deletions test/test_sparsearraydok.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ arrayts = (Array,)
@test b == [0 24; 0 0]
@test storedlength(b) == 1

# isstored
a = SparseArrayDOK{elt}(undef, 4, 4)
a[2, 3] = 23
for I in CartesianIndices(a)
if I == CartesianIndex(2, 3)
@test isstored(a, I)
@test isstored(a, Tuple(I)...)
else
@test !isstored(a, I)
@test !isstored(a, Tuple(I)...)
end
end

# isstored SubArray
a′ = SparseArrayDOK{elt}(undef, 4, 4)
a′[2, 3] = 23
a = @view a′[2:3, 2:3]
for I in CartesianIndices(a)
if I == CartesianIndex(1, 2)
@test isstored(a, I)
@test isstored(a, Tuple(I)...)
else
@test !isstored(a, I)
@test !isstored(a, Tuple(I)...)
end
end

a = SparseArrayDOK{elt}(undef, 3, 3, 3)
a[1, 2, 3] = 123
b = permutedims(a, (2, 3, 1))
Expand Down
Loading