Skip to content

Commit 2e1be08

Browse files
author
pevnak
committed
Merge branch '2025W' of github.com:JuliaTeachingCTU/Scientific-Programming-in-Julia into 2025W
2 parents fae1fe2 + fc35078 commit 2e1be08

File tree

1 file changed

+15
-14
lines changed
  • docs/src/lectures/lecture_06

1 file changed

+15
-14
lines changed

docs/src/lectures/lecture_06/lab.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ We will start with a question: Can we spot internally some difference between ty
7171

7272
!!! details
7373
```julia
74-
@code_warntype explicit_sum(x)
75-
@code_warntype implicit_sum()
74+
@code_warntype explicit_len(x)
75+
@code_warntype implicit_len()
7676

77-
@code_typed debuginfo=:none explicit_sum(x)
78-
@code_typed debuginfo=:none implicit_sum()
77+
@code_typed debuginfo=:none explicit_len(x)
78+
@code_typed debuginfo=:none implicit_len()
7979

80-
@code_llvm debuginfo=:none explicit_sum(x)
81-
@code_llvm debuginfo=:none implicit_sum()
80+
@code_llvm debuginfo=:none explicit_len(x)
81+
@code_llvm debuginfo=:none implicit_len()
8282

83-
@code_native debuginfo=:none explicit_sum(x)
84-
@code_native debuginfo=:none implicit_sum()
83+
@code_native debuginfo=:none explicit_len(x)
84+
@code_native debuginfo=:none implicit_len()
8585
```
8686

8787
In this case we see that the generated code for such a simple operation is much longer in the type unstable case resulting in longer run times. However in the next example we will see that having longer code is not always a bad thing.
@@ -155,6 +155,13 @@ Inlining[^2] is another compiler optimization that allows us to speed up the cod
155155
end
156156
```
157157

158+
**HINTS**:
159+
- define two methods `_polynomial!(ac, x, a...)` and `_polynomial!(ac, x, a)` for the case of ≥2 coefficients and the last coefficient
160+
- use splatting together with range indexing `a[1:end-1]...`
161+
- the correctness can be checked using the built-in `evalpoly`
162+
- recall that these kind of optimization are possible just around the type inference stage
163+
- use container of known length to store the coefficients
164+
158165
!!! info "Splatting/slurping operator `...`"
159166
The operator `...` serves two purposes inside function calls [^3][^4]:
160167
- combines multiple arguments into one
@@ -180,12 +187,6 @@ Inlining[^2] is another compiler optimization that allows us to speed up the cod
180187
[^3]: [https://docs.julialang.org/en/v1/manual/faq/#What-does-the-...-operator-do?](https://docs.julialang.org/en/v1/manual/faq/#What-does-the-...-operator-do?)
181188
[^4]: [https://docs.julialang.org/en/v1/manual/functions/#Varargs-Functions](https://docs.julialang.org/en/v1/manual/functions/#Varargs-Functions)
182189

183-
**HINTS**:
184-
- define two methods `_polynomial!(ac, x, a...)` and `_polynomial!(ac, x, a)` for the case of ≥2 coefficients and the last coefficient
185-
- use splatting together with range indexing `a[1:end-1]...`
186-
- the correctness can be checked using the built-in `evalpoly`
187-
- recall that these kind of optimization are possible just around the type inference stage
188-
- use container of known length to store the coefficients
189190

190191
!!! details
191192
```@example lab06_intro

0 commit comments

Comments
 (0)