Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.

Commit 8acbd05

Browse files
committed
Test getindex
1 parent 9fb78a8 commit 8acbd05

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/sparse.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ blockdim = 5
1818
@test size(d_x,1) == m
1919
@test size(d_x,2) == 1
2020
@test ndims(d_x) == 1
21+
CuArrays.@allowscalar begin
22+
@test Array(d_x[:]) == x[:]
23+
@test d_x[firstindex(d_x)] == x[firstindex(x)]
24+
@test d_x[div(end, 2)] == x[div(end, 2)]
25+
@test d_x[end] == x[end]
26+
@test Array(d_x[firstindex(d_x):end]) == x[firstindex(x):end]
27+
end
28+
@test_throws BoundsError d_x[firstindex(d_x) - 1]
29+
@test_throws BoundsError d_x[end + 1]
2130
@test nnz(d_x) == nnz(x)
2231
@test Array(nonzeros(d_x)) == nonzeros(x)
2332
@test Array(SparseArrays.nonzeroinds(d_x)) == SparseArrays.nonzeroinds(x)
@@ -30,6 +39,26 @@ blockdim = 5
3039
@test size(d_x,2) == n
3140
@test size(d_x,3) == 1
3241
@test ndims(d_x) == 2
42+
CuArrays.@allowscalar begin
43+
@test Array(d_x[:]) == x[:]
44+
@test d_x[firstindex(d_x)] == x[firstindex(x)]
45+
@test d_x[div(end, 2)] == x[div(end, 2)]
46+
@test d_x[end] == x[end]
47+
@test d_x[firstindex(d_x), firstindex(d_x)] == x[firstindex(x), firstindex(x)]
48+
@test d_x[div(end, 2), div(end, 2)] == x[div(end, 2), div(end, 2)]
49+
@test d_x[end, end] == x[end, end]
50+
@test Array(d_x[firstindex(d_x):end, firstindex(d_x):end]) == x[:, :]
51+
end
52+
@test_throws BoundsError d_x[firstindex(d_x) - 1]
53+
@test_throws BoundsError d_x[end + 1]
54+
@test_throws BoundsError d_x[firstindex(d_x) - 1, firstindex(d_x) - 1]
55+
@test_throws BoundsError d_x[end + 1, end + 1]
56+
@test_throws BoundsError d_x[firstindex(d_x) - 1:end + 1, :]
57+
@test_throws BoundsError d_x[firstindex(d_x) - 1, :]
58+
@test_throws BoundsError d_x[end + 1, :]
59+
@test_throws BoundsError d_x[:, firstindex(d_x) - 1:end + 1]
60+
@test_throws BoundsError d_x[:, firstindex(d_x) - 1]
61+
@test_throws BoundsError d_x[:, end + 1]
3362
@test nnz(d_x) == nnz(x)
3463
@test Array(nonzeros(d_x)) == nonzeros(x)
3564
@test nnz(d_x) == length(nonzeros(d_x))

0 commit comments

Comments
 (0)