Skip to content

Commit

Permalink
work around length problem
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Dec 12, 2022
1 parent dfd30d8 commit f3afe13
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/apiutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end
###################################

@generated function dualize(::Type{T}, x::StaticArray) where T
N = length(x)
N = _static_length(StaticArraysCore.Size(x))
dx = Expr(:tuple, [:(Dual{T}(x[$i], chunk, Val{$i}())) for i in 1:N]...)
V = StaticArraysCore.similar_type(x, Dual{T,eltype(x),N})
return quote
Expand All @@ -29,6 +29,9 @@ end
end
end

# This works around length(::Type{StaticArray}) not being defined in this world-age:
_static_length(::StaticArraysCore.Size{s}) where {s} = StaticArraysCore.tuple_prod(s)

@inline static_dual_eval(::Type{T}, f, x::StaticArray) where T = f(dualize(T, x))

function vector_mode_dual_eval!(f::F, cfg::Union{JacobianConfig,GradientConfig}, x) where {F}
Expand Down

0 comments on commit f3afe13

Please sign in to comment.