Successfully reported this slideshow.
Upcoming SlideShare
×

# プログラミング言語 Julia の紹介

26,469 views

Published on

プログラミング言語 Julia の簡単な紹介です

Published in: Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No

Are you sure you want to  Yes  No
• Dating direct: ♥♥♥ http://bit.ly/369VOVb ♥♥♥

Are you sure you want to  Yes  No

Are you sure you want to  Yes  No
• accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } .........................................................................................................................

Are you sure you want to  Yes  No
• accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } .........................................................................................................................

Are you sure you want to  Yes  No

### プログラミング言語 Julia の紹介

1. 1. プログラミング言語 の紹介 2014/9/16 Kentaro Iizuka Github: iizukak
2. 2. • 一言で言えば、科学技術計算向けの高速なLL • 数値計算 ∪ 確率統計 ∪ 機械学習 ∪ 画像処理 ∪ 等々
3. 3. ぱっと見、普通なLL function randmatstat(t) n = 5 v = zeros(t) w = zeros(t) for i=1:t a = randn(n,n) b = randn(n,n) c = randn(n,n) d = randn(n,n) P = [a b c d] Q = [a b; c d] v[i] = trace((P.'*P)^4) w[i] = trace((Q.'*Q)^4) end return (std(v)/mean(v), std(w)/ mean(w)) end function mandel(z) c = z maxiter = 80 for n = 1:maxiter if abs(z) > 2 return n-­‐1 end z = z^2 + c end return maxiter end
4. 4. もちろん対話環境有 \$ julia _ _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: http://docs.julialang.org _ _ _| |_ __ _ | Type "help()" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.3.0 (2014-­‐08-­‐20 20:43 UTC) _/ |__'_|_|_|__'_| | Official http://julialang.org/ release |__/ | x86_64-­‐apple-­‐darwin13.3.0 julia> 1 + 2 3 julia> ans 3 http://docs.julialang.org/en/release-0.3/manual/getting-started/
5. 5. でいいじゃん？
6. 6. CPython, R よりは速い http://julialang.org/benchmarks/
7. 7. NumPy, PyPy でいいじゃん？
8. 8. そ、そうかな…？ • 確かにNumPyは速い • 線形代数関係の使い勝手がよい、と思う • ユーザー数多い • だが、NumPyのソースコードを読むのは難易度高
9. 9. NumPy is 半分 C
10. 10. NumPy is 半分 C • 神によってチューニングされた C • 使うのは簡単だが、改造/改良は難易度高 • NumPy に限らず、LLで書いて遅いところはCで書 きなおすのは定石
11. 11. Julia is だいたい Julia だいたいJulia どうしてもなところはC
12. 12. function randmatstat(t) n = 5 v = zeros(t) w = zeros(t) for i=1:t a = randn(n,n) b = randn(n,n) c = randn(n,n) d = randn(n,n) P = [a b c d] Q = [a b; c d] v[i] = trace((P.'*P)^4) w[i] = trace((Q.'*Q)^4) end return (std(v)/mean(v), std(w)/ mean(w)) end struct double_pair randmatstat(int t) { dsfmt_t dsfmt; dsfmt_init_gen_rand(&dsfmt, 1234); int n = 5; struct double_pair r; double *v = (double*)calloc(t,sizeof(double)); double *w = (double*)calloc(t,sizeof(double)); double *a C = (double*)malloc((n)*(n)*sizeof(double)); double *b = (double*)malloc((n)*(n)*sizeof(double)); double *c = (double*)malloc((n)*(n)*sizeof(double)); double *d = (double*)malloc((n)*(n)*sizeof(double)); double *P = (double*)malloc((n)*(4*n)*sizeof(double)); double *Q = (double*)malloc((2*n)*(2*n)*sizeof(double)); double *PtP1 = (double*)malloc((4*n)*(4*n)*sizeof(double)); double *PtP2 = (double*)malloc((4*n)*(4*n)*sizeof(double)); double *QtQ1 = (double*)malloc((2*n)*(2*n)*sizeof(double)); double *QtQ2 = (double*)malloc((2*n)*(2*n)*sizeof(double)); for (int i=0; i < t; i++) { randmtzig_fill_randn(&dsfmt, a, n*n); randmtzig_fill_randn(&dsfmt, b, n*n); randmtzig_fill_randn(&dsfmt, c, n*n); randmtzig_fill_randn(&dsfmt, d, n*n); memcpy(P+0*n*n, a, n*n*sizeof(double)); memcpy(P+1*n*n, b, n*n*sizeof(double)); memcpy(P+2*n*n, c, n*n*sizeof(double)); memcpy(P+3*n*n, d, n*n*sizeof(double)); for (int j=0; j < n; j++) { for (int k=0; k < n; k++) { Q[2*n*j+k] = a[k]; Q[2*n*j+n+k] = b[k]; Q[2*n*(n+j)+k] = c[k]; Q[2*n*(n+j)+n+k] = d[k]; } } cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, n, n, 4*n, 1.0, P, 4*n, P, 4*n, 0.0, PtP1, 4*n); cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, 4*n, 4*n, 4*n, 1.0, PtP1, 4*n, PtP1, 4*n, 0.0, PtP2, 4*n); cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, 4*n, 4*n, 4*n, 1.0, PtP2, 4*n, PtP2, 4*n, 0.0, PtP1, 4*n); for (int j=0; j < n; j++) { v[i] += PtP1[(n+1)*j]; } cblas_dgemm(CblasColMajor, CblasTrans, CblasNoTrans, 2*n, 2*n, 2*n, 1.0, Q, 2*n, Q, 2*n, 0.0, QtQ1, 2*n); cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, 2*n, 2*n, 2*n, 1.0, QtQ1, 2*n, QtQ1, 2*n, 0.0, QtQ2, 2*n); Julia
13. 13. Julia プログラマは Julia 本体のコードが読める
14. 14. 低レイヤ層マンにも優しい julia> f(x) = x * x! f (generic function with 1 method)! ! julia> f(2.0)! 4.0! ! julia> code_llvm(f, (Float64,))! ! define double @julia_f662(double) {! top:! %1 = fmul double %0, %0, !dbg !3553! ret double %1, !dbg !3553! }! ♥ 出力される LLVM コードの チェックも楽
15. 15. Julia では、ドメインエキスパートと 速度マニアが一緒に仕事ができる。 これは大きな達成である。 Why I’m Betting on Julia By Evan Miller http://www.evanmiller.org/why-im-betting-on-julia.html
16. 16. 絶賛開発中 • 0.1 : 2013/02 • 0.2 : 2013/11 • 0.3 : 2014/08 • JuliaCon 2014 : 2014/06