@@ -71,29 +71,29 @@ differentiate the function based on the input types. However, this function has
71
71
` xx = [1.0, 2.0, 3.0, 4.0] ` followed by a ` xx[1] = var[1] - v_true[1] ` where ` var ` might
72
72
be a Dual number. This causes the error. To fix it:
73
73
74
- 1 . Specify the ` autodiff ` to be ` AutoFiniteDiff `
75
-
76
- ``` @example dual_error_faq
77
- sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff());
78
- maxiters = 10000, abstol = 1e-8)
79
- ```
80
-
81
- This worked but, Finite Differencing is not the recommended approach in any scenario.
82
-
83
- 2 . Rewrite the function to use
84
- [ PreallocationTools.jl] ( https://github.com/SciML/PreallocationTools.jl ) or write it as
85
-
86
- ``` @example dual_error_faq
87
- function fff_correct(var, p)
88
- v_true = [1.0, 0.1, 2.0, 0.5]
89
- xx = eltype(var)[1.0, 2.0, 3.0, 4.0]
90
- xx[1] = var[1] - v_true[1]
91
- return xx - v_true
92
- end
93
-
94
- prob_oop = NonlinearLeastSquaresProblem{false}(fff_correct, v_init)
95
- sol = solve(prob_oop, LevenbergMarquardt(); maxiters = 10000, abstol = 1e-8)
96
- ```
74
+ 1 . Specify the ` autodiff ` to be ` AutoFiniteDiff `
75
+
76
+ ``` @example dual_error_faq
77
+ sol = solve(prob_oop, LevenbergMarquardt(; autodiff = AutoFiniteDiff());
78
+ maxiters = 10000, abstol = 1e-8)
79
+ ```
80
+
81
+ This worked but, Finite Differencing is not the recommended approach in any scenario.
82
+
83
+ 2. Rewrite the function to use
84
+ [PreallocationTools.jl](https://github.com/SciML/PreallocationTools.jl) or write it as
85
+
86
+ ```@example dual_error_faq
87
+ function fff_correct(var, p)
88
+ v_true = [1.0, 0.1, 2.0, 0.5]
89
+ xx = eltype(var)[1.0, 2.0, 3.0, 4.0]
90
+ xx[1] = var[1] - v_true[1]
91
+ return xx - v_true
92
+ end
93
+
94
+ prob_oop = NonlinearLeastSquaresProblem{false}(fff_correct, v_init)
95
+ sol = solve(prob_oop, LevenbergMarquardt(); maxiters = 10000, abstol = 1e-8)
96
+ ```
97
97
98
98
## I thought NonlinearSolve.jl was type-stable and fast. But it isn't, why?
99
99
0 commit comments