Skip to content

Commit d01eb1f

Browse files
authored
Merge branch 'main' into constructors2
2 parents 3fce692 + 4e94eea commit d01eb1f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/wrappers.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ function storedparentvalues(a::SubArray)
106106
return StoredValues(parent(a), collect(eachstoredparentindex(a)))
107107
end
108108

109+
@interface ::AbstractArrayInterface function isstored(a::SubArray, I::Int...)
110+
return isstored(parent(a), index_to_parentindex(a, I...)...)
111+
end
112+
109113
using LinearAlgebra: Transpose
110114
function parentindex_to_index(a::Transpose, I::CartesianIndex{2})
111115
return cartesianindex_reverse(I)

test/test_basics.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using SparseArraysBase:
1111
storedlength,
1212
storedpairs,
1313
storedvalues
14-
using Test: @test, @testset
14+
using Test: @test, @test_throws, @testset
1515

1616
elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
1717
arrayts = (Array, JLArray)
@@ -43,6 +43,15 @@ arrayts = (Array, JLArray)
4343
@test iszero(getunstoredindex(a, I))
4444
end
4545

46+
n = 2
47+
a = @view dev(randn(elt, n, n))[1:2, 1]
48+
@test storedlength(a) == length(a)
49+
for indexstyle in (IndexLinear(), IndexCartesian())
50+
for I in eachindex(indexstyle, a)
51+
@test isstored(a, I)
52+
end
53+
end
54+
4655
a = dev(randn(elt, n, n))
4756
for I in ((1, 2), (CartesianIndex(1, 2),))
4857
b = copy(a)

test/test_sparsearraydok.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,33 @@ arrayts = (Array,)
5656
@test b == [0 24; 0 0]
5757
@test storedlength(b) == 1
5858

59+
# isstored
60+
a = SparseArrayDOK{elt}(undef, 4, 4)
61+
a[2, 3] = 23
62+
for I in CartesianIndices(a)
63+
if I == CartesianIndex(2, 3)
64+
@test isstored(a, I)
65+
@test isstored(a, Tuple(I)...)
66+
else
67+
@test !isstored(a, I)
68+
@test !isstored(a, Tuple(I)...)
69+
end
70+
end
71+
72+
# isstored SubArray
73+
a′ = SparseArrayDOK{elt}(undef, 4, 4)
74+
a′[2, 3] = 23
75+
a = @view a′[2:3, 2:3]
76+
for I in CartesianIndices(a)
77+
if I == CartesianIndex(1, 2)
78+
@test isstored(a, I)
79+
@test isstored(a, Tuple(I)...)
80+
else
81+
@test !isstored(a, I)
82+
@test !isstored(a, Tuple(I)...)
83+
end
84+
end
85+
5986
a = SparseArrayDOK{elt}(undef, 3, 3, 3)
6087
a[1, 2, 3] = 123
6188
b = permutedims(a, (2, 3, 1))

0 commit comments

Comments
 (0)