0 1 2 34
play

!"#$%&'()*(+,-.'%"-% /0-,+".%1,-#2,#'34% - PowerPoint PPT Presentation

!"#$%&'()*(+,-.'%"-% /0-,+".%1,-#2,#'34% 56789%#2'3:%1'.:2('% ;(*)6%<:'='-%>6%?*$-3*-% @AB%C&&1"'/%@,:$'+,:".3D%@AB%;$03".3% 1 Dynamic languages for interactive math The two-language


  1. !"#$%&'()*(+,-.'%"-% /0-,+".%1,-#2,#'34% 56789%#2'3:%1'.:2('% ;(*)6%<:'='-%>6%?*$-3*-% @AB%C&&1"'/%@,:$'+,:".3D%@AB%;$03".3% 1

  2. Dynamic languages for interactive math… The two-language approach: High-level dynamic language for productivity, + low-level language (C, Fortran, Cython, …) for performance-critical code. = Huge jump in complexity, loss of generality. 2

  3. Just vectorize your code? = rely on mature external libraries, operating on large blocks of data, for performance-critical code Good advice! But… • Someone has to write those libraries. • Eventually that person will be you. — some problems are impossible or just very awkward to vectorize. 3

  4. !"#$%"&'()'*++,#)"-*#).*)$/" !-*#"GH$-+*#" L,'*-"MN*N" 2"TUV"F" C$II"J$K*#A(#" 0.-,*-*#)1(')" M@$I*#"O*'&,#A>," 23$).#"45567"8519:",#"459;7"<=5>"?(++,@A7" 2";5P"H$Q$-(&$'A"%,@N"955P"?(++,@A7" 851B:"'$-$*A$",#"C.#$"459D7" 9555P"$R@$'#*-"&*?>*)$A7"= @N" C.-,*S(#",#"459D"F" 915"'$-$*A$",#"!.).A@"459E"F" !A"N,)NW-$Q$-"*#H",#@$'*?@,Q$"*A"T*@-*3"('"XY@N(#PUXY@N(#7" *A")$#$'*-W&.'&(A$"*A"XY@N(#7" *A"&'(H.?@,Q$"I('"@$?N#,?*-"%('>"*A"T*@-*3"('"XY@N(#PM?,XY7" 3.@"*A" !"#$%"#%& 1" 4

  5. !"#"$%&'#()*%#+"$,-#+"),%&$'."/) ('0"#)1)2)34 5 6)4 7 6)896)("#"$%&":) ;<,=>) ? numpy.vander @:) !"#$$#%&$'()*+& =>&A-#).-+") 8B$%C/)D).-+") 8)B$%C/)("#"$%&"+)D).-+") &>C"E("#"$'.)%&)A'(AEF"0"F6)G<&) F-B)F"0"F)F','&"+)&-)/,%FF)/"&)-H)&>C"/I) J$'&'#()H%/&).-+")K'#L)=>&A-#)-$)M%&F%G)2),'#'#()&A")/&%#+%$+)F'G$%$>) H-$)C$"EB$'&&"#)H<#.&'-#/)?',CF","#&"+)'#)D)-$)N-$&$%#@I) OH)&A")C$-GF",)+-"/#P&)K0".&-$'Q"L)'#&-)G<'F&E'#)H<#.&'-#/6) 'H)>-<)A%0")&-)B$'&")>-<$)-B#)'##"$)F--C/)8)/<.R/)H-$)>-<I) 5

  6. !"#"$%&'#()*%#+"$,-#+"),%&$'."/) ('0"#)1)2)34 5 6)4 7 6)896)("#"$%&":) ;<,=>) ? numpy.vander @:) !"#$$#%&$'()*+& =>&A-#).-+") 8B$%C/)D).-+") 8)B$%C/)("#"$%&"+)D).-+") &>C"E("#"$'.)%&)A'(AEF"0"F6)G<&) F-B)F"0"F)F','&"+)&-)/,%FF)/"&)-H)&>C"/I) J<F'%)?&>C"E("#"$'.).-+"@:) function vander(x, n=length(x)) m = length(x) V = Array(eltype(x), m, n) for j = 1:m V[j,1] = one(x[j]) end for i = 2:n for j = 1:m V[j,i] = x[j] * V[j,i-1] end end return V end 6

  7. !"#"$%&'#()*%#+"$,-#+"),%&$'."/) function vander(x, n=length(x)) m = length(x) V = Array(eltype(x), m, n) #-&"0)1-$2/)3-$)%#4)).-#&%'#"$) for j = 1:m -3)%#4)&45")1'&6)789)-5"$%&'-#) V[j,1] = one(x[j]) :)5"$3-$,%#.");)'#3<"='>'<'&4) end for i = 2:n for j = 1:m V[j,i] = x[j] * V[j,i-1] end end return V end 7

  8. Special Functions in Julia Special functions s(x): classic case that cannot be vectorized well … switch between various polynomials depending on x Many of Julia’s special functions come from the usual C/Fortran libraries, but some are written in pure Julia code. Pure Julia erfinv(x) [ = erf –1 (x) ] 3–4× faster than Matlab’s and 2–3× faster than SciPy’s (Fortran Cephes). Pure Julia polygamma(m, z) [ = (m+1) th derivative of the ln Γ function ] ~ 2× faster than SciPy’s (C/Fortran) for real z … and unlike SciPy’s, same code supports complex argument z Julia code can actually be faster than typical “optimized” C/Fortran code, by using techniques [metaprogramming/codegen generation] that are hard in a low-level language. 8

  9. Why can Julia be fast? First need to understand: Why is Python slow? goto Jupyter/IJulia notebooks from 18.S096. 9

  10. MIT OpenCourseWare https://ocw.mit.edu 6.172 Performance Engineering of Software Systems Fall 2018 For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms. 10

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend