Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
courses
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
R3
school
courses
Merge requests
!174
Mk julia5 hw3
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Mk julia5 hw3
mk-julia5-hw3
into
develop
Overview
0
Commits
13
Pipelines
0
Changes
2
Merged
Miroslav Kratochvil
requested to merge
mk-julia5-hw3
into
develop
1 year ago
Overview
0
Commits
13
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
c9bdf932
13 commits,
1 year ago
2 files
+
69
−
103
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
2023/2023-03-09_ProgrammingWithJulia-2/slides/2a-details.md
+
1
−
72
Options
@@ -6,82 +6,11 @@
<i
class=
"twa twa-mechanical-leg"
></i>
<br>
Compiler
&
language internals
(part 1)
</div>
# What is this "compiled code"?
You can inspect various stages of code representation (and reveal bugs):
-
`code_lowered(+)`
-
`code_typed(+)`
-
`code_typed(+, (Int, Float64))`
-
`code_llvm`
-
`code_native`
What happens if we use an abstract type?
<center
style=
"font-size:200%; line-height:120%; margin-bottom: 1em"
>
Performance rule #1:
<br><br>
<strong>
Less instructions is typically better,
</strong><br>
<strong>
less jumps is typically much better.
</strong>
</center>
<center
style=
"font-size:200%; line-height:120%; margin-bottom: 1em"
>
Performance rule #2:
<br><br>
<strong>
Memory allocations comprise of many instructions
<br>
and plenty of jumps.
</strong>
</center>
# What are all these things starting with `@`?
Macros allow you to generate code before compiler runs it:
-
`@info`
can know what variable names to display
-
`@benchmark`
can run the code several times
-
`@test`
can safely wrap the failing code and print what failed
## Important types for macros:
-
symbols:
`:abc`
,
`:+`
, ...
-
expressions:
`:(1+2)`
,
`quote ... end`
Macros are functions that get unevaluated arguments (as expressions) and return unevaluated results (as expressions).
```
julia
macro
clear_data
(
v
)
quote
$
(
Symbol
(
v
,
:
_orig
))
=
load_original_data
()
$
(
Symbol
(
v
,
:
_enriched
))
=
nothing
$
(
Symbol
(
v
,
:
_final
))
=
nothing
end
end
@clear_data
patients
# reloads patients_orig, clears patients_enriched, patients_final
```
# Macro use-cases
Use macros to improve your code whenever Julia syntax is too unwieldy.
```
julia
model
=
@reaction_network
MyModel
begin
c1
,
s
+
i
-->
2
i
c2
,
i
-->
r
end
```
(Taken from
`Catalyst.jl`
)
# How do I package my code?
Use
`] generate MyPackageName`
.
Loading