11module PreallocationTools
22
3- using ForwardDiff, LabelledArrays
3+ using ForwardDiff, ArrayInterface, LabelledArrays
44
55struct DiffCache{T<: AbstractArray , S<: AbstractArray }
66 du:: T
2222
2323`dualcache(u::AbstractArray, N = Val{default_cache_size(length(u))})`
2424
25- Builds a `DualCache` object that stores versions of the cache for `u` and for the `Dual` version of `u` allowing use of pre-cached arrays with
25+ Builds a `DualCache` object that stores both a version of the cache for `u`
26+ and for the `Dual` version of `u`, allowing use of pre-cached vectors with
2627forward-mode automatic differentiation.
2728
2829"""
@@ -37,17 +38,17 @@ Returns the `Dual` or normal cache array stored in `dc` based on the type of `u`
3738"""
3839function get_tmp (dc:: DiffCache , u:: T ) where T<: ForwardDiff.Dual
3940 nelem = div (sizeof (T), sizeof (eltype (dc. dual_du)))* prod (size (dc. du))
40- reshape ( reinterpret (T, view (dc. dual_du, 1 : nelem)), size (dc . du ))
41+ ArrayInterface . restructure (dc . du, reinterpret (T, view (dc. dual_du, 1 : nelem)))
4142end
4243
4344function get_tmp (dc:: DiffCache , u:: AbstractArray{T} ) where T<: ForwardDiff.Dual
4445 nelem = div (sizeof (T), sizeof (eltype (dc. dual_du)))* prod (size (dc. du))
45- reshape ( reinterpret (T, view (dc. dual_du, 1 : nelem)), size (dc . du ))
46+ ArrayInterface . restructure (dc . du, reinterpret (T, view (dc. dual_du, 1 : nelem)))
4647end
4748
4849function get_tmp (dc:: DiffCache , u:: LabelledArrays.LArray{T,N,D,Syms} ) where {T,N,D,Syms}
4950 nelem = div (sizeof (T), sizeof (eltype (dc. dual_du)))* prod (size (dc. du))
50- _x = reshape ( reinterpret (T, view (dc. dual_du, 1 : nelem)), size (dc . du ))
51+ _x = ArrayInterface . restructure (dc . du, reinterpret (T, view (dc. dual_du, 1 : nelem)))
5152 LabelledArrays. LArray {T,N,D,Syms} (_x)
5253end
5354
0 commit comments