This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,9 @@ jobs: | |
matrix: | ||
version: | ||
- '1.6' | ||
- '1.9' | ||
- '1.7' | ||
- '1.8' | ||
- '1' | ||
- 'nightly' | ||
os: | ||
- ubuntu-latest | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Format suggestions | ||
on: | ||
pull_request: | ||
jobs: | ||
code-style: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: julia-actions/julia-format@v2 |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
# FastForwardDiff | ||
# FastForwardDiff.jl | ||
|
||
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://gerlero.github.io/FastForwardDiff.jl/stable/) | ||
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://gerlero.github.io/FastForwardDiff.jl/dev/) | ||
[![Build Status](https://github.com/gerlero/FastForwardDiff.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/gerlero/FastForwardDiff.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
[![Coverage](https://codecov.io/gh/gerlero/FastForwardDiff.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/gerlero/FastForwardDiff.jl) | ||
[![PkgEval](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/F/FastForwardDiff.svg)](https://JuliaCI.github.io/NanosoldierReports/pkgeval_badges/F/FastForwardDiff.html) | ||
[![Aqua](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) | ||
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle) | ||
|
||
**Fast and easy derivatives of scalar functions** with forward-mode automatic differentiation. | ||
|
||
Compared to the scalar differentiation offered by the very popular [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) package, **FastForwardDiff** adds: | ||
|
||
- **Efficient single-pass value and derivatives** with the `value_and_derivative` and `value_and_derivatives` functions. Faster and easier than ForwardDiff's equivalent (i.e., the [DiffResults API](https://github.com/JuliaDiff/DiffResults.jl)) ✅ | ||
- **[Unitful.jl](https://github.com/PainterQubits/Unitful.jl) support.** Correctly handles units in the inputs and outputs of functions ✅ | ||
|
||
Internally, it relies on the proven dual-number implementation from ForwardDiff. | ||
|
||
## Example | ||
|
||
```julia | ||
julia> using FastForwardDiff | ||
|
||
julia> f(x) = x^2 + 2x + 1 | ||
|
||
julia> derivative(f, 3) | ||
8 | ||
|
||
julia> value_and_derivative(f, 3) | ||
(16, 8) | ||
``` | ||
|
||
## Documentation | ||
|
||
- [**STABLE**](https://gerlero.github.io/FastForwardDiff.jl/stable/) — documentation of the most recent release | ||
- [**DEV**](https://gerlero.github.io/FastForwardDiff.jl/dev/) — documentation of the in-development version |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
using FastForwardDiff | ||
using Documenter | ||
|
||
DocMeta.setdocmeta!(FastForwardDiff, :DocTestSetup, :(using FastForwardDiff); recursive=true) | ||
DocMeta.setdocmeta!(FastForwardDiff, | ||
:DocTestSetup, | ||
:(using FastForwardDiff); | ||
recursive = true) | ||
|
||
makedocs(; | ||
modules=[FastForwardDiff], | ||
authors="Gabriel Gerlero", | ||
repo="https://github.com/gerlero/FastForwardDiff.jl/blob/{commit}{path}#{line}", | ||
sitename="FastForwardDiff.jl", | ||
format=Documenter.HTML(; | ||
prettyurls=get(ENV, "CI", "false") == "true", | ||
canonical="https://gerlero.github.io/FastForwardDiff.jl", | ||
edit_link="main", | ||
assets=String[], | ||
), | ||
pages=[ | ||
modules = [FastForwardDiff], | ||
authors = "Gabriel Gerlero", | ||
repo = "https://github.com/gerlero/FastForwardDiff.jl/blob/{commit}{path}#{line}", | ||
sitename = "FastForwardDiff.jl", | ||
format = Documenter.HTML(; | ||
prettyurls = get(ENV, "CI", "false") == "true", | ||
canonical = "https://gerlero.github.io/FastForwardDiff.jl", | ||
edit_link = "main", | ||
assets = String[],), | ||
pages = [ | ||
"Home" => "index.md", | ||
], | ||
) | ||
],) | ||
|
||
deploydocs(; | ||
repo="github.com/gerlero/FastForwardDiff.jl", | ||
devbranch="main", | ||
) | ||
repo = "github.com/gerlero/FastForwardDiff.jl", | ||
devbranch = "main",) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,44 @@ | ||
module FastForwardDiff | ||
|
||
# Write your package code here. | ||
using ForwardDiff: Dual, Tag, value, extract_derivative | ||
using Unitful: unit, ustrip | ||
|
||
""" | ||
derivative(f, x) -> f'(x) | ||
Compute the derivative of `f` at `x` using forward-mode automatic differentiation. | ||
""" | ||
@inline function derivative(f, x) | ||
T = typeof(Tag(f, typeof(one(x)))) | ||
ydual = f(Dual{T}(ustrip(x), one(x)) * unit(x)) | ||
return extract_derivative(T, ustrip(ydual)) * unit(ydual) / unit(x) | ||
end | ||
|
||
""" | ||
value_and_derivative(f, x) -> f(x), f'(x) | ||
Compute the value and derivative of `f` at `x` in a single pass using forward-mode automatic differentiation. | ||
""" | ||
@inline function value_and_derivative(f, x) | ||
T = typeof(Tag(f, typeof(one(x)))) | ||
ydual = f(Dual{T}(ustrip(x), one(x)) * unit(x)) | ||
return value(T, ustrip(ydual)) * unit(ydual), | ||
extract_derivative(T, ustrip(ydual)) * unit(ydual) / unit(x) | ||
end | ||
|
||
""" | ||
value_and_derivatives(f, x) -> f(x), f'(x), f''(x) | ||
Compute the value and first and second derivatives of `f` at `x` in a single pass using forward-mode automatic differentiation. | ||
""" | ||
@inline function value_and_derivatives(f, x) | ||
T = typeof(Tag(f, typeof(one(x)))) | ||
ydual, ddual = value_and_derivative(f, Dual{T}(ustrip(x), one(x)) * unit(x)) | ||
return value(T, ustrip(ydual)) * unit(ydual), | ||
value(T, ustrip(ddual)) * unit(ddual), | ||
extract_derivative(T, ustrip(ddual)) * unit(ddual) / unit(x) | ||
end | ||
|
||
export derivative, value_and_derivative, value_and_derivatives | ||
|
||
end |
This file contains 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
5f39551
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
5f39551
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/97348
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: