Skip to content

Commit a50ae63

Browse files
committed
Further reduce imports.
1 parent 2a25d64 commit a50ae63

File tree

5 files changed

+34
-39
lines changed

5 files changed

+34
-39
lines changed

src/GPUArrays.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ using Random
99
using LinearAlgebra
1010
using Printf
1111

12-
import Random: rand, rand!
1312
using LinearAlgebra.BLAS
14-
import Base: pointer, similar, size, convert
15-
using Base: @propagate_inbounds, @pure, RefValue
1613
using Base.Cartesian
1714

1815
using FFTW

src/array.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ end
2424

2525
## getters
2626

27-
size(x::JLArray) = x.size
27+
Base.size(x::JLArray) = x.size
2828

29-
pointer(x::JLArray) = pointer(x.data)
29+
Base.pointer(x::JLArray) = pointer(x.data)
3030

3131

3232
## other
@@ -40,7 +40,7 @@ end
4040

4141
to_device(state, x::JLArray) = x.data
4242
to_device(state, x::Tuple) = to_device.(Ref(state), x)
43-
to_device(state, x::RefValue{<: JLArray}) = RefValue(to_device(state, x[]))
43+
to_device(state, x::Base.RefValue{<: JLArray}) = Base.RefValue(to_device(state, x[]))
4444
to_device(state, x) = x
4545
# creates a `local` vector for each thread group
4646
to_device(state, x::LocalMemory{T}) where T = LocalMem(ntuple(i-> Vector{T}(x.size), blockdim_x(state)))
@@ -49,7 +49,7 @@ to_blocks(state, x) = x
4949
# unpacks local memory for each block
5050
to_blocks(state, x::LocalMem) = x.x[blockidx_x(state)]
5151

52-
similar(::Type{<: JLArray}, ::Type{T}, size::Base.Dims{N}) where {T, N} = JLArray{T, N}(size)
52+
Base.similar(::Type{<: JLArray}, ::Type{T}, size::Base.Dims{N}) where {T, N} = JLArray{T, N}(size)
5353

5454
unsafe_reinterpret(::Type{T}, A::JLArray, size::Tuple) where T =
5555
reshape(reinterpret(T, A.data), size)

src/base.jl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import Base: count, map!, permutedims!, cat_t, vcat, hcat
2-
using Base: @pure
3-
41
allequal(x) = true
52
allequal(x, y, z...) = x == y && allequal(y, z...)
63
function map!(f, y::GPUArray, xs::GPUArray...)
@@ -13,11 +10,11 @@ function map(f, y::GPUArray, xs::GPUArray...)
1310
end
1411

1512
# Break ambiguities with base
16-
map!(f, y::GPUArray) =
13+
Base.map!(f, y::GPUArray) =
1714
invoke(map!, Tuple{Any,GPUArray,Vararg{GPUArray}}, f, y)
18-
map!(f, y::GPUArray, x::GPUArray) =
15+
Base.map!(f, y::GPUArray, x::GPUArray) =
1916
invoke(map!, Tuple{Any,GPUArray, Vararg{GPUArray}}, f, y, x)
20-
map!(f, y::GPUArray, x1::GPUArray, x2::GPUArray) =
17+
Base.map!(f, y::GPUArray, x1::GPUArray, x2::GPUArray) =
2118
invoke(map!, Tuple{Any,GPUArray, Vararg{GPUArray}}, f, y, x1, x2)
2219

2320

@@ -49,36 +46,36 @@ map!(f, y::GPUArray, x1::GPUArray, x2::GPUArray) =
4946
# return dest
5047
# end
5148
#
52-
# function cat_t(dims::Integer, T::Type, x::GPUArray, xs::GPUArray...)
49+
# function Base.cat_t(dims::Integer, T::Type, x::GPUArray, xs::GPUArray...)
5350
# catdims = Base.dims2cat(dims)
5451
# shape = Base.cat_shape(catdims, (), size.((x, xs...))...)
5552
# dest = Base.cat_similar(x, T, shape)
5653
# _cat(dims, dest, x, xs...)
5754
# end
5855
#
59-
# vcat(xs::GPUArray...) = cat(1, xs...)
60-
# hcat(xs::GPUArray...) = cat(2, xs...)
56+
# Base.vcat(xs::GPUArray...) = cat(1, xs...)
57+
# Base.hcat(xs::GPUArray...) = cat(2, xs...)
6158

