In [1]:
for x in ARGS; println(x); end


/Users/utensil/Library/Jupyter/runtime/kernel-28d6ca25-a548-4761-a6ed-7b0076c765b8.json

In [2]:
println("Greetings! 你好! 안녕하세요?")


Greetings! 你好! 안녕하세요?

In [3]:
run(`julia --help`)


julia [switches] -- [programfile] [args...]
 -v, --version             Display version information
 -h, --help                Print this message

 -J, --sysimage <file>     Start up with the given system image file
 --precompiled={yes|no}    Use precompiled code from system image if available
 -H, --home <dir>          Set location of julia executable
 --startup-file={yes|no}   Load ~/.juliarc.jl
 -f, --no-startup          Don't load ~/.juliarc (deprecated, use --startup-file=no)
 -F                        Load ~/.juliarc (deprecated, use --startup-file=yes)
 --handle-signals={yes|no} Enable or disable Julia's default signal handlers

 -e, --eval <expr>         Evaluate <expr>
 -E, --print <expr>        Evaluate and show <expr>
 -P, --post-boot <expr>    Evaluate <expr>, but don't disable interactive mode (deprecated, use -i -e instead)
 -L, --load <file>         Load <file> immediately on all processors

 -p, --procs {N|auto}      Integer value N launches N additional local worker processes
                           "auto" launches as many workers as the number of local cores
 --machinefile <file>      Run processes on hosts listed in <file>

 -i                        Interactive mode; REPL runs and isinteractive() is true
 -q, --quiet               Quiet startup (no banner)
 --color={yes|no}          Enable or disable color text
 --history-file={yes|no}   Load or save history
 --no-history-file         Don't load history file (deprecated, use --history-file=no)

 --compile={yes|no|all}    Enable or disable compiler, or request exhaustive compilation
 -C, --cpu-target <target> Limit usage of cpu features up to <target>
 -O, --optimize            Run time-intensive code optimizations
 --inline={yes|no}         Control whether inlining is permitted (overrides functions declared as @inline)
 --check-bounds={yes|no}   Emit bounds checks always or never (ignoring declarations)
 --math-mode={ieee,fast}   Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)

 --depwarn={yes|no|error}  Enable or disable syntax and method deprecation warnings ("error" turns warnings into errors)

 --output-o name           Generate an object file (including system image data)
 --output-ji name          Generate a system image data file (.ji)
 --output-bc name          Generate LLVM bitcode (.bc)

 --output-incremental=no   Generate an incremental output file (rather than complete)

 --code-coverage={none|user|all}, --code-coverage
                           Count executions of source lines (omitting setting is equivalent to "user")
 --track-allocation={none|user|all}, --track-allocation
                           Count bytes allocated by each source line

In [4]:
理念="idea"


Out[4]:
"idea"

In [6]:
println("$理念")


idea

In [7]:
π


Out[7]:
π = 3.1415926535897...

From Variables: Stylistic Conventions

While Julia imposes few restrictions on valid names, it has become useful to adopt the following conventions:

  • Names of variables are in lower case.
  • Word separation can be indicated by underscores ('_'), but use of underscores is discouraged unless the name would be hard to read otherwise.
  • Names of Types and Modules begin with a capital letter and word separation is shown with upper camel case instead of underscores.
  • Names of functions and macros are in lower case, without underscores.
  • Functions that write to their arguments have names that end in !. These are sometimes called “mutating” or “in-place” functions because they are intended to produce changes in their arguments after the function is called, not just return a value.

In [9]:
WORD_SIZE


Out[9]:
64

In [10]:
UInt


Out[10]:
UInt64

In [11]:
typeof(WORD_SIZE)


Out[11]:
Int64

In [12]:
typeof(π)


Out[12]:
Irrational{:π}

In [13]:
0b10


Out[13]:
0x02

In [14]:
0o10


Out[14]:
0x08

In [15]:
for T in [Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128]
    println("$(lpad(T,7)): [$(typemin(T)),$(typemax(T))]")
end


   Int8: [-128,127]
  Int16: [-32768,32767]
  Int32: [-2147483648,2147483647]
  Int64: [-9223372036854775808,9223372036854775807]
 Int128: [-170141183460469231731687303715884105728,170141183460469231731687303715884105727]
  UInt8: [0,255]
 UInt16: [0,65535]
 UInt32: [0,4294967295]
 UInt64: [0,18446744073709551615]
UInt128: [0,340282366920938463463374607431768211455]

In [17]:
typemax(Int64) + 1 == typemin(Int64)


Out[17]:
true

In [18]:
typemax(UInt64) + 1 == typemin(UInt64)


Out[18]:
true

In [19]:
div(typemax(Int64), 0)


LoadError: DivideError: integer division error
while loading In[19], in expression starting on line 1

 in div at /opt/homebrew-cask/Caskroom/julia/0.4.5/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib

In [21]:
@printf "%ld" typemin(Int64)
div(typemin(Int64), -1)


-9223372036854775808
LoadError: DivideError: integer division error
while loading In[21], in expression starting on line 2

 in div at /opt/homebrew-cask/Caskroom/julia/0.4.5/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib

In [37]:
0x.1p0 == (1.0/16.0)


Out[37]:
true

In [43]:
0x.1p1 == (1.0/16.0) * 2^1


Out[43]:
true

In [44]:
sizeof(0x.1p0)


Out[44]:
8

In [45]:
1/Inf


Out[45]:
0.0

In [46]:
sizeof(Inf)


Out[46]:
8

In [47]:
0/0


Out[47]:
NaN

In [48]:
2 * Inf


Out[48]:
Inf

In [49]:
Inf^Inf


Out[49]:
Inf

In [51]:
Inf / Inf


Out[51]:
NaN

In [52]:
0 * Inf


Out[52]:
NaN

In [53]:
(typemin(Float64),typemax(Float64))


Out[53]:
(-Inf,Inf)

In [56]:
eps(Float32),eps(Float64), eps(Float32) / eps(Float64)


Out[56]:
(1.1920929f-7,2.220446049250313e-16,5.36870912e8)

In [57]:
nextfloat(π)


LoadError: MethodError: `nextfloat` has no method matching nextfloat(::Irrational{:π})
while loading In[57], in expression starting on line 1

In [58]:
nextfloat(3.141592653)


Out[58]:
3.1415926530000005

In [59]:
1.1 + 0.1


Out[59]:
1.2000000000000002

In [60]:
with_rounding(Float64,RoundDown) do
    1.1 + 0.1
end


Out[60]:
1.2

In [61]:
1.1 + 0.1 == with_rounding(Float64,RoundDown) do
    1.1 + 0.1
end


Out[61]:
false

In [1]:
BigInt(typemax(Int64))*BigInt(12345678)


Out[1]:
113868781241213194875412146

In [2]:
parse(BigFloat, "1.23456789012345678901")


Out[2]:
1.234567890123456789010000000000000000000000000000000000000000000000000000000004

In [3]:
BigFloat(π)


Out[3]:
3.141592653589793238462643383279502884197169399375105820974944592307816406286198

In [7]:
factorial(BigInt(40))


Out[7]:
815915283247897734345611269596115894272000000000

In [8]:
@doc factorial


Out[8]:
..  factorial(n,k)

Compute ``factorial(n)/factorial(k)``
..  factorial(n)

Factorial of ``n``.  If ``n`` is an :obj:`Integer`, the factorial
is computed as an integer (promoted to at least 64 bits).  Note
that this may overflow if ``n`` is not small, but you can use
``factorial(big(n))`` to compute the result exactly in arbitrary
precision.  If ``n`` is not an ``Integer``, ``factorial(n)`` is
equivalent to :func:`gamma(n+1) <gamma>`.

In [9]:
x = 3


Out[9]:
3

In [10]:
2x^2 - 3x + 1


Out[10]:
10

In [11]:
1.5x^2 - .5x + 1


Out[11]:
13.0

In [12]:
2^2x


Out[12]:
64

In [13]:
(2^2)x


Out[13]:
12

In [47]:
print_type_info(T) = begin
    const COLUME_WIDTH = 20
    # TODO %s can't preserve literal
    @printf "%s:\n" T
    @printf "\t%s\t%s\n" rpad("zero:",COLUME_WIDTH) zero(T)
    @printf "\t%s\t%s\n" rpad("one:",COLUME_WIDTH) one(T)
    try
        @printf "\t%s\t%s\n" rpad("typemin:",COLUME_WIDTH) typemin(T)
        @printf "\t%s\t%s\n" rpad("typemax:",COLUME_WIDTH) typemax(T)
    catch e
        # do nothing
    end
end
    
for t in [Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128,BigInt]
    print_type_info(t)
end
for t in [Float16,Float32,Float64,BigFloat]
    print_type_info(t)
end


Int8:
	zero:               	0
	one:                	1
	typemin:            	-128
	typemax:            	127
Int16:
	zero:               	0
	one:                	1
	typemin:            	-32768
	typemax:            	32767
Int32:
	zero:               	0
	one:                	1
	typemin:            	-2147483648
	typemax:            	2147483647
Int64:
	zero:               	0
	one:                	1
	typemin:            	-9223372036854775808
	typemax:            	9223372036854775807
Int128:
	zero:               	0
	one:                	1
	typemin:            	-170141183460469231731687303715884105728
	typemax:            	170141183460469231731687303715884105727
UInt8:
	zero:               	0
	one:                	1
	typemin:            	0
	typemax:            	255
UInt16:
	zero:               	0
	one:                	1
	typemin:            	0
	typemax:            	65535
UInt32:
	zero:               	0
	one:                	1
	typemin:            	0
	typemax:            	4294967295
UInt64:
	zero:               	0
	one:                	1
	typemin:            	0
	typemax:            	18446744073709551615
UInt128:
	zero:               	0
	one:                	1
	typemin:            	0
	typemax:            	340282366920938463463374607431768211455
BigInt:
	zero:               	0
	one:                	1
Float16:
	zero:               	0.0
	one:                	1.0
	typemin:            	-Inf
	typemax:            	Inf
Float32:
	zero:               	0.0
	one:                	1.0
	typemin:            	-Inf
	typemax:            	Inf
Float64:
	zero:               	0.0
	one:                	1.0
	typemin:            	-Inf
	typemax:            	Inf
BigFloat:
	zero:               	0.000000000000000000000000000000000000000000000000000000000000000000000000000000
	one:                	1.000000000000000000000000000000000000000000000000000000000000000000000000000000
	typemin:            	-inf
	typemax:            	inf

In [48]:
one(Float32)


Out[48]:
1.0f0

In [50]:
one(Float64)


Out[50]:
1.0

In [51]:
1 / 2


Out[51]:
0.5

In [52]:
typeof(1 / 2)


Out[52]:
Float64

In [53]:
2 \ 1


Out[53]:
0.5

In [54]:
100 % 33


Out[54]:
1

In [58]:
bits(~0b1010101010101010)


Out[58]:
"0101010101010101"

In [59]:
bits(0b11 & 0b10)


Out[59]:
"00000010"

In [60]:
bits(0b11 | 0b10)


Out[60]:
"00000011"

In [63]:
bits(0b1010 $ 0b1100) # xor


Out[63]:
"00000110"

In [65]:
1 >> 2 == 1 >>> 2 # TODO what's the difference?


Out[65]:
true

In [66]:
isequal(1 >> 2, 1 >>> 2)


Out[66]:
true

In [67]:
1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5


Out[67]:
true

In [68]:
Float32(π)


Out[68]:
3.1415927f0

In [69]:
Float64(π)


Out[69]:
3.141592653589793

In [71]:
cos(1 + 2im) == cos(complex(1, 2))


Out[71]:
true

In [72]:
complex(Inf, NaN)


Out[72]:
Inf + NaN*im

