diff --git a/REQUIRE b/REQUIRE index 25bf9de45..fa0ae4dc6 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,7 @@ julia 0.4 AutoGrad 0.0.7 Compat 0.16.0 # for @views +Requires # We need these for some examples. They get automatically installed when needed. # ArgParse diff --git a/src/Knet.jl b/src/Knet.jl index 3b0fa575c..ebc5dabce 100644 --- a/src/Knet.jl +++ b/src/Knet.jl @@ -39,7 +39,7 @@ dir(path...) = joinpath(dirname(dirname(@__FILE__)),path...) # See if we have a gpu at initialization: -function __init__() +@init begin try r = gpu(true) # info(r >= 0 ? "Knet using GPU $r" : "No GPU found, Knet using the CPU") diff --git a/src/karray.jl b/src/karray.jl index 56884991e..4fbee7b39 100644 --- a/src/karray.jl +++ b/src/karray.jl @@ -42,7 +42,7 @@ operations. * Reduction operators: countnz, maximum, minimum, prod, sum, sumabs, sumabs2, vecnorm. - + * Linear algebra: (*), axpy!, permutedims (up to 5D), transpose * Knet extras: relu, sigm, invx, logp, logsumexp, conv4, pool, @@ -345,12 +345,12 @@ summary(a::KnetDisplay) = summary(a.a) summary(a::KnetArray) = string(Base.dims2string(size(a)), " ", typeof(a)) display(a::KnetArray) = display(KnetDisplay(a)) -# Hack for JLD file load/save of KnetArrays: -if Pkg.installed("JLD") != nothing - import JLD: writeas, readas +using Requires + +@require JLD begin type KnetJLD; a::Array; end - writeas(c::KnetArray) = KnetJLD(Array(c)) - readas(d::KnetJLD) = (gpu() >= 0 ? KnetArray(d.a) : d.a) + JLD.writeas(c::KnetArray) = KnetJLD(Array(c)) + JLD.readas(d::KnetJLD) = (gpu() >= 0 ? KnetArray(d.a) : d.a) end # Array/KnetArray Transfer