Skip to content

Instantly share code, notes, and snippets.

View timholy's full-sized avatar

Tim Holy timholy

View GitHub Profile
-- isequal(REPL.LineEdit.Prompt, REPL.LineEdit.Prompt)
-- isequal(Method, Method)
-- isequal(Distributed.RemoteChannel{Base.Channel{Any}}, WeakRef)
-- isequal(Distributed.RemoteChannel{Base.Channel{Any}}, Distributed.RemoteChannel{Base.Channel{Any}})
-- isequal(Core.TypeName, Core.TypeName)
-- isequal(Symbol, Symbol)
-- isequal(String, Int64)
-- isequal(String, Char)
-- isequal(String, String)
-- isequal(Char, Char)
@timholy
timholy / nspecializations.jl
Created March 16, 2020 17:20
Counting the number of specializations of a method
function nspecializations(m::Method)
return isdefined(m, :specializations) ? nspecializations(m.specializations) : 0
end
nspecializations(::Nothing) = 0
function nspecializations(tme::Core.TypeMapEntry)
n = 0
while tme !== nothing
n += 1
tme = tme.next
end
@timholy
timholy / expandci.jl
Created March 11, 2020 13:59
A demo of external compiler passes in Julia
using Base.Meta: isexpr
# Grabbing the inferred code
function disable_pass!(src)
for (line, stmt) in enumerate(src.code)
if isexpr(stmt, :meta, 1)
a = stmt.args[1]
if isexpr(a, :external_pass)
mode = a.args[1]
@timholy
timholy / imfilter.jl
Last active March 4, 2020 23:38
ImageFiltering and LoopVectorization, perfect together
using ImageFiltering, ImageCore, OffsetArrays
using ImageFiltering: safehead, safetail, safe_for_prod
using LoopVectorization
function old!(out, A, kern, R=CartesianIndices(out), z=zero(eltype(out)))
Rk = CartesianIndices(axes(kern))
for I in safetail(R), i in safehead(R)
tmp = z
@inbounds for J in safetail(Rk), j in safehead(Rk)
tmp += safe_for_prod(A[i+j,I+J], tmp)*kern[j,J]
@timholy
timholy / newtests.jl
Created February 12, 2020 14:48
Additional type-system tests for ColorTypes
using FixedPointNumbers, ColorTypes, Test
AbstractAGrayT{T} = AlphaColor{C,T,2} where C<:AbstractGray{T} # Like AbstractAGray but having just an eltype type-parameter
AbstractGrayAT{T} = ColorAlpha{C,T,2} where C<:AbstractGray{T}
using ColorTypes: TwoColorTypeError
const all_colorants = map(s->getfield(ColorTypes,s),
filter(names(ColorTypes, all=false)) do s
isdefined(ColorTypes, s) || return false
t = getfield(ColorTypes, s)
isa(t, Type) && t <: Colorant && !isabstracttype(t)
@timholy
timholy / NaNIntegers.jl
Created January 15, 2020 11:57
Prototype of NaNIntegers
module NaNIntegers
import Base: <, <=, +, -, *, ~, &, |, <<, >>, >>>, xor
export NInt16, NInt32, NInt64, NInt128, NInt
export NaNI16, NaNI32, NaNI64, NaNI128
abstract type NSigned <: Signed end
primitive type NInt16 <: NSigned 16 end
@timholy
timholy / Manifest.toml
Created January 1, 2020 18:53
TOML files with potential resolver bug
# This file is machine-generated - editing it directly is not advised
[[AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "051c95d6836228d120f5f4b984dd5aba1624f716"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "0.5.0"
[[ArgCheck]]
deps = ["Random"]
# This file is machine-generated - editing it directly is not advised
[[ATK_jll]]
deps = ["Glib_jll", "Libdl", "Pkg"]
git-tree-sha1 = "7129d58ed99d42032cefe21bcd14171a878143d2"
uuid = "7b86fcea-f67b-53e1-809c-8f1719c154e8"
version = "2.34.1+2"
[[AbstractFFTs]]
deps = ["LinearAlgebra"]
@timholy
timholy / recache.log
Created December 10, 2019 12:47
Log file of `sig`s from `jl_recache_method_instance`
This file has been truncated, but you can view the full file.
Tuple{getfield(Core, Symbol("#Type##kw")), Any, Type{Base.GenericIOBuffer{Array{UInt8, 1}}}}
Tuple{Type{Base.GenericIOBuffer{Array{UInt8, 1}}}}
Tuple{typeof(Base.:(^)), T, T} where T<:Integer
Tuple{typeof(Base.isempty), Tuple}
Tuple{typeof(Base.:(==)), T, T} where T<:Number
Tuple{typeof(Base.convert), Type{T}, T} where T<:Number
Tuple{typeof(Base.getproperty), Any, Symbol}
Tuple{Type{Float32}, Float64}
Tuple{getfield(Base, Symbol("##IOBuffer#311")), Union{Nothing, Bool}, Union{Nothing, Bool}, Union{Nothing, Bool}, Union{Nothing, Bool}, Integer, Union{Nothing, Integer}, Type{Base.GenericIOBuffer{Array{UInt8, 1}}}}
Tuple{typeof(Base.print), IO, Char}
@timholy
timholy / traverse.jl
Last active November 20, 2019 11:50
Traversing all compiled methods
function traverse(val, mod::Module, visiting=Set{Module}())
push!(visiting, mod)
val = increment(val, mod)
for nm in names(mod; all=true)
if isdefined(mod, nm)
obj = getfield(mod, nm)
if isa(obj, Module)
obj in visiting && continue
val = traverse(val, obj, visiting)
else