Skip to content

Instantly share code, notes, and snippets.

@apow2
apow2 / demo.jl
Last active January 10, 2021 19:54
abstract type Person end
abstract type Tourist <:Person end
abstract type Deer end
encounter(a::Deer, b::Tourist) = "bows politely"
encounter(a::Tourist, b::Deer) = "feeds"
encounter(a::Person, b::Deer) = "beckons"
encounter(a::Deer, b::Person) = "ignores"
encounter(a::Tourist, b::Deer, foo::String) = "feeds deer $foo"
import LinearAlgebra.det
encounter(a::Person, b::Person) = "hello"
encounter(a::Person, b:: Tourist) = "takes picture"
encounter(a::Person, b::Person, c::Person) = "converses"
dine(a::Tourist) = "picks up fork"
parfor i = 1:100
A(i) = eig(rand(500))
end
x = [1, 1];
for k = 3:1000000
x(k) = x(k-1) + x(k-2);
end
x = zeros(1000000, 1); x(1:2) = [1, 1]
for k = 3:1000000
x(k) = x(k-1) + x(k-2);
end
a = rand(500, 500)
b = rand(500, 500)
c = rand(500, 1)
a*b*c % O(N^3) time complexity
a*(b*c) % O(N^2) time complexity
ddddd
t = 0:.05:20;
y = exp(t);
i = 0;
for t = 0:.05:20
i = i + 1;
y(i) = exp(t);
end
@apow2
apow2 / sparse.m
Last active January 11, 2021 10:59
x = diag(ones(10000, 1)) % matrix with ones on diagonal and zero elsewhere
z = sparse(x) % compressed adjacency list representation
using DataFrames
using CSV
using Random
using LinearAlgebra
redwine = DataFrames.DataFrame(CSV.File("winequality-red.csv"))
mat = Matrix(redwine)[:, 1:11]
A = mat[:, 1:end-1] #features
y = mat[:, end]; #labels