[su_row]
[su_column]
[su_box title=”Getting started” style=”bubbles” box_color=”#63eb2a” radius=”8″]
Pkg.add("QuantumLab") using QuantumLab
[/su_box]
[su_box title=”DataTypes” style=”bubbles” box_color=”#ef5908″ radius=”8″]
[table]
Group, Keyword, Explanation
Data Types, abstract
, only for internal nodes of the type-tree
Data Types, bitstype N
, basal type of length N bits
Data Types, type
, like a struct in C
Data Types, immutable
, type that is totally defined by the values of its fields
Other Types, TupleTypes, e.g. (a,b,c)
\, covariant with a\,b\,c
Other Types, UnionTypes, (e.g. Union(a,b,c)
)
Parametric Types, type ...{T}
, invariant with T
Parametric Types, abstract ...{T}
,
Parametric Types, Type{T}
, only T <: Type{T}
Parametric Types, bitstype N ...{T}
, T is only an abstract tag
Typealias, typealias
, e.g. typealias Matrix{T} Array{T,2}
[/table]
[/su_box]
[su_box title=”Optimizations” style=”bubbles” box_color=”#ef2708″ radius=”8″]
- Avoid global variables (at least declare them const or annotate their types at the point of use)
- Always at least @time and pay attention to memory allocations (they might be a sign for type instability)
- @profile and ProfileView.view()
- @allocated or julia –track-allocation=user
- @code_warntype
- Lint and TypeCheck (if they work)
- Don’t use abstract types as parameters to parametric types (including Arrays)
- Don’t use abstract types for fields of a type (rather make the type parametric instead)
- When you know the explicit type to an abstract type given to your function, declare it on first use (this automatically makes for a runtime type check)
- sizehint!
- for i in 1:3 getfield(obj,i) end is faster than for f in fieldnames(obj) obj.(f) end
- push! is faster than append! when adding a single element
[/su_box]
[su_box title=”Tips and Tricks” style=”bubbles” box_color=”#ef9808″ radius=”8″]
- symlink /usr/share/julia/base (or equivalent on other OSs) to an easy to access location for quick reference (e.g. ~/juliabase)
- ~/juliabase/latex_symbols.jl is the reference for latex-codes (unicode input)
- adam-p has a comprehensive Markdown-Cheatsheet
[/su_box]
[/su_column][su_column]
[su_box title=”Module Import vs. Using” style=”bubbles” box_color=”#c12beb” radius=”8″]
if MyModule exports x
but a
not necessarily:
[table]
Import Command, Into Scope
using MyModule
, x; MyModule.a
using MyModule.a
, a
using MyModule:a
, a
import MyModule
, MyModule.a
import MyModule.a
, a
import MyModule:a
, a
importall MyModule
, x
[/table]
[/su_box]
[su_box title=”Module Search Path” style=”bubbles” box_color=”#462aeb” radius=”8″]
[table]
Command, Search Location
using Modulename
, $PATH/*
using("Modulename")
, $pwd/Modulename.jl
[/table]
[/su_box]
[su_box title=”Control Flow” style=”bubbles” box_color=”#08efee” radius=”8″]
[table]
Expression Type, Code
Compound Expressions, begin
and (;)
.
Conditional Evaluation, if-elseif-else
and ?:
(ternary operator).
Short-Circuit Evaluation, &&
\, ||
and chained comparisons.
Repeated Evaluation\, Loops, while
and for
.
Exception Handling, try-catch
\, error()
and throw()
.
Tasks (aka Coroutines), yieldto()
.
[/table]
[/su_box]
[su_box title=”Representation Layers” style=”bubbles” box_color=”#efee08″ radius=”8″]
[table]
#, Name, obtained by, comment
1, AST, :f
,
2, Lowered AST, @code_lowered f(x)
, desugared and unnested
3, Typed AST, @code_typed f(x)
, type-inferred and optimized
4, LLVM, @code_llvm f(x)
,
5, Assembly, @code_native f(x)
, machine-specific
[/table]
[/su_box]
[/su_column]
[/su_row]