In [73]:
typeof(2//3)


Out[73]:
Rational{Int64}

In [74]:
0.33 < 1//3


Out[74]:
true

In [75]:
str = "Hello, world.\n"


Out[75]:
"Hello, world.\n"

In [76]:
str[end]


Out[76]:
'\n'

In [77]:
str[end÷2]


Out[77]:
' '

In [78]:
str[end÷3]


Out[78]:
'l'

In [79]:
str[end÷3:end÷2]


Out[79]:
"lo, "

In [80]:
s = "\u2200 x \u2203 y"


Out[80]:
"∀ x ∃ y"

In [81]:
for i = 1:endof(s)
    try
        println(s[i])
    catch
        # ignore the index error
    end
end


∀
 
x
 
∃
 
y

In [82]:
for c in s
    println(c)
end


∀
 
x
 
∃
 
y

In [85]:
language="Julia"
"Hello $language\!" == string("Hello ", language, "!")


Out[85]:
true

In [86]:
"1 + 2 = $(1 + 2)"


Out[86]:
"1 + 2 = 3"

In [88]:
str = """
   Hello,
   $language.
 """


Out[88]:
"  Hello,\n  Julia.\n"

In [1]:
last_index = -1
while last_index != 0
    last_index = last_index < 0 ? search("xylophone", 'o') : search("xylophone", 'o', last_index + 1)
    @printf "%d\n" last_index
end


4
7
0

In [2]:
repeat(".:Z:.", 10)


Out[2]:
".:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:."

In [4]:
join(["apples", "bananas", "pear", "pineapples"], ", ", " and ")


Out[4]:
"apples, bananas, pear and pineapples"

In [8]:
regex = r"^\s*(?:#|$)"


Out[8]:
r"^\s*(?:#|$)"

In [9]:
ismatch(regex, "not a comment")


Out[9]:
false

In [10]:
ismatch(regex, "# a comment")


Out[10]:
true

In [11]:
typeof(regex)


Out[11]:
Regex

In [14]:
m = match(r"^\s*(?:#\s*(.*?)\s*$|$)", "# a comment")


Out[14]:
RegexMatch("# a comment", 1="a comment")

In [15]:
m[1]


Out[15]:
"a comment"

In [16]:
m.match


Out[16]:
"# a comment"

In [17]:
m.captures


Out[17]:
1-element Array{Union{SubString{UTF8String},Void},1}:
 "a comment"

In [18]:
m.offsets


Out[18]:
1-element Array{Int64,1}:
 3

In [27]:
replace("first second third", r"^(\w+) (?P<agroup>\w+)", s"\g<agroup> \1")


Out[27]:
"second first third"

In [28]:
replace("first second third", r"(\w+) (?P<agroup>\w+)$", s"\g<agroup> \1")


Out[28]:
"first third second"

In [29]:
b"DATA\xff\u2200"


Out[29]:
8-element Array{UInt8,1}:
 0x44
 0x41
 0x54
 0x41
 0xff
 0xe2
 0x88
 0x80

In [31]:
bits('\u2200')


Out[31]:
"00000000000000000010001000000000"

In [33]:
bits('\xe2\x88\x80')


Out[33]:
"00000000000000000010001000000000"

In [38]:
function f(x,y)
  x + y
end
  = f


Out[38]:
f (generic function with 1 method)

In [39]:
f(2, 3) ==  (2, 3)


Out[39]:
true

In [40]:
function hypot(x,y)
  x = abs(x)
  y = abs(y)
  if x > y
    r = y/x
    return x*sqrt(1+r*r)
  end
  if y == 0
    return zero(x)
  end
  r = x/y
  return y*sqrt(1+r*r)
end


Out[40]:
hypot (generic function with 1 method)

In [41]:
hypot(3, 4)


Out[41]:
5.0

In [42]:
+(1,2,3)


Out[42]:
6

In [43]:
fadd = +
fadd(1, 2, 3)


Out[43]:
6

In [45]:
[1 2 3]


Out[45]:
1x3 Array{Int64,2}:
 1  2  3

In [46]:
[1, 2, 3]


Out[46]:
3-element Array{Int64,1}:
 1
 2
 3

In [47]:
[1 2; 3 4; 5 6]


Out[47]:
3x2 Array{Int64,2}:
 1  2
 3  4
 5  6

In [48]:
hcat(1, 2, 3) == [1 2 3]


Out[48]:
true

In [49]:
vcat(1, 2, 3) == [1, 2, 3]


Out[49]:
true

In [58]:
hvcat( (2, 2, 2) , 1, 2, 3, 4, 5, 6) == [1 2; 3 4; 5 6]


Out[58]:
true

In [66]:
hvcat(2, 1, 2, 3, 4, 5, 6) == [1 2; 3 4; 5 6]


Out[66]:
true

In [71]:
mx = [1 2im; 3im 4; 5 6im]


Out[71]:
3x2 Array{Complex{Int64},2}:
 1+0im  0+2im
 0+3im  4+0im
 5+0im  0+6im

In [72]:
mx'


Out[72]:
2x3 Array{Complex{Int64},2}:
 1+0im  0-3im  5+0im
 0-2im  4+0im  0-6im

In [73]:
mx.'


Out[73]:
2x3 Array{Complex{Int64},2}:
 1+0im  0+3im  5+0im
 0+2im  4+0im  0+6im

In [75]:
1:100 == colon(1, 100)


Out[75]:
true

In [76]:
# See Functions: Operators With Special Names

In [77]:
x -> x^2 + 2x - 1


Out[77]:
(anonymous function)

In [78]:
function (x)
   x^2 + 2x - 1
end


Out[78]:
(anonymous function)

In [79]:
map(x -> x^2 + 2x - 1, [1,3,-1])


Out[79]:
3-element Array{Int64,1}:
  2
 14
 -2

In [80]:
function foo(a,b)
    a+b, a*b
end
foo(2, 3)


Out[80]:
(5,6)

In [81]:
bar(a,b,x...) = (a,b,x)
bar(1,2,3,4,5,6)


Out[81]:
(1,2,(3,4,5,6))

In [82]:
baz(a,b) = a + b
args = [1,2]
baz(args...)


Out[82]:
3

In [86]:
function bonus_add(a, b, c=5)
    a + b + c
end
bonus_add(2, 3) == bonus_add(2, 3, 5)


Out[86]:
true

In [91]:
function extra_add(a; b=3, c=5)
    a + b + c
end
extra_add(2, b=4, c=4) == extra_add(0, b=5) == extra_add(2)


Out[91]:
true

In [95]:
map(x->begin
           if x < 0 && iseven(x)
               return 0
           elseif x == 0
               return 1
           else
               return x
           end
       end,
[1, 2, 3]) == map([1, 2, 3]) do x # Am I writing ruby? ^_^
    if x < 0 && iseven(x)
        return 0
    elseif x == 0
        return 1
    else
        return x
    end
end # The do x syntax creates an anonymous function with argument x and passes it as the first argument


Out[95]:
true

In [101]:
begin
    x = 1
    y = 2
    x + y
end == (x = 1; y = 2; x + y)


Out[101]:
true

In [102]:
# Although it is typical, there is no requirement that begin blocks be multiline or that (;) chains be single-line
begin x = 1; y = 2; x + y end == (x = 1;
        y = 2;
        x + y)


Out[102]:
true

In [105]:
function test_order(x, y)
 if x < y
   println("$x is less than $y")
 elseif x > y
   println("$x is greater than $y")
 else
   println("$x is equal to $y")
 end
end


Out[105]:
test_order (generic function with 1 method)

In [106]:
test_order(1, 3)


1 is less than 3

if blocks are “leaky”, i.e. they do not introduce a local scope. This means that new variables defined inside the ìf clauses can be used after the if block, even if they weren’t defined before.


In [107]:
function test_order_leaky(x,y)
 if x < y
   relation = "less than"
 elseif x == y
   relation = "equal to"
 end
 println("$x is ", relation, " $y.")
end


Out[107]:
test_order_leaky (generic function with 1 method)

In [110]:
test_order_leaky(1, 3)


1 is less than 3.

In [111]:
test_order_leaky(11, 3)


LoadError: UndefVarError: relation not defined
while loading In[111], in expression starting on line 1

 in test_order_leaky at In[107]:7

In [112]:
5 > 1 && println("5 > 1")


5 > 1

In [113]:
4 < 1 || println("false")


false

In [114]:
i = 1
while i <= 5
 println(i)
 i += 1
end


1
2
3
4
5

In [116]:
for j=1:5; println(j); end


1
2
3
4
5

In [117]:
for s in ["foo","bar","baz"]
 println(s)
end


foo
bar
baz

In [119]:
# OH! This is AWESOME!
for i = 1:2, j in ["apple", "banana", "pear"]
 println((i, j))
end


(1,"apple")
(1,"banana")
(1,"pear")
(2,"apple")
(2,"banana")
(2,"pear")

In [120]:
positive_exp(x) = x>=0 ? exp(-x) : throw(DomainError())


Out[120]:
positive_exp (generic function with 1 method)

In [121]:
positive_exp(1)


Out[121]:
0.36787944117144233

In [122]:
positive_exp(-100)


LoadError: DomainError:
while loading In[122], in expression starting on line 1

 in positive_exp at In[120]:1

In [123]:
typeof(DomainError()) <: Exception


Out[123]:
true

In [125]:
throw(UndefVarError(:a_missing_variable))


LoadError: UndefVarError: a_missing_variable not defined
while loading In[125], in expression starting on line 1

In [126]:
fussy_sqrt(x) = x >= 0 ? sqrt(x) : error("negative x not allowed")


Out[126]:
fussy_sqrt (generic function with 1 method)

In [127]:
fussy_sqrt(100)


Out[127]:
10.0

In [128]:
fussy_sqrt(-250)


LoadError: negative x not allowed
while loading In[128], in expression starting on line 1

 in fussy_sqrt at In[126]:1

In [129]:
function verbose_fussy_sqrt(x)
 println("before fussy_sqrt")
 r = fussy_sqrt(x)
 println("after fussy_sqrt")
 return r
end


Out[129]:
verbose_fussy_sqrt (generic function with 1 method)

In [130]:
verbose_fussy_sqrt(-1)


before fussy_sqrt
LoadError: negative x not allowed
while loading In[130], in expression starting on line 1

 in verbose_fussy_sqrt at In[129]:3

In [131]:
info("Hi"); 1+1
warn("Hi"); 1+1
error("Hi"); 1+1


INFO: Hi
WARNING: Hi
LoadError: Hi
while loading In[131], in expression starting on line 3

In [132]:
try error() end #Returns nothing

In [133]:
try
    println("step 1 ok")
    error("step 2 failed")
    println("step 3 was never reached")
catch e
    if isa(e, DomainError)
        # Obviously, it's not
    else
        println(e)
    end
finally
    println("step 4 is ensured")
end


step 1 ok
ErrorException("step 2 failed")
step 4 is ensured

In [134]:
# https://github.com/transcranial/jupyter-themer
run(`pip install jupyter-themer`)


Collecting jupyter-themer
  Downloading jupyter-themer-0.1.2.tar.gz
Requirement already satisfied (use --upgrade to upgrade): jupyter in /Users/utensil/miniconda2/lib/python2.7/site-packages (from jupyter-themer)
Requirement already satisfied (use --upgrade to upgrade): notebook in /Users/utensil/miniconda2/lib/python2.7/site-packages (from jupyter-themer)
Building wheels for collected packages: jupyter-themer
  Running setup.py bdist_wheel for jupyter-themer: started
  Running setup.py bdist_wheel for jupyter-themer: finished with status 'done'
  Stored in directory: /Users/utensil/Library/Caches/pip/wheels/de/60/66/02ff107061ba3f1122bc30954652709197d6cd66c0ccdcdfb0
Successfully built jupyter-themer
Installing collected packages: jupyter-themer
Successfully installed jupyter-themer-0.1.2

In [148]:
run(`jupyter-themer -c tomorrow-night-eighties`)


Custom jupyter notebook theme created - refresh any open jupyter notebooks to apply theme.

In [149]:
run(`jupyter-themer`)


Jupyter notebook reverted to default style.

In [150]:
function producer()
    produce("start")
    for n=1:4
        produce(2n)
    end
    produce("stop")
end


Out[150]:
producer (generic function with 1 method)

In [155]:
p = Task(producer)


Out[155]:
Task (runnable) @0x000000010d322620

In [156]:
for i=0:6
    got = consume(p)
    println("$(typeof(got)): $got")
end


ASCIIString: start
Int64: 2
Int64: 4
Int64: 6
Int64: 8
ASCIIString: stop
Tuple{}: ()

In [157]:
for got in Task(producer)
    println("$(typeof(got)): $got")
end


ASCIIString: start
Int64: 2
Int64: 4
Int64: 6
Int64: 8
ASCIIString: stop

In [158]:
p.state


Out[158]:
:done
Scope name block/construct introducing this kind of scope
global
module, baremodule, at interactive prompt (REPL)
local soft
for, while, list-comprehensions, try-catch-finally, let
hard
functions (either syntax, anonymous & do-blocks)
type, immutable, macro

In [162]:
let
    global x = "global"
    # a new scope
    let
        local x = "local_let"
        # not a new scope
        begin
            # not a new scope
            if x == "local_let"
                println(x)
            end
        end
        let
            local x = "local_let_2"
            println(x)
        end
    end
end
x


local_let
local_let_2
Out[162]:
"global"

for loops and comprehensions have the following behavior: any new variables introduced in their body scopes are freshly allocated for each loop iteration. This is in contrast to while loops which reuse the variables for all iterations. Therefore these constructs are similar to while loops with let blocks inside


In [163]:
i = 0
for i = 1:3
end
i  # here equal to 3


Out[163]:
3

In [164]:
x = 0
[ x for x=1:3 ]
x  # here still equal to 0


Out[164]:
0

In [3]:
i = 0
j = 3
while j > i
    println((i, j))
    j -= 1
end
(i, j)


(0,3)
(0,2)
(0,1)
Out[3]:
(0,0)

In [4]:
e


Out[4]:
e = 2.7182818284590...

In [5]:
const K = e * π


Out[5]:
8.539734222673566

In [6]:
(1+2)::Int


Out[6]:
3

In [12]:
function foo()
 x::Int8 = 100
 x
end


Out[12]:
foo (generic function with 1 method)

In [13]:
typeof(foo())


Out[13]:
Int8

In [20]:
local y::Int8 = 10


Out[20]:
10

In [21]:
y = 200


Out[21]:
200

In [22]:
y


Out[22]:
200

In [23]:
typeof(y)


Out[23]:
Int64

In [24]:
local y::Int8=200


LoadError: InexactError()
while loading In[24], in expression starting on line 1

 in convert at int.jl:172
abstract Number
abstract Real     <: Number
abstract AbstractFloat <: Real
abstract Integer  <: Real
abstract Signed   <: Integer
abstract Unsigned <: Integer

In [25]:
Integer <: Number


Out[25]:
true

In [26]:
Integer <: AbstractFloat


Out[26]:
false

In [27]:
bitstype 7 sevenbit


LoadError: invalid number of bits in type sevenbit
while loading In[27], in expression starting on line 1

In [28]:
bitstype 128 onetwoeightbits

In [29]:
bitstype 128 

In [30]:
sizeof()


Out[30]:
16

In [32]:
type footype
     bar
     baz::Int
     qux::Float64
end

In [36]:
ft = footype("bar", 8, 12.9)


Out[36]:
footype("bar",8,12.9)

In [37]:
footype("bar", 8, 12)


Out[37]:
footype("bar",8,12.0)

In [38]:
footype("bar", 8, "12.9")


LoadError: MethodError: `convert` has no method matching convert(::Type{Float64}, ::ASCIIString)
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Closest candidates are:
  call{T}(::Type{T}, ::Any)
  convert(::Type{Float64}, !Matched::Int8)
  convert(::Type{Float64}, !Matched::Int16)
  ...
while loading In[38], in expression starting on line 1

 in call at In[32]:2

In [39]:
typeof(ft)


Out[39]:
footype

In [40]:
fieldnames(ft)


Out[40]:
3-element Array{Symbol,1}:
 :bar
 :baz
 :qux

In [41]:
fieldnames(footype)


Out[41]:
3-element Array{Symbol,1}:
 :bar
 :baz
 :qux

In [42]:
ft.bar = 1//2


Out[42]:
1//2

Composite types with no fields are singletons; there can be only one instance of such types:


In [43]:
type NoFields
end

In [44]:
is(NoFields(), NoFields())


Out[44]:
true

In [45]:
immutable MyComplex
  real::Float64
  imag::Float64
end

In [46]:
c = MyComplex(12, 34)


Out[46]:
MyComplex(12.0,34.0)

In [47]:
c.real


Out[47]:
12.0

In [48]:
c.real = 13


LoadError: type MyComplex is immutable
while loading In[48], in expression starting on line 1

In [49]:
IntOrString = Union{Int,AbstractString}


Out[49]:
Union{AbstractString,Int64}

In [50]:
1 :: IntOrString


Out[50]:
1

In [51]:
"1" :: IntOrString


Out[51]:
"1"

In [52]:
1.0 :: IntOrString


LoadError: TypeError: typeassert: expected Union{AbstractString,Int64}, got Float64
while loading In[52], in expression starting on line 1

In [53]:
type MyPoint{T}
  x::T
  y::T
end

In [54]:
mp = MyPoint(1, 2)


Out[54]:
MyPoint{Int64}(1,2)

In [55]:
mp = MyPoint(1, "2")


LoadError: MethodError: `convert` has no method matching convert(::Type{MyPoint{T}}, ::Int64, ::ASCIIString)
This may have arisen from a call to the constructor MyPoint{T}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  MyPoint{T}(::T, !Matched::T)
  call{T}(::Type{T}, ::Any)
  convert{T}(::Type{T}, !Matched::T)
while loading In[55], in expression starting on line 1

 in call at essentials.jl:57

In [57]:
MyPoint{Float64} <: MyPoint


Out[57]:
true

In [58]:
Float64 <: Real


Out[58]:
true

In [59]:
MyPoint{Float64} <: MyPoint{Real}


Out[59]:
false

In [60]:
abstract Pointly{T}

In [61]:
Pointly{Int} <: Pointly


Out[61]:
true

In [63]:
type SpecificPoint{T} <: Pointly{T}
  x::T
  y::T
end

In [65]:
SpecificPoint{AbstractString} <: Pointly


Out[65]:
true

In [66]:
SpecificPoint("a", "b")


Out[66]:
SpecificPoint{ASCIIString}("a","b")

In [67]:
abstract RealPoint{T<:Real}

In [72]:
RealPoint{Float32} <: RealPoint


Out[72]:
true

In [73]:
Tuple{Int,AbstractString} <: Tuple{Real,Any}


Out[73]:
true

In [74]:
Tuple{Int,AbstractString} <: Tuple{Real,}


Out[74]:
false

In [77]:
(1.0, 1.0) :: Tuple{Vararg{Real}}


Out[77]:
(1.0,1.0)

In [78]:
isa(("1",1,2), Tuple{AbstractString,Vararg{Int}})


Out[78]:
true

In [79]:
isa(("1",1,2,3.0), Tuple{AbstractString,Vararg{Int}})


Out[79]:
false

In [81]:
isa(Float64, Type{Float64})


Out[81]:
true

In [82]:
isa(Float64, Type{Real})


Out[82]:
false

In [83]:
bitstype 64 MyPtr{T}

In [84]:
MyPtr{Float64} <: MyPtr{Real}


Out[84]:
false

In [85]:
MyPtr{Float64} <: MyPtr


Out[85]:
true

In [86]:
MyPtr{onetwoeightbits}


Out[86]:
MyPtr{onetwoeightbits}

In [88]:
typealias MyAliasPtr MyPtr


Out[88]:
MyPtr{T}

In [89]:
MyAliasPtr <: MyPtr


Out[89]:
true

In [90]:
MyPtr <: MyPtr


Out[90]:
true

In [91]:
Array{Float64,1} <: Array{Float64} <: Array


Out[91]:
true

In [92]:
typealias MyVector{T} Array{T,1}
typealias MyMatrix{T} Array{T,2}


Out[92]:
Array{T,2}

In [93]:
super(Float64)


Out[93]:
AbstractFloat

In [94]:
super(ans)


Out[94]:
Real

In [95]:
super(ans)


Out[95]:
Number

In [96]:
super(ans)


Out[96]:
Any

In [97]:
function firstlast(b::Bool)
    return b ? "First" : "Last"
end

println(firstlast(true))


First

In [98]:
firstlast(::Type{Val{true}}) = "First"
firstlast(::Type{Val{false}}) = "Last"


Out[98]:
firstlast (generic function with 3 methods)

In [99]:
@doc firstlast


Out[99]:

No documentation found.

firstlast is a generic Function.

# 3 methods for generic function "firstlast":
firstlast(b::Bool) at In[97]:2
firstlast(::Type{Val{true}}) at In[98]:1
firstlast(::Type{Val{false}}) at In[98]:2

In [106]:
firstlast(Val{true})


Out[106]:
"First"

In [107]:
firstlast(::Type{Val{3}}) = "3"


Out[107]:
firstlast (generic function with 4 methods)

In [108]:
firstlast(Val{3})


Out[108]:
"3"

In [109]:
firstlast(3)


LoadError: MethodError: `firstlast` has no method matching firstlast(::Int64)
while loading In[109], in expression starting on line 1

In [110]:
isnull(3)


LoadError: MethodError: `isnull` has no method matching isnull(::Int64)
while loading In[110], in expression starting on line 1

In [111]:
isnull(Nullable(3))


Out[111]:
false

In [112]:
get(Nullable{Float64}())


LoadError: NullException()
while loading In[112], in expression starting on line 1

 in get at nullable.jl:30

In [113]:
methods(display)


Out[113]:
20 methods for generic function display:

In [115]:
optional_function(a=1, b=2) = a + b


Out[115]:
optional_function (generic function with 3 methods)

In [116]:
methods(optional_function)


Out[116]:
3 methods for generic function optional_function:
  • optional_function() at In[115]:1
  • optional_function(a) at In[115]:1
  • optional_function(a, b) at In[115]:1

In [119]:
println("abc\ufff9abc\ufffbabc")


abcabcabc

In [122]:
println("abc\ufffaabc\ufffbabc")


abcabcabc

In [123]:
println("\u202eABCDE\u202dXYZ")


‮ABCDE‭XYZ

In [124]:
println("大字\u200d小字")


大字‍小字

In [125]:
Base.call(x::Number, arg) = x * arg


Out[125]:
call (generic function with 1094 methods)

In [126]:
a_number=10


Out[126]:
10

In [127]:
10(20)


Out[127]:
200

In [128]:
function emptyfunc
end


Out[128]:
emptyfunc (generic function with 0 methods)

In [1]:
type OrderedPair
  x::Real
  y::Real

  OrderedPair(x,y) = x > y ? error("out of order") : new(x,y)
end

In [2]:
OrderedPair(1, 2)


Out[2]:
OrderedPair(1,2)

In [3]:
OrderedPair(2, 1)


LoadError: out of order
while loading In[3], in expression starting on line 1

 in call at In[1]:5

In [4]:
type Foo
  bar
  baz

  Foo(bar,baz) = new(bar,baz)
end

In [1]:
type SelfReferential
  obj::SelfReferential
end

In [2]:
type BetterSelfReferential
  obj::BetterSelfReferential

  BetterSelfReferential() = (x = new(); x.obj = x)
end

In [4]:
sr = SelfReferential()


LoadError: MethodError: `convert` has no method matching convert(::Type{SelfReferential})
This may have arisen from a call to the constructor SelfReferential(...),
since type constructors fall back to convert methods.
Closest candidates are:
  convert{T}(::Type{T}, !Matched::T)
  SelfReferential(, !Matched::SelfReferential)
  SelfReferential(, !Matched::Any)
  ...
while loading In[4], in expression starting on line 1

 in call at essentials.jl:57

In [5]:
bsr = BetterSelfReferential()


Out[5]:
BetterSelfReferential(BetterSelfReferential(#= circular reference =#))

In [6]:
is(bsr, bsr.obj.obj)


Out[6]:
true

In some cases you could consider adding methods to Base.convert instead of defining a constructor, because defining a convert() method automatically defines a corresponding constructor, while the reverse is not true. That is, defining Base.convert(::Type{T}, args...) = ... automatically defines a constructor T(args...) = ....


In [7]:
type SummedArray{T<:Number,S<:Number}
    data::Vector{T}
    sum::S

    function call{T}(::Type{SummedArray}, a::Vector{T})
        S = widen(T)
        new{T,S}(a, sum(S, a))
    end
end

In [11]:
sa = SummedArray(Vector{Int32}([1, 2, 3]))


Out[11]:
SummedArray{Int32,Int64}(Int32[1,2,3],6)

In [12]:
sa.sum


Out[12]:
6
promote_rule(::Type{UInt8}, ::Type{Int8}) = Int
promote_rule(::Type{BigInt}, ::Type{Int8}) = BigInt

In [13]:
promote_type(Int8, UInt16)


Out[13]:
Int64
promote_rule{T<:Integer}(::Type{Rational{T}}, ::Type{T}) = Rational{T}
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)}
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)}
promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S)

