mirror of
https://gitlab.rlp.net/mobitar/julia_course.git
synced 2024-11-16 13:28:10 +00:00
Fixes day 4
This commit is contained in:
parent
91b415dd8b
commit
c525c0e890
1 changed files with 16 additions and 10 deletions
|
@ -21,9 +21,14 @@ begin
|
||||||
TableOfContents()
|
TableOfContents()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ╔═╡ 899a86c4-89e5-4779-8191-2b38ead6d567
|
||||||
|
md"""
|
||||||
|
# Workflow
|
||||||
|
"""
|
||||||
|
|
||||||
# ╔═╡ 81b6211e-b065-11ec-0a86-375721c85b07
|
# ╔═╡ 81b6211e-b065-11ec-0a86-375721c85b07
|
||||||
md"""
|
md"""
|
||||||
# Jupyter notebooks
|
## Jupyter notebooks
|
||||||
Although Pluto notebooks are very interactive and revolutionary, there are some cases where they provide you with too much interactivity. This is especially a problem when you are mutating a variable in a different cell. You can always use `begin` blocks, but sometimes, this is not practical.
|
Although Pluto notebooks are very interactive and revolutionary, there are some cases where they provide you with too much interactivity. This is especially a problem when you are mutating a variable in a different cell. You can always use `begin` blocks, but sometimes, this is not practical.
|
||||||
|
|
||||||
Jupyter notebooks don't rerun every cell depending on a variable that was just updated. Cells are only run manually.
|
Jupyter notebooks don't rerun every cell depending on a variable that was just updated. Cells are only run manually.
|
||||||
|
@ -59,7 +64,7 @@ Launch JupyterLab or Jupyter. You should see the Julia kernel listed now! 🎉
|
||||||
|
|
||||||
# ╔═╡ 7f45c502-0909-42df-b93d-384f743df6a9
|
# ╔═╡ 7f45c502-0909-42df-b93d-384f743df6a9
|
||||||
md"""
|
md"""
|
||||||
# VS Code/Codium
|
## VS Code/Codium
|
||||||
If you are working on a big project, then splitting code up into different files does help maintaining it. Therefore, notebooks should not be used for big projects.
|
If you are working on a big project, then splitting code up into different files does help maintaining it. Therefore, notebooks should not be used for big projects.
|
||||||
|
|
||||||
Because you should avoid using global variables in Julia and instead only call functions, you will not achieve the maximum performance using a notebook because of its workflow that does not support working only with functions. See the section about performance in this notebook.
|
Because you should avoid using global variables in Julia and instead only call functions, you will not achieve the maximum performance using a notebook because of its workflow that does not support working only with functions. See the section about performance in this notebook.
|
||||||
|
@ -89,7 +94,7 @@ I you are using the last method, consider using [Revise](https://timholy.github.
|
||||||
|
|
||||||
# ╔═╡ f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8
|
# ╔═╡ f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8
|
||||||
md"""
|
md"""
|
||||||
# Environments
|
## Environments
|
||||||
If you are working on a project and not using Pluto notebooks, you should be using environments.
|
If you are working on a project and not using Pluto notebooks, you should be using environments.
|
||||||
|
|
||||||
Environments separate project dependencies (packages). Therefore, you are less likely to have any conflicts between two packages. They also allow you to use a different version of a package for every project.
|
Environments separate project dependencies (packages). Therefore, you are less likely to have any conflicts between two packages. They also allow you to use a different version of a package for every project.
|
||||||
|
@ -127,7 +132,7 @@ In the package manager prompt, run the following to remove a package from your e
|
||||||
|
|
||||||
# ╔═╡ 6340aec8-6f77-4a30-8815-ce76ddecd6e8
|
# ╔═╡ 6340aec8-6f77-4a30-8815-ce76ddecd6e8
|
||||||
md"""
|
md"""
|
||||||
# REPL
|
## REPL
|
||||||
The Julia REPL is what you get when you launch Julia in the terminal.
|
The Julia REPL is what you get when you launch Julia in the terminal.
|
||||||
|
|
||||||
The REPL is very useful if you want to quickly experiment with something or test if a function works how you do imagine.
|
The REPL is very useful if you want to quickly experiment with something or test if a function works how you do imagine.
|
||||||
|
@ -301,7 +306,7 @@ function thread_unsafe_sum(N)
|
||||||
sum_of_sums = 0
|
sum_of_sums = 0
|
||||||
|
|
||||||
Threads.@threads for i in 1:N
|
Threads.@threads for i in 1:N
|
||||||
sum_of_sums = sum(1:i)
|
sum_of_sums += sum(1:i)
|
||||||
end
|
end
|
||||||
|
|
||||||
return sum_of_sums
|
return sum_of_sums
|
||||||
|
@ -334,11 +339,11 @@ end
|
||||||
|
|
||||||
# ╔═╡ 8ad3daa6-d221-4ff7-9bc2-8e8a66bdd8c7
|
# ╔═╡ 8ad3daa6-d221-4ff7-9bc2-8e8a66bdd8c7
|
||||||
# Stable!
|
# Stable!
|
||||||
@btime thread_safe_sum(N2)
|
sum_of_sums = @btime thread_safe_sum(N2)
|
||||||
|
|
||||||
# ╔═╡ 95dffc7f-3393-487e-8521-c96291cdc7bf
|
# ╔═╡ 95dffc7f-3393-487e-8521-c96291cdc7bf
|
||||||
# Verify that we did not exceed the limit!
|
# Verify that we did not exceed the limit!
|
||||||
typemax(Int64)
|
typemax(Int64) > sum_of_sums
|
||||||
|
|
||||||
# ╔═╡ ebd3a9d9-7a12-4001-9b53-913f664fb1c8
|
# ╔═╡ ebd3a9d9-7a12-4001-9b53-913f664fb1c8
|
||||||
# Lets try shuffling again
|
# Lets try shuffling again
|
||||||
|
@ -408,7 +413,7 @@ md"""
|
||||||
N3 = 1000000
|
N3 = 1000000
|
||||||
|
|
||||||
# ╔═╡ 2a24aebc-0654-4d00-bdab-627a8e1a75f2
|
# ╔═╡ 2a24aebc-0654-4d00-bdab-627a8e1a75f2
|
||||||
# Use a global array of type Any
|
# Bad usage of a global array of type Any (container with abstract type)
|
||||||
begin
|
begin
|
||||||
sin_vals = []
|
sin_vals = []
|
||||||
|
|
||||||
|
@ -491,13 +496,13 @@ end
|
||||||
# ╔═╡ 43d2cbda-a21b-46ae-8433-7a9ef30c536b
|
# ╔═╡ 43d2cbda-a21b-46ae-8433-7a9ef30c536b
|
||||||
md"""
|
md"""
|
||||||
## `StaticArrays`
|
## `StaticArrays`
|
||||||
If you are dealing with small arrays with less than 100 elements, then take a look at the package [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl). Especially if you are dealing with 2d or 3d coordinates, using `StaticArrays` will make a big performance difference.
|
If you are dealing with small arrays with less than 100 elements, then take a look at the package [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl). Especially if you are dealing with 2D or 3D coordinates, using `StaticArrays` will make a big performance difference.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ╔═╡ f0b634a5-19a9-4c61-932f-7ae357e13be2
|
# ╔═╡ f0b634a5-19a9-4c61-932f-7ae357e13be2
|
||||||
md"""
|
md"""
|
||||||
## Profiling
|
## Profiling
|
||||||
Of course, you can profile your code in Julia. Check the package [ProfileView](https://github.com/timholy/ProfileView.jl) for example.
|
Of course, you can profile your code in Julia. Check out the package [ProfileView](https://github.com/timholy/ProfileView.jl) for example.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ╔═╡ 00000000-0000-0000-0000-000000000001
|
# ╔═╡ 00000000-0000-0000-0000-000000000001
|
||||||
|
@ -729,6 +734,7 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ╔═╡ Cell order:
|
# ╔═╡ Cell order:
|
||||||
|
# ╟─899a86c4-89e5-4779-8191-2b38ead6d567
|
||||||
# ╟─81b6211e-b065-11ec-0a86-375721c85b07
|
# ╟─81b6211e-b065-11ec-0a86-375721c85b07
|
||||||
# ╟─7f45c502-0909-42df-b93d-384f743df6a9
|
# ╟─7f45c502-0909-42df-b93d-384f743df6a9
|
||||||
# ╟─f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8
|
# ╟─f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8
|
||||||
|
|
Loading…
Reference in a new issue