Skip to content

Instantly share code, notes, and snippets.

@mauro3
mauro3 / Manifest.toml
Last active Nov 17, 2020
Appl-GL Ng & Björnsson 2003
View Manifest.toml
# This file is machine-generated - editing it directly is not advised
[[Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "42c42f2221906892ceb765dbcb1a51deeffd86d7"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "2.3.0"
[[ArnoldiMethod]]
deps = ["DelimitedFiles", "LinearAlgebra", "Random", "SparseArrays", "StaticArrays", "Test"]
@mauro3
mauro3 / inpoly.jl
Created Oct 11, 2016
inpoly using winding number
View inpoly.jl
"""
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 Jun 30, 2016
forwarddiff with in-place functions
View fd.jl
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
View keybase
g6Rib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEg4nED35D0YZDTJsyP7FhhmPVJNpmBvyVfqvBryngYSNUKp3BheWxvYWTFAud7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwZTI3MTAzZGY5MGY0NjE5MGQzMjZjYzhmZWM1ODYxOThmNTQ5MzY5OTgxYmYyNTVmYWFmMDZiY2E3ODE4NDhkNTBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwZTI3MTAzZGY5MGY0NjE5MGQzMjZjYzhmZWM1ODYxOThmNTQ5MzY5OTgxYmYyNTVmYWFmMDZiY2E3ODE4NDhkNTBhIiwidWlkIjoiOTQwOGZhZGRmNGEwOTgzYjI0NmEyMGFiMTIyMWI1MTkiLCJ1c2VybmFtZSI6Im1hdXJvMyJ9LCJzZXJ2aWNlIjp7Im5hbWUiOiJnaXRodWIiLCJ1c2VybmFtZSI6Im1hdXJvMyJ9LCJ0eXBlIjoid2ViX3NlcnZpY2VfYmluZGluZyIsInZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVyc2lvbiI6IjEuMC45In0sImN0aW1lIjoxNDU1MDk5MzE5LCJleHBpcmVfaW4iOjUwNDU3NjAwMCwibWVya2xlX3Jvb3QiOnsiY3RpbWUiOjE0NTUwOTkyNzUsImhhc2giOiJjMzdiNDlmYjk5NGU3ZjE5MzQyMDA4MGJkZmM0ZjM5ZDk5ODFmODg0NWRmNTM4MmZiM2FmZTg4YzI0MTcyNjNhNGQ0ZTYyOWZmZTA3MTg1MDQ4NDIzMGQzNTkyYzgyMjYxMWI2YTdlZDVhZTkzZmRjNDE4YjUxNjMwMWNlODYyMCIsInNlcW5vIjozODAxOTl9LCJwcmV2IjoiYjI1MzNkMzYwZmU3MGRjYzRhNDM5MDAyODA0MmY2MGVjMWJhNjlk
View methods_vs_function_doc.jl
# How to document functions vs methods?
function plot(x::Vector, y::Vector)
doc"""
Line-plot of x vs y.
"""
...
end
function plot(a::Matrix)
View lorem_v2.jl
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.
View sortperm_reg.jl
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]
View sparse_getindex_range_of_cols.jl
# 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)
View v0.2.1
sparse_getindex_small1,Small sparse matrix with 10 entries/column, indexing with integers,0.448931,0.468407,0.454377,0.007985
sparse_getindex_small2,Small sparse matrix with 100 entries/column, indexing with integers,0.651765,0.696139,0.668417,0.016734
sparse_getindex_medium1,Medium sparse matrix with 10 entries/column, indexing with integers,0.795296,0.856736,0.811085,0.025680
sparse_getindex_medium2,Medium sparse matrix with 100 entries/column, indexing with integers,1.253497,1.260646,1.256850,0.003009
sparse_getindex_small3,Sparse matrix with 10 entries/column, indexing rows with a range,1.731063,9.425001,4.829933,3.849493
sparse_getindex_small4,Sparse matrix with 10 entries/column, indexing rows with a ordered array,1.619907,8.389759,2.987851,3.019779
sparse_getindex_small5,Sparse matrix with 10 entries/column, indexing rows with a disordered array,1.837361,1.860880,1.850504,0.009153
sparse_getindex_small6,Sparse matrix with 10 entries/column, indexing rows with a range,0.616219,0.638256,0.621277,0.009504
View comp_2.jl
using Base.Order
using Base.SparseMatrix.binarysearch
const N = 10^2
const NN = N*10^2
const rowvalA = sort(randperm(NN)[1:N])
const iss = randperm(NN) # disordered needle
const iso = [1:NN] # ordered needles
function h1(rowvalA, iss)