In [14]:
immutable Squares
   count::Int
end
Base.start(::Squares) = 1
Base.next(S::Squares, state) = (state*state, state+1)
Base.done(S::Squares, s) = s > S.count;
Base.eltype(::Type{Squares}) = Int # Note that this is defined for the type
Base.length(S::Squares) = S.count;

In [15]:
for i in Squares(7)
   println(i)
end


1
4
9
16
25
36
49

In [16]:
length(Squares(100)) == 100


Out[16]:
true

In [17]:
25 in Squares(10)


Out[17]:
true

In [18]:
mean(Squares(100)), std(Squares(100))


Out[18]:
(3383.5,3024.355854282583)

In [19]:
collect(Squares(100))'


Out[19]:
1x100 Array{Int64,2}:
 1  4  9  16  25  36  49  64  81  100  …  9025  9216  9409  9604  9801  10000

In [21]:
Base.sum(S::Squares) = (n = S.count; return n*(n+1)*(2n+1)÷6)
       sum(Squares(1803))


Out[21]:
1955361914

In [23]:
1 + 2 | 3 == (1 + 2) | 3


Out[23]:
true

In [24]:
1 .* 2


Out[24]:
2
module MyModule
using Lib

using BigLib: thing1, thing2

import Base.show

importall OtherLib

export MyType, foo

type MyType
    x
end

bar(x) = 2x
foo(a::MyType) = bar(a.x) + 1

show(io, a::MyType) = print(io, "MyType $(a.x)")
end
module Parent

module Utils
...
end

using .Utils

...
end

In [25]:
?@time


Out[25]:
@time

A macro to execute an expression, printing the time it took to execute, the number of allocations, and the total number of bytes its execution caused to be allocated, before returning the value of the expression.


In [35]:
@time collect(Squares(300000000))'


  4.591638 seconds (10 allocations: 4.470 GB, 4.91% gc time)
Out[35]:
1x300000000 Array{Int64,2}:
 1  4  9  16  25  36  49  64  81  100  121  144  169  …  90000000000000000

to re-use documentation between different versions of a function:

@doc "..." foo!
@doc (@doc foo!) foo

In [36]:
foo = (x) -> 0


Out[36]:
(anonymous function)

In [37]:
@doc "fooing" foo

In [38]:
@doc foo


Out[38]:

fooing


In [39]:
"`abc` is just _ABC_ as we know"
abc = "abc"


Out[39]:

abc is just ABC as we know


In [40]:
@doc abc


Out[40]:

abc is just ABC as we know


In [1]:
intarray = Array(Int64, 100)


Out[1]:
100-element Array{Int64,1}:
 2190216240
 2153360720
 2153360736
 2153360752
 2153360768
 2225828400
 2225828432
 2225828528
 2205896976
 2225828592
 2222477008
 2206633168
 2206633232
          ⋮
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0
          0

In [2]:
intarray = zeros(Int64, 100)


Out[2]:
100-element Array{Int64,1}:
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 ⋮
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0
 0

In [3]:
eltype(intarray)


Out[3]:
Int64

In [4]:
length(intarray)


Out[4]:
100

In [5]:
ndims(intarray)


Out[5]:
1

In [6]:
size(intarray)


Out[6]:
(100,)

In [7]:
strides(intarray)


Out[7]:
(1,)

In [8]:
@doc strides


Out[8]:
strides(A)

Returns a tuple of the memory strides in each dimension


In [10]:
array = cell((3, 3))


Out[10]:
3x3 Array{Any,2}:
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef

In [11]:
m = zeros((3, 3))


Out[11]:
3x3 Array{Float64,2}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

In [12]:
size(m)


Out[12]:
(3,3)

In [13]:
size(m, 2)


Out[13]:
3

In [14]:
strides(m)


Out[14]:
(1,3)

In [15]:
rand(3)


Out[15]:
3-element Array{Float64,1}:
 0.262588
 0.68179 
 0.995355

In [17]:
randn(3)


Out[17]:
3-element Array{Float64,1}:
  1.62027
 -1.53208
  2.52513

In [18]:
@doc eye


Out[18]:
eye(m, n)

m-by-n identity matrix

eye(A)

Constructs an identity matrix of the same dimensions and type as A.

eye(n)

n-by-n identity matrix


In [19]:
ey = eye(3, 2)


Out[19]:
3x2 Array{Float64,2}:
 1.0  0.0
 0.0  1.0
 0.0  0.0

In [20]:
fm = fill(3, (3, 3))


Out[20]:
3x3 Array{Int64,2}:
 3  3  3
 3  3  3
 3  3  3
Expression Calls
[A; B; C; ...] vcat()
[A B C ...] hcat()
[A B; C D; ...] hvcat()

In [21]:
a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
 [a b c; d e f]


Out[21]:
2x3 Array{Int64,2}:
 1  2  3
 4  5  6

In [22]:
hvcat((3,3), a,b,c,d,e,f)


Out[22]:
2x3 Array{Int64,2}:
 1  2  3
 4  5  6

In [23]:
[a b;c d; e f]


Out[23]:
3x2 Array{Int64,2}:
 1  2
 3  4
 5  6

In [24]:
hvcat((2,2,2), a,b,c,d,e,f)


Out[24]:
3x2 Array{Int64,2}:
 1  2
 3  4
 5  6

In [25]:
@doc hvcat


Out[25]:
hvcat(rows::Tuple{Vararg{Int}}, values...)

Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.

jldoctest
julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1,2,3,4,5,6)

julia> [a b c; d e f]
2x3 Array{Int64,2}:
 1  2  3
 4  5  6

