Created
March 15, 2023 04:22
-
-
Save antimon2/1a97a393cf243ef3cc7ed15196ec92fb to your computer and use it in GitHub Desktop.
applicable_sample.jl.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:20:13.645Z", | |
"end_time": "2023-03-15T13:20:13.209000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "versioninfo()", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Julia Version 1.8.5\nCommit 17cfb8e65ea (2023-01-08 06:45 UTC)\nPlatform Info:\n OS: Linux (x86_64-linux-gnu)\n CPU: 12 × Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\n WORD_SIZE: 64\n LIBM: libopenlibm\n LLVM: libLLVM-13.0.1 (ORCJIT, skylake)\n Threads: 1 on 12 virtual cores\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:20:36.399Z", | |
"end_time": "2023-03-15T13:20:34.821000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "A = rand(Float32, 2, 2);\nx = [1, -2];", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:21:20.856Z", | |
"end_time": "2023-03-15T13:21:19.434000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "?hasmethod", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "search: \u001b[0m\u001b[1mh\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1ms\u001b[22m\u001b[0m\u001b[1mm\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\u001b[0m\u001b[1mh\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1md\u001b[22m\n\n", | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"execution_count": 6, | |
"data": { | |
"text/plain": "\u001b[36m hasmethod(f, t::Type{<:Tuple}[, kwnames]; world=get_world_counter()) -> Bool\u001b[39m\n\n Determine whether the given generic function has a method matching the given\n \u001b[36mTuple\u001b[39m of argument types with the upper bound of world age given by \u001b[36mworld\u001b[39m.\n\n If a tuple of keyword argument names \u001b[36mkwnames\u001b[39m is provided, this also checks\n whether the method of \u001b[36mf\u001b[39m matching \u001b[36mt\u001b[39m has the given keyword argument names. If\n the matching method accepts a variable number of keyword arguments, e.g.\n with \u001b[36mkwargs...\u001b[39m, any names given in \u001b[36mkwnames\u001b[39m are considered valid. Otherwise\n the provided names must be a subset of the method's keyword arguments.\n\n See also \u001b[36mapplicable\u001b[39m.\n\n\u001b[39m\u001b[1m │ \u001b[22m\u001b[39m\u001b[1mJulia 1.2\u001b[22m\n\u001b[39m\u001b[1m │\u001b[22m\n\u001b[39m\u001b[1m │\u001b[22m Providing keyword argument names requires Julia 1.2 or later.\n\n\u001b[1m Examples\u001b[22m\n\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n\n\u001b[36m julia> hasmethod(length, Tuple{Array})\u001b[39m\n\u001b[36m true\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> f(; oranges=0) = oranges;\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> hasmethod(f, Tuple{}, (:oranges,))\u001b[39m\n\u001b[36m true\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> hasmethod(f, Tuple{}, (:apples, :bananas))\u001b[39m\n\u001b[36m false\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> g(; xs...) = 4;\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> hasmethod(g, Tuple{}, (:a, :b, :c, :d)) # g accepts arbitrary kwargs\u001b[39m\n\u001b[36m true\u001b[39m", | |
"text/markdown": "```\nhasmethod(f, t::Type{<:Tuple}[, kwnames]; world=get_world_counter()) -> Bool\n```\n\nDetermine whether the given generic function has a method matching the given `Tuple` of argument types with the upper bound of world age given by `world`.\n\nIf a tuple of keyword argument names `kwnames` is provided, this also checks whether the method of `f` matching `t` has the given keyword argument names. If the matching method accepts a variable number of keyword arguments, e.g. with `kwargs...`, any names given in `kwnames` are considered valid. Otherwise the provided names must be a subset of the method's keyword arguments.\n\nSee also [`applicable`](@ref).\n\n!!! compat \"Julia 1.2\"\n Providing keyword argument names requires Julia 1.2 or later.\n\n\n# Examples\n\n```jldoctest\njulia> hasmethod(length, Tuple{Array})\ntrue\n\njulia> f(; oranges=0) = oranges;\n\njulia> hasmethod(f, Tuple{}, (:oranges,))\ntrue\n\njulia> hasmethod(f, Tuple{}, (:apples, :bananas))\nfalse\n\njulia> g(; xs...) = 4;\n\njulia> hasmethod(g, Tuple{}, (:a, :b, :c, :d)) # g accepts arbitrary kwargs\ntrue\n```\n", | |
"text/latex": "\\begin{verbatim}\nhasmethod(f, t::Type{<:Tuple}[, kwnames]; world=get_world_counter()) -> Bool\n\\end{verbatim}\nDetermine whether the given generic function has a method matching the given \\texttt{Tuple} of argument types with the upper bound of world age given by \\texttt{world}.\n\nIf a tuple of keyword argument names \\texttt{kwnames} is provided, this also checks whether the method of \\texttt{f} matching \\texttt{t} has the given keyword argument names. If the matching method accepts a variable number of keyword arguments, e.g. with \\texttt{kwargs...}, any names given in \\texttt{kwnames} are considered valid. Otherwise the provided names must be a subset of the method's keyword arguments.\n\nSee also \\href{@ref}{\\texttt{applicable}}.\n\n\\begin{quote}\n\\textbf{compat}\n\nJulia 1.2\n\nProviding keyword argument names requires Julia 1.2 or later.\n\n\\end{quote}\n\\section{Examples}\n\\begin{verbatim}\njulia> hasmethod(length, Tuple{Array})\ntrue\n\njulia> f(; oranges=0) = oranges;\n\njulia> hasmethod(f, Tuple{}, (:oranges,))\ntrue\n\njulia> hasmethod(f, Tuple{}, (:apples, :bananas))\nfalse\n\njulia> g(; xs...) = 4;\n\njulia> hasmethod(g, Tuple{}, (:a, :b, :c, :d)) # g accepts arbitrary kwargs\ntrue\n\\end{verbatim}\n" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:20:52.419Z", | |
"end_time": "2023-03-15T13:20:51.077000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "hasmethod(*, Base.typesof(A, x))", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 3, | |
"data": { | |
"text/plain": "true" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:21:12.710Z", | |
"end_time": "2023-03-15T13:21:11.814000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "?applicable", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "search: \u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1ml\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mb\u001b[22m\u001b[0m\u001b[1ml\u001b[22m\u001b[0m\u001b[1me\u001b[22m\n\n", | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": "\u001b[36m applicable(f, args...) -> Bool\u001b[39m\n\n Determine whether the given generic function has a method applicable to the\n given arguments.\n\n See also \u001b[36mhasmethod\u001b[39m.\n\n\u001b[1m Examples\u001b[22m\n\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n\n\u001b[36m julia> function f(x, y)\u001b[39m\n\u001b[36m x + y\u001b[39m\n\u001b[36m end;\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> applicable(f, 1)\u001b[39m\n\u001b[36m false\u001b[39m\n\u001b[36m \u001b[39m\n\u001b[36m julia> applicable(f, 1, 2)\u001b[39m\n\u001b[36m true\u001b[39m", | |
"text/markdown": "```\napplicable(f, args...) -> Bool\n```\n\nDetermine whether the given generic function has a method applicable to the given arguments.\n\nSee also [`hasmethod`](@ref).\n\n# Examples\n\n```jldoctest\njulia> function f(x, y)\n x + y\n end;\n\njulia> applicable(f, 1)\nfalse\n\njulia> applicable(f, 1, 2)\ntrue\n```\n", | |
"text/latex": "\\begin{verbatim}\napplicable(f, args...) -> Bool\n\\end{verbatim}\nDetermine whether the given generic function has a method applicable to the given arguments.\n\nSee also \\href{@ref}{\\texttt{hasmethod}}.\n\n\\section{Examples}\n\\begin{verbatim}\njulia> function f(x, y)\n x + y\n end;\n\njulia> applicable(f, 1)\nfalse\n\njulia> applicable(f, 1, 2)\ntrue\n\\end{verbatim}\n" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2023-03-15T04:21:00.146Z", | |
"end_time": "2023-03-15T13:20:58.478000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "applicable(*, A, x)", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 4, | |
"data": { | |
"text/plain": "true" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "julia-1.8", | |
"display_name": "Julia 1.8.5", | |
"language": "julia" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"name": "julia", | |
"mimetype": "application/julia", | |
"version": "1.8.5" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "applicable_sample.jl.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment