Skip to content

Instantly share code, notes, and snippets.

@mauro3
mauro3 / Project.toml
Last active October 23, 2024 19:26
HA!
[deps]
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
[compat]
julia = "1.10"
# löse aufgabe a/b=0.567567567567567567567567567567567567
# für a und b integer
#
# Plan: b * 0.567567567567567567567567567567567567 muss ein Integer sein, test für viele b's
c = 0.567567567567567567
for b in (1:10000000)
a = b * c
if isapprox(a, round(a), atol= 0.000000001)
@mauro3
mauro3 / Project.toml
Last active November 7, 2023 21:51
Appl-GL Ng & Björnsson 2003
[deps]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
@mauro3
mauro3 / inpoly.jl
Created October 11, 2016 19:28
inpoly using winding number
"""
Determines the winding number of a point and a polygon, i.e. how many
times a polygon winds around the point.
It follows Dan Sunday: http://geomalgorithms.com/a03-_inclusion.html.
"""
function windnr(p, poly::Matrix)
@assert length(p)==2
@assert poly[:,1]==poly[:,end]
# Loop over edges
@mauro3
mauro3 / fd.jl
Created June 30, 2016 20:01
forwarddiff with in-place functions
using ForwardDiff
const T = Float64 # the datatype used, probably Float64
const dof = 4
fn!(;T_::Type=T, dof_=dof) = zeros(T_,dof_)
function fn!(res, y)#, dydt)
@show typeof(res), typeof(y)
for i=1:dof
@mauro3
mauro3 / keybase
Created February 10, 2016 10:17
keybase
g6Rib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEg4nED35D0YZDTJsyP7FhhmPVJNpmBvyVfqvBryngYSNUKp3BheWxvYWTFAud7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwZTI3MTAzZGY5MGY0NjE5MGQzMjZjYzhmZWM1ODYxOThmNTQ5MzY5OTgxYmYyNTVmYWFmMDZiY2E3ODE4NDhkNTBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwZTI3MTAzZGY5MGY0NjE5MGQzMjZjYzhmZWM1ODYxOThmNTQ5MzY5OTgxYmYyNTVmYWFmMDZiY2E3ODE4NDhkNTBhIiwidWlkIjoiOTQwOGZhZGRmNGEwOTgzYjI0NmEyMGFiMTIyMWI1MTkiLCJ1c2VybmFtZSI6Im1hdXJvMyJ9LCJzZXJ2aWNlIjp7Im5hbWUiOiJnaXRodWIiLCJ1c2VybmFtZSI6Im1hdXJvMyJ9LCJ0eXBlIjoid2ViX3NlcnZpY2VfYmluZGluZyIsInZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVyc2lvbiI6IjEuMC45In0sImN0aW1lIjoxNDU1MDk5MzE5LCJleHBpcmVfaW4iOjUwNDU3NjAwMCwibWVya2xlX3Jvb3QiOnsiY3RpbWUiOjE0NTUwOTkyNzUsImhhc2giOiJjMzdiNDlmYjk5NGU3ZjE5MzQyMDA4MGJkZmM0ZjM5ZDk5ODFmODg0NWRmNTM4MmZiM2FmZTg4YzI0MTcyNjNhNGQ0ZTYyOWZmZTA3MTg1MDQ4NDIzMGQzNTkyYzgyMjYxMWI2YTdlZDVhZTkzZmRjNDE4YjUxNjMwMWNlODYyMCIsInNlcW5vIjozODAxOTl9LCJwcmV2IjoiYjI1MzNkMzYwZmU3MGRjYzRhNDM5MDAyODA0MmY2MGVjMWJhNjlk
# How to document functions vs methods?
function plot(x::Vector, y::Vector)
doc"""
Line-plot of x vs y.
"""
...
end
function plot(a::Matrix)
module LoremIpsum
doc"""
LoremIpsum: dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
n = 200
reps = 10^4
orderedinds = [1:n]
disorderedinds = orderedinds[randperm(n)]
function frows()
acc = 0
inds = disorderedinds
for i in rand(1:n, reps)
acc += sortperm(inds)[1]
# This performance regression seems to be fixed now. Maybe one of the many commits of @vtjnash?
#
# sandbox/performance_regressions>> julia sg.jl # 664cab522c0
# elapsed time: 0.268316893 seconds (14911976 bytes allocated)
# elapsed time: 0.267490744 seconds (14837704 bytes allocated)
# elapsed time: 0.275272316 seconds (14793688 bytes allocated, 3.10% gc time)
# sandbox/performance_regressions>> juliamf sg.jl # around 66cfa99913
# elapsed time: 0.413370651 seconds (14868712 bytes allocated)
# elapsed time: 0.41186328 seconds (14828776 bytes allocated)
# elapsed time: 0.427139988 seconds (14916648 bytes allocated, 1.98% gc time)