Skip to content

Commit 5af27fe

Browse files
authored
Merge branch 'master' into patch
2 parents ee25a5c + 0886582 commit 5af27fe

File tree

7 files changed

+127
-10
lines changed

7 files changed

+127
-10
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
push:
7+
branches:
8+
- master
9+
tags: '*'
10+
jobs:
11+
test:
12+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
13+
runs-on: ${{ matrix.os }}
14+
continue-on-error: ${{ matrix.version == 'nightly' }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
version:
19+
- '1.0'
20+
- '1'
21+
- 'nightly'
22+
os:
23+
- ubuntu-latest
24+
arch:
25+
- x64
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: julia-actions/setup-julia@v1
29+
with:
30+
version: ${{ matrix.version }}
31+
arch: ${{ matrix.arch }}
32+
- uses: actions/cache@v1
33+
env:
34+
cache-name: cache-artifacts
35+
with:
36+
path: ~/.julia/artifacts
37+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
38+
restore-keys: |
39+
${{ runner.os }}-test-${{ env.cache-name }}-
40+
${{ runner.os }}-test-
41+
${{ runner.os }}-
42+
- uses: julia-actions/julia-buildpkg@v1
43+
- uses: julia-actions/julia-runtest@v1
44+
- uses: julia-actions/julia-processcoverage@v1
45+
- uses: codecov/codecov-action@v1
46+
with:
47+
file: lcov.info

.github/workflows/docs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Documentation
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags: '*'
7+
pull_request:
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1.5'
16+
- name: Install dependencies
17+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
18+
- name: Build and deploy
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
21+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
22+
run: julia --project=docs/ docs/make.jl

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# DiffRules
22

3-
[![Build Status](https://travis-ci.org/JuliaDiff/DiffRules.jl.svg?branch=master)](https://travis-ci.org/JuliaDiff/DiffRules.jl)
3+
[![Travis CI Status](https://travis-ci.org/JuliaDiff/DiffRules.jl.svg?branch=master)](https://travis-ci.org/JuliaDiff/DiffRules.jl)
4+
[![Github CI Status](https://github.com/JuliaDiff/DiffRules.jl/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JuliaDiff/DiffRules.jl/actions/workflows/ci.yml)
45
[![Coverage Status](https://coveralls.io/repos/github/JuliaDiff/DiffRules.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaDiff/DiffRules.jl?branch=master)
56

67
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliadiff.org/DiffRules.jl/stable)

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"

docs/make.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ using Documenter, DiffRules
22

33
makedocs(modules=[DiffRules],
44
doctest = false,
5-
format = :html,
65
sitename = "DiffRules",
7-
pages = ["Documentation" => "index.md"])
6+
pages = ["Documentation" => "index.md"],
7+
format = Documenter.HTML(
8+
prettyurls = get(ENV, "CI", nothing) == "true"
9+
),
10+
)
811

9-
deploydocs(repo = "github.com/JuliaDiff/DiffRules.jl.git",
10-
osname = "linux",
11-
julia = "0.6",
12-
target = "build",
13-
deps = nothing,
14-
make = nothing)
12+
deploydocs(repo = "github.com/JuliaDiff/DiffRules.jl")

src/rules.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@
5757
@define_diffrule Base.asech(x) = :( -inv($x * sqrt(1 - $x^2)) )
5858
@define_diffrule Base.acsch(x) = :( -inv(abs($x) * sqrt(1 + $x^2)) )
5959
@define_diffrule Base.acoth(x) = :( inv(1 - $x^2) )
60+
@define_diffrule Base.sinc(x) = :( cosc($x) )
6061
@define_diffrule Base.deg2rad(x) = :( π / 180 )
6162
@define_diffrule Base.mod2pi(x) = :( isinteger($x / 2pi) ? NaN : 1 )
6263
@define_diffrule Base.rad2deg(x) = :( 180 / π )
64+
6365
@define_diffrule SpecialFunctions.gamma(x) =
6466
:( SpecialFunctions.digamma($x) * SpecialFunctions.gamma($x) )
6567
@define_diffrule SpecialFunctions.loggamma(x) =
6668
:( SpecialFunctions.digamma($x) )
69+
70+
@define_diffrule Base.identity(x) = :( 1 )
71+
@define_diffrule Base.conj(x) = :( 1 )
72+
@define_diffrule Base.adjoint(x) = :( 1 )
6773
@define_diffrule Base.transpose(x) = :( 1 )
6874
@define_diffrule Base.abs(x) = :( DiffRules._abs_deriv($x) )
6975

@@ -87,12 +93,22 @@ else
8793
@define_diffrule Base.atan(x, y) = :( $y / ($x^2 + $y^2) ), :( -$x / ($x^2 + $y^2) )
8894
end
8995
@define_diffrule Base.hypot(x, y) = :( $x / hypot($x, $y) ), :( $y / hypot($x, $y) )
96+
@define_diffrule Base.log(b, x) = :( log($x) * inv(-log($b)^2 * $b) ), :( inv($x) / log($b) )
97+
9098
@define_diffrule Base.mod(x, y) = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :( z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -floor(z)), NaN)) )
9199
@define_diffrule Base.rem(x, y) = :( first(promote(ifelse(isinteger($x / $y), NaN, 1), NaN)) ), :( z = $x / $y; first(promote(ifelse(isinteger(z), NaN, -trunc(z)), NaN)) )
92100
@define_diffrule Base.rem2pi(x, r) = :( 1 ), :NaN
93101
@define_diffrule Base.max(x, y) = :( $x > $y ? one($x) : zero($x) ), :( $x > $y ? zero($y) : one($y) )
94102
@define_diffrule Base.min(x, y) = :( $x > $y ? zero($x) : one($x) ), :( $x > $y ? one($y) : zero($y) )
95103

104+
# trinary #
105+
#---------#
106+
107+
@define_diffrule Base.muladd(x, y, z) = :($y), :($x), :(one($z))
108+
@define_diffrule Base.fma(x, y, z) = :($y), :($x), :(one($z))
109+
110+
@define_diffrule Base.ifelse(p, x, y) = false, :($p), :(!$p)
111+
96112
####################
97113
# SpecialFunctions #
98114
####################

test/runtests.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function finitediff(f, x)
1616
end
1717

1818

19-
non_numeric_arg_functions = [(:Base, :rem2pi, 2)]
19+
non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3)]
2020

2121
for (M, f, arity) in DiffRules.diffrules()
2222
(M, f, arity) non_numeric_arg_functions && continue
@@ -46,6 +46,22 @@ for (M, f, arity) in DiffRules.diffrules()
4646
@test isapprox(dy, finitediff(z -> $M.$f(foo, z), bar), rtol=0.05)
4747
end
4848
end
49+
elseif arity == 3
50+
@test DiffRules.hasdiffrule(M, f, 3)
51+
derivs = DiffRules.diffrule(M, f, :foo, :bar, :goo)
52+
@eval begin
53+
foo, bar, goo = randn(3)
54+
dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3])
55+
if !(isnan(dx))
56+
@test isapprox(dx, finitediff(x -> $M.$f(x, bar, goo), foo), rtol=0.05)
57+
end
58+
if !(isnan(dy))
59+
@test isapprox(dy, finitediff(y -> $M.$f(foo, y, goo), bar), rtol=0.05)
60+
end
61+
if !(isnan(dz))
62+
@test isapprox(dz, finitediff(z -> $M.$f(foo, bar, z), goo), rtol=0.05)
63+
end
64+
end
4965
end
5066
end
5167

@@ -62,3 +78,17 @@ for xtype in [:Float64, :BigFloat, :Int64]
6278
end
6379
end
6480
end
81+
82+
# Test ifelse separately as first argument is boolean
83+
@test DiffRules.hasdiffrule(:Base, :ifelse, 3)
84+
derivs = DiffRules.diffrule(:Base, :ifelse, :foo, :bar, :goo)
85+
for cond in [true, false]
86+
@eval begin
87+
foo = $cond
88+
bar, gee = randn(2)
89+
dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3])
90+
@test isapprox(dy, finitediff(y -> ifelse(foo, y, goo), bar), rtol=0.05)
91+
@test isapprox(dz, finitediff(z -> ifelse(foo, bar, z), goo), rtol=0.05)
92+
end
93+
end
94+

0 commit comments

Comments
 (0)