Julia Lightning Round MIT IAP Tutorial January 15, 2013 Doug Bates Jeff Bezanson Britni Crocker Iain Dunning Alan Edelman

Keno Fischer Stefan Karpinski Miles Lubin Jameson Nash Viral Shah John Myles White

Quitting • Two ways to quit the interactive session – (known as a REPL: Read-Eval-Print-Loop)

D • quit()  Need Parens • Clear the current Command at the prompt: • C

Julia Documentation • Well written! – http://docs.julialang.org/en/latest/

• google: julia documentation • Much of Julia is written (elegantly!) in Julia – it won’t take you long before you start looking at Julia to learn Julia – When you are ready: google “julia source” and click on “base” or “examples” and browse around

Indexing: 1 based Square brackets • • • •

A=rand(5,5) A[1,1] rand(5,5)[1,1] Remember – parens for functions, – square brackets for indexing

Comprehensions (elegant “array constructors”) • • • • •

[i for i=1:5] [trace(rand(n,n)) for n=1:5] x=rand(10); [ x[i]+x[i+1] for i=1:9 ] {eye(n) for n=1:5} [i+j for i=1:5, j=1:5] • Vision: automatic parallelism

Parentheses also used for multiple outputs • A=rand(5,6); • svd(A) • (u,s,v)=ans – Notice that s is a vector

• type #tab completion • ndims(u), typeof(u) • ndims(s), typeof(s)

Ternary Operator • si(x) = (x>0) ? 1 : -1 • si(x) = (x>0) ? 1 : ((x<0) ? -1: 0) # Chained “sign” (Comment: “#”)

Complex Numbers • • • • • • •

im typeof(2im) typeof(2.0im) complex(3,4) complex(3,4.0) #multiple dispatch (more later) sqrt(-1) sqrt(complex(-1))

Issues Culture

• Old days: wait for a new release • Julia: easy bugs fixed at the speed of light, Press me: rationale explained Don’t be shy • No newbie question too embarrassing https://github.com/JuliaLang/julia/issues

Vectors • • • •

A=rand(5,5) v=rand(5,1) ; w=rand(5) typeof(v) # Array{Float64,1} typeof(1.0 : 5) #Range1{Float64} w=1.0: 5; A*w; #error (maybe shouldn’t be?) w=[1.0:5]; A*w; #ok

• ones(5) #vector! • eye(5) #matrix (makes sense!)

running a file • include(“file.jl”) – note that commands without semicolons won’t print without “println” (print line)

deploy.jl

Deployment

n=int(ARGS[1]) println(randn(n,n)) • in shell: • ./julia deploy.jl 5

• (lots more in “Getting Started” doc)

dice

.. or even better

#! fullpath/julia n=int(ARGS[1]) println(randn(n,n)) count=0 for i=1:n a=randi(6,3) count += (3==length(unique(a))) end println(count/n)

• in shell: • chmod +x dice • ./dice 1000

Outside Calls • Shell – run(`cal`) – run(`cal` | `grep Sa`)

• C-function call – ccall(:clock, Int32, ()) – bytestring(ccall(:ctime, Ptr{Uint8}, ()))

Punctuation Review () Parentheses: Function Calls Required! quit(),tic(),toc(),help() Output Arguments [] Brackets: Indexing Array Constructors Comprehensions {} Braces: Any Arrays

Packages • check out all the available packages off of docs.julialang.org • Click, for example, on Calendar and get to the github project page Pkg.add(“Calendar”) #Only first time using Calendar #Calendar exists now Calendar.now() now()

Packages (cont) • • • • • • • • • •

now() Calendar. quit() # get out of julia and back in now # find line number in source #click on “src” typeof(now()) n=now() n.tz n.millis z=convert(Array, @parallel [ Calendar.now().millis for x=1:10]);z-mean(z)

Interesting Type strang(n)=SymTridiagonal(2*ones(n),-ones(n-1)) lit=strang(500) big=full(strang(500)) @time eigvals(lit) @time eigvals(big) big+big; lit+lit; #watch it break import Base.+ xdump(lit) +(a::SymTridiagonal,b::SymTridiagonal)=SymTridiagonal(a.dv+ b.dv,a.ev+b.ev) lit+lit

Tasks (“produce”) “pause” and “play” later function stepbystep() for n=1:3 produce(n^2) end end

p=Task(stepbystep); consume(p) consume(p) consume(p) consume(p) #What should happen now?

Parallelism (more later) • • • •

julia –p 5 #5 local processes julia –machinefile file #hosts in file addprocs_local(5) #inside a julia session @parallel #execute using every processor

Design Decisions • Return type should not depend on value • sqrt(-1) #error • anothersqrt(x) = x<0 ? sqrt(complex(x)) : sqrt(x) • [anothersqrt(x) for x=-2:3]

IAP 2013 Julia Tutorial Schedule - GitHub

Jan 15, 2013 - Punctuation Review. () Parentheses: Function Calls. Required! quit(),tic(),toc(),help() ... julia –machinefile file #hosts in file. • addprocs_local(5) ...

348KB Sizes 6 Downloads 293 Views

Recommend Documents

