i have a vector-valued function mapping from R^n -> R^m
I compute its Jacobian Matrix as well as the Hessian Matrix of each output with regard to the inputs, which works so far.
Now I would like to use the CodeGeneration package to generate optimized C Code to compute these matrices numerically. This is, where i encounter a Problem:
I would like to optimize Code for all matrixes at once, because they contain common subexpressions. However CodeGeneration::C tells me it is unable to optimize the given input and generates unoptimized code.
I appended an exemplary file to illustrate the problem: Jacobian_Hessian_codeGeneration_tryout.mw
C(Jac, optimize = tryhard, resultname = JacobianMatrix);
C(H1, optimize = tryhard, resultname = Hessian1);
C(H2, optimize = tryhard, resultname = Hessian2);
C(H3, optimize = tryhard, resultname = Hessian3)
works, but is suboptimal.
C([JacobianMatrix = Jac, Hessian1 = H1, Hessian2 = H2, Hessian3 = H3], optimize)
fails to optimize and
C([Jac, H1, H2, H3], optimize)
(With Jac beeing a m by n matrix and H1-3 beeing n by n matrices)
If anyone can tell me what I'm missing here I'd really appreciate the help.