https://github.com/xzackli/referenceimplementations.jl
nested implementation selector
https://github.com/xzackli/referenceimplementations.jl
julia metaprogramming
Last synced: about 2 months ago
JSON representation
nested implementation selector
- Host: GitHub
- URL: https://github.com/xzackli/referenceimplementations.jl
- Owner: xzackli
- License: mit
- Created: 2021-04-02T19:25:24.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-12T20:38:22.000Z (about 4 years ago)
- Last Synced: 2025-04-04T01:03:22.962Z (2 months ago)
- Topics: julia, metaprogramming
- Language: Julia
- Homepage:
- Size: 229 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ReferenceImplementations.jl
[](https://xzackli.github.io/ReferenceImplementations.jl/dev)
[](https://github.com/xzackli/ReferenceImplementations.jl/actions)
[](https://codecov.io/gh/xzackli/ReferenceImplementations.jl)This package exports the `@refimpl` macro to help you write fast scientific code. It lets you define two implementations of the same method, by prefacing the reference implementation's definition with `@refimpl`. The non-reference implementation is called by default, but the reference implementation can be invoked in an expression using the same macro `@refimpl`, even if the method call is deeply nested.
For more instructions, please consult the [documentation](https://xzackli.github.io/ReferenceImplementations.jl/dev).
## How?
If the `@refimpl` macro is applied to a method definition, it injects a first argument of type `ReferenceImplementations.RefImpl` into the signature. This performs the transform
```julia
func(args...; kwargs...) ⇨ func(::ReferenceImplementations.RefImpl, args...; kwargs...)
```
with the type signatures preserved (so `where` and `::T` match, for example). When you apply the `@refimpl` macro to an expression that isn't a function definition, it applies a Cassette pass for each top-level function call in an expression, which replaces `func(args...; kwargs...)` with `func(::ReferenceImplementations.RefImpl, args...; kwargs...)` if that method exists.This also means that you can manually call the reference implementation without the macro, using
```julia
using ReferenceImplementations: RefImpl
func(RefImpl(), args...; kwargs...)
```