JuliaGPU / ArrayFire.jl
1
import Base: rand, randn
2
export srand
3

4
function rand(::Type{AFArray{T,N}}, t::NTuple{N,Int}) where {T,N}
5 4
    out = RefValue{af_array}(0)
6 4
    _error(ccall((:af_randu,af_lib),af_err,(Ptr{af_array},UInt32,Ptr{dim_t},af_dtype),
7
                 out,UInt32(N),[t...],af_type(T)))
8 4
    AFArray{T,N}(out[])
9
end
10 4
rand(::Type{AFArray{T}}, t::NTuple{N,Int}) where {T,N}= rand(AFArray{T,N}, t)
11 4
rand(::Type{AFArray}, t::NTuple{N,Int}) where {N} = rand(AFArray{Float32,N}, t)
12 4
rand(::Type{AFArray{T}}, t::Int...) where {T} = rand(AFArray{T}, t)
13 4
rand(::Type{AFArray}, t::Int...) = rand(AFArray, t)
14

15
function randn(::Type{AFArray{T,N}}, t::NTuple{N,Int}) where {T,N}
16 4
    out = RefValue{af_array}(0)
17 4
    _error(ccall((:af_randn,af_lib),af_err,(Ptr{af_array},UInt32,Ptr{dim_t},af_dtype),
18
                 out,UInt32(N),[t...],af_type(T)))
19 4
    AFArray{T,N}(out[])
20
end
21 4
randn(::Type{AFArray{T}}, t::NTuple{N,Int}) where {T,N} = randn(AFArray{T,N}, t)
22 4
randn(::Type{AFArray}, t::NTuple{N,Int}) where {N} = randn(AFArray{Float32,N}, t)
23 4
randn(::Type{AFArray{T}}, t::Int...) where {T} = randn(AFArray{T}, t)
24 4
randn(::Type{AFArray}, t::Int...) = randn(AFArray, t)
25

26 4
srand(::Type{AFArray}, i) = set_seed(UInt(abs(i)))

Read our documentation on viewing source code .

Loading