Skip to content

Commit

Permalink
use requires for conditional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Oct 5, 2017
1 parent 557ffbd commit 03dab6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Knet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions src/karray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 03dab6e

Please sign in to comment.