From 03dab6e6cbf2504c93d1fb72033a33c9dafc9c54 Mon Sep 17 00:00:00 2001 From: Mike J Innes Date: Thu, 5 Oct 2017 12:50:49 +0100 Subject: [PATCH] use requires for conditional dependency --- REQUIRE | 1 + src/Knet.jl | 2 +- src/karray.jl | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/REQUIRE b/REQUIRE index 2a4e855f8..0164b5ae9 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,7 @@ julia 0.4 AutoGrad 0.0.8 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 99f25d6a8..bfaaec465 100644 --- a/src/Knet.jl +++ b/src/Knet.jl @@ -41,7 +41,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 4279d144f..6a3a38565 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, @@ -354,12 +354,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