Skip to content

Instantly share code, notes, and snippets.

@jiahao
jiahao / perf.scilab
Created December 9, 2013 07:16
Performance benchmarks for Scilab
warning off;
function assert(bool)
if ~bool
error('Assertion failed')
end
endfunction
function timeit(name, func, varargin1)
lang = 'scilab';
@jiahao
jiahao / cg_hs.jl
Last active August 29, 2015 13:56
Conjugate gradients (Hestenes-Stiefel algorithm) implemented as a Julia iterator
import Base: start, next, done
immutable Terminator #Stores information related to when the algorithm should terminate
maxiter :: Int
resabsthresh :: Real
resrelthresh :: Real
end
Terminator(maxiter::Integer) = Terminator(maxiter, eps(), eps())
Terminator() = Terminator(0) #By default, always terminate.
@jiahao
jiahao / multipledispatchstats.jl
Last active August 29, 2015 13:58
Implement some statistics from 'Multiple Dispatch in Practice' in Julia
#Computes the dispatch ratio for each generic function defined in a module
#all: iterate over exported methods, or all methods?
function dispatchratio(M::Module=Base, all=false)
methodcount = Dict{Symbol, Int}()
for name in names(M, all)
try #name may not represent a function or function-able type
methodcount[name] = length(methods(eval(M, name)))
catch continue end
end
methodcount
@jiahao
jiahao / CheckUnicodeWidths.jl
Last active August 29, 2015 14:02
Check Unicode widths reported in Julia
RawUnicodeData=readdlm(download("http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt"), ';', String)
#UAX11 - http://www.unicode.org/reports/tr11/
widthmap={
"A "=>0, #ambiguous
"W "=>2, #wide
"F "=>2, #full
"N "=>0, #neutral
"Na "=>1, #narrow
"H "=>1, #half
@jiahao
jiahao / juliacontribmontage.jl
Last active October 14, 2020 05:55
Creates a photo montage of Julia contributors using ImageMagick
#Working version
using JSON
auth_token= #fill in to access Github API
function getcontribs(owner, repo, auth_token)
#Download information about contributors
page, authors=0, {}
while true #Download every page
page += 1
url="https://api.github.com/repos/$owner/$repo/contributors?page=$(page)&access_token=$(auth_token)"
@jiahao
jiahao / Computing character widths.ipynb
Last active August 29, 2015 14:04
Computing character widths.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jiahao
jiahao / methodsbyrank.jl
Created August 24, 2014 14:45
Which functions have methods defined only for scalars, vectors, or 2d-arrays?
el = Float64
types=(el, Vector{el}, Matrix{el})
functions=Dict()
for mytype in types
functions[mytype]={}
for method in methodswith(mytype, true)
(length(method.sig) == 1) || #Unary functions
(length(method.sig) == 2 && method.va) || #Binary function with varargs
continue
method.func.code.name in functions[mytype] && continue #Don't duplicate
@jiahao
jiahao / doublelength.jl
Last active August 29, 2015 14:05
An implementation of doublelength floating point arithmetic as described in Dekker, 1971. http://link.springer.com/article/10.1007%2FBF01397083 (See also https://github.com/jiahao/DoublelengthFloat.jl)
import Base: +, -, ⋅, *, /, √, convert
export DoublelengthFloat
immutable DoublelengthFloat{T<:FloatingPoint} <: FloatingPoint
head :: T
tail :: T
end
DoublelengthFloat(x::FloatingPoint) = DoublelengthFloat(x, zero(x))
convert{T<:FloatingPoint}(::Type{DoublelengthFloat{T}}, x::T) = DoublelengthFloat(x)
@jiahao
jiahao / .gitignore
Last active May 13, 2018 18:46
Julia Package Digest: automatic weekly summarizer of what's new in the Julia package ecosystem
.ipynb_checkpoints
*.ipynb
@jiahao
jiahao / githubworkflow.svg
Last active September 2, 2019 02:15
Julia developers' basic Github workflow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.