Mais conteúdo relacionado
Semelhante a 20190907 Julia the language for future (20)
20190907 Julia the language for future
- 10. a = [1, 2, 3, 4, 5]
function square(x)
return x^2
end
for x in a
println(square(x))
end
10
- 33. for i = 1:100000
do_something()
end
@parallel for i = 1:100000
do_something()
end
37
- 34. Julia mode:
julia> using Pkg
julia> Pkg.update()
julia> Pkg.add(“Foo”)
julia> Pkg.rm(“Foo”)
38
Pkg mode:
v(1.1) pkg> update
v(1.1) pkg> add Foo
v(1.1) pkg> rm Foo
- 35. julia> @code_native add(1, 2)
.text
Filename: REPL[2]
pushq %rbp
movq %rsp, %rbp
Source line: 2
leaq (%rcx,%rdx), %rax
popq %rbp
retq
nopw (%rax,%rax)
function add(a, b)
return a+b
end
39
- 36. julia> @code_llvm add(1, 2.0)
; Function Attrs: uwtable
define double @julia_add_71636(i64, double) #0 {
top:
%2 = sitofp i64 %0 to double
%3 = fadd double %2, %1
ret double %3
}
function add(a, b)
return a+b
end
40
- 43. julia> using DataFrames
julia> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4× 2 DataFrame
│ Row │ A │ B │
├─────┼───┼───┤
│ 1 │ 1 │ M │
│ 2 │ 2 │ F │
│ 3 │ 3 │ F │
│ 4 │ 4 │ M │
56
- 45. julia> df = readtable("data.csv")
julia> df = DataFrame(A = 1:10);
julia> writetable("output.csv", df)
58
- 46. julia> names = DataFrame(ID = [1, 2], Name = ["John Doe",
"Jane Doe"])
julia> jobs = DataFrame(ID = [1, 2], Job = ["Lawyer",
"Doctor"])
julia> full = join(names, jobs, on = :ID)
2× 3 DataFrame
│ Row │ ID │ Name │ Job │
├─────┼────┼──────────┼────────┤
│ 1 │ 1 │ John Doe │ Lawyer │
│ 2 │ 2 │ Jane Doe │ Doctor │ 59
- 47. julia> q1 = @from i in df begin
@where i.age > 40
@select {number_of_children=i.children, i.name}
@collect DataFrame
end
60
- 51. 64
julia> data = DataFrame(X=[1,2,3], Y=[2,4,7])
3x2 DataFrame
|-------|---|---|
| Row # | X | Y |
| 1 | 1 | 2 |
| 2 | 2 | 4 |
| 3 | 3 | 7 |
- 52. 65
julia> OLS = glm(@formula(Y ~ X), data, Normal(),
IdentityLink())
DataFrameRegressionModel{GeneralizedLinearModel,Float64}:
Coefficients:
Estimate Std.Error z value Pr(>|z|)
(Intercept) -0.666667 0.62361 -1.06904 0.2850
X 2.5 0.288675 8.66025 <1e-17
- 53. 66
julia> newX = DataFrame(X=[2,3,4]);
julia> predict(OLS, newX, :confint)
3× 3 Array{Float64,2}:
4.33333 1.33845 7.32821
6.83333 2.09801 11.5687
9.33333 1.40962 17.257
# The columns of the matrix are prediction, 95% lower and
upper confidence bounds
- 55. 68
# initialize the attractor
n = 1500
dt = 0.02
σ, ρ, β = 10., 28., 8/3
x, y, z = 1., 1., 1.
# initialize a 3D plot with 1 empty series
plt = plot3d(1, xlim=(-25,25), ylim=(-25,25), zlim=(0,50), xlab = "x",
ylab = "y", zlab = "z", title = "Lorenz Attractor", marker = 1)
# build an animated gif, saving every 10th frame
@gif for i=1:n
dx = σ*(y - x) ; x += dt * dx
dy = x*(ρ - z) - y ; y += dt * dy
dz = x*y - β*z ; z += dt * dz
push!(plt, x, y, z)
end every 10
- 69.
Next: Machine Learning and Deep Learning
on Quantum Computing
82
https://github.com/QuantumBFS/Yao.jl
- 73.
86
Objective types
• Linear
• Convex Quadratic
• Nonlinear (convex and
nonconvex)
Constraint types
• Linear
• Convex Quadratic
• Second-order Conic
• Semidefinite
• Nonlinear (convex and
nonconvex)
Variable types
• Continuous
• Integer-valued
• Semicontinuous
• Semi-integer
- 82. Lack of users and developers
Lack of internet resources