https://github.com/julialang/functionwrappers.jl
Type stable and efficient wrapper of arbitrary Julia functions
https://github.com/julialang/functionwrappers.jl
julia
Last synced: 27 days ago
JSON representation
Type stable and efficient wrapper of arbitrary Julia functions
- Host: GitHub
- URL: https://github.com/julialang/functionwrappers.jl
- Owner: JuliaLang
- License: other
- Created: 2016-08-01T08:27:42.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-11-09T14:37:57.000Z (about 1 year ago)
- Last Synced: 2025-03-28T13:46:05.481Z (9 months ago)
- Topics: julia
- Language: Julia
- Homepage:
- Size: 59.6 KB
- Stars: 110
- Watchers: 13
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# FunctionWrappers.jl: Type stable and efficient wrapper of arbitrary functions
[](https://github.com/JuliaLang/FunctionWrappers.jl/actions)
[](https://codecov.io/gh/JuliaLang/FunctionWrappers.jl)
Proof of principle implementation of [JuliaLang/julia#13984](https://github.com/JuliaLang/julia/issues/13984).
## Limitations
1. Does not handle more than 128 arguments without jlcall wrapper
128 is an arbitrary limit. Should be high enough for all practical cases
2. Does not support vararg argument types
3. Wrapper Object cannot be serialized by `dump.c` and therefore the
precompilation of `FunctionWrappers` is done using a runtime branch
and by making the wrapper type mutable.
## Compared to `@cfunction`
This does not require LLVM trampoline support, which is not currently supported by LLVM
on all the architectures julia runs on ([JuliaLang/julia#27174](https://github.com/JuliaLang/julia/issues/27174)).
Other than this issue `@cfunction` should cover all of the use cases.
## Simple Usage Example
```julia
using FunctionWrappers
import FunctionWrappers: FunctionWrapper
# For a function that sends (x1::T1, x2::T2, ...) -> ::TN, you use
# a FunctionWrapper{TN, Tuple{T1, T2, ...}}.
struct TypeStableStruct
fun::FunctionWrapper{Float64, Tuple{Float64, Float64}}
second_arg::Float64
end
evaluate_strfun(str, arg) = str.fun(arg, str.second_arg)
example = TypeStableStruct(hypot, 1.0)
@code_warntype evaluate_strfun(example, 1.5) # all good
```