Skip to content

Commit

Permalink
Fix typo, formatting and deploy.
Browse files Browse the repository at this point in the history
Add let...end block prepended with #md to only include them for markdown deploy (in Franklin) but filter them for notebook output. Fix typos, add hyperlinks to links.
  • Loading branch information
luraess committed Sep 18, 2021
1 parent cfb4ede commit 4ffa896
Showing 1 changed file with 60 additions and 27 deletions.
87 changes: 60 additions & 27 deletions slide-notebooks/l1_3-julia-intro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ md"""
These slides are a [Jupyter notebook](https://jupyter.org/); a browser-based computational notebook.
> You can follow the lecture along live at https://achtzack01.ethz.ch/, login with your first-name and an
> You can follow the lecture along live at [https://achtzack01.ethz.ch/](https://achtzack01.ethz.ch/), login with your first-name and an
> arbitrary password. You have to be within the ETHZ network or use a VPN connection.
Code cells are executed by putting the cursor into the cell and hitting `shift + enter`. For more
Expand Down Expand Up @@ -47,7 +47,7 @@ language with a bend on technical computing.
- first released in 2012
- reached version 1.0 in 2018
- current version 1.6.2
- current version 1.6.2 (09.2021)
- thriving community, for instance there are currently around 6300 packages registered
"""

Expand Down Expand Up @@ -109,11 +109,11 @@ Features:
md"""
### The two language problem
**One language to prototype --- one language for production**
**One language to prototype -- one language for production**
- example from Ludovic's past: prototype in Matlab, production in CUDA-C
**One language for the users --- one language for under-the-hood**
- Numpy (python --- C)
**One language for the users -- one language for under-the-hood**
- Numpy (python -- C)
- machine-learning: pytorch, tensorflow
"""

