Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ end
## utilities

cu(xs) = adapt(CuArray{Float32}, xs)
cu(::Type{Array{T,N}}) where {T,N} = CuArray{T,N,Nothing}
cu(::Type{Array{T}}) where {T} = CuArray{T}
Base.getindex(::typeof(cu), xs...) = CuArray([xs...])

zeros(T::Type, dims...) = fill!(CuArray{T}(undef, dims...), 0)
Expand Down
3 changes: 3 additions & 0 deletions test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ end
@test cu(1:3) === 1:3
@test Base.elsize(xs) == sizeof(Int)
@test CuArray{Int, 2}(xs) === xs
@test cu(Array{Float64,1}) == CuArray{Float64,1, Nothing}
@test cu(Array{Float64,4}) == CuArray{Float64,4, Nothing}
@test cu(Array{Float64}) == CuArray{Float64}

@test_throws ArgumentError Base.unsafe_convert(Ptr{Int}, xs)
@test_throws ArgumentError Base.unsafe_convert(Ptr{Float32}, xs)
Expand Down