julia> hvcat((3,3), a,b,c,d,e,f)
2x3 Array{Int64,2}:
 1  2  3
 4  5  6

julia> [a b;c d; e f]
3x2 Array{Int64,2}:
 1  2
 3  4
 5  6

julia> hvcat((2,2,2), a,b,c,d,e,f)
3x2 Array{Int64,2}:
 1  2
 3  4
 5  6

If the first argument is a single integer n, then all block rows are assumed to have n block columns.

Indexing

The general syntax for indexing into an n-dimensional array A is:

X = A[I_1, I_2, ..., I_n]

where each I_k may be:

  1. A scalar integer
  2. A Range of the form a:b, or a:b:c
  3. A : or Colon() to select entire dimensions
  4. An arbitrary integer vector, including the empty vector []
  5. A boolean vector

The result X generally has dimensions (length(I_1), length(I_2), ..., length(I_n)), with location (i_1, i_2, ..., i_n) of X containing the value A[I_1[i_1], I_2[i_2], ..., I_n[i_n]]. Trailing dimensions indexed with scalars are dropped. For example, the dimensions of A[I, 1] will be (length(I),). Boolean vectors are first transformed with find; the size of a dimension indexed by a boolean vector will be the number of true values in the vector. As a special part of this syntax, the end keyword may be used to represent the last index of each dimension within the indexing brackets, as determined by the size of the innermost array being indexed.

Alternatively, single elements of a multidimensional array can be indexed as

x = A[I]

where I is a CartesianIndex, effectively an n-tuple of integers. See Iteration below.

Indexing syntax is equivalent to a call to getindex:

X = getindex(A, I_1, I_2, ..., I_n)

Example:

julia> x = reshape(1:16, 4, 4)
4x4 Array{Int64,2}:
 1  5   9  13
 2  6  10  14
 3  7  11  15
 4  8  12  16

julia> x[2:3, 2:end-1]
2x2 Array{Int64,2}:
 6  10
 7  11

Empty ranges of the form n:n-1 are sometimes used to indicate the inter-index location between n-1 and n. For example, the searchsorted() function uses this convention to indicate the insertion point of a value not found in a sorted array:

julia> a = [1,2,5,6,7];

julia> searchsorted(a, 3)
3:2

In [26]:
x = reshape(1:16, 4, 4)


Out[26]:
4x4 Array{Int64,2}:
 1  5   9  13
 2  6  10  14
 3  7  11  15
 4  8  12  16

In [27]:
x[2:3, 2:end-1]


Out[27]:
2x2 Array{Int64,2}:
 6  10
 7  11

In [28]:
3:2


Out[28]:
3:2

In [29]:
typeof(3:2)


Out[29]:
UnitRange{Int64}

In [30]:
typeof(1:50)


Out[30]:
UnitRange{Int64}

In [31]:
A = rand(4,3)
B = sub(A, 1:3, 2:3)
(A, B)


Out[31]:
(
4x3 Array{Float64,2}:
 0.897381  0.230063   0.999231 
 0.387111  0.0517558  0.188619 
 0.80081   0.984446   0.0437768
 0.169907  0.683732   0.517761 ,

3x2 SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},1}:
 0.230063   0.999231 
 0.0517558  0.188619 
 0.984446   0.0437768)

In [32]:
square(x) = x^2
 @vectorize_1arg Number square


Out[32]:
square (generic function with 4 methods)

In [33]:
methods(square)


Out[33]:
4 methods for generic function square:

In [34]:
square(A)


Out[34]:
4x3 Array{Float64,2}:
 0.805292   0.052929    0.998462 
 0.149855   0.00267866  0.035577 
 0.641296   0.969134    0.0019164
 0.0288685  0.467489    0.268077 

In [35]:
a = rand(2,1); A = rand(2,3);
(a, A)


Out[35]:
(
2x1 Array{Float64,2}:
 0.243233
 0.467999,

2x3 Array{Float64,2}:
 0.911001  0.851159  0.112441
 0.190415  0.946762  0.682602)

In [36]:
broadcast(+, a, A)


Out[36]:
2x3 Array{Float64,2}:
 1.15423   1.09439  0.355674
 0.658414  1.41476  1.1506  

In [37]:
b = rand(1,2)
broadcast(+, a, b)


Out[37]:
2x2 Array{Float64,2}:
 1.02773  1.03444
 1.2525   1.2592 

In [38]:
spzeros(3,5)


Out[38]:
3x5 sparse matrix with 0 Float64 entries:

In [39]:
speye(3,5)


Out[39]:
3x5 sparse matrix with 3 Float64 entries:
	[1, 1]  =  1.0
	[2, 2]  =  1.0
	[3, 3]  =  1.0

In [40]:
I = [1, 4, 3, 5]; J = [4, 7, 18, 9]; V = [1, 2, -5, 3];
S = sparse(I,J,V)


Out[40]:
5x18 sparse matrix with 4 Int64 entries:
	[1 ,  4]  =  1
	[4 ,  7]  =  2
	[5 ,  9]  =  3
	[3 , 18]  =  -5

In [41]:
findn(S)


Out[41]:
([1,4,5,3],[4,7,9,18])

In [42]:
findnz(S)


Out[42]:
([1,4,5,3],[4,7,9,18],[1,2,3,-5])

In [44]:
@doc findn


Out[44]:
findn(A)

Return a vector of indexes for each dimension giving the locations of the non-zeros in A (determined by A[i]!=0).


In [45]:
@doc findnz


Out[45]:
findnz(A)

Return a tuple (I, J, V) where I and J are the row and column indexes of the non-zero values in matrix A, and V is a vector of the non-zero values.


In [46]:
sparse(eye(5))


Out[46]:
5x5 sparse matrix with 5 Float64 entries:
	[1, 1]  =  1.0
	[2, 2]  =  1.0
	[3, 3]  =  1.0
	[4, 4]  =  1.0
	[5, 5]  =  1.0

In [47]:
issparse(speye(5))


Out[47]:
true

In [48]:
full(S)


Out[48]:
5x18 Array{Int64,2}:
 0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0   0
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0   0
 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  -5
 0  0  0  0  0  0  2  0  0  0  0  0  0  0  0  0  0   0
 0  0  0  0  0  0  0  0  3  0  0  0  0  0  0  0  0   0

Linear algebra

Matrix factorizations

Matrix factorizations (a.k.a. matrix decompositions) compute the factorization of a matrix into a product of matrices, and are one of the central concepts in linear algebra.

The following table summarizes the types of matrix factorizations that have been implemented in Julia. Details of their associated methods can be found in the Linear Algebra section of the standard library documentation.

Cholesky Cholesky factorization
CholeskyPivoted Pivoted Cholesky factorization
LU LU factorization
LUTridiagonal LU factorization for Tridiagonal matrices
UmfpackLU LU factorization for sparse matrices (computed by UMFPack)
QR QR factorization
QRCompactWY Compact WY form of the QR factorization
QRPivoted Pivoted QR factorization
Hessenberg Hessenberg decomposition
Eigen Spectral decomposition
SVD Singular value decomposition
GeneralizedSVD Generalized SVD

Special matrices

Matrices with special symmetries and structures arise often in linear algebra and are frequently associated with various matrix factorizations. Julia features a rich collection of special matrix types, which allow for fast computation with specialized routines that are specially developed for particular matrix types.

The following tables summarize the types of special matrices that have been implemented in Julia, as well as whether hooks to various optimized methods for them in LAPACK are available.

Hermitian Hermitian matrix
UpperTriangular Upper triangular matrix
LowerTriangular Lower triangular matrix
Tridiagonal Tridiagonal matrix
SymTridiagonal Symmetric tridiagonal matrix
Bidiagonal Upper/lower bidiagonal matrix
Diagonal Diagonal matrix
UniformScaling Uniform scaling operator

Elementary operations

Matrix type + - * \ Other functions with optimized methods
Hermitian       MV inv(), sqrtm(), expm()
UpperTriangular     MV MV inv(), det()
LowerTriangular     MV MV inv(), det()
SymTridiagonal M M MS MV eigmax(), eigmin()
Tridiagonal M M MS MV  
Bidiagonal M M MS MV  
Diagonal M M MV MV inv(), det(), logdet(), /()
UniformScaling M M MVS MVS /()

Legend:

M (matrix) An optimized method for matrix-matrix operations is available
V (vector) An optimized method for matrix-vector operations is available
S (scalar) An optimized method for matrix-scalar operations is available

Matrix factorizations

Matrix type LAPACK eig() eigvals() eigvecs() svd() svdvals()
Hermitian HE   ARI      
UpperTriangular TR A A A    
LowerTriangular TR A A A    
SymTridiagonal ST A ARI AV    
Tridiagonal GT          
Bidiagonal BD       A A
Diagonal DI   A      

Legend:

A (all) An optimized method to find all the characteristic values and/or vectors is available e.g. eigvals(M)
R (range) An optimized method to find the ilth through the ihth characteristic values are available eigvals(M, il, ih)
I (interval) An optimized method to find the characteristic values in the interval [vl, vh] is available eigvals(M, vl, vh)
V (vectors) An optimized method to find the characteristic vectors corresponding to the characteristic values x=[x1, x2,...] is available eigvecs(M, x)

The uniform scaling operator

A UniformScaling operator represents a scalar times the identity operator, λ*I. The identity operator I is defined as a constant and is an instance of UniformScaling. The size of these operators are generic and match the other matrix in the binary operations +, -, * and \. For A+I and A-I this means that A must be square. Multiplication with the identity operator I is a noop (except for checking that the scaling factor is one) and therefore almost without overhead.


In [49]:
I


Out[49]:
4-element Array{Int64,1}:
 1
 4
 3
 5

In [50]:
write(STDOUT,"Hello World")


Hello World
Out[50]:
11

In [ ]:
read(STDIN,Char)

In [ ]:
a

In [1]:
write(STDOUT,0x61)


a
Out[1]:
1

In [2]:
print(STDOUT,0x61)


97

In [4]:
open("hello.txt", "w") do f
    write(f, "Hello")
end


Out[4]:
5

In [6]:
open("hello.txt", "r") do f
    uppercase(readall(f))
end


Out[6]:
"HELLO"

In [7]:
running = true


Out[7]:
true

In [8]:
@async begin
    server = listen(2000)
    while running
       sock = accept(server)
       println("Hello World\n")
     end
end


Out[8]:
Task (waiting) @0x0000000082e2b490

In [9]:
connect(2000)


Out[9]:
TCPSocket(open, 0 bytes waiting)
Hello World


In [10]:
running = false


Out[10]:
false

In [11]:
connect(2000)


Out[11]:
TCPSocket(open, 0 bytes waiting)
Hello World


In [12]:
connect(2000)


Out[12]:
TCPSocket(open, 0 bytes waiting)
Hello World


In [1]:
listen(ip"127.0.0.1",2000)


Out[1]:
Base.TCPServer(active)

In [2]:
@async begin
         server = listen(2001)
         while true
           sock = accept(server)
           @async while isopen(sock)
             write(sock,readline(sock))
           end
         end
       end


Out[2]:
Task (waiting) @0x00000000827b7490

In [3]:
clientside=connect(2001)


Out[3]:
TCPSocket(open, 0 bytes waiting)

In [4]:
@async while true
          write(STDOUT,readline(clientside))
       end


Out[4]:
Task (waiting) @0x00000000827b4010

In [5]:
println(clientside,"Hello World from the Echo Server")


Hello World from the Echo Server

In [6]:
close(clientside)


ERROR (unhandled task failure): ArgumentError: stream is closed or unusable
 in check_open at stream.jl:329

In [7]:
clientside=connect(2001)


Out[7]:
TCPSocket(open, 0 bytes waiting)

In [8]:
close(clientside)


ERROR (unhandled task failure): ArgumentError: stream is closed or unusable
 in check_open at stream.jl:329

In [9]:
getaddrinfo("github.com")


Out[9]:
ip"192.30.252.131"

In [10]:
r = remotecall(2, rand, 2, 2)


LoadError: no process with id 2 exists
while loading In[10], in expression starting on line 1

In [11]:
@doc remotecall


Out[11]:
remotecall(id, func, args...)

Call a function asynchronously on the given arguments on the specified process. Returns a RemoteRef.


In [12]:
r = remotecall(1, rand, 2, 2)


Out[12]:
RemoteRef{Channel{Any}}(1,1,1)

In [13]:
fetch(r)


Out[13]:
2x2 Array{Float64,2}:
 0.0962851  0.575182
 0.317417   0.794743

In [15]:
s = @spawnat 1 1 .+ fetch(r)


Out[15]:
RemoteRef{Channel{Any}}(1,1,2)

In [16]:
fetch(s)


Out[16]:
2x2 Array{Float64,2}:
 1.09629  1.57518
 1.31742  1.79474

In [17]:
remotecall_fetch(1, getindex, r, 1, 1)


Out[17]:
0.09628513808182326

In [18]:
@doc @everywhere


Out[18]:
@everywhere

Execute an expression on all processes. Errors on any of the processes are collected into a CompositeException and thrown.

A file can also be preloaded on multiple processes at startup, and a driver script can be used to drive the computation:

julia -p <n> -L file1.jl -L file2.jl driver.jl

Functions addprocs(), rmprocs(), workers(), and others are available as a programmatic means of adding, removing and querying the processes in a cluster.


In [19]:
@doc addprocs


Out[19]:
addprocs(machines; keyword_args...) -> List of process identifiers

Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system.

machines is a vector of machine specifications. Worker are started for each specification.

A machine specification is either a string machine_spec or a tuple - (machine_spec, count).

machine_spec is a string of the form [user@]host[:port] [bind_addr[:port]]. user defaults to current user, port to the standard ssh port. If [bind_addr[:port]] is specified, other workers will connect to this worker at the specified bind_addr and port.

count is the number of workers to be launched on the specified host. If specified as :auto it will launch as many workers as the number of cores on the specific host.

Keyword arguments:

  • tunnel: if true then SSH tunneling will be used to connect to the worker from the master process. Default is false.

  • sshflags: specifies additional ssh options, e.g.

