You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/lectures/lecture_06/lab.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,17 +71,17 @@ We will start with a question: Can we spot internally some difference between ty
71
71
72
72
!!! details
73
73
```julia
74
-
@code_warntype explicit_sum(x)
75
-
@code_warntype implicit_sum()
74
+
@code_warntype explicit_len(x)
75
+
@code_warntype implicit_len()
76
76
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()
79
79
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()
82
82
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()
85
85
```
86
86
87
87
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
155
155
end
156
156
```
157
157
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
+
158
165
!!! info "Splatting/slurping operator `...`"
159
166
The operator `...` serves two purposes inside function calls [^3][^4]:
160
167
- combines multiple arguments into one
@@ -180,12 +187,6 @@ Inlining[^2] is another compiler optimization that allows us to speed up the cod
0 commit comments