Skip to content

Commit 18fb047

Browse files
committed
Lec6 updates.
1 parent e530493 commit 18fb047

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/src/lecture_06/lecture.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ We can see that
153153
- The expression `a + b` has been also replaced with its implementation in terms of the `add_int` intrinsic and its result type annotated as Int64.
154154
- And the return type of the entire function body has been annotated as `Int64`.
155155
- The phi-instruction `%2 = φ (#1 => 1, #3 => %6)` is a **selector function**, which returns the value depending on from which branch do you come from. In this case, variable `%2` will have value 1, if the control was transfered from block `#1` and it will have value copied from variable `%6` if the control was transferreed from block `3` [see also](https://llvm.org/docs/LangRef.html#phi-instruction). The `φ` stands from *phony* variable.
156-
When we have called `@code_lower`, the role of types of the argument was in selecting the approapriate function body, they are needed for multiple dispatch. Contrary in `@code_typed`, the types of parameters determine the choice if inner methods that needs to be called (again the multiple dispatch), which can trigger other optimization, such as inlining, which seen in `One(n)`.
156+
157+
When we have called `@code_lower`, the role of types of arguments was in selecting - via multiple dispatch - the appropriate function body among different methods. Contrary in `@code_typed`, the types of parameters determine the choice of inner methods that need to be called (again with multiple dispatch). This process can trigger other optimization, such as inlining, as seen in the case of `one(n)` being replaced with `1` directly, though here this replacement is hidden in the `φ` function.
157158

158159
Note that the same view of the code is offered by the `@code_warntype` macro, which we have seen in the previous [lecture](@ref perf_lecture). The main difference from `@code_typed` is that it highlights type instabilities with red color and shows only unoptimized view of the code. You can view the unoptimized code with a keyword argument `optimize=false`:
159160
```julia
@@ -247,7 +248,7 @@ and the output is used mainly for debugging / inspection.
247248
Language introspection is very convenient for investigating, how things are implemented and how they are optimized / compiled to the native code.
248249

249250
!!! note "Reminder `@which`"
250-
Though we have already used it quite a few times, recall the very useful macro `@which`, which identifies the concrete function called in the function call. For example `@which mapreduce(sin, +, [1,2,3,4])`. Note again that the macro here is a convenience macro to obtain types of arguments from the expression. Under the hood, it calls `InteractiveUtils.which(function_name, (Base.typesof)(args...))`. Funnily enough, you can call `@which InteractiveUtils.which(+, (Base.typesof)(1,1))` to inspect, where `which` is defined.
251+
Though we have already used it quite a few times, recall the very useful macro `@which`, which identifies the concrete function called in a function call. For example `@which mapreduce(sin, +, [1,2,3,4])`. Note again that the macro here is a convenience macro to obtain types of arguments from the expression. Under the hood, it calls `InteractiveUtils.which(function_name, (Base.typesof)(args...))`. Funnily enough, you can call `@which InteractiveUtils.which(+, (Base.typesof)(1,1))` to inspect, where `which` is defined.
251252

252253
### Broadcasting
253254
Broadcasting is not a unique concept in programming languages (Python/Numpy, MATLAB), however its implementation in Julia allows to easily fuse operations. For example
@@ -349,7 +350,7 @@ The type returned by the quotation depends on what is quoted. Observe the return
349350
```julia
350351
:(1) |> typeof
351352
:(:x) |> typeof
352-
:(1 + x) |> typeof
353+
:(1 + x) |> typeof
353354
quote
354355
1 + x
355356
x + 1
@@ -428,9 +429,7 @@ The parsed code `p` is of type `Expr`, which according to Julia's help[^2] is *a
428429
429430
[^3]: An example provided by Stefan Karpinski [https://stackoverflow.com/questions/23480722/what-is-a-symbol-in-julia](https://stackoverflow.com/questions/23480722/what-is-a-symbol-in-julia)
430431
431-
!!! info
432-
### Expressions
433-
432+
!!! info "`Expr`essions"
434433
From Julia's help[^2]:
435434
436435
`Expr(head::Symbol, args...)`

0 commit comments

Comments
 (0)