sshflags=`-i /home/foo/bar.pem`
  • max_parallel: specifies the maximum number of workers connected to in parallel at a host. Defaults to 10.

  • dir: specifies the working directory on the workers. Defaults to the host's current directory (as found by pwd())

  • exename: name of the julia executable. Defaults to "$JULIA_HOME/julia" or "$JULIA_HOME/julia-debug" as the case may be.

  • exeflags: additional flags passed to the worker processes.

  • topology: Specifies how the workers connect to each other. Sending a message between unconnected workers results in an error.

  • topology=:all_to_all : All processes are connected to each other. This is the default.

  • topology=:master_slave : Only the driver process, i.e. pid 1 connects to the workers. The workers do not connect to each other.

  • topology=:custom : The launch method of the cluster manager specifes the connection topology via fields ident and connect_idents in WorkerConfig. A worker with a cluster manager identity ident will connect to all workers specified in connect_idents.

Environment variables :

If the master process fails to establish a connection with a newly launched worker within 60.0 seconds, the worker treats it a fatal situation and terminates. This timeout can be controlled via environment variable JULIA_WORKER_TIMEOUT. The value of JULIA_WORKER_TIMEOUT on the master process, specifies the number of seconds a newly launched worker waits for connection establishment.

..  addprocs(manager::ClusterManager; kwargs...) -> List of process identifiers

Launches worker processes via the specified cluster manager.

For example Beowulf clusters are  supported via a custom cluster manager implemented in package ``ClusterManagers``.

The number of seconds a newly launched worker waits for connection establishment from the master can be
specified via variable ``JULIA_WORKER_TIMEOUT`` in the worker process's environment. Relevant only when using TCP/IP as transport.
..  addprocs(n::Integer; exeflags=``) -> List of process identifiers

Launches workers using the in-built ``LocalManager`` which only launches workers on the local host.
This can be used to take advantage of multiple cores. ``addprocs(4)`` will add 4 processes on the local machine.
..  addprocs() -> List of process identifiers

Equivalent to ``addprocs(CPU_CORES)``

Note that workers do not run a ``.juliarc.jl`` startup script, nor do they synchronize their global state
(such as global variables, new method definitions, and loaded modules) with any of the other running processes.

In [20]:
addprocs(CPU_CORES)


Out[20]:
4-element Array{Int64,1}:
 2
 3
 4
 5

In [21]:
@doc rmprocs


Out[21]:
rmprocs(pids...)

Removes the specified workers.


In [22]:
rmprocs(2:5)


Out[22]:
:ok

In [23]:
@doc workers


Out[23]:
workers()

Returns a list of all worker process identifiers.


In [24]:
workers()


Out[24]:
1-element Array{Int64,1}:
 1

In [25]:
addprocs(1)


Out[25]:
1-element Array{Int64,1}:
 6

In [27]:
A = rand(1000,1000)
Bref = @spawn A^2
fetch(Bref)


Out[27]:
1000x1000 Array{Float64,2}:
 246.404  242.221  238.032  254.706  …  243.282  245.487  252.118  241.057
 243.339  240.513  234.222  250.723     237.769  238.703  250.145  245.079
 250.637  255.786  242.935  257.452     247.73   245.781  262.319  248.367
 243.908  242.856  230.648  255.754     238.263  231.553  254.253  239.455
 244.036  238.761  229.236  251.831     242.485  237.91   247.073  237.546
 254.596  242.011  239.943  253.43   …  243.616  241.755  255.826  245.333
 248.791  243.126  240.897  256.155     237.722  242.708  255.275  243.837
 259.934  249.063  245.371  257.475     248.154  247.738  253.799  251.775
 255.142  257.627  238.962  258.874     247.536  250.887  262.788  250.339
 258.439  246.099  239.835  258.725     246.266  247.585  256.336  250.304
 251.8    249.872  243.343  263.129  …  243.956  246.421  258.376  248.238
 254.33   252.212  244.981  266.164     249.301  247.607  260.646  251.5  
 239.953  238.257  231.743  248.553     234.31   236.973  245.512  242.757
   ⋮                                 ⋱                                    
 251.985  246.712  244.032  259.113     247.198  245.376  255.362  246.29 
 241.387  237.25   227.91   246.957     231.149  234.83   243.936  237.991
 247.982  239.343  242.975  252.364  …  242.299  243.514  253.694  244.807
 246.281  240.536  235.542  254.281     241.636  239.819  254.562  248.062
 240.949  240.212  228.712  252.72      233.891  241.514  244.912  238.206
 249.677  241.039  238.226  255.855     245.584  242.288  254.834  240.649
 258.221  255.998  243.612  265.073     252.986  251.552  256.02   250.876
 255.235  254.157  244.438  260.01   …  246.602  247.79   261.32   256.728
 258.449  255.126  241.177  262.322     251.234  247.363  265.31   255.299
 246.749  241.591  234.83   252.649     239.62   242.041  250.532  244.319
 249.495  252.653  241.14   260.425     247.769  243.989  254.85   249.385
 256.806  249.05   238.676  254.243     250.715  244.72   256.024  248.573

In [28]:
Bref = @spawn rand(1000,1000)^2
fetch(Bref)


Out[28]:
1000x1000 Array{Float64,2}:
 251.595  254.33   247.193  252.501  …  248.91   258.599  244.762  247.464
 250.565  248.217  246.03   258.234     247.108  260.579  244.798  255.41 
 260.231  258.129  257.54   261.643     255.022  268.091  253.707  258.482
 261.73   252.601  258.425  259.525     252.993  264.234  246.043  251.129
 250.694  248.909  251.479  258.033     251.815  260.496  246.965  250.312
 254.487  256.475  257.219  258.062  …  252.266  265.012  249.896  251.187
 264.973  262.663  253.166  265.109     258.167  267.081  252.323  259.728
 255.139  255.575  253.545  251.209     248.798  256.714  241.387  243.304
 248.275  248.251  244.467  250.769     244.57   256.027  243.599  244.343
 251.918  254.828  249.018  257.571     251.384  258.705  249.207  251.484
 249.905  250.095  252.897  252.255  …  250.972  261.598  245.073  255.24 
 258.952  258.266  253.873  263.242     260.085  263.137  256.564  255.885
 260.467  259.49   253.134  263.376     254.741  262.654  249.372  255.604
   ⋮                                 ⋱                                    
 251.179  247.748  247.126  253.16      250.674  257.49   244.074  245.429
 258.505  254.735  250.735  261.631     253.725  264.102  251.939  254.412
 254.342  254.287  248.055  247.69   …  244.079  258.708  248.105  248.718
 249.458  245.795  251.603  248.344     245.072  253.275  239.518  238.998
 255.037  250.388  249.593  257.99      250.008  258.415  248.764  245.302
 260.354  253.519  250.388  261.4       253.847  262.321  249.825  253.66 
 250.958  254.052  253.002  260.023     247.009  257.92   250.149  253.321
 258.911  258.788  260.826  260.788  …  257.425  267.35   259.65   260.313
 248.889  255.415  251.825  256.738     247.799  264.224  248.672  250.647
 250.901  252.492  245.985  257.337     246.684  255.26   247.935  245.354
 253.665  253.649  242.45   251.805     248.893  252.77   245.057  247.608
 251.039  251.621  254.743  254.528     253.081  259.847  250.169  249.423

In [29]:
@everywhere function count_heads(n)
    c::Int = 0
    for i=1:n
        c += rand(Bool)
    end
    c
end

In [30]:
a = @spawn count_heads(100000000)
b = @spawn count_heads(100000000)
fetch(a)+fetch(b)


Out[30]:
99986694

In [31]:
nheads = @parallel (+) for i=1:200000000
  Int(rand(Bool))
end


Out[31]:
99987084

Using “outside” variables in parallel loops is perfectly reasonable if the variables are read-only:


In [33]:
a = randn(1000)
f = (x) -> x + 1
@parallel (+) for i=1:100000
  f(a[rand(1:end)])
end


Out[33]:
98074.77751656536

In [34]:
M = Matrix{Float64}[rand(1000,1000) for i=1:10]
pmap(svd, M)


