Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch on StaticArray instead of SArray #7

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

devmotion
Copy link
Member

Currently only SArrays are supported and no other StaticArrays such as SLArrays (https://github.com/JuliaDiffEq/LabelledArrays.jl). Together with a similar PR to ForwardDiff this seems to fix issues I experienced with SLArrays without breaking existing SArray support. However, since we do not dispatch on the mutability of the static arrays unfortunately even DiffResults for mutable static arrays such as MArray will be immutable.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 87.302% when pulling c7e6b0a on devmotion:staticarray into d49bd6d on JuliaDiff:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 87.302% when pulling c7e6b0a on devmotion:staticarray into d49bd6d on JuliaDiff:master.

@@ -79,7 +79,7 @@ shape information. If you want to allocate storage yourself, use the `DiffResult
constructor instead.
"""
JacobianResult(x::AbstractArray) = DiffResult(similar(x), similar(x, length(x), length(x)))
JacobianResult(x::SArray{<:Any,T,<:Any,L}) where {T,L} = DiffResult(x, zeros(SMatrix{L,L,T}))
JacobianResult(x::StaticArray) = DiffResult(x, zeros(StaticArrays.similar_type(typeof(x), Size(length(x),length(x)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the length(x) here cause the size parameter of the resulting array to be uninferrable, or does constant prop take care of that for us?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant prop seems to take care of it (as I assumed without worrying much 😄):

using DiffResults, StaticArrays, Test

v = SVector([1, 2.5, 4])
@inferred DiffResults.JacobianResult(v)
@code_warntype DiffResults.JacobianResult(v)

outputs

Body::DiffResults.ImmutableDiffResult{1,SArray{Tuple{3},Float64,1,3},Tuple{SArray{Tuple{3,3},Float64,2,9}}}
1%1 = %new(DiffResults.ImmutableDiffResult{1,SArray{Tuple{3},Float64,1,3},Tuple{SArray{Tuple{3,3},Float64,2,9}}}, x, ([0.0 0.0 0.0; 0.0 0.0 0.0; 0.0 0.0 0.0],))::DiffResults.ImmutableDiffResult{1,SArray{Tuple{3},Float64,1,3},Tuple{SArray{Tuple{3,3},Float64,2,9}}}
└──      return %1

@jrevels jrevels merged commit 8d12336 into JuliaDiff:master Feb 12, 2019
@devmotion devmotion deleted the staticarray branch February 12, 2019 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants