From 1ecf150a33b033959d34f607fcb89c4cd4ea2eec Mon Sep 17 00:00:00 2001 From: Ellipse0934 Date: Wed, 15 Jul 2020 19:44:59 +0530 Subject: [PATCH] fix when length = 0 --- src/host/construction.jl | 1 + test/testsuite/construction.jl | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/host/construction.jl b/src/host/construction.jl index f55ddc63..43b57f5d 100644 --- a/src/host/construction.jl +++ b/src/host/construction.jl @@ -9,6 +9,7 @@ function Base.fill(X::Type{<: AbstractGPUArray{T}}, val, dims::NTuple{N, Integer fill!(res, convert(T, val)) end function Base.fill!(A::AbstractGPUArray{T}, x) where T + length(A) == 0 && return A gpu_call(A, convert(T, x)) do ctx, a, val idx = @linearidx(a, ctx) @inbounds a[idx] = val diff --git a/test/testsuite/construction.jl b/test/testsuite/construction.jl index 97bc6526..4b3fb362 100644 --- a/test/testsuite/construction.jl +++ b/test/testsuite/construction.jl @@ -152,6 +152,14 @@ end @test all(x-> x == 2f0, Array(x1)) @test all(x-> x == Int32(77), Array(x2)) + x = fill(zero(T), (0, 2)) + x1 = fill(AT{T}, T(0), (0, 2)) + x2 = fill(AT{T}, T(0), (0, 2)) + x3 = fill(AT{T, 2}, T(0), (0, 2)) + @test Array(x1) ≈ x + @test Array(x2) ≈ x + @test Array(x3) ≈ x + x = Matrix{T}(I, 4, 2) x1 = AT{T, 2}(I, 4, 2)