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/lecture_04/DataFrames.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,13 @@ df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"], C = rand(4))
16
16
17
17
Since each column is stored in a `DataFrame` as a separate vector, it is possible to combine columns of different element types. Columns can be accessed directly without copying.
18
18
19
-
```@example dfbasics
19
+
```@repl dfbasics
20
20
df.A
21
21
```
22
22
23
23
Another way is to use the indexing syntax similar to the one for arrays.
24
24
25
-
```@example dfbasics
25
+
```@repl dfbasics
26
26
df[!, :A]
27
27
```
28
28
@@ -77,7 +77,7 @@ Alternatively, we can use the `insertcols!` function. This function can insert m
New rows can be added to an existing `DataFrame` by the `push!` function. It is possible to append a new row in the form of a vector or a tuple of the correct length or in the form of a dictionary with the correct keys.
80
+
New rows can be added to an existing `DataFrame` by the `push!` function. It is possible to append a new row in the form of a vector or a tuple of the correct length or in the form of a dictionary or `DataFrame`with the correct keys.
Copy file name to clipboardExpand all lines: docs/src/lecture_04/Plots.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -134,9 +134,9 @@ where ``t \in [0, 2\pi]``. Create a plot of the curve described by the equations
134
134
2. The line color should change with the changing line width.
135
135
Use `:viridis` color scheme or any other [color scheme](http://docs.juliaplots.org/latest/generated/colorschemes/) supported by the Plots package. Use additional plot attributes to get a nice looking graph.
136
136
137
-
**Hint:** use the `pallete` function combined with the `collect` function to generate a vector of colors from the `:viridis` color scheme.
138
-
139
-
**Hint:** remove all decorators by using: `axis = nothing`, `border = :none`.
137
+
**Hints:**
138
+
- use the `pallete` function combined with the `collect` function to generate a vector of colors from the `:viridis` color scheme.
139
+
- remove all decorators by using: `axis = nothing`, `border = :none`.
The previous section showed basic functionality of `plot`. We first calculated the values to be plotted and then created the graphs. However, it is possible to pass functions directly to `plot`.
224
+
The previous section showed basic functionality of the `plot` function. We first calculated the values to be plotted and then created the graphs. However, it is possible to pass functions directly to the `plot` function.
Draw this function for ``x, y \in [-5, 5]``. Use the following three plot series `contourf`, `heatmap`, and `surface` with the following settings:
325
-
-`:viridis` color scheme;
326
-
- camera angle `(25, 65)`;
325
+
-`:viridis` color scheme,
326
+
- camera angle `(25, 65)`,
327
327
- no legend, color bar, or decorators (`axis`, `frame` and `ticks`).
328
328
329
329
```@raw html
@@ -353,7 +353,7 @@ kwargs = (
353
353
nothing # hide
354
354
```
355
355
356
-
We use the `plot` function with the `seriestype = :contourf` keyword to draw a filled contour plot. The simpler option is to use the `contourf` function.
356
+
We can use the `plot` function with the `seriestype = :contourf` keyword to draw a filled contour plot. The simpler option is to use the `contourf` function.
It is possible to create more advanced layouts with the `@layout` macro. In the example below, we create a non-symmetric layout with one subplot in the first row and two subplots in the second row. Moreover, we set the width of the first subplot in the second row to be `0.3` the whole plot width.
409
+
It is possible to create more advanced layouts with the `@layout` macro. In the example below, we create a non-symmetric layout with one subplot in the first row and two subplots in the second row. Moreover, we set the width of the first subplot in the second row to be `0.3`of the whole plot width.
Copy file name to clipboardExpand all lines: docs/src/lecture_04/interaction.md
+17-15Lines changed: 17 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,33 @@
1
1
# Interaction with other languages
2
2
3
-
One of the biggest advantages of Julia is its speed. As we discussed in the section [Why julia?](@ref Why-julia?), Julia is fast out-of-box without the necessity to do any additional steps. As a result, Julia solves the so-called Two-Language problem:*users are programming in a high-level language such as R and Python, but the performance-critical parts of the code have to be rewritten in C/Fortran for performance.* Since Julia is fast enough, most of the libraries are written in pure Julia and there is no need to use C/Fortran for performance. However, there are many high-quality, mature libraries for numerical computing already written in C and Fortran. It would be a shame if it will not be possible to use them in Julia.
3
+
One of the most significant advantages of Julia is its speed. As we discussed in the section [Why julia?](@ref Why-julia?), Julia is fast out-of-box without the necessity to do any additional steps. As a result, Julia solves the so-called Two-Language problem:
4
4
5
-
To allow easy use of this existing code, Julia makes it simple and efficient to call C and Fortran functions. Julia has a **no boilerplate** philosophy: functions can be called directly from Julia without any glue code generation, or compilation – even from the interactive prompt. This is accomplished just by making an appropriate call with `ccall` syntax, which looks like an ordinary function call. Moreover, it is possible to pass Julia functions to native C functions that accept function pointer arguments. In this section, we will show one example of the interaction between Julia and C. Extensive description of all provided functionality can be found in the [official manual](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/).
5
+
> Users are programming in a high-level language such as R and Python, but the performance-critical parts of the code have to be rewritten in C/Fortran for performance.
6
6
7
-
The following example is taken from the official manual. Consider the situation, that we want to use the `qsort` function from the standard C library. The `qsort` function sortrs an array and is edclared as follows
7
+
Since Julia is fast enough, most of the libraries are written in pure Julia, and there is no need to use C/Fortran for performance. However, there are many high-quality, mature libraries for numerical computing already written in C and Fortran. It would be a shame if it will not be possible to use them in Julia.
8
+
9
+
To allow easy use of this existing code, Julia makes it simple and efficient to call C and Fortran functions. Julia has a **no boilerplate** philosophy: functions can be called directly from Julia without any glue code generation or compilation – even from the interactive prompt. This is accomplished just by making an appropriate call with the `ccall` syntax, which looks like an ordinary function call. Moreover, it is possible to pass Julia functions to native C functions that accept function pointer arguments. This section will show one example of the interaction between Julia and C. Extensive description of all provided functionality can be found in the [official manual](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/).
10
+
11
+
The following example is taken from the official manual. Consider the situation that we want to use the `qsort` function from the standard C library. The `qsort` function sorts an array and is declared as follows.
8
12
9
13
```c
10
14
voidqsort(void *base, size_t nitems, size_t size,
11
15
int (*compare)(const void*, const void*))
12
16
```
13
17
14
-
The `base` is the pointer to the first element of the array to be sorted. The `nitems` is the number of elements in the array pointed by `base` and the `size` is the size in bytes of each element in the array. Finally, the `compare` is the function that compares two elements. The `compare` function should return a negative integer if the first argument is less than the second, a positive integer if the first argument is greater than the second, and otherwise zero. Such a function can be in Julia defined as follows.
18
+
The `base` is the pointer to the first element of the array to be sorted. The `nitems` is the number of elements in the array pointed by `base`. The `size` is the size in bytes of each element in the array. Finally, the `compare` is the function that compares two elements. The `compare` function should return a negative integer if the first argument is less than the second, a positive integer if the first argument is greater than the second, and otherwise zero. Such a Julia function can be defined as follows.
15
19
16
20
```julia
17
21
mycompare(a, b)::Cint = sign(a - b)
18
22
```
19
23
20
-
Since the `qsort` function expects, that the return type of the `compare` function is C `int`, we annotate the return type to be `Cint`. In order to pass this function to C, we obtain its address using the macro `@cfunction`.
24
+
Since the `qsort` function expects that the return type of the `compare` function is C `int`, we annotate the return type to be `Cint`. In order to pass this function to C, we obtain its address using the macro `@cfunction`.
The `@cfunction` macro requires three arguments: the Julia function, the return type, and tuple of the input argument types. Finally we can use the `ccall` function to call the `qsort` function.
30
+
The `@cfunction` macro requires three arguments: the Julia function, the return type, and the tuple of the input argument types. Finally, we can use the `ccall` function to call the `qsort` function.
27
31
28
32
```julia
29
33
julia> A = [1.3, -2.7, 4.4, 3.1];
@@ -39,7 +43,7 @@ julia> A
39
43
4.4
40
44
```
41
45
42
-
Besides C and Fortran that can be called directly using `ccall` function, it is possible to interact with other languages. There are many packages that provide an interface to interact with other languages. The following table shows an overview of those packagess
46
+
Besides C and Fortran that can be called directly using `ccall` function, it is possible to interact with other languages using third-party packages. The following table shows an overview of those packages.
43
47
44
48
| Language | Calling from Julia | Calling Julia |
45
49
| :--- | :--- | :--- |
@@ -50,11 +54,11 @@ Besides C and Fortran that can be called directly using `ccall` function, it is
Moreover, there are other Julia packages that provide Julia interface for some well-known libraries from other languages. As an example, we can mention ScikitLear.jl which provides an interface for the [scikit-learn](https://scikit-learn.org/stable/) library from Python or the [RDatasets.jl](https://github.com/JuliaStats/RDatasets.jls) that provides an easy way to load famous R datasets.
57
+
Moreover, other Julia packages provide Julia interface for some well-known libraries from other languages. As an example, we can mention [ScikitLear.jl](https://github.com/cstjean/ScikitLearn.jl), which provides an interface for the [scikit-learn](https://scikit-learn.org/stable/) library from Python or the [RDatasets.jl](https://github.com/JuliaStats/RDatasets.jls) that provides an easy way to load famous R datasets.
54
58
55
59
## RCall.jl
56
60
57
-
The [RCall.jl](https://github.com/JuliaInterop/RCall.jl) package provides an interface for calling R functions from Julia and passing data between these two languages. The package provides an interactive REPL for the R language that can be accessed from the Julia REPL by typing `$` symbol. As a consequence, it is possible to easily switch between these languages and use functionality provided by both languages simultaneously.
61
+
The [RCall.jl](https://github.com/JuliaInterop/RCall.jl) package provides an interface for calling R functions from Julia and passing data between these two languages. The package provides an interactive REPL for the R language that can be accessed from the Julia REPL by typing the `$` symbol. Consequently, it is possible to easily switch between these languages and use functionality provided by both languages simultaneously.
Note that we use multiline string syntax, but it is also possible to use standard string syntax as well. This multiline string syntax is very useful especially when we want to perform multiple operations in R at once and then just return the result to Julia.
87
+
Note that we use multiline string syntax, but it is also possible to use standard string syntax. This multiline string syntax is very useful, especially when we want to perform multiple operations in R at once and then just return the result to Julia.
84
88
85
89
## MATLAB.jl
86
90
87
-
The [MATLAB.jl](https://github.com/JuliaInterop/MATLAB.jl) provides an easy interface for calling Matlab functions and passing data between Julia and Matlab. Consider the situation, that you wrote a Matlab function, that uses some special functionality that is not available in Julia. Using the MATLAB.jl package, it is very easy to call this function directly from Julia as can be seen in the following example
91
+
The [MATLAB.jl](https://github.com/JuliaInterop/MATLAB.jl) provides an easy interface for calling Matlab functions and passing data between Julia and Matlab. Consider the situation that you wrote a Matlab function that uses some special functionality that is not available in Julia. MATLAB.jl package provides an interface to call this function directly from Julia, as can be seen in the following example.
88
92
89
93
```julia
90
94
using MATLAB, BSON
@@ -97,7 +101,7 @@ The `mxcall` function accepts the name of the function as the first argument and
97
101
98
102

99
103
100
-
The packagealso provides string syntax, that allows writing the code in Matlab syntax. The previous example can be rewritten as follows.
104
+
Like the RCall.jl package, the MATLAB.jl package also provides string syntax that allows for Matlab syntax. The previous example can be rewritten as follows.
101
105
102
106
```julia
103
107
using MATLAB, BSON
@@ -107,5 +111,3 @@ mat"""
107
111
MakeVideo($(X), 30, "Video2.gif");
108
112
"""
109
113
```
110
-
111
-
Note that we use multiline string syntax as in the case of R.
Copy file name to clipboardExpand all lines: docs/src/lecture_04/standardlibrary.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Note that for `D+I` and `D-I`, the matrix `D` must be square.
64
64
65
65
## Random
66
66
67
-
The last package that we will describe in more detail is the [Random](https://docs.julialang.org/en/v1/stdlib/Random/) package. This package provides more functionality for generating random numbers in Julia. The package allows setting the seed for the random generator using the `seed!` function. The `seed!` function is used to create a reproducible code that contains randomly generated values.
67
+
The last package that we will describe in more detail is the [Random](https://docs.julialang.org/en/v1/stdlib/Random/) package. This package provides advanced functionality for generating random numbers in Julia. The package allows setting the seed for the random generator using the `seed!` function. The `seed!` function is used to create a reproducible code that contains randomly generated values.
0 commit comments