Expand Down Expand Up @@ -170,19 +170,21 @@ We will now look at
- functions
- modules and packages
The documentation of Julia is good and can be found at https://docs.julialang.org; although for learning it might be a bit terse...
The documentation of Julia is good and can be found at [https://docs.julialang.org](https://docs.julialang.org); although for learning it might be a bit terse...
There are also tutorials, see https://julialang.org/learning/.
There are also tutorials, see [https://julialang.org/learning/](https://julialang.org/learning/).
Furthermore, documentation can be gotten with `?xyz`
"""
#md let
## ?cos
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
md"""
## Variables, assignments, and types
https://docs.julialang.org/en/v1/manual/variables/
[https://docs.julialang.org/en/v1/manual/variables/](https://docs.julialang.org/en/v1/manual/variables/)
"""

a = 4
Expand All @@ -200,11 +202,11 @@ Conventions:
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
md"""
### Variables: Unicode
From https://docs.julialang.org/en/v1/manual/variables/:
From [https://docs.julialang.org/en/v1/manual/variables/](https://docs.julialang.org/en/v1/manual/variables/):
Unicode names (in UTF-8 encoding) are allowed:
```jldoctest
```julia
julia> δ = 0.00001
1.0e-5
Expand All @@ -220,7 +222,9 @@ that you don't know how to type, the REPL help will tell you: just type `?` and
then paste the symbol.)
"""

#md let
##
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
Expand Down Expand Up @@ -271,7 +275,6 @@ a = [2, 3]

# Add new elements to the end of Vector `b` (hint look up the documentation for `push!`)

##
#md push!(b, 1)
#md push!(b, 3, 4)

Expand All @@ -283,15 +286,18 @@ md"""
Concatenate a Range, say `1:10`, with a Vector, say [4,5]:
"""

#md let
## [ ; ]
#md end


md"""
Make a random array of size (3,3). Look up `?rand`. Assign it to `a`
"""

#md let
##

#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -301,11 +307,15 @@ md"""
Access element `[1,2]` and `[2,1]` of Matrix `a` (hint use []):
"""

#md let
## a[ ... ], a[ ... ]
#md end

# Put those two values into a vector

#md let
##
#md end

# Linear vs Cartesian indexing,
# access the first element:
Expand All @@ -315,9 +325,10 @@ a[1,1]

# Access the last element (look up `?end`) both with linear and Cartesian indices

#md let
## a[...]
## a[..., ...]

#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -327,10 +338,14 @@ md"""
Access the last row of `a` (hint use `1:end`)
"""

#md let
## a[... , ...]
#md end

# Access a 2x2 sub-matrix
#md let
## a[ ]
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand Down Expand Up @@ -386,7 +401,9 @@ b[1] = 99

# check whether the change in `b` is reflected in `a`:

#md let
## @assert ...
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -406,19 +423,24 @@ String["one", "two"]

# Create an array taking `Int` with no elements

#md let
##
#md end

#-
# Make an array of type `Any` (which can store any value). Push a value of type
# Int and one of type String to it.

#md let
##
#md end

#-
# Try to assgin 1.5 to the first element of an array of type Array{Int,1}

#md let
##

#md end


#src #########################################################################
Expand All @@ -439,7 +461,7 @@ First look up the docs of Array with `?Array`
md"""
### Array exercises: ALL DONE
The rest will be learing-by-doing
The rest will be learning-by-doing
"""

#src #########################################################################
Expand All @@ -460,7 +482,7 @@ md"""
### Conditional evaluation
Read the first paragraph of
https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation
[https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation](https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation)
(up to "... and no further condition expressions or blocks are evaluated.")
"""

Expand Down Expand Up @@ -493,9 +515,9 @@ end
#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
md"""
### Short cirquit operators `&&` and `||`
### Short circuit operators `&&` and `||`
Read https://docs.julialang.org/en/v1/manual/control-flow/#Short-Circuit-Evaluation
Read [https://docs.julialang.org/en/v1/manual/control-flow/#Short-Circuit-Evaluation](https://docs.julialang.org/en/v1/manual/control-flow/#Short-Circuit-Evaluation)
Explain what this does
Expand Down Expand Up @@ -527,7 +549,7 @@ f(a, b) = a * b
Defining many, short functions is typical in good Julia code.
Read https://docs.julialang.org/en/v1/manual/functions/ up to an including "The return Keyword"
Read [https://docs.julialang.org/en/v1/manual/functions/](https://docs.julialang.org/en/v1/manual/functions/) up to an including "The return Keyword"
"""

#src #########################################################################
Expand All @@ -539,7 +561,9 @@ Define a function in long-form which takes two arguments.
Use some if-else statements and the return keyword.
"""

#md let
##
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -552,7 +576,9 @@ does the same. Map `sin` over the vector `1:10`.
(Note, this is a higher-order function: a function which take a function as a argument)
"""

#md let
##
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -565,12 +591,16 @@ function over values.
Exercise: apply the `sin` function to a vector `1:10`:
"""

#md let
##
#md end

# Broadcasting will extend row and column vectors into a matrix.
# Try `(1:10) .+ (1:10)'` (Note the `'`, this is the transpose operator)

#md let
##
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
Expand All @@ -581,24 +611,27 @@ Evaluate the function `sin(x) + cos(y)` for
`x = 0:0.1:pi` and `y = -pi:0.1:pi`. Remember to use `'`.
"""

#md let
##
#md end

#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
md"""
### Functions: anonymous functions
So far our function got a name with the definition. They can also be defined without name.
So far our function got a name with the definition. They can also be defined without name.
Read https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions
Read [https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions](https://docs.julialang.org/en/v1/manual/functions/#man-anonymous-functions)
Map the function `f(x,y) = sin(x) + cos(x)` over `1:10` but define it as an anonymous
function.
"""

#md let
##
#md end

#src #########################################################################
#src #########################################################################
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
md"""
Expand Down Expand Up @@ -687,7 +720,7 @@ md"""
Modules can be used to structure code into larger entities, and be used to divide it into
different name spaces. We will not make much use of those, but if interested see
https://docs.julialang.org/en/v1/manual/modules/
[https://docs.julialang.org/en/v1/manual/modules/](https://docs.julialang.org/en/v1/manual/modules/)
**Packages** are the way people distribute code and we'll make use of them extensively.
In the first example, the Lorenz ODE, you saw
Expand All @@ -706,7 +739,7 @@ plot( (1:10).^2 )
md"""
### Packages
All public Julia packages are listed on https://juliahub.com/ui/Packages.
All public Julia packages are listed on [https://juliahub.com/ui/Packages](https://juliahub.com/ui/Packages).
You can install a package, say `UnPack.jl` by
```
Expand All @@ -725,10 +758,10 @@ md"""
## This concludes the rapid Julia tour
There are many more features of Julia for sure but this should get you started, and setup for
the exercises. (let us know if you feel we left something out which would have been helpful for the exercises).
the exercises. (Let us know if you feel we left something out which would have been helpful for the exercises).
Remember you can self-help with:
- using `?` at the notebook. Similarly there is an `apropos` function.
- the docs are your friend https://docs.julialang.org/en/v1/
- ask for help in our chat channel: see moodle
- the docs are your friend [https://docs.julialang.org/en/v1/](https://docs.julialang.org/en/v1/)
- ask for help in our chat channel: see Moodle
"""

3 comments on commit 4ffa896

@luraess
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauro3 Until a fix comes from Franklin for the parsing issue 885, I added let .. .end blocks around commented script blocks in order to allow successful build in Franklin. The let ... end statement are filtered with #nb keyword so they are excluded in the .ipynb notebook generation. The hyperlinks are now all active and some minor typos are discarded.

@tlienart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix already, doing the tests and will release this within an hour or so

@luraess
Copy link
Member Author

@luraess luraess commented on 4ffa896 Sep 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix already, doing the tests and will release this within an hour or so

Thanks so much! It works as expected now 🙂

Please sign in to comment.