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

0 1 2 34
SMART_READER_LITE
LIVE PREVIEW

!"#$%&'()*(+,-.'%"-% /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


slide-1
SLIDE 1

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

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

1

slide-2
SLIDE 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

slide-3
SLIDE 3

Just vectorize your code?

= rely on mature external libraries,

  • perating 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

slide-4
SLIDE 4

!"#$%"&'()'*++,#)"-*#).*)$/"

0.-,*-*#)1(')"

!-*#"GH$-+*#" L,'*-"MN*N" 2"TUV"F" C$II"J$K*#A(#" 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

slide-5
SLIDE 5

('0"#)1)2)3456)476)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

slide-6
SLIDE 6

!"#"$%&'#()*%#+"$,-#+"),%&$'."/)

;<,=>)?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

('0"#)1)2)3456)476)896)("#"$%&":)

6

slide-7
SLIDE 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]) end

:)5"$3-$,%#.");)'#3<"='>'<'&4)

for i = 2:n for j = 1:m V[j,i] = x[j] * V[j,i-1] end end return V end

7

slide-8
SLIDE 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

slide-9
SLIDE 9

Why can Julia be fast?

First need to understand: Why is Python slow? goto Jupyter/IJulia notebooks from 18.S096.

9

slide-10
SLIDE 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