Skip to content

Commit 7f84a0d

Browse files
committed
fix for #42
1 parent e5ff5bd commit 7f84a0d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/abstractarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ for (D, S) in ((AbstractAccArray, AbstractArray), (AbstractArray, AbstractAccArr
270270
copy!(dest, drange, src, srange)
271271
end
272272
function copy!{T}(
273-
dest::$D{T, 1}, d_range::CartesianRange{CartesianIndex{1}},
274-
src::$S{T, 1}, s_range::CartesianRange{CartesianIndex{1}},
273+
dest::$D{T}, d_range::CartesianRange{CartesianIndex{1}},
274+
src::$S{T}, s_range::CartesianRange{CartesianIndex{1}},
275275
)
276276
amount = length(d_range)
277277
if length(s_range) != amount
@@ -395,7 +395,7 @@ function Base.getindex{T, N}(A::AbstractAccArray{T, N}, indexes...)
395395
checkbounds(A, cindexes...)
396396

397397
shape = map(length, cindexes)
398-
result = Array{T, N}(shape)
398+
result = Array{T, length(shape)}(shape)
399399
ranges_src = to_cartesian(A, cindexes)
400400
ranges_dest = CartesianRange(shape)
401401
copy!(result, ranges_dest, A, ranges_src)

test/indexing.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,32 @@ for T in (Float32, Int32)
2828
# @test Array(src) == T[0, 77, 77, 77, 77, 77, 77]
2929
end
3030
end
31+
32+
for T in (Float32, Int32)
33+
@allbackends "Indexing with $T" backend begin
34+
x = zeros(T, 7)
35+
src = GPUArray(x)
36+
for i = 1:7
37+
src[i] = i
38+
end
39+
@test Array(src) == T[1:7;]
40+
src[1:3] = T[77, 22, 11]
41+
@test src[1:3] == T[77, 22, 11]
42+
# src[2:end] = 77
43+
# src[1] = T(0)
44+
# @test Array(src) == T[0, 77, 77, 77, 77, 77, 77]
45+
end
46+
end
47+
48+
using GPUArrays
49+
CLBackend.init()
50+
51+
for T in (Float32, Int32)
52+
@allbackends "issue #42 with $T" backend begin
53+
Ac = rand(Float32, 2, 2)
54+
A = GPUArray(Ac)
55+
@test A[1] == Ac[1]
56+
@test A[end] == Ac[end]
57+
@test A[1, 1] == Ac[1, 1]
58+
end
59+
end

0 commit comments

Comments
 (0)