Skip to content

Commit a908e5a

Browse files
authored
Merge branch 'master' into dependabot/github_actions/codecov/codecov-action-4
2 parents 0c7dbb4 + 2a6e5e9 commit a908e5a

File tree

20 files changed

+181
-32
lines changed

20 files changed

+181
-32
lines changed

.github/workflows/benchmark-comment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
${{ github.event.workflow_run.event == 'pull_request' &&
2525
github.event.workflow_run.conclusion == 'success' }}
2626
steps:
27-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v4
2828
# restore records from the artifacts
2929
- uses: dawidd6/action-download-artifact@v2
3030
with:
@@ -41,7 +41,7 @@ jobs:
4141
echo ::set-output name=body::$(cat ./pull-request-number.artifact)
4242
# check if the previous comment exists
4343
- name: find comment
44-
uses: peter-evans/find-comment@v1
44+
uses: peter-evans/find-comment@v3
4545
id: fc
4646
with:
4747
issue-number: ${{ steps.output-pull-request-number.outputs.body }}

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
if: contains(github.event.pull_request.labels.*.name, 'performance critical')
1717
steps:
1818
# setup
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
2020
- uses: julia-actions/setup-julia@v1
2121
with:
2222
version: '1.7'
@@ -47,7 +47,7 @@ jobs:
4747
- name: record pull request number
4848
run: echo ${{ github.event.pull_request.number }} > ./pull-request-number.artifact
4949
# save as artifacts (performance tracking (comment) workflow will use it)
50-
- uses: actions/upload-artifact@v2
50+
- uses: actions/upload-artifact@v4
5151
with:
5252
name: Benchmarking
5353
path: ./*.artifact

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- 'MultiOutput'
3636
- 'Others'
3737
steps:
38-
- uses: actions/checkout@v2
38+
- uses: actions/checkout@v4
3939
- uses: julia-actions/setup-julia@v1
4040
with:
4141
version: ${{ matrix.version }}

.github/workflows/doc_preview_cleanup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout gh-pages branch
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313
with:
1414
ref: gh-pages
1515
- name: Delete preview and history + push changes

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2121
- uses: julia-actions/setup-julia@latest
2222
with:
2323
version: '1'

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
format:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717
- uses: julia-actions/setup-julia@v1
1818
with:
1919
version: 1

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "KernelFunctions"
22
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
3-
version = "0.10.60"
3+
version = "0.10.63"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# KernelFunctions.jl
22

3-
![CI](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/workflows/CI/badge.svg?branch=master)
3+
[![CI](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/actions/workflows/ci.yml?query=branch%3Amaster)
44
[![codecov](https://codecov.io/gh/JuliaGaussianProcesses/KernelFunctions.jl/branch/master/graph/badge.svg?token=rmDh3gb7hN)](https://codecov.io/gh/JuliaGaussianProcesses/KernelFunctions.jl)
55
[![Documentation (stable)](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliagaussianprocesses.github.io/KernelFunctions.jl/stable)
66
[![Documentation (latest)](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev)

src/KernelFunctions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export tensor, ⊗, compose
4848

4949
using Compat
5050
using ChainRulesCore: ChainRulesCore, Tangent, ZeroTangent, NoTangent
51-
using ChainRulesCore: @thunk, InplaceableThunk
51+
using ChainRulesCore: @thunk, InplaceableThunk, ProjectTo, unthunk
5252
using CompositionsBase
5353
using Distances
5454
using FillArrays

src/chainrules.jl

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,113 @@ end
111111

112112
function ChainRulesCore.rrule(s::Sinus, x::AbstractVector, y::AbstractVector)
113113
d = x - y
114-
sind = sinpi.(d)
115-
abs2_sind_r = abs2.(sind) ./ s.r
114+
abs2_sind_r = (sinpi.(d) ./ s.r) .^ 2
116115
val = sum(abs2_sind_r)
117-
gradx = twoπ .* cospi.(d) .* sind ./ (s.r .^ 2)
116+
gradx = π .* sinpi.(2 .* d) ./ s.r .^ 2
118117
function evaluate_pullback::Any)
119-
return (r=-2Δ .* abs2_sind_r,), Δ * gradx, -Δ * gradx
118+
= -2Δ .* abs2_sind_r ./ s.r
119+
= ChainRulesCore.Tangent{typeof(s)}(; r=r̄)
120+
return s̄, Δ * gradx, -Δ * gradx
120121
end
121122
return val, evaluate_pullback
122123
end
123124

125+
function ChainRulesCore.rrule(
126+
::typeof(Distances.pairwise), d::Sinus, x::AbstractMatrix; dims=2
127+
)
128+
project_x = ProjectTo(x)
129+
function pairwise_pullback(z̄)
130+
Δ = unthunk(z̄)
131+
n = size(x, dims)
132+
= collect(zero(x))
133+
= zero(d.r)
134+
if dims == 1
135+
for j in 1:n, i in 1:n
136+
xi = view(x, i, :)
137+
xj = view(x, j, :)
138+
ds = π .* Δ[i, j] .* sinpi.(2 .* (xi .- xj)) ./ d.r .^ 2
139+
.-= 2 .* Δ[i, j] .* sinpi.(xi .- xj) .^ 2 ./ d.r .^ 3
140+
x̄[i, :] += ds
141+
x̄[j, :] -= ds
142+
end
143+
elseif dims == 2
144+
for j in 1:n, i in 1:n
145+
xi = view(x, :, i)
146+
xj = view(x, :, j)
147+
ds = twoπ .* Δ[i, j] .* sinpi.(xi .- xj) .* cospi.(xi .- xj) ./ d.r .^ 2
148+
.-= 2 .* Δ[i, j] .* sinpi.(xi .- xj) .^ 2 ./ d.r .^ 3
149+
x̄[:, i] .+= ds
150+
x̄[:, j] .-= ds
151+
end
152+
end
153+
= ChainRulesCore.Tangent{typeof(d)}(; r=r̄)
154+
return NoTangent(), d̄, @thunk(project_x(x̄))
155+
end
156+
return Distances.pairwise(d, x; dims), pairwise_pullback
157+
end
158+
159+
function ChainRulesCore.rrule(
160+
::typeof(Distances.pairwise), d::Sinus, x::AbstractMatrix, y::AbstractMatrix; dims=2
161+
)
162+
project_x = ProjectTo(x)
163+
project_y = ProjectTo(y)
164+
function pairwise_pullback(z̄)
165+
Δ = unthunk(z̄)
166+
n = size(x, dims)
167+
m = size(y, dims)
168+
= collect(zero(x))
169+
= collect(zero(y))
170+
= zero(d.r)
171+
if dims == 1
172+
for j in 1:m, i in 1:n
173+
xi = view(x, i, :)
174+
yj = view(y, j, :)
175+
ds = π .* Δ[i, j] .* sinpi.(2 .* (xi .- yj)) ./ d.r .^ 2
176+
.-= 2 .* Δ[i, j] .* sinpi.(xi .- yj) .^ 2 ./ d.r .^ 3
177+
x̄[i, :] .+= ds
178+
ȳ[j, :] .-= ds
179+
end
180+
elseif dims == 2
181+
for j in 1:m, i in 1:n
182+
xi = view(x, :, i)
183+
yj = view(y, :, j)
184+
ds = π .* Δ[i, j] .* sinpi.(2 .* (xi .- yj)) ./ d.r .^ 2
185+
.-= 2 .* Δ[i, j] .* sinpi.(xi .- yj) .^ 2 ./ d.r .^ 3
186+
x̄[:, i] .+= ds
187+
ȳ[:, j] .-= ds
188+
end
189+
end
190+
= ChainRulesCore.Tangent{typeof(d)}(; r=r̄)
191+
return NoTangent(), d̄, @thunk(project_x(x̄)), @thunk(project_y(ȳ))
192+
end
193+
return Distances.pairwise(d, x, y; dims), pairwise_pullback
194+
end
195+
196+
function ChainRulesCore.rrule(
197+
::typeof(Distances.colwise), d::Sinus, x::AbstractMatrix, y::AbstractMatrix
198+
)
199+
project_x = ProjectTo(x)
200+
project_y = ProjectTo(y)
201+
function colwise_pullback(z̄)
202+
Δ = unthunk(z̄)
203+
n = size(x, 2)
204+
= collect(zero(x))
205+
= collect(zero(y))
206+
= zero(d.r)
207+
for i in 1:n
208+
xi = view(x, :, i)
209+
yi = view(y, :, i)
210+
ds = π .* Δ[i] .* sinpi.(2 .* (xi .- yi)) ./ d.r .^ 2
211+
.-= 2 .* Δ[i] .* sinpi.(xi .- yi) .^ 2 ./ d.r .^ 3
212+
x̄[:, i] .+= ds
213+
ȳ[:, i] .-= ds
214+
end
215+
= ChainRulesCore.Tangent{typeof(d)}(; r=r̄)
216+
return NoTangent(), d̄, @thunk(project_x(x̄)), @thunk(project_y(ȳ))
217+
end
218+
return Distances.colwise(d, x, y), colwise_pullback
219+
end
220+
124221
## Reverse Rules for matrix wrappers
125222

126223
function ChainRulesCore.rrule(::Type{<:ColVecs}, X::AbstractMatrix)

0 commit comments

Comments
 (0)