11"""
2- get_linearization_func(NT, f!, h!, nu, nx, ny, nd, p) -> linfunc!
2+ get_linearization_func(NT, f!, h!, nu, nx, ny, nd, p, backend ) -> linfunc!
33
44Return the `linfunc!` function that computes the Jacobians of `f!` and `h!` functions.
55
66The function has the following signature:
77```
8- linfunc!(xnext, y, A, Bu, C, Bd, Dd, x, u, d, cst_x, cst_u, cst_d) -> nothing
8+ linfunc!(xnext, y, A, Bu, C, Bd, Dd, backend, x, u, d, cst_x, cst_u, cst_d) -> nothing
99```
10- and it should modifies in-place all the arguments before `x`. The `cst_x`, `cst_u`, `cst_d`
11- and are `DifferentiationInterface.Constant` objects with the linearization points.
10+ and it should modifies in-place all the arguments before `backend`. The `backend` argument
11+ is an `AbstractADType` backend from `DifferentiationInterface`. The `cst_x`, `cst_u` and
12+ `cst_d` are `DifferentiationInterface.Constant` objects with the linearization points.
1213"""
13- function get_linearization_func (NT, f!, h!, nu, nx, ny, nd, p)
14+ function get_linearization_func (NT, f!, h!, nu, nx, ny, nd, p, backend )
1415 f_x! (xnext, x, u, d) = f! (xnext, x, u, d, p)
1516 f_u! (xnext, u, x, d) = f! (xnext, x, u, d, p)
1617 f_d! (xnext, d, x, u) = f! (xnext, x, u, d, p)
1718 h_x! (y, x, d) = h! (y, x, d, p)
1819 h_d! (y, d, x) = h! (y, x, d, p)
19- backend = AutoForwardDiff ()
2020 strict = Val (true )
2121 xnext = zeros (NT, nx)
2222 y = zeros (NT, ny)
@@ -31,7 +31,7 @@ function get_linearization_func(NT, f!, h!, nu, nx, ny, nd, p)
3131 Bd_prep = prepare_jacobian (f_d!, xnext, backend, d, cst_x, cst_u; strict)
3232 C_prep = prepare_jacobian (h_x!, y, backend, x, cst_d ; strict)
3333 Dd_prep = prepare_jacobian (h_d!, y, backend, d, cst_x ; strict)
34- function linfunc! (xnext, y, A, Bu, C, Bd, Dd, x, u, d, cst_x, cst_u, cst_d)
34+ function linfunc! (xnext, y, A, Bu, C, Bd, Dd, backend, x, u, d, cst_x, cst_u, cst_d)
3535 # all the arguments before `x` are mutated in this function
3636 jacobian! (f_x!, xnext, A, A_prep, backend, x, cst_u, cst_d)
3737 jacobian! (f_u!, xnext, Bu, Bu_prep, backend, u, cst_x, cst_d)
@@ -183,10 +183,11 @@ end
183183function linearize_core! (linmodel:: LinModel , model:: SimModel , x0, u0, d0)
184184 xnext0, y0 = linmodel. buffer. x, linmodel. buffer. y
185185 A, Bu, C, Bd, Dd = linmodel. A, linmodel. Bu, linmodel. C, linmodel. Bd, linmodel. Dd
186- cx = Constant (x0)
187- cu = Constant (u0)
188- cd = Constant (d0)
189- model. linfunc! (xnext0, y0, A, Bu, C, Bd, Dd, x0, u0, d0, cx, cu, cd)
186+ cst_x = Constant (x0)
187+ cst_u = Constant (u0)
188+ cst_d = Constant (d0)
189+ backend = model. jacobian
190+ model. linfunc! (xnext0, y0, A, Bu, C, Bd, Dd, backend, x0, u0, d0, cst_x, cst_u, cst_d)
190191 return nothing
191192end
192193
0 commit comments