Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use requires for conditional JLD dependency #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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