Skip to content

Instantly share code, notes, and snippets.

@jiahao
Created August 24, 2014 14:45
Show Gist options
  • Save jiahao/8c0f9166bb979ca9faa5 to your computer and use it in GitHub Desktop.
Save jiahao/8c0f9166bb979ca9faa5 to your computer and use it in GitHub Desktop.
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
push!(functions[mytype], method.func.code.name)
end
end
#This should be a list of all currently defined functions in the current namespace
allfunctions = unique([values(functions)...])
#Construct power sets of types
for powersetpattern in 0:2^(length(types))-1
for f in allfunctions
for (j, mytype) in enumerate(types)
hastype = bool((powersetpattern >> (j-1)) & 1)
f in functions[mytype] == hastype || @goto skip
end
for mytype in types
print(f in functions[mytype] ? "Y " : "- ")
end
println(string(f))
@label skip
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment