-
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
1 parent
208c42b
commit a047799
Showing
5 changed files
with
69 additions
and
34 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
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
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,22 @@ | ||
function sum_floop(x::AbstractArray; ex=ThreadedEx()) | ||
value = 0.0 | ||
@floop ex for i in 1:length(x) | ||
@reduce value += x[i] | ||
end | ||
return value | ||
end | ||
|
||
function sum_floop_grad(x::AbstractArray) | ||
return ones(size(x)...) | ||
end | ||
|
||
function ChainRulesCore.rrule(::typeof(sum_floop), x::AbstractArray; ex=ThreadedEx()) | ||
y = sum_floop(x; ex=ex) | ||
function pullback(Δy) | ||
f̄bar = NoTangent() | ||
xbar = @thunk(sum_floop_grad(x) .* Δy) | ||
exbar = NoTangent() | ||
return f̄bar, xbar, exbar | ||
end | ||
return y, pullback | ||
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