Instead of a 3-tensor, the natural datastructure is a vector of matrices, which will make the calculation of likelihoods/etc. and simulatino much more convenient. Basically we want to have the transformation of the current structure from C_2 to C_2_new and then get rid of the old C_2.
[ ] Same with the C_2_p, A_2, and A_2_p where the _p become vectors of vectors of matrices.
[ ] Find all usage for C_2 and change to use the new datstrcuture. For example, inhttps://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/generate_perturbation.jl#L365-L370
fill!(c.C_2, zero(eltype(c.C_2))) # reset as we need to use `+=`
for i in 1:n_z
for j in 1:n_y
c.C_2[i, :, :] += 0.5 * c.Q[i, j] * c.g_xx[j, :, :]
end
end
becomes something like
fill!.(c.C_2, Ref(zero(eltype(c.C_2[1]))) # reset as we need to use `+=`
for i in 1:n_z
for j in 1:n_y
c.C_2[i]+= 0.5 * c.Q[i, j] * c.g_xx[j, :, :]
end
end
[ ] Same sort of thing for all uses of C_2, C_2_p, A_2, A_2_p etc.
The storage order for the
A_2
andC_2
3-tensors should be reversed. This shoudl be done in conjunction with https://github.com/SciML/DifferenceEquations.jl/issues/54Instead of a 3-tensor, the natural datastructure is a vector of matrices, which will make the calculation of likelihoods/etc. and simulatino much more convenient. Basically we want to have the transformation of the current structure from
C_2
toC_2_new
and then get rid of the oldC_2
.To do this,
C_2
in https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/types.jl#L223 to beC_2::Union{Nothing,Vector{Array{Float64,2}}}
or something like that.C_2_p, A_2
, andA_2_p
where the_p
become vectors of vectors of matrices.C_2
and change to use the new datstrcuture. For example, inhttps://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/v0.4.19/src/generate_perturbation.jl#L365-L370becomes something like
C_2, C_2_p, A_2, A_2_p
etc.A_2
andC_2
in https://github.com/HighDimensionalEconLab/DifferentiableStateSpaceModels.jl/blob/main/src/types.jl#L454-L496 need to change to theVector{<:AbstractMatrix}
or something like that. instead, which should then work with the constructorAfter this is done, https://github.com/SciML/DifferenceEquations.jl/issues/54 can then be sync'd up - which might be required for the full unit tests to pass.