Skip to content

Commit b5f007e

Browse files
committed
Merge branch 'main' of https://github.com/JuliaDiff/ChainRules.jl into spdiag
2 parents d550288 + e3b8bf5 commit b5f007e

File tree

10 files changed

+57
-9
lines changed

10 files changed

+57
-9
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue"

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- x86
2222
- x64
2323
steps:
24-
- uses: actions/checkout@v4.0.0
24+
- uses: actions/checkout@v4
2525
- uses: julia-actions/setup-julia@v1
2626
with:
2727
version: ${{ matrix.version }}

.github/workflows/Cancel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
cancel:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: styfle/cancel-workflow-action@0.9.0
16+
- uses: styfle/cancel-workflow-action@0.12.0
1717
with:
1818
all_but_latest: true
1919
workflow_id: ${{ github.event.workflow.id }}

.github/workflows/IntegrationTest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ jobs:
2525
# package: {user: JuliaDiff, repo: Diffractor.jl}
2626

2727
steps:
28-
- uses: actions/checkout@v4.0.0
28+
- uses: actions/checkout@v4
2929
- uses: julia-actions/setup-julia@v1
3030
with:
3131
version: ${{ matrix.julia-version }}
3232
arch: x64
3333
- uses: julia-actions/julia-buildpkg@latest
3434
- name: Clone Downstream
35-
uses: actions/checkout@v4.0.0
35+
uses: actions/checkout@v4
3636
with:
3737
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
3838
path: downstream

.github/workflows/JuliaNightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- x86
2424
- x64
2525
steps:
26-
- uses: actions/checkout@v4.0.0
26+
- uses: actions/checkout@v4
2727
- uses: julia-actions/setup-julia@v1
2828
with:
2929
version: ${{ matrix.version }}

.github/workflows/VersionVigilante_pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
VersionVigilante:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v4.0.0
9+
- uses: actions/checkout@v4
1010
- uses: julia-actions/setup-julia@latest
1111
- name: VersionVigilante.main
1212
id: versionvigilante_main

.github/workflows/format.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Format suggestions
2+
3+
on:
4+
pull_request:
5+
6+
concurrency:
7+
# Skip intermediate builds: always.
8+
# Cancel intermediate builds: only if it is a pull request build.
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
11+
12+
jobs:
13+
format:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: julia-actions/setup-julia@latest
18+
with:
19+
version: 1
20+
- run: |
21+
julia -e 'using Pkg; Pkg.add("JuliaFormatter")'
22+
julia -e 'using JuliaFormatter; format("."; verbose=true)'
23+
- uses: reviewdog/action-suggester@v1
24+
with:
25+
tool_name: JuliaFormatter
26+
fail_on_error: true
27+
filter_mode: added

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRules"
22
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
3-
version = "1.54.0"
3+
version = "1.55.0"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/rulesets/Base/indexing.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Int rather than Int64/Integer is intentional
2-
function frule((_, ẋ), ::typeof(getfield), x::Tuple, i::Int)
3-
return x.i, ẋ.i
2+
function ChainRulesCore.frule((_, Δ, _), ::typeof(getfield), strct, sym::Union{Int,Symbol})
3+
return (getfield(strct, sym), isa(Δ, NoTangent) ? NoTangent() : getproperty(Δ, sym))
4+
end
5+
6+
function ChainRulesCore.frule((_, Δ, _, _), ::typeof(getfield), strct, sym::Union{Int,Symbol}, inbounds)
7+
return (getfield(strct, sym, inbounds), isa(Δ, NoTangent) ? NoTangent() : getproperty(Δ, sym))
48
end
59

610
"for a given tuple type, returns a Val{N} where N is the length of the tuple"

test/rulesets/Base/indexing.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
struct FooTwoField
2+
x::Float64
3+
y::Float64
4+
end
5+
6+
7+
@testset "getfield" begin
8+
test_frule(getfield, FooTwoField(1.5, 2.5), :x, check_inferred=false)
9+
10+
test_frule(getfield, (; a=1.5, b=2.5), :a, check_inferred=false)
11+
test_frule(getfield, (; a=1.5, b=2.5), 2)
12+
13+
test_frule(getfield, (1.5, 2.5), 2)
14+
test_frule(getfield, (1.5, 2.5), 2, true)
15+
end
16+
117
@testset "getindex" begin
218
@testset "getindex(::Tuple, ...)" begin
319
x = (1.2, 3.4, 5.6)

0 commit comments

Comments
 (0)