6259

6360
# Base functions that are sadly not fit for the the GPU yet (they only work for Int64)
64-
@pure @inline function gpu_ind2sub(A::AbstractArray, ind::T) where T
61+
Base.@pure @inline function gpu_ind2sub(A::AbstractArray, ind::T) where T
6562
_ind2sub(size(A), ind - T(1))
6663
end
67-
@pure @inline function gpu_ind2sub(dims::NTuple{N}, ind::T) where {N, T}
64+
Base.@pure @inline function gpu_ind2sub(dims::NTuple{N}, ind::T) where {N, T}
6865
_ind2sub(NTuple{N, T}(dims), ind - T(1))
6966
end
70-
@pure @inline _ind2sub(::Tuple{}, ind::T) where {T} = (ind + T(1),)
71-
@pure @inline function _ind2sub(indslast::NTuple{1}, ind::T) where T
67+
Base.@pure @inline _ind2sub(::Tuple{}, ind::T) where {T} = (ind + T(1),)
68+
Base.@pure @inline function _ind2sub(indslast::NTuple{1}, ind::T) where T
7269
((ind + T(1)),)
7370
end
74-
@pure @inline function _ind2sub(inds, ind::T) where T
71+
Base.@pure @inline function _ind2sub(inds, ind::T) where T
7572
r1 = inds[1]
7673
indnext = div(ind, r1)
7774
f = T(1); l = r1
7875
(ind-l*indnext+f, _ind2sub(Base.tail(inds), indnext)...)
7976
end
8077

81-
@pure function gpu_sub2ind(dims::NTuple{N}, I::NTuple{N2, T}) where {N, N2, T}
78+
Base.@pure function gpu_sub2ind(dims::NTuple{N}, I::NTuple{N2, T}) where {N, N2, T}
8279
Base.@_inline_meta
8380
_sub2ind(NTuple{N, T}(dims), T(1), T(1), I...)
8481
end

src/construction.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Base: fill!, similar, zeros, ones, fill
1+
import Base: fill!, zeros, ones, fill
22

33

44

@@ -43,10 +43,10 @@ end
4343
(T::Type{<: GPUArray{X} where X})(dims::NTuple{N, Integer}) where N = similar(T, eltype(T), dims)
4444
(T::Type{<: GPUArray{X} where X})(::UndefInitializer, dims::NTuple{N, Integer}) where N = similar(T, eltype(T), dims)
4545

46-
similar(x::X, ::Type{T}, size::Base.Dims{N}) where {X <: GPUArray, T, N} = similar(X, T, size)
47-
similar(::Type{X}, ::Type{T}, size::NTuple{N, Base.OneTo{Int}}) where {X <: GPUArray, T, N} = similar(X, T, length.(size))
46+
Base.similar(x::X, ::Type{T}, size::Base.Dims{N}) where {X <: GPUArray, T, N} = similar(X, T, size)
47+
Base.similar(::Type{X}, ::Type{T}, size::NTuple{N, Base.OneTo{Int}}) where {X <: GPUArray, T, N} = similar(X, T, length.(size))
4848

49-
convert(AT::Type{<: GPUArray{T, N}}, A::GPUArray{T, N}) where {T, N} = A
49+
Base.convert(AT::Type{<: GPUArray{T, N}}, A::GPUArray{T, N}) where {T, N} = A
5050

5151
function indexstyle(x::T) where T
5252
style = try
@@ -73,7 +73,7 @@ eltype_or(::Type{<: GPUArray}, or) = or
7373
eltype_or(::Type{<: GPUArray{T}}, or) where T = T
7474
eltype_or(::Type{<: GPUArray{T, N}}, or) where {T, N} = T
7575

