-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
8c59e9a
commit d354ba7
Showing
6 changed files
with
159 additions
and
150 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,23 @@ | ||
### Projecting a tuple to SMatrix leads to ChainRulesCore._projection_mismatch by default, so overloaded here | ||
function (project::ProjectTo{<:Tangent{<:Tuple}})(dx::StaticArrays.SArray) | ||
dy = reshape(dx, axes(project.elements)) # allows for dx::OffsetArray | ||
dz = ntuple(i -> project.elements[i](dy[i]), length(project.elements)) | ||
return project_type(project)(dz...) | ||
end | ||
|
||
### Project SArray to SArray | ||
function ProjectTo(x::StaticArrays.SArray{S,T}) where {S, T} | ||
return ProjectTo{StaticArrays.SArray}(; element=_eltype_projectto(T), axes=S) | ||
end | ||
|
||
function (project::ProjectTo{StaticArrays.SArray})(dx::AbstractArray{S,M}) where {S,M} | ||
return StaticArrays.SArray{project.axes}(dx) | ||
end | ||
|
||
### Adjoint for SArray constructor | ||
|
||
function rrule(::Type{T}, x::Tuple) where {T<:StaticArrays.SArray} | ||
project_x = ProjectTo(x) | ||
Array_pullback(ȳ) = (NoTangent(), project_x(ȳ)) | ||
return T(x), Array_pullback | ||
end |
Oops, something went wrong.