Skip to content

Instantly share code, notes, and snippets.

@Jutho
Created June 28, 2015 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jutho/373f2c65ec129790426e to your computer and use it in GitHub Desktop.
Save Jutho/373f2c65ec129790426e to your computer and use it in GitHub Desktop.
function analyzeconvert()
methodlist = methods(convert,Tuple{Type,Number})
dict = Dict{DataType,Vector{Any}}()
for m in methodlist
to = m.sig.parameters[1].parameters[1]
from = m.sig.parameters[2]
TT = isa(to,Union) ? to.types : Base.svec(to)
TF = isa(from,Union) ? from.types : Base.svec(from)
for to in TT
for from in TF
if to<:Number && from<:Number
dict[Tuple{to,from}] = vcat(get(dict,Tuple{to,from},Any[]),[m])
end
end
end
end
types = [ Bool,
Int8, Int16, Int32, Int64, Int128,
UInt8, UInt16, UInt32, UInt64, UInt128,
Float16, Float32, Float64,
BigInt, BigFloat,
Signed, Unsigned, Integer,
Rational, Rational{BigInt}, FloatingPoint, Real, Complex, Number,
TypeVar(:T,Unsigned), TypeVar(:T,Signed), TypeVar(:T,Integer),
TypeVar(:T,Real), TypeVar(:T,Number) ]
N = length(types)
table = Array{Int}(N,N)
for i=1:N
for j=1:N
Ti = types[i]
Tj = types[j]
table[i,j] = 0
if haskey(dict,Tuple{Ti,Tj})
m = dict[Tuple{Ti,Tj}]
if length(m)>1
@show Tuple{Ti,Tj}
@show m
elseif Ti != m[1].sig.parameters[1].parameters[1]
@show Tuple{Ti,Tj}
@show m[1]
to = m[1].sig.parameters[1].parameters[1]
from = m[1].sig.parameters[2]
@show haskey(dict,Tuple{to,from})
elseif Tj != m[1].sig.parameters[2]
@show Tuple{Ti,Tj}
@show m[1]
to = m[1].sig.parameters[1].parameters[1]
from = m[1].sig.parameters[2]
@show haskey(dict,Tuple{to,from})
else
table[i,j] = 1
end
end
end
end
return types, table, dict
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment