Skip to content

Commit

Permalink
tutorial fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Sep 28, 2020
1 parent 945ab88 commit f7e54ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/cuarrays/cubytes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tutorial/00.Julia_is_fast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions tutorial/15.quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,:));"
]
Expand Down
2 changes: 1 addition & 1 deletion tutorial/20.mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
20 changes: 10 additions & 10 deletions tutorial/25.iterators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
]
},
Expand Down Expand Up @@ -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;"
]
},
Expand All @@ -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;"
]
},
Expand All @@ -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;"
]
},
Expand All @@ -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;"
]
},
Expand All @@ -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;"
]
},
Expand All @@ -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;"
]
},
Expand Down Expand Up @@ -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;"
]
Expand Down
4 changes: 2 additions & 2 deletions tutorial/30.lin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)));"
]
},
Expand Down

0 comments on commit f7e54ea

Please sign in to comment.