DSQSS Tutorial 2015.12.01 - GitHub
Dec 1, 2015 - Step1 :Choose a site and an imaginary time point. Step2 :Put a worm pair. if no, go to Step4. Step3 :The worm-head moving. When the head ...

Epic Vim Tutorial - GitHub
Jan 19, 2012 - Move back to the start of the first email address in the file. 7. Press Ctrl+v to enter visual block mode. 8. Using the arrow keys, select all email ...

Monteleone Pierangeli Allocation criteria for Pillar 2 IAP 2013.pdf ...
allocation system endorsing the current distribution. of resources, which largely reflects the past spending. framework, and disregarding the use of objective cri- ...

Tutorial OpenPIV - GitHub
Sep 6, 2012 - ... is an open source Particle Image Velocimetry (PIV) analysis software ... the visualization of the vectors but it has to be taken into account ...

Custom Skin Tutorial - GitHub
dashboard.html – defines all dashboard elements supported by the skin .... There are two ways to display numbers: as a string value or as an analog meter.

Metaparse tutorial - GitHub
"a.*a" int main(). { string s; cin

BamTools API Tutorial - GitHub
Mar 23, 2011 - https://github.com/pezmaster31/bamtools/wiki/BamTools-1x_PortingGuide.pdf ... adjust how your app locates the shared library at runtime.

GNU gdb Tutorial - GitHub
The apropos command can be used to find commands. 3. Basic Debugging .... exist in your program; they are assigned by GDB to give you a way of designating ...

Vulkan Tutorial - GitHub
cross-platform and allows you to develop for Windows, Linux and Android at ..... to be described explicitly, there is no default color blend state, for example. 10 ...

WiFiMCU Tutorial - GitHub
2, Quickly Start with WiFiMCU STUDIO ................................................................................. 3 .... 2 Breathing LED -use PWM module . .... Content-Type:text/html. 7.

Cryptography Tutorial Contents - GitHub
In Erlang to encode some data we might do something like: Bin1 = encrypt(Bin, SymKey), ...... Trying all the small strings on your hard disk to see if they are passwords. • Analyzing the swap .... http://cr.yp.to/highspeed/ · coolnacl-20120725.pdf.

Tutorial for Overture/VDM++ - GitHub
Sep 6, 2015 - Overture Technical Report Series. No. TR-004. September ... Year Version Version of Overture.exe. January. 2010. 0.1.5 ... Contents. 3 Overture Tool Support for VDM++. 1. 3.1 Introduction . .... classes and their usage in class diagrams

wavez 2013- schedule -
Robo-Oceana. 9AM to 12 noon. Wavez quiz finals. 11AM to 12noon. Project X. 12:30PM to 2:30PM. Research Expo. 1PM to 3PM. House Structures Fail. 2:30PM ...

2013 Schedule L.pdf
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. 2013 Schedule L.pdf. 2013 Schedule L.pdf. Open. Extract.

Vowpal Wabbit 7 Tutorial - GitHub
Weight 1 by default. – Label: use {-1,1} for classification, or any real value for regression. 1 | 1:0.43 5:2.1 10:0.1. -1 | I went to school. 10 | race=white sex=male ...

Normalized Online Learning Tutorial - GitHub
Normalized Online Learning Tutorial. Paul Mineiro joint work with Stephane Ross & John Langford. December 9th, 2013. Paul Mineiro. Normalized Online ...

D Templates: A Tutorial - GitHub
In the next chapters, you'll see how to define function, struct and class templates. ...... can find on the D Programming Language website, but they act in a natural ...... opDispatch is a sort of operator overloading (it's in the same place in the o

Problem Tutorial: “Apples” - GitHub
careful when finding x, cause the multiplication might not fit in the limits of long long. Also don't the forget the case when there's no answer. Page 1 of 1.

Tutorial Schedule 2016.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Tutorial ...

Maui Bus Schedule as PDF - GitHub
Harbor Lights / UH Maui College. 6:38. 7:38. 8:38. 9:38. 10:38. 11:38. 12:38. 1:38. 2:38. 3:38. 4:38. 5:38. 6:38. 7:38. 8:38. Roselani Place. 6:41. 7:41. 8:41. 9:41.

Nemo: a computer algebra package for Julia - GitHub
Jul 12, 2017 - Antic. ▷ Singular kernel (via Singular.jl). Generic algorithms: ▷ Residue rings. ▷ Fraction fields. ▷ Dense univariate polynomials. ▷ Sparse distributed multivariate polynomials. ▷ Dense linear algebra. ▷ Power series : a

MeqTrees Batch Mode: A Short Tutorial - GitHub
tdlconf.profiles is where you save/load options using the buttons at ... Section is the profile name you supply ... around the Python interface (~170 lines of code).

Tutorial for Overture/VDM-SL - GitHub
2010 1. 0.2. February. 2011 2. 1.0.0. April. 2013 3. 2.0.0. September 2015 4 ..... Figure 3.13: The generated pdf file with test coverage information .... the Overture documentation at http://overturetool.org/documentation/manuals.html for the.

Notes and Tutorial on GDB - GitHub
CSM Linux Users Group ... GDB can make use of special symbols in your program to help you debug. ... exists and is up to date, and if so, call the debugger.