76-
function convert(AT::Type{<: GPUArray}, iter)
76+
function Base.convert(AT::Type{<: GPUArray}, iter)
7777
isize = Base.IteratorSize(iter)
7878
style = indexstyle(iter)
7979
ettrait = Base.IteratorEltype(iter)
@@ -87,17 +87,18 @@ function convert(AT::Type{<: GPUArray}, iter)
8787
end
8888
end
8989

90-
function convert(AT::Type{<: GPUArray{T, N}}, A::DenseArray{T, N}) where {T, N}
90+
function Base.convert(AT::Type{<: GPUArray{T, N}}, A::DenseArray{T, N}) where {T, N}
9191
copyto!(AT(Base.size(A)), A)
9292
end
9393

94-
function convert(AT::Type{<: GPUArray{T1}}, A::DenseArray{T2, N}) where {T1, T2, N}
94+
function Base.convert(AT::Type{<: GPUArray{T1}}, A::DenseArray{T2, N}) where {T1, T2, N}
9595
copyto!(similar(AT, T1, size(A)), convert(Array{T1, N}, A))
9696
end
97-
function convert(AT::Type{<: GPUArray}, A::DenseArray{T2, N}) where {T2, N}
97+
98+
function Base.convert(AT::Type{<: GPUArray}, A::DenseArray{T2, N}) where {T2, N}
9899
copyto!(similar(AT, T2, size(A)), A)
99100
end
100101

101-
function convert(AT::Type{Array{T, N}}, A::GPUArray{CT, CN}) where {T, N, CT, CN}
102+
function Base.convert(AT::Type{Array{T, N}}, A::GPUArray{CT, CN}) where {T, N, CT, CN}
102103
convert(AT, copyto!(Array{CT, CN}(undef, size(A)), A))
103104
end

src/random.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let rand_state_dict = Dict()
5555
end
5656
end
5757
end
58-
function rand!(A::GPUArray{T}) where T <: Number
58+
function Random.rand!(A::GPUArray{T}) where T <: Number
5959
rstates = cached_state(A)
6060
gpu_call(A, (rstates, A,)) do state, randstates, a
6161
idx = linear_index(state)
@@ -66,14 +66,14 @@ function rand!(A::GPUArray{T}) where T <: Number
6666
A
6767
end
6868

69-
rand(X::Type{<: GPUArray}, i::Integer...) = rand(X, Float32, i...)
70-
rand(X::Type{<: GPUArray}, size::NTuple{N, Int}) where N = rand(X, Float32, size...)
71-
rand(X::Type{<: GPUArray{T}}, i::Integer...) where T = rand(X, T, i...)
72-
rand(X::Type{<: GPUArray{T}}, size::NTuple{N, Int}) where {T, N} = rand(X, T, size...)
73-
rand(X::Type{<: GPUArray{T, N}}, size::NTuple{N, Integer}) where {T, N} = rand(X, T, size...)
74-
rand(X::Type{<: GPUArray{T, N}}, size::NTuple{N, Int}) where {T, N} = rand(X, T, size...)
69+
Random.rand(X::Type{<: GPUArray}, i::Integer...) = rand(X, Float32, i...)
70+
Random.rand(X::Type{<: GPUArray}, size::NTuple{N, Int}) where N = rand(X, Float32, size...)
71+
Random.rand(X::Type{<: GPUArray{T}}, i::Integer...) where T = rand(X, T, i...)
72+
Random.rand(X::Type{<: GPUArray{T}}, size::NTuple{N, Int}) where {T, N} = rand(X, T, size...)
73+
Random.rand(X::Type{<: GPUArray{T, N}}, size::NTuple{N, Integer}) where {T, N} = rand(X, T, size...)
74+
Random.rand(X::Type{<: GPUArray{T, N}}, size::NTuple{N, Int}) where {T, N} = rand(X, T, size...)
7575

76-
function rand(X::Type{<: GPUArray}, ::Type{ET}, size::Integer...) where ET
76+
function Random.rand(X::Type{<: GPUArray}, ::Type{ET}, size::Integer...) where ET
7777
A = similar(X, ET, size)
7878
rand!(A)
7979
end

0 commit comments

Comments
 (0)