-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from SciML/type2
More extensive handling of dispatching on type
- Loading branch information
Showing
5 changed files
with
107 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module PreallocationToolsSymbolicsExt | ||
|
||
using PreallocationTools | ||
import PreallocationTools: _restructure, get_tmp | ||
using Symbolics, ForwardDiff | ||
|
||
function get_tmp(dc::DiffCache, u::Type{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
end | ||
|
||
function get_tmp(dc::DiffCache, u::X) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
end | ||
|
||
function get_tmp(dc::DiffCache, u::AbstractArray{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
end | ||
|
||
function get_tmp(dc::FixedSizeDiffCache, u::Type{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
end | ||
|
||
function get_tmp(dc::FixedSizeDiffCache, u::X) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
end | ||
|
||
function get_tmp(dc::FixedSizeDiffCache, u::AbstractArray{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} | ||
if length(dc.du) > length(dc.any_du) | ||
resize!(dc.any_du, length(dc.du)) | ||
end | ||
_restructure(dc.du, dc.any_du) | ||
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