-
Notifications
You must be signed in to change notification settings - Fork 35
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
Showing
5 changed files
with
33 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ComponentArraysOptimisersExt | ||
|
||
using ComponentArrays, Optimisers | ||
|
||
# Optimisers can handle componentarrays by default, but we can vectorize the entire | ||
# operation here instead of doing multiple smaller operations | ||
Optimisers.setup(opt::AbstractRule, ps::ComponentArray) = Optimisers.setup(opt, getdata(ps)) | ||
|
||
function Optimisers.update(tree, ps::ComponentArray, gs::ComponentArray) | ||
gs_flat = ComponentArrays.__value(getdata(gs)) # Safety against ReverseDiff | ||
tree, ps_new = Optimisers.update(tree, getdata(ps), gs_flat) | ||
return tree, ComponentArray(ps_new, getaxes(ps)) | ||
end | ||
|
||
function Optimisers.update!(tree::Optimisers.Leaf, ps::ComponentArray, gs::ComponentArray) | ||
gs_flat = ComponentArrays.__value(getdata(gs)) # Safety against ReverseDiff | ||
tree, ps_new = Optimisers.update!(tree, getdata(ps), gs_flat) | ||
return tree, ComponentArray(ps_new, getaxes(ps)) | ||
end | ||
|
||
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
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