Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI
on:
push:
branches: [master]
tags: [v*]
pull_request:
schedule:
- cron: "0 0 * * *" # run on default branch every night at midnight UTC

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.0'
- '1'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x86
- x64
# 32-bit Julia binaries are not available on macOS
exclude:
- os: macOS-latest
arch: x86
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
20 changes: 20 additions & 0 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Documenter
on:
push:
branches: [master]
tags: [v*]
pull_request:

jobs:
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: julia-actions/julia-docdeploy@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesTestUtils"
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
version = "0.5.8"
version = "0.5.9"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ChainRulesTestUtils.jl

[![CI](https://github.com/JuliaDiff/ChainRulesTestUtils.jl/workflows/CI/badge.svg?branch=master)](https://github.com/JuliaDiff/ChainRulesTestUtils.jl/actions?query=workflow%3ACI)
[![Travis](https://travis-ci.org/JuliaDiff/ChainRulesTestUtils.jl.svg?branch=master)](https://travis-ci.org/JuliaDiff/ChainRulesTestUtils.jl)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
Expand Down
8 changes: 4 additions & 4 deletions src/check_result.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function check_equal(actual::Composite{P}, expected::Composite{P}; kwargs...) wh
end

function check_equal(
::Composite{ActualPrimal}, expected::Composite{ExpectedPrimal}
::Composite{ActualPrimal}, expected::Composite{ExpectedPrimal}; kwargs...
) where {ActualPrimal, ExpectedPrimal}
# this will certainly fail as we have another dispatch for that, but this will give as
# good error message
Expand All @@ -99,10 +99,10 @@ end
check_equal(x, y::Composite; kwargs...) = check_equal(y, x; kwargs...)

# This catches comparisons of Composites and Tuples/NamedTuple
# and gives a error messaage complaining about that
# and gives an error message complaining about that
const LegacyZygoteCompTypes = Union{Tuple,NamedTuple}
check_equal(::C, expected::T) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test C === T
check_equal(::T, expected::C) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test T === C
check_equal(::C, ::T; kwargs...) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test C === T
check_equal(::T, ::C; kwargs...) where {C<:Composite,T<:LegacyZygoteCompTypes} = @test T === C

# Generic fallback, probably a tuple or something
function check_equal(actual::A, expected::E; kwargs...) where {A, E}
Expand Down
11 changes: 9 additions & 2 deletions src/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function _make_j′vp_call(fdm, f, ȳ, xs, ignores)
@assert length(fd) == length(arginds)

for (dx, ind) in zip(fd, arginds)
args[ind] = dx
args[ind] = _maybe_fix_to_composite(dx)
end
return (args...,)
end
Expand All @@ -97,9 +97,16 @@ function _make_jvp_call(fdm, f, xs, ẋs, ignores)
ignores = collect(ignores)
all(ignores) && return ntuple(_->nothing, length(xs))
sigargs = zip(xs[.!ignores], ẋs[.!ignores])
return jvp(fdm, f2, sigargs...)
return _maybe_fix_to_composite(jvp(fdm, f2, sigargs...))
end

# TODO: remove after https://github.com/JuliaDiff/FiniteDifferences.jl/issues/97
# For functions which return a tuple, FD returns a tuple to represent the differential. Tuple
# is not a natural differential, because it doesn't overload +, so make it a Composite.
_maybe_fix_to_composite(x::Tuple) = Composite{typeof(x)}(x...)
_maybe_fix_to_composite(x::NamedTuple) = Composite{typeof(x)}(;x...)
_maybe_fix_to_composite(x) = x

"""
test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=central_fdm(5, 1), fkwargs=NamedTuple(), kwargs...)

Expand Down
10 changes: 10 additions & 0 deletions test/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ end
end
end

@testset "tuple output (backing type of Composite =/= natural differential)" begin
tuple_out(x) = return (x, 1.0) # i.e. (x, 1.0) and not (x, x)
function ChainRulesCore.frule((_, dx), ::typeof(tuple_out), x)
Ω = tuple_out(x)
∂Ω = Composite{typeof(Ω)}(dx, Zero())
return Ω, ∂Ω
end
frule_test(tuple_out, (2.0, 1))
end

@testset "ignoring arguments" begin
fsymtest(x, s::Symbol) = x
ChainRulesCore.frule((_, Δx, _), ::typeof(fsymtest), x, s) = (x, Δx)
Expand Down