Giter Club home page Giter Club logo

functionwrappers.jl's Introduction

FunctionWrappers.jl: Type stable and efficient wrapper of arbitrary functions

Build Status Build Status Build status codecov.io

Proof of principle implementation of JuliaLang/julia#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). Other than this issue @cfunction should cover all of the use cases.

Simple Usage Example

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

functionwrappers.jl's People

Contributors

ancapdev avatar cgeoga avatar chrisrackauckas avatar sethaxen avatar staticfloat avatar tkoolen avatar yuyichao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.