Spring 2026
@ symbolx = 6
@show x^3
@assert x>1000 "x show be bigger than 1000"
@time sum(sqrt.(rand(10000)))
using BenchmarkTools
@benchmark sum(sqrt.(rand(10000)))
using ProgressMeter
@showprogress for idx in 1:216
sleep(0.1);
end
@. makes every operation in an expression dotted (vectorized)@threads before a loop makes the loop multithreaded@simd before a loop allows a loop to be fully vectorized@async wraps an expression in a task that can be run asyncronouslyquote … end defines a block of code that will not be executed until explicitly evaluated:( .. )eval(...)@macroexpand will display the macroMore Info: https://docs.julialang.org/en/v1/manual/metaprogramming/#man-macros
macro time(ex)
return quote
local start = time_ns()
local val = $ex # Evaluate the expression
local stop = time_ns()
println("elapsed time: ", (stop-start)/1e9, " seconds")
val
end
end
PyCall that let’s you call Python directlyusing Pkg
Pkg.add("PyCall") # Install, just once
More Info: https://github.com/JuliaPy/PyCall.jl
CondaPkg.build("PyCall")
using Conda
Conda.add(["numpy", "pandas", "scipy", "matplotlib"])
ENV["PYTHON"] = "/opt/local/bin/python" # Or Wherever yours is ...
Pkg.build("PyCall")
pyimportnp = pyimport("numpy");
x = np.random.normal(size=10, scale=2.5);
println("x = $x");
pd = pyimport("pandas");
foo = pd.read_csv("foo.csv")
foo["Name"]
RCall that let’s you use an R environment from inside Juliausing Pkg
Pkg.add("RCall") # Install, just once
using RCall # Whenever you want to use R
More Info: https://juliainterop.github.io/RCall.jl/stable/gettingstarted/
$@rputx = 3.1415; @rput x;
@rget@rget y;
println("y = $y");
x = R"rnorm(10)"
z = rcopy(R"rnorm(10)")
rdf = robject(df);
@rput rdf;
R"""
library(ggplot2)
ggplot(rdf, aes(x=sepal_length, y=sepal_width, fill=species)) +
geom_point(size=4, shape=21, color="black") +
xlab("Sepal Length of Iris") + ylab("Sepal Width of Iris")
"""
@rimport base as rbase rbase.sum(df.sepal_length) rcall(:summary, rdf)
? key puts you in Help mode] key puts you in Pkg mode (for package management); key from the Julia REPL^R$ key will switch the REPL to R mode@rput and @rgetx = [1,2,3];
y = [4,5,6];
z = x .* y;
println("z = $z");
string([1,2,3]) string.([1,2,3]) string([1,2,3], ["a", "b", "c"]) string.([1,2,3], ["a", "b", "c"])
fib(n) = n ≤ 2 ? one(n) : fib(n-1) + fib(n-2) # Fibonacci number dist(X,Y) = .√sum((X-Y).^2, dims=2) # Distance between every row vector betwen X and Y norm(X) = X./sum(X, dims=2) # Normalize each row vector in a matrix avglag(X) = sum(X[2:end] - X[1:end-1], dims=1) / (size(X)[1]-1) # Average lag between numbers in a list # Here's a cooler estimator for pi (Bailey-Borwein-Plouffe) bppEstimate(n) = sum([(1/16^k) * sum([4,-2,-1,-1] ./ (8*k .+ [1,4,5,6])) for k in 0:n])
M1 = M = [1 2 3; 4 5 6; 7 8 9]; M2 = rand(Float64, (3,3)); zero(M1) # What is zero for this data type? zero(M2) zero(6) zero(-1.77) one(M1) # What is identity for this data type? one(M2) one(6) one(-1.77) similar(M2) # Give me an uninitialized structure just like this one
≻(a,b) = all(a.>=b) && any(a.>b); x = [1,2,3]; y = [0,2,2]; z = [1,4,1]; x ≻ y x ≻ z
# Users can only send float matrices and vectors to this
function Print1(A::Matrix{Float64}, x::Vector{Float64})
println("A = $A");
println("x = $x");
end
# Users can send any matrix or vector that's an int, float, or complex
function Print2(A::Matrix{<:Real}, x::Vector{<:Real})
println("A = $A");
println("x = $x");
end
# Users can send any kind of matrix or vector to this
function Print2(A::AbstractMatrix, x::AbstractVector)
println("A = $A");
println("x = $x");
end