Out[34]:
10-element Array{Any,1}:
 (
1000x1000 Array{Float64,2}:
 -0.0315076  -0.00394116   0.0152079    …   0.0559766   -0.0285426 
 -0.0315637  -0.0107547   -0.00628968       0.0284223   -0.0173019 
 -0.0320324  -0.0184949   -0.0250978       -0.0190912    0.00138123
 -0.0314264   0.00468772   0.0325694        0.0037514    0.0455322 
 -0.0320306  -0.0151644   -0.0186629       -0.0225571   -0.0254369 
 -0.0314197   0.0113611   -0.000590949  …  -0.0322469   -0.00495385
 -0.0315449   0.0406572    0.0304707        0.0444839   -0.0188762 
 -0.0319561   0.0423949    2.5135e-5        0.0177694   -0.00352942
 -0.0317524  -0.00495734   0.0261374       -0.037082    -0.0116135 
 -0.0328785  -0.0187632    0.0179927       -0.0138243   -0.0395738 
 -0.0317036  -0.0566868   -0.0353252    …   0.068039    -0.0230809 
 -0.0316762  -0.0128482    0.0308106       -0.0625659    0.0237697 
 -0.0318716  -0.00144806   0.033064        -0.00426291   0.0150939 
  ⋮                                     ⋱                          
 -0.0322185   0.0165      -0.0200463        0.00525218   0.0551763 
 -0.0313118   0.00816003   0.0213329        0.0182953    0.0229839 
 -0.0317269   0.0562589   -0.0624505    …   0.0307722    0.0204416 
 -0.0309255  -0.0451962   -0.0157127        0.0119718   -0.0031531 
 -0.0313113  -0.00891258  -0.0375671       -0.0262898    0.01854   
 -0.0308739   0.0312588   -0.017244        -0.00583114  -0.0447455 
 -0.031074    0.0382753    0.0218454       -0.0132529    0.0451067 
 -0.033338    0.00602266   0.0252348    …   0.0136868   -0.0174889 
 -0.0310656  -0.0266702   -0.016436         0.0214547   -0.0182285 
 -0.031242    0.0219562    0.00621808      -0.0257647    0.0376388 
 -0.0315242   0.0285014   -0.0647479       -0.00650076  -0.0425272 
 -0.031818    0.0294657    0.0350669        0.0370064   -0.042589  ,

[500.078,18.2116,18.1256,18.0308,17.9203,17.8838,17.7771,17.7282,17.6893,17.6449  …  0.125908,0.111749,0.0975661,0.0871337,0.0764787,0.0616545,0.0513208,0.0327209,0.0215172,0.00618509],
1000x1000 Array{Float64,2}:
 -0.0321022   0.0125305   -0.0379696    …   0.0302175     0.0209978 
 -0.0312126   0.026984     0.0290173        0.0285233    -0.0920189 
 -0.0325228  -0.0163886    0.0231622       -0.0277859    -0.0376601 
 -0.0318726   0.00379603   0.0114026        0.00431671    0.0286438 
 -0.0314643   0.0213968    0.04075         -0.0498138     0.02521   
 -0.0306719   0.0203558   -0.0352077    …  -0.00810685    0.00414028
 -0.0307735   0.00272036  -0.00768623      -0.0189556    -0.0340436 
 -0.0314703   0.0414934   -0.0263514        0.0360221    -0.00789824
 -0.0318822   0.00349579  -0.051908        -0.0435776     0.0331852 
 -0.0305805   0.0474127   -0.0283175        0.0328199    -0.00600489
 -0.0324702   0.014295    -0.0146088    …  -0.006769      0.0154264 
 -0.0310654  -0.040948    -0.0286198       -0.010489     -0.00698593
 -0.0319896  -0.0581159   -0.0711226        0.0284807     0.0207051 
  ⋮                                     ⋱                           
 -0.0317756  -0.0131395   -0.0173488        0.0276041    -0.017685  
 -0.0325533  -0.0617124    0.0109088       -0.000187059  -0.0317461 
 -0.0319628  -0.0063972   -0.0327233    …  -0.0121039     0.0178259 
 -0.0313488   0.0553619    0.000414503      0.0279295     0.00224771
 -0.0314997   0.0652608    0.00948205       0.0280437    -0.0199604 
 -0.0318132  -0.00374133   0.0511152        0.0717837    -0.00520064
 -0.0311504  -0.032205     0.00664681       0.0464839     0.0216108 
 -0.0315776   0.0097719   -0.0594107    …  -0.00926987   -0.0374131 
 -0.0324715  -0.0100932    0.00995832      -0.0338846     0.0193121 
 -0.0320531  -0.0196288    0.0582223        0.00147772    0.00283298
 -0.0311122  -0.0638033    0.0213591       -0.0116204     0.0236912 
 -0.0306413   0.0624477   -0.038788         0.0366932     0.0694174 )                                                
 (
1000x1000 Array{Float64,2}:
 -0.031557    0.000809726   0.0425272   …   0.00189846   0.0260888 
 -0.0308023   0.0196923     0.0117304      -0.00966993   0.04579   
 -0.0306265  -0.0348289     0.0210133      -0.0259416    0.0146443 
 -0.0326539  -0.0455918    -0.0319635      -0.0353741   -0.0416734 
 -0.0311372  -0.0200775    -0.0359903       0.00848781   0.00414307
 -0.0318315  -0.0159663    -0.0212469   …   0.029011    -0.01009   
 -0.0312407  -0.00659232   -0.00479347      0.0115306   -0.0185008 
 -0.0315681   0.0148979     0.031864        0.0102818    0.0331084 
 -0.0304966  -0.0233305     0.0520341       0.0202252   -0.0117715 
 -0.0324375  -0.016741      0.0489545       0.0297409   -0.0181066 
 -0.0317083  -0.0232255    -0.0888333   …  -0.0125819    0.0155961 
 -0.0315541   0.0328582     0.0171883       0.0239055    0.0276558 
 -0.0315724  -0.0148754     0.0194482      -0.0498967    0.016641  
  ⋮                                     ⋱                          
 -0.0320811   0.0269917    -0.0668625       0.00275912  -0.0523007 
 -0.031869   -0.012895      0.0279492      -0.055544    -0.0156635 
 -0.0313654  -0.0244134    -0.0422854   …   0.0266855   -0.025834  
 -0.0328418   0.0040094     0.00188551     -0.00468431  -0.0110108 
 -0.0315265  -0.014648     -0.00201023      0.0330393    0.00775819
 -0.0323802   0.0153614     0.0681191      -0.0349856    0.0822445 
 -0.0319539   0.0257984    -0.0266217      -0.0144766    0.0318933 
 -0.0315634  -0.0159416    -0.0226942   …   0.0395155   -0.0383682 
 -0.0322324   0.0333303    -0.0420694      -0.0285821   -0.0667933 
 -0.0320952  -0.0167283    -0.0112928       0.0395484   -0.00446055
 -0.0317135  -0.0184464     0.0809096       0.0043491    0.0408432 
 -0.031171   -0.0529677     0.00186183      0.00279767   0.0135637 ,

[500.395,18.2141,18.0274,17.9565,17.906,17.8287,17.7876,17.7266,17.6374,17.603  …  0.129974,0.122283,0.0935079,0.0924594,0.0701529,0.0601114,0.0401296,0.0249021,0.0125487,0.00587976],
1000x1000 Array{Float64,2}:
 -0.0317983  -0.0268214    0.006167     …   0.0325403    0.0117969  
 -0.0329574  -0.028161     0.00114836      -0.0100315   -0.000168175
 -0.0314555   0.0178818   -0.0234348       -0.00669     -0.0852728  
 -0.0319125  -0.0503363    0.0336986       -0.00323489   0.0256359  
 -0.0312301   0.0366113    0.015047        -0.0126038    0.0291512  
 -0.0325283   0.0248081    0.0296879    …  -0.0340952    0.0200699  
 -0.0295127  -0.0247109    0.0185352        0.0286824   -0.00172437 
 -0.0317683   0.0123171    0.00836527       0.0248073   -0.0199029  
 -0.0320157   0.0357404    0.000661759     -0.0738432    0.0439522  
 -0.0309156   0.0409218    0.00320615       0.0129139   -0.040532   
 -0.032073   -0.0494123    0.0114987    …  -0.0380306   -0.000768886
 -0.0311     -0.0275052   -0.0818356        0.00485796   0.0316721  
 -0.0317746  -0.0574391    0.0144781       -0.0143499    0.0044058  
  ⋮                                     ⋱                           
 -0.0319861   0.0179196   -0.0337763        0.0103865   -0.0576365  
 -0.0319748   0.0165166   -0.00916954      -0.0178959   -0.0376451  
 -0.0316738   0.0241889   -0.004005     …   0.0111851    0.0545147  
 -0.0317992  -0.00684388  -0.00564003       0.0121008   -0.00262623 
 -0.0317589   0.049606     0.0219306       -0.00755596  -0.00848859 
 -0.0313821   0.0131994    0.0388193       -0.00708719   0.00547208 
 -0.0313058   0.0391574    0.0131313       -0.0430989   -0.0554414  
 -0.0325822   0.0171259   -0.030388     …   0.0336817    0.00727338 
 -0.0318821  -0.019732    -0.00519187      -0.00077444  -0.00194128 
 -0.0318859   0.027801    -0.0301998        0.031169    -0.0190829  
 -0.0311901   0.0155775   -0.0142834       -0.0524959    0.0379099  
 -0.0321048  -0.0121762   -0.00570517       0.0283391   -0.0102456  )                                                  
 (
1000x1000 Array{Float64,2}:
 -0.0314434  -0.0199186    0.0282312   …   0.00393603   0.00983636
 -0.031417    0.083845    -0.0220263      -0.0726024    0.0279476 
 -0.0323292  -0.00549819  -0.0127762      -0.0217685    0.016697  
 -0.0316943   0.0108053   -0.0395658       0.0110868   -0.0441592 
 -0.0312875   0.00220478   0.0465343      -0.0261228    0.00396805
 -0.0311767  -0.0202222    0.0631626   …   0.0126775   -0.0276189 
 -0.0318256  -0.00610205  -0.0113687       0.0206423   -0.0236173 
 -0.0323789   0.0301817    0.0355916       0.0461506    0.0448634 
 -0.0315768   0.00233143   0.0447515       0.0153171    0.0612859 
 -0.0312338   0.0198569    0.0389874       0.0514996   -0.0014599 
 -0.0322648   0.043873     0.0180339   …  -0.0691276   -0.00685685
 -0.029701    0.0152194    0.00127234      0.0378202   -0.036429  
 -0.0312402  -0.0325817    0.0188224      -0.0197274   -0.013216  
  ⋮                                    ⋱                          
 -0.0312917  -0.0249343    0.0115052      -0.0333592   -0.0726567 
 -0.030909   -0.0591007    0.0774181       0.0267962    0.0265446 
 -0.0312343   0.0123066   -0.00969192  …  -0.0265291    0.0401165 
 -0.0306335   0.0136617   -0.0339053       0.0399674    0.00338514
 -0.030883    0.00418401   0.0294056       0.0444305   -0.0486901 
 -0.0315824   0.00510517   0.0136219       0.0163882   -0.0306642 
 -0.03162    -0.0183563   -0.0221163      -0.0434854    0.0115545 
 -0.031023    0.0271458   -0.0122713   …  -0.0478216    0.0332501 
 -0.0321558  -0.0372447   -0.0100942      -0.0360431   -0.0118828 
 -0.0315548   0.0552516   -0.04741         0.00986887  -0.0190811 
 -0.0319848   0.00100517   0.0108871       0.0349122   -0.0237772 
 -0.0320391   0.0270897    0.00419907     -0.0584444    0.0300926 ,

[500.067,18.2038,18.0371,17.9469,17.8981,17.792,17.7471,17.7111,17.6353,17.602  …  0.124867,0.112387,0.0949634,0.0838646,0.0763925,0.0594904,0.0478936,0.0382033,0.0281761,0.00873282],
1000x1000 Array{Float64,2}:
 -0.0322135   0.00159176   -0.00277963  …   0.010999      0.00425634
 -0.0313307   0.000441664   0.0172297       0.0739596     0.0165787 
 -0.0317067   0.0464951     0.0225618       0.000913603  -0.0039565 
 -0.0316716  -0.0681298     0.0111545       0.0221072     0.0385276 
 -0.0313728   0.0154032    -0.0971626      -0.000884029  -0.0191517 
 -0.0320758  -0.00356557   -0.0221612   …   0.0334739     0.112022  
 -0.0314876  -0.0927453    -0.0678757      -0.0168774     0.00165263
 -0.0316362  -0.0575995     0.0537223      -0.024613      0.0157039 
 -0.0323064   0.0250947    -0.0122391      -0.0492711    -0.0268793 
 -0.0313081  -0.0574475    -0.0187848       0.0108059     0.0413828 
 -0.0313682   0.0183131    -0.0152342   …   0.0562119     0.00749888
 -0.0303333  -0.0343073     0.0711252      -0.000109615   0.00475342
 -0.0314051  -0.0671007     0.0213975      -0.0287047    -0.0360852 
  ⋮                                     ⋱                           
 -0.0315347  -0.018345     -0.0257471      -0.0415757     0.0308311 
 -0.0318514  -0.0349882    -0.015449       -0.0578713    -0.0511267 
 -0.0319375   0.0043436     0.00527623  …  -0.0211139     0.00234594
 -0.0325304   0.0185599    -0.0194278      -0.0288434     0.0779177 
 -0.0316012  -0.0142134     0.0209328      -0.0301348    -0.0469619 
 -0.0316241   0.0122844    -0.0108214      -0.0148955    -0.00538358
 -0.0322226   0.0361088     0.0653018      -0.000308181  -0.0523222 
 -0.0326107  -0.0136566     0.00579636  …   0.000497499  -0.0471113 
 -0.0312086  -0.0641714     0.0205916      -0.0123794     0.0109742 
 -0.0331914   0.0162244    -0.0472981      -0.0108841    -0.009811  
 -0.0316527   0.0269314    -0.0047998       0.030521      0.0332735 
 -0.0310981   0.00933591   -0.0417669      -0.0359394    -0.00884193)                                                                            
 (
1000x1000 Array{Float64,2}:
 -0.0316742   0.0133352    0.0690014    …   0.011025      0.0335572  
 -0.0311683   0.00875399   0.00516719       0.0450326     0.0723881  
 -0.0311652   0.0330259    0.000611455      0.010652     -0.0735924  
 -0.0321694  -0.0139728    0.000789206     -0.000279067   0.0244743  
 -0.0310415  -0.0143442    0.00368245      -0.0095839     0.00572993 
 -0.0322922  -0.00941438   0.0682178    …  -0.0344233     0.0161699  
 -0.0317523   0.0290766   -0.0484861        0.0074016     0.0190238  
 -0.0318697  -0.0388748    0.0235967        0.000293481  -0.0228653  
 -0.0307828   0.00288349  -0.0437993        0.0243672    -0.0504049  
 -0.0319087  -0.0124359   -0.0162832        7.57735e-5   -0.000638359
 -0.032215    0.0289518   -0.0490708    …   0.050434      0.0138031  
 -0.0310621  -0.0094173   -0.0465291       -0.0933316     0.0169076  
 -0.0318591  -0.00286037  -0.0277179       -0.0688017     0.0553198  
  ⋮                                     ⋱                            
 -0.031332   -0.0761597    0.0174579       -0.00173552   -0.0273398  
 -0.031163   -0.037718    -0.0341829       -0.0235745    -0.0561075  
 -0.031918   -0.0449337    0.00149095   …  -0.0382406     0.0252183  
 -0.0311726   0.055643     0.0598952       -0.00563334   -0.00254933 
 -0.0315303  -0.0204432    0.0257702       -0.0144664    -0.0260362  
 -0.0317664   0.0028352   -0.0501187       -0.0379457    -0.0706308  
 -0.0314343   0.0150337   -0.00508089      -0.0461069     0.00236515 
 -0.0315283  -0.0680254   -0.0302134    …  -0.0174229    -0.0460683  
 -0.0315663  -0.00326671  -0.0117204        0.0301        6.3492e-5  
 -0.0315926   0.0293577   -0.0131278        0.0266707     0.0712346  
 -0.0319065   0.0668894   -0.0190189       -0.0118277    -0.0165466  
 -0.0313485  -0.0413029    0.01193         -0.00232755   -0.000904978,

[500.393,18.2235,17.9481,17.8871,17.8252,17.7927,17.7352,17.6434,17.6207,17.5731  …  0.139686,0.114952,0.110336,0.0891982,0.0704565,0.0579395,0.0439509,0.0237667,0.0140053,0.0063497],
1000x1000 Array{Float64,2}:
 -0.0323971  -0.019804     0.0122853    …  -0.0415299   -0.0337334 
 -0.0316869   0.0717261    0.00247079       0.0365673    0.00322119
 -0.0316037  -0.00813614   0.0293037       -0.00806884   0.00833362
 -0.0318182   0.00435003   0.052725         0.0161566   -0.0952855 
 -0.0314181   0.00614265   0.0117191       -0.00910285   0.0216504 
 -0.0313496  -0.0103057   -0.00396766   …  -0.00815199  -0.0445661 
 -0.0316662  -0.0220428   -0.0319395        0.032139    -0.00930452
 -0.0314797  -0.0276505   -0.0347551        0.0245779    0.0377811 
 -0.0313735  -0.0278106    0.000578976     -0.0884256   -0.0163933 
 -0.032048   -0.0341336   -0.0144842       -0.00184892   0.00888547
 -0.0320024  -0.00208102  -0.0067106    …  -0.0144954   -0.016149  
 -0.0303233  -0.0567099    0.0268157        0.0591741   -0.00977062
 -0.0310098  -0.0331823   -0.0398185       -0.0124341   -0.0206787 
  ⋮                                     ⋱                          
 -0.0318475  -0.00210586   0.0445142       -0.0561807    0.0281494 
 -0.0303687  -0.0182227    0.00750648      -0.0202667   -0.0364346 
 -0.0319894  -0.0292941    0.00611443   …  -0.0251062   -0.0680616 
 -0.0309075  -0.0194046    0.0758658       -0.0464734    0.00405091
 -0.0306355   0.0278935   -0.0253172        0.0342084   -0.00870195
 -0.0313635  -0.0100404    0.0114461        0.0138491    0.00321393
 -0.0312089  -0.0269243   -0.0251306       -0.0369785    0.0240726 
 -0.0312864  -0.0287158   -0.0427157    …   0.0130747   -0.00518499
 -0.0321317  -0.0021758   -0.0258771        0.0278179    0.00540127
 -0.0311823   0.00552868   0.0238407       -0.0259865   -0.0119136 
 -0.03212     0.022716    -0.0180176        0.0307461   -0.0292826 
 -0.0310157   0.041626    -0.00730649       0.0192799   -0.036322  )                        
 (
1000x1000 Array{Float64,2}:
 -0.0313103  -0.00654472    0.0232018   …   0.014148     -0.00638094
 -0.032494    0.0612264     0.00858063      0.000706781   0.0197958 
 -0.0319192  -0.0155472    -0.0441549      -0.000518325   0.0143044 
 -0.0313091   0.0136935    -0.0435657       0.0244352     0.0437781 
 -0.0319251   7.95102e-5   -0.0430864      -0.00766091    0.0248205 
 -0.0314974  -0.0487074    -0.0227527   …  -0.0241266    -0.0447643 
 -0.031868    0.00825494   -0.0263624      -0.0342141     0.013869  
 -0.0310828   0.0160234     0.00581315     -0.0552734     0.0730481 
 -0.032524    0.0161058    -0.0216034       0.0115189     0.0115605 
 -0.0318202  -0.0524714    -0.0463726       0.0445718    -0.0154837 
 -0.0309111  -0.00846765    0.0199479   …   0.020984     -0.0526211 
 -0.0315168  -0.0269704     0.0144803      -0.0253552     0.0524088 
 -0.0315824  -0.0109065    -0.0136127       0.0173422    -0.0346089 
  ⋮                                     ⋱                           
 -0.0318814  -0.00447242    0.0210847       0.0058284    -0.0163197 
 -0.0318218   0.0267268     0.0262059      -0.0394745    -0.0350299 
 -0.0315341   0.0189244     0.0288839   …  -0.0345313    -0.0117691 
 -0.0313643   0.03903      -0.0150623      -0.016677     -0.0130801 
 -0.0314724  -0.000999495  -0.0726285       0.0185769    -0.00630888
 -0.031472   -0.0040652    -0.0397396      -0.0435321    -0.0410513 
 -0.031696    0.00274857    0.0746628       0.0825487     0.039045  
 -0.0316337   0.00667949   -0.0313588   …   0.0348399     0.0168814 
 -0.0306343   0.0282756     0.0340377      -0.0613424    -0.013787  
 -0.0317294   0.0355864     0.0204791      -0.0137689    -0.033657  
 -0.0314863  -0.0148033    -0.0330459      -0.0257287     0.00569726
 -0.0309081   0.00145199   -0.0161258      -0.00774622    0.0019543 ,

[500.07,18.3177,18.0657,17.9968,17.9511,17.8783,17.7254,17.6869,17.6507,17.5437  …  0.130419,0.118004,0.0887669,0.0715227,0.0668923,0.0493285,0.0404486,0.0230007,0.0121696,0.00457546],
1000x1000 Array{Float64,2}:
 -0.0323215   0.0046697   -0.0604904    …   0.0058598     0.0133527 
 -0.0316767  -0.00832939   0.0312464        9.8159e-7    -0.0238586 
 -0.0310617  -0.0158523    0.00080219       0.034673     -0.0191501 
 -0.0308987  -0.0314435   -0.0089861       -0.0337042    -0.0265893 
 -0.0311711   0.0188564   -0.0215295       -0.0340563    -0.0388881 
 -0.0313024   0.0713723   -0.0492369    …   0.000369149  -0.0242741 
 -0.0313375  -0.0300517    0.0252754       -0.00528919    0.0325308 
 -0.0316665  -0.00667602  -0.0425922        0.00118308   -0.0382542 
 -0.0321321  -0.00622843  -0.0329253        0.00237012    0.0280785 
 -0.0319443   0.00677986  -0.0151098        0.124002      0.0173138 
 -0.0326735  -0.0325995    0.0509412    …   0.0102699     0.0562535 
 -0.0314319  -0.01813     -0.0102444        0.0246966    -0.00711401
 -0.0322092   0.00170078  -0.0508389       -0.0264247    -0.0154128 
  ⋮                                     ⋱                           
 -0.0324738  -0.00133808  -0.00522284      -0.0578332    -0.00627328
 -0.0315814   0.0325167   -0.00261848       0.0384872     0.0274652 
 -0.0316801  -0.010338    -0.000382101  …  -0.0176569    -0.0126999 
 -0.032174   -0.0251472   -0.0434373       -0.0100413     0.0495711 
 -0.0311594   0.00413731  -0.00230771       0.0018824    -0.0161502 
 -0.0310629   0.0240398    0.0152629       -0.0115553     0.00728717
 -0.0311931   0.0561461   -0.0320042        0.000420811  -0.00861563
 -0.0314455   0.0159121    0.0159869    …   0.0268653    -0.00801381
 -0.0316997   0.0230297   -0.00270103       0.0153495    -0.0518636 
 -0.032134    0.024718    -0.0264364       -0.00153078   -0.0479481 
 -0.0324275  -0.03345     -0.0349998       -0.0563842     0.0125677 
 -0.0315684   0.00935097   0.0194398        0.0629849    -0.00549577)                       
 (
1000x1000 Array{Float64,2}:
 -0.0318711   0.00805696   -0.0480637    …  -0.0263535    0.0643412 
 -0.0311581  -0.00765909   -0.0508839        0.0243035   -0.0650702 
 -0.0322328  -0.00150308    0.0427082       -0.0426653   -0.0219997 
 -0.0312797   0.0171424     0.0159806       -0.0572747   -0.0161803 
 -0.0319439  -0.00941684    0.0157746       -0.0280482   -0.00169979
 -0.0314744   0.0112993    -0.0229107    …   0.00432614  -0.0453518 
 -0.0307109   0.0216907    -0.0344932       -0.00614394   0.034677  
 -0.0317127   0.0285976    -0.0254382       -0.00369774   0.0718086 
 -0.031273   -0.0455377    -0.0119652        0.00994258   0.0458068 
 -0.0314815   0.0440214    -0.0188127       -0.0515394   -0.00788544
 -0.0321459   0.0177682     0.0537503    …   0.0514284    0.010644  
 -0.0310081  -0.00530729    0.0257753        0.0149043    0.033315  
 -0.0311187  -0.00110058    0.000869105      0.0521005   -0.0548737 
  ⋮                                      ⋱                          
 -0.0322764  -0.0129767    -0.00620114      -0.0242401   -0.0262943 
 -0.0311549  -0.0461249    -0.0162866        0.0304655   -0.00806029
 -0.0315172   0.0484705     0.0537086    …   0.0310412   -0.0145127 
 -0.0313789  -0.0433694    -0.0267059       -0.00112547  -0.0446374 
 -0.031019   -0.00932382    0.0242568        0.0211282   -0.0703968 
 -0.032305    0.00237796    0.0104905       -0.0253304   -0.0677107 
 -0.0322402  -0.000537845  -0.00865849       0.0406577   -0.0016998 
 -0.0317196  -0.0414265    -0.0470206    …  -0.0396345    0.0309912 
 -0.031637   -0.0198547     0.0415703        0.0141807    0.00644777
 -0.0324679   0.0766867    -0.0231011        0.0287489    0.00722737
 -0.0317849   0.0321807     0.0148137       -0.0253065   -0.0256928 
 -0.0314195  -0.00171852    0.0127046        0.0407049    0.0399023 ,

[500.245,18.1703,18.1023,17.9333,17.8339,17.7536,17.6742,17.6659,17.6064,17.568  …  0.121678,0.111591,0.105031,0.0799438,0.068434,0.062672,0.0498136,0.0315141,0.0201857,0.00639745],
1000x1000 Array{Float64,2}:
 -0.0315337   0.00740407  -0.0243968    …  -0.0462548   -0.0240054 
 -0.0319597  -0.0199967    0.0347326       -0.0534377    0.0173708 
 -0.0309367  -0.0214384   -0.059438        -0.00904282   0.0310046 
 -0.0326446   0.0106368   -0.0283319       -0.0812897    0.056655  
 -0.0301924   0.0221773   -0.0150877        0.0121352    0.0018212 
 -0.0314182  -0.0106393   -0.00139447   …   0.0138019   -0.00528798
 -0.0310204   0.0132042    0.009797         0.0298461   -0.0213781 
 -0.0315759  -0.0533861   -0.0102707       -0.0415492   -0.0184072 
 -0.0319066   0.0217607   -0.0560619        0.0547258    0.0170306 
 -0.0321263  -0.0177006    0.0123787       -0.014285    -0.0439551 
 -0.0312619   0.0018398   -0.000146243  …  -0.0321149    0.010872  
 -0.0317229  -0.00255452   0.060842         0.0120574    0.00605955
 -0.0310997   0.0517467   -0.0156236       -0.0344767   -0.0157497 
  ⋮                                     ⋱                          
 -0.0316006  -0.00346457   0.0157845        0.0561398   -0.00542239
 -0.0325761   0.0244137   -0.00558137       0.0229194   -0.0217075 
 -0.032504    0.0245811    0.0145313    …   0.0350604   -0.012603  
 -0.0324605  -0.0386595   -0.0519366        0.0638144    0.0397181 
 -0.0308784   0.0296649    0.0186231       -0.0102554    0.0408453 
 -0.0310478  -0.00560497  -0.0766063       -0.0209058   -0.00962382
 -0.0313773   0.0149166   -0.0317488        0.0229147   -0.0373831 
 -0.0314047   0.0196051    0.0107712    …   0.0135458   -0.0366481 
 -0.0311971  -0.0313826   -0.0558892       -0.0266967   -0.0105156 
 -0.0308406  -0.00836099   0.0171308        0.0720033   -0.0281147 
 -0.0322703  -0.0235145   -0.00141545      -0.0302422    0.0674788 
 -0.0313456   0.0143972    0.0311205        0.0173958   -0.0285275 )                                                    
 (
1000x1000 Array{Float64,2}:
 -0.0313983   0.0207022   -0.0055052   …   0.0226979    0.0517453 
 -0.0314834  -0.0223501    0.00396015      0.0171947    0.00227511
 -0.0316995  -0.026657    -0.00554984      0.028354     0.0527908 
 -0.0313885   0.022713    -0.028284        0.0376386   -0.0590775 
 -0.0324213   0.028        0.0164005      -0.0163999    0.0185516 
 -0.0312068   0.047732    -0.0473609   …  -0.0211494   -0.0310258 
 -0.0316333   0.0122893    0.0143514       0.0518656    0.0168077 
 -0.0313218   0.00794023   0.018072        0.0309595   -0.0155998 
 -0.0310841  -0.00719546   0.0390157      -0.0107155   -0.0302309 
 -0.031279   -0.0164453   -0.00142131      0.00348101   0.0310096 
 -0.0322281  -0.0360295    0.014       …  -0.048226     0.0221374 
 -0.0317016   0.00517955   0.00973832     -0.0700627   -0.00744733
 -0.0319883   0.025996    -0.00826132     -0.0452517   -0.0594304 
  ⋮                                    ⋱                          
 -0.0309215  -0.00596426  -0.00819372      0.0268047   -0.0461233 
 -0.0311933  -0.0192625   -0.0117496       0.0102788    0.0386931 
 -0.0305746  -0.0147678   -0.052843    …   0.0122167   -0.012118  
 -0.0323169   0.0570554    0.0697525      -0.0154428    0.0307955 
 -0.0304591   0.0203      -0.0203509      -0.0535934   -0.0288091 
 -0.0320544   0.0185867   -0.0250957       0.0218188    0.00668421
 -0.0320508  -0.0285497   -0.0135095       0.0454763    0.00130004
 -0.0320282  -0.0411153   -0.00779455  …   0.0376908    0.0221182 
 -0.0318897   0.00804967   0.0153071      -0.00594068  -0.0122297 
 -0.0316086   0.0471243    0.0106773       0.0607075   -0.0308945 
 -0.0314557   0.0221995   -0.0284412      -0.0683159   -0.0247252 
 -0.030863    0.0556676    0.0371675      -0.0409062   -0.0288518 ,

[500.321,18.181,18.0505,17.9344,17.898,17.8245,17.7573,17.6777,17.6014,17.5441  …  0.156115,0.12965,0.0971935,0.0944057,0.0694325,0.0631605,0.0443681,0.0266521,0.0104378,0.00346263],
1000x1000 Array{Float64,2}:
 -0.0317875   0.0471097    -0.00295984  …  -0.00869957  -0.0133237 
 -0.0317651   0.0175946    -0.00350022     -0.0153195    0.0684645 
 -0.0319868  -0.0375753    -0.0333957       0.00730299   0.0336145 
 -0.0321155   0.0363559    -0.00378868      0.00667307   0.0315361 
 -0.0319453  -0.00974674   -0.0174119       0.0241573    0.0630485 
 -0.0317155  -0.000510777  -0.0791593   …  -0.0223518    0.0286323 
 -0.0323415   0.00328858   -0.0234512      -0.0196757    0.0136216 
 -0.0320037   0.0839315     0.0388716      -0.0197626   -0.00091601
 -0.0313539   0.000998398   0.00486185      0.00184992   0.0254469 
 -0.0318889  -0.0614657     0.0385123      -0.00376092   0.00523793
 -0.0318812   0.0510955    -0.0336364   …   0.0290682   -0.0431204 
 -0.0305451   0.0683755     0.0156913       0.00183959  -0.0182877 
 -0.0315011  -0.00415316   -0.00260902     -0.0334304   -0.0212339 
  ⋮                                     ⋱                          
 -0.0317028   0.00289791   -0.00734486     -0.0175891    0.0370482 
 -0.0314042  -0.0177879    -0.00409227      0.0613305   -0.00554942
 -0.0320101  -0.0338723     0.0325182   …   0.0436543   -0.0333089 
 -0.0316752  -0.0701275    -0.0217455       0.0288082    0.0018414 
 -0.0318266  -0.0432967     0.0250375       0.0280274   -0.0392404 
 -0.0311565  -0.00477509    0.003031       -0.0268792   -0.0216355 
 -0.0322985   0.0529426    -0.0111843      -0.018867    -0.0608454 
 -0.0309273   0.0194525    -0.0737109   …  -0.0266395   -0.0374482 
 -0.0324693  -0.0397818    -0.00849708      0.0120955   -0.0270653 
 -0.0318806  -0.0137879     0.0393443      -0.0226053   -0.0311311 
 -0.0320795  -0.0345222     0.00283574     -0.0654261    0.0203869 
 -0.0312096  -0.00564373   -0.0200581      -0.0121886    0.0272924 )                                                                                                       
 (
1000x1000 Array{Float64,2}:
 -0.0320206  -0.0089758     0.000502019  …  -0.0131309    -0.0477539 
 -0.0314596  -0.017347      0.0294323       -0.0363836     0.0273141 
 -0.0318783  -0.0107089    -0.0348978        0.0498776    -0.0044475 
 -0.0309504  -0.0804055    -0.0182298        0.0291982     0.0103861 
 -0.0322564  -0.00318544    0.0171213        0.0555446    -0.0670248 
 -0.0307806   0.0178743     0.016444     …  -0.0293933    -0.00711265
 -0.031443    0.022308      0.00854311       0.0347318    -0.0342855 
 -0.0320006   0.00820901    0.00411599      -0.0404357    -0.0285995 
 -0.0310788  -0.0396377     0.0511615        0.0179447    -0.013625  
 -0.03101     0.0117374     0.0251036       -0.0609646     0.00295707
 -0.0320174  -0.0031705     0.015451     …  -0.00361907    0.00786946
 -0.031203   -0.018154     -0.0413482       -0.0143969     0.044221  
 -0.0309658   0.00142843   -0.0494183        0.0403491     0.0135499 
  ⋮                                      ⋱                           
 -0.0320566   0.0182308    -0.000800792     -0.0140785     0.00450973
 -0.0321562   0.00496867    0.00955546      -0.0141052    -0.00861834
 -0.0319402  -0.0266798     0.00699837   …   0.000106863  -0.0102904 
 -0.0316157  -0.0106662    -0.0120287        0.0293757     0.037387  
 -0.0324989   0.00712198   -0.0273992       -0.0329815    -0.0171051 
 -0.0322805   0.0363943    -0.00984008       0.0507507     0.0322282 
 -0.0306987   0.0336603    -0.0367372       -0.0200794     0.0344693 
 -0.0322965   0.0203074     0.0204259    …   0.0369977     0.032771  
 -0.0318243  -0.0307868    -0.00341934      -0.0137891    -0.00259121
 -0.0327057   0.000389455  -0.00171509       0.00959172    0.0104363 
 -0.0317213   0.00698544   -0.0172345        0.00346828    0.0295164 
 -0.0310285   0.0479227    -0.00106766       0.0109743    -0.0234314 ,

[500.442,18.0878,17.9036,17.85,17.7784,17.741,17.6732,17.6608,17.6067,17.5366  …  0.136784,0.111486,0.10281,0.0868323,0.0778595,0.0627772,0.0598781,0.0283203,0.0131372,0.000861846],
1000x1000 Array{Float64,2}:
 -0.0310477  -0.0422837    0.00734554   …  -0.0239202    -0.029389  
 -0.0306813   0.0184844    0.000406712      0.0105943    -0.048032  
 -0.0317307  -0.0404743    0.0368213       -0.00109987   -0.0160552 
 -0.0321309   0.0188876   -0.0440159       -0.000633591  -0.0595851 
 -0.0314003  -0.0137317    0.0312613        0.0180577    -0.0548753 
 -0.0310507   0.00535978  -0.0334515    …  -0.0303517    -0.0258753 
 -0.0323151  -0.0768978   -0.00399152      -0.0119047     0.00578381
 -0.0310891   0.0420879   -0.00175882       0.0291853     0.0234839 
 -0.0321265  -0.0100029   -0.0319528        0.0297878    -0.071327  
 -0.032419    0.0279999    0.0221839        0.0688604     0.0290567 
 -0.031819   -0.00552401  -0.0192874    …   0.00393955    0.0253776 
 -0.0311273   0.0118443    0.0259216       -0.00433602    0.0399149 
 -0.0314836  -0.00971391  -0.0384086        0.00307012    0.00872351
  ⋮                                     ⋱                           
 -0.0304155  -0.0213964   -0.013749         0.0221127    -0.0242921 
 -0.0308451  -0.0503676   -0.0133873        0.013527      0.00210509
 -0.0318423  -0.0295342   -0.0144618    …  -0.0300665     0.0376749 
 -0.0315525   0.00999213  -0.0340122        0.00517422    0.019973  
 -0.0318201   0.00171744   0.0382823       -0.031971     -0.0174228 
 -0.0313731   0.0537227    0.00235029      -0.0178175    -0.022608  
 -0.0316823   0.0463977    0.00392586      -0.0398985     0.00361874
 -0.0315631  -0.0238631   -0.0054913    …   0.0283301     0.0172016 
 -0.0313477  -0.0356621    0.0541013        0.0478828    -0.0357583 
 -0.0320047   0.054402    -0.0487756        0.0108888    -0.0352822 
 -0.0315672  -0.038902     0.00345088       0.0112731     0.0248229 
 -0.0312429  -0.00225537   0.000547145     -0.0185298     0.0478664 )
 (
1000x1000 Array{Float64,2}:
 -0.0323357   0.0221509    -0.0526412   …   0.0201623     0.00696258
 -0.0310968   0.00290013    0.0332939      -0.0122061    -0.0186167 
 -0.0324101  -0.0332535    -0.031153        0.00674823    0.0292135 
 -0.0315218  -0.0675527     0.0066112      -0.0205861    -0.00758214
 -0.0317544   0.0177152    -0.00458172      0.0310801     0.00849678
 -0.0312928   0.0423726     0.0449908   …  -0.0421133     0.0298728 
 -0.0315021   0.0618166    -0.00884772     -0.000674594   0.0034676 
 -0.0315466  -0.0527486     0.0121004      -0.0124539    -0.0101208 
 -0.0316488   0.00827793   -0.00247849     -0.0146089    -0.0297506 
 -0.0312519   0.0377762     0.0396419      -0.030673      0.0449258 
 -0.0310857  -0.0153248     0.0147796   …   0.02401      -0.00637954
 -0.0311531  -0.00919443    0.0341344      -0.000373942  -0.00786406
 -0.031492   -0.00997172    0.0516605      -0.0162703    -0.0595931 
  ⋮                                     ⋱                           
 -0.0322688   0.000986941   0.0471894      -0.00535209    0.0100576 
 -0.0313299  -0.0439111     0.0124698      -0.0241713    -0.00626812
 -0.030482   -0.0164279    -0.00514223  …   0.0173929     0.0313134 
 -0.0313018   0.0706865     0.0047833       0.052498      0.021586  
 -0.0316512  -0.0107718    -0.105356       -0.021864      0.033522  
 -0.0320653  -0.0166917    -0.0376717      -0.0344816    -0.0439615 
 -0.0315346   0.0295491     0.0420079      -0.0218553     0.0252366 
 -0.030643   -0.00999785    0.00499473  …   0.0167872    -0.0443659 
 -0.0315505   0.00366892   -0.0383638       0.0154938     0.0307068 
 -0.0317362   0.0115278     0.0182906      -0.0120225    -0.0342313 
 -0.0318841  -0.0228648     0.0590071       0.00592778   -0.0696986 
 -0.0327502  -0.00898135   -0.0257754      -0.00592045    0.0230224 ,

[500.007,18.1359,17.9385,17.8959,17.8611,17.7391,17.7121,17.6883,17.6336,17.5897  …  0.119142,0.115771,0.0893288,0.0766316,0.0612852,0.048867,0.0370283,0.0351352,0.0187093,0.00680023],
1000x1000 Array{Float64,2}:
 -0.0322955   0.00119357   -0.0243035   …  -0.0227516   -0.0121238 
 -0.032971   -0.0800886    -0.0698668      -0.0348376   -0.0238516 
 -0.03195    -0.0537429    -0.0584575       0.00896812  -0.0121454 
 -0.032239   -0.0065838    -0.0196659       0.0119562   -0.0231176 
 -0.0325748  -0.0309026    -0.0448319      -0.00174992   0.045656  
 -0.0308427   0.0187781    -0.057677    …   0.0514889    0.00401818
 -0.0305522  -0.0112776    -0.0539562      -0.00645983  -0.0296273 
 -0.032046   -0.0146263    -0.0349177       0.0103019   -0.0324972 
 -0.0310646   0.0897599     0.00122506      0.00921706   0.00301892
 -0.0320768  -0.00169417    0.0302692      -0.0173668   -0.0202389 
 -0.0318762  -0.0202933     0.0172769   …  -0.0546352    0.0294239 
 -0.0319001  -0.0210667     0.0560677       0.0479624    0.0213666 
 -0.0312647  -0.0498571     0.0159029       0.0394486    0.0222858 
  ⋮                                     ⋱                          
 -0.0315633  -0.0600609    -0.0271722       0.0531922    0.020346  
 -0.0311739  -0.0287136     0.0762643      -0.0558777    0.0262713 
 -0.0323909  -0.0515567     0.0402287   …   0.0122158   -0.00730309
 -0.032061    0.0366136    -0.0131001       0.0182199   -0.0116899 
 -0.0303308  -0.0126467     0.00137868      0.0212807   -0.0297874 
 -0.0308367  -0.0711133    -0.0277149      -0.035673    -0.012492  
 -0.0319187  -0.00153539    0.0307764       0.00933752  -0.0328619 
 -0.0318414  -0.0143061    -0.0236149   …  -0.0320921    0.0229836 
 -0.0321053   0.0585957     0.00319534     -0.0797821    0.0603332 
 -0.0322764  -0.000890043  -0.0790576      -0.00331492  -0.0163157 
 -0.0313317  -0.0085886    -0.0217407      -0.00376247   0.0119448 
 -0.033249   -0.0278551    -0.0182775      -0.0213252    0.0265923 )                                                 
 (
1000x1000 Array{Float64,2}:
 -0.0321836  -0.00297745    0.0111187   …  -0.0337682   -0.0182998 
 -0.0308504   0.0248013     0.0148731      -0.0252999   -0.0471536 
 -0.0325281   0.0395512     0.0297088      -0.00022007  -0.0362721 
 -0.0307975   0.0322079     0.00908688     -0.0456193   -0.0230697 
 -0.0314328  -0.0187266    -0.0595569      -0.00282989   0.0313624 
 -0.031832    0.00260467   -0.0243129   …  -0.0170886    0.0478207 
 -0.0319826   0.0113779     0.00822741      0.0290871   -0.00869156
 -0.0312552   0.0333114     0.0194111       0.065326     0.0060968 
 -0.0316926  -0.0451339    -0.0384118      -0.0177176    0.00381441
 -0.0320891  -0.0506606    -0.00506552     -0.0145112    0.0160023 
 -0.0330957   0.0108475    -0.00624669  …   0.0135705   -0.020802  
 -0.0323914  -0.00855534   -0.00955634      0.0161693   -0.0337319 
 -0.031605    0.0325389    -0.0432339       0.0607388   -0.0105273 
  ⋮                                     ⋱                          
 -0.0313625   0.0111191     0.0698121      -0.0312024   -0.0324048 
 -0.0320718  -0.0391466    -0.00594814     -0.0541554   -0.0436086 
 -0.031523   -0.000152669  -0.0119542   …   0.010718    -0.0283745 
 -0.0314384   0.022198     -0.0314677      -0.0200211   -0.0402655 
 -0.0325266  -0.0243512     0.00420992     -0.0462169   -0.0600497 
 -0.0307989   0.00870659   -0.0348654      -0.0163026   -0.0184254 
 -0.0319537   0.0138771     0.00553334      0.00332206   0.0435255 
 -0.0326789  -0.0197221     0.0350814   …  -0.0502508    0.0753324 
 -0.0311312  -0.0273051    -0.0339983      -0.017892    -0.0291703 
 -0.0312967   0.0428873     0.0292752      -0.0176499    0.00114455
 -0.0305234   0.0273568     0.0325067       0.0115195   -0.0308264 
 -0.0319621   0.0439981    -0.0400634      -0.0199784    0.0226343 ,

[500.618,18.3127,18.1638,18.0177,17.9535,17.9021,17.7955,17.745,17.6996,17.5864  …  0.126605,0.118031,0.107663,0.0941558,0.0903263,0.0464589,0.0393581,0.0291049,0.0198956,0.00311996],
1000x1000 Array{Float64,2}:
 -0.0318578   0.0204752   -0.00259606   …   0.0537378     0.0128961  
 -0.0312428  -0.0561763    0.0646875       -0.000457539   0.0284767  
 -0.0314256  -0.0628404    0.0603249       -0.0102337     0.0401459  
 -0.0312844   0.0288765    0.0120206       -0.0471644     0.0103918  
 -0.0317169   0.0407339    0.0119454        0.0390132    -0.000723993
 -0.0313529  -0.014059     0.0132301    …  -0.0143319    -0.00873342 
 -0.0307497   0.0347104    0.0246775       -0.000547225  -0.0165542  
 -0.0315722   0.0204099   -0.0216212       -0.0306536    -0.0119713  
 -0.0306945  -0.0323832    0.0211347        0.0678719     0.0127193  
 -0.0307669  -0.032466     0.016163         0.0298962     0.0386185  
 -0.0323766  -0.0161015    0.0320944    …  -0.0200903    -0.00446966 
 -0.0313843   0.0157253   -0.00443882       0.012719      0.00390969 
 -0.0326451   0.073238     0.00368126       0.0354305     0.0639259  
  ⋮                                     ⋱                            
 -0.031067   -0.055187    -0.0206122        0.036984      0.0202349  
 -0.030995   -0.0144559    0.000107196     -0.0121713     0.0183217  
 -0.0319696   0.0137264   -0.00490151   …   0.0288551     0.0100012  
 -0.0316169  -0.034485    -0.0242088        0.00759825    0.0216443  
 -0.0313676  -0.0299706   -0.0357974        0.00434088    0.0230899  
 -0.0313323   0.0250718   -0.00571447      -0.0179489    -0.0373981  
 -0.0316393  -0.0216792    0.0155216        0.0228069     0.0150528  
 -0.0311551   0.0829593    0.00214394   …  -0.0323333     0.0367447  
 -0.0321172   0.0411034   -0.00270131       0.000343015   0.0123599  
 -0.0312701   0.0516698   -0.0408235       -0.0238943    -0.0309582  
 -0.0318623  -0.0124982    0.0486201       -0.0591437     0.00963327 
 -0.0329565   0.00959101  -0.0339874       -0.0210767     0.0204057  )                        

