From f7e54ea69a729d9a10d5b8d5296ddc58fcf7c534 Mon Sep 17 00:00:00 2001 From: Deniz Yuret Date: Mon, 28 Sep 2020 10:20:27 +0300 Subject: [PATCH] tutorial fixes --- src/cuarrays/cubytes.jl | 2 +- tutorial/00.Julia_is_fast.ipynb | 4 +--- tutorial/15.quickstart.ipynb | 4 ++-- tutorial/20.mnist.ipynb | 2 +- tutorial/25.iterators.ipynb | 20 ++++++++++---------- tutorial/30.lin.ipynb | 4 ++-- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cuarrays/cubytes.jl b/src/cuarrays/cubytes.jl index 86f40ee2f..b357fdda2 100644 --- a/src/cuarrays/cubytes.jl +++ b/src/cuarrays/cubytes.jl @@ -6,7 +6,7 @@ using CUDA: CuArray cuarrays(x, c=CuArray[], d=IdDict{Any,Bool}()) = (_cuarrays(x,c,d); c) _cuarrays(x::CuArray, c::Vector{CuArray}, d::IdDict{Any,Bool}) = - if !haskey(d,x); d[x] = true; push!(c,x); x.parent === nothing || _cuarrays(x.parent,c,d); end + if !haskey(d,x); d[x] = true; push!(c,x); if hasfield(typeof(x),:parent) && x.parent !== nothing; _cuarrays(x.parent,c,d); end; end _cuarrays(x::Union{Module,String,Symbol,Core.MethodInstance,Method,GlobalRef,DataType,Union,UnionAll,Task,Regex}, c::Vector{CuArray}, d::IdDict{Any,Bool}) = return diff --git a/tutorial/00.Julia_is_fast.ipynb b/tutorial/00.Julia_is_fast.ipynb index 3d91dbf47..c50b15ab7 100644 --- a/tutorial/00.Julia_is_fast.ipynb +++ b/tutorial/00.Julia_is_fast.ipynb @@ -165,9 +165,7 @@ ], "source": [ "using Pkg\n", - "for p in (\"BenchmarkTools\",\"Plots\",\"PyCall\",\"Conda\")\n", - " haskey(Pkg.installed(),p) || Pkg.add(p)\n", - "end" + "pkg\"add BenchmarkTools Plots PyCall Conda\"" ] }, { diff --git a/tutorial/15.quickstart.ipynb b/tutorial/15.quickstart.ipynb index 21cdba60b..8eb44919f 100644 --- a/tutorial/15.quickstart.ipynb +++ b/tutorial/15.quickstart.ipynb @@ -64,8 +64,8 @@ "outputs": [], "source": [ "# Load MNIST data\n", - "xtrn,ytrn = MNIST.traindata(Float32)\n", - "xtst,ytst = MNIST.testdata(Float32)\n", + "xtrn,ytrn = MNIST.traindata(Float32); ytrn[ytrn.==0] .= 10\n", + "xtst,ytst = MNIST.testdata(Float32); ytst[ytst.==0] .= 10\n", "dtrn = minibatch(xtrn, ytrn, 100; xsize=(size(xtrn,1),size(xtrn,2),1,:))\n", "dtst = minibatch(xtst, ytst, 100; xsize=(size(xtst,1),size(xtst,2),1,:));" ] diff --git a/tutorial/20.mnist.ipynb b/tutorial/20.mnist.ipynb index ef51b05af..afec5f2ca 100644 --- a/tutorial/20.mnist.ipynb +++ b/tutorial/20.mnist.ipynb @@ -193,7 +193,7 @@ "# dtst generates 100 minibatches of 100 images (total 10000)\n", "n = 0\n", "for (x,y) in dtrn\n", - " n += 1\n", + " global n += 1\n", "end\n", "n" ] diff --git a/tutorial/25.iterators.ipynb b/tutorial/25.iterators.ipynb index 27feb040c..1442e77cd 100644 --- a/tutorial/25.iterators.ipynb +++ b/tutorial/25.iterators.ipynb @@ -116,7 +116,7 @@ "# Iterators can be used in for loops\n", "# Let's count the elements in dtst:\n", "n = 0\n", - "for (x,y) in dtst; n += 1; end\n", + "for (x,y) in dtst; global n += 1; end\n", "@show n;" ] }, @@ -167,7 +167,7 @@ "# We can generate an iterator for multiple epochs using `ncycle`\n", "# (an epoch is a single pass over the dataset)\n", "n = 0\n", - "for (x,y) in ncycle(dtst,5); n += 1; end\n", + "for (x,y) in ncycle(dtst,5); global n += 1; end\n", "@show n;" ] }, @@ -191,7 +191,7 @@ "source": [ "# We can generate partial epochs using `take` which takes the first n elements\n", "n = 0\n", - "for (x,y) in take(dtst,20); n += 1; end\n", + "for (x,y) in take(dtst,20); global n += 1; end\n", "@show n;" ] }, @@ -215,7 +215,7 @@ "source": [ "# We can also generate partial epochs using `drop` which drops the first n elements\n", "n = 0\n", - "for (x,y) in drop(dtst,20); n += 1; end\n", + "for (x,y) in drop(dtst,20); global n += 1; end\n", "@show n;" ] }, @@ -240,7 +240,7 @@ "# We can repeat forever using `cycle`\n", "# You do not want to collect a cycle or run a for loop without break! \n", "n = 0\n", - "for (x,y) in cycle(dtst); (n += 1) > 1234 && break; end\n", + "for (x,y) in cycle(dtst); (global n += 1) > 1234 && break; end\n", "@show n;" ] }, @@ -261,7 +261,7 @@ "# We can repeat until a condition is met using `takewhile`\n", "# This is useful to train until convergence\n", "n = 0\n", - "for (x,y) in takewhile(x->(n<56), dtst); n += 1; end\n", + "for (x,y) in takewhile(x->(n<56), dtst); global n += 1; end\n", "@show n;" ] }, @@ -282,7 +282,7 @@ "# We can take every nth element using `takenth`\n", "# This is useful to report progress every nth iteration\n", "n = 0\n", - "for (x,y) in takenth(dtst,6); n += 1; end\n", + "for (x,y) in takenth(dtst,6); global n += 1; end\n", "@show n;" ] }, @@ -337,9 +337,9 @@ "# Here is how the for loop for dtst is implemented:\n", "n = 0; next = iterate(dtst)\n", "while next != nothing\n", - " ((x,y), state) = next\n", - " n += 1\n", - " next = iterate(dtst,state)\n", + " ((_x,_y), state) = next\n", + " global n += 1\n", + " global next = iterate(dtst,state)\n", "end\n", "@show n;" ] diff --git a/tutorial/30.lin.ipynb b/tutorial/30.lin.ipynb index 771e973e7..9e3c9d5f5 100644 --- a/tutorial/30.lin.ipynb +++ b/tutorial/30.lin.ipynb @@ -74,8 +74,8 @@ "# Load MNIST data\n", "xtrn,ytrn = MNIST.traindata(Float32); ytrn[ytrn.==0] .= 10\n", "xtst,ytst = MNIST.testdata(Float32); ytst[ytst.==0] .= 10\n", - "dtrn = minibatch(xtrn, ytrn, 100; xsize = (784,:))\n", - "dtst = minibatch(xtst, ytst, 100; xsize = (784,:))\n", + "dtrn = minibatch(xtrn, ytrn, 100; xsize = (784,:), xtype = Array)\n", + "dtst = minibatch(xtst, ytst, 100; xsize = (784,:), xtype = Array)\n", "println.(summary.((dtrn,dtst)));" ] },