In [35]:
@doc pmap


Out[35]:
..  pmap(f, lsts...; err_retry=true, err_stop=false, pids=workers())

Transform collections ``lsts`` by applying ``f`` to each element in parallel.
(Note that ``f`` must be made available to all worker processes; see :ref:`Code Availability and Loading Packages <man-parallel-computing-code-availability>` for details.)
If ``nprocs() > 1``, the calling process will be dedicated to assigning tasks.
All other available processes will be used as parallel workers, or on the processes specified by ``pids``.

If ``err_retry`` is ``true``, it retries a failed application of ``f`` on a different worker.
If ``err_stop`` is ``true``, it takes precedence over the value of ``err_retry`` and ``pmap`` stops execution on the first error.

In [36]:
@doc svd


Out[36]:
svd(A, B) -> U, V, Q, D1, D2, R0

Wrapper around svdfact extracting all parts the factorization to a tuple. Direct use of svdfact is therefore generally more efficient. The function returns the generalized SVD of A and B, returning U, V, Q, D1, D2, and R0 such that A = U*D1*R0*Q' and B = V*D2*R0*Q'.

svd(A, [thin=true]) -> U, S, V

Wrapper around svdfact extracting all parts the factorization to a tuple. Direct use of svdfact is therefore generally more efficient. Computes the SVD of A, returning U, vector S, and V such that A == U*diagm(S)*V'. If thin is true, an economy mode decomposition is returned. The default is to produce a thin decomposition.


In [ ]: