# \#forwarddiff

**URL:** https://discourse.julialang.org/tag/forwarddiff/363.md?match_all_tags=true&page=2&tags%5B%5D=forwarddiff

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 3

---

## [My function works on it's own but not in NonLinearSolve](https://discourse.julialang.org/t/my-function-works-on-its-own-but-not-in-nonlinearsolve/113204)

<div class="topic-metadata">

**Author:** [@Laura](https://discourse.julialang.org/u/Laura)\
**Replies:** 10\
**Last updated:** [April 22, 2024, 3:13pm UTC](https://discourse.julialang.org/t/my-function-works-on-its-own-but-not-in-nonlinearsolve/113204 "2024-04-22T15:13:41Z")

</div>

I have a set of equations that I would like to solve using the non linear equation solver NonLinearSolve.jl. I have writen a function for this which runs fine on it’s own but when I try to solve it I get an error message…

---

## [Is there a differentiable implementation of matrix square root?](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 5\
**Last updated:** [March 31, 2024, 10:15pm UTC](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334 "2024-03-31T22:15:47Z")

</div>

Hello! I’m trying to make the following code work: using ForwardDiff, LinearAlgebra # Fidelity between two density matrices function fidelity(ρ::AbstractMatrix, σ::AbstractMatrix) sqrt\_ρ = sqrt(ρ) abs2(tr(sqrt…

---

## [Sparse matrix error with forward diff](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170)

<div class="topic-metadata">

**Author:** [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Replies:** 16\
**Last updated:** [March 29, 2024, 1:53am UTC](https://discourse.julialang.org/t/sparse-matrix-error-with-forward-diff/108170 "2024-03-29T01:53:38Z")

</div>

Hi all. I have the following MWE. I get a stackoverflow error when using a sparse matrix in a function that I am using ForwardDiff to find the gradient of. When using a dense matrix (i.e. change W1s to W1d in the anonymo…

---

## [Looking for SciMLSensitivity Example with LinearSolve](https://discourse.julialang.org/t/looking-for-scimlsensitivity-example-with-linearsolve/111900)

<div class="topic-metadata">

**Author:** [@Mark\_Lau](https://discourse.julialang.org/u/Mark_Lau)\
**Replies:** 3\
**Last updated:** [March 20, 2024, 10:20pm UTC](https://discourse.julialang.org/t/looking-for-scimlsensitivity-example-with-linearsolve/111900 "2024-03-20T22:20:39Z")

</div>

I’m new to SciMLSensitivity.jl and am trying to learn the ropes. I wanted to try something simple to find the sensitivities of the solution to a LinearProblem with respect to parameters. I couldn’t find an example of how…

---

## [ForwardDiff.jl returns NaNs for calculating gradient of simulation model](https://discourse.julialang.org/t/forwarddiff-jl-returns-nans-for-calculating-gradient-of-simulation-model/109796)

<div class="topic-metadata">

**Author:** [@fnoessler](https://discourse.julialang.org/u/fnoessler)\
**Replies:** 2\
**Last updated:** [February 8, 2024, 12:45pm UTC](https://discourse.julialang.org/t/forwarddiff-jl-returns-nans-for-calculating-gradient-of-simulation-model/109796 "2024-02-08T12:45:28Z")

</div>

Hello, this is a follow up post to Differential evolution MCMC in Julia? I want to try HMC/Nuts (via DynamicHMC.jl or AdvancedHMC.jl) because the algorithms may be more efficient than Differential Evolution MCMC. I tr…

---

## [Autodiff removing singularity](https://discourse.julialang.org/t/autodiff-removing-singularity/109498)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 5\
**Last updated:** [January 31, 2024, 2:46pm UTC](https://discourse.julialang.org/t/autodiff-removing-singularity/109498 "2024-01-31T14:46:31Z")

</div>

I have a function whose derivative isn’t defined at the origin, but is known ahead of time when approaching from x\>0, which is the limit I want. How can I add a special case to the ForwardDiff dual such that it uses this…

---

## [Issue while using nested ForwardDiff.Dual](https://discourse.julialang.org/t/issue-while-using-nested-forwarddiff-dual/107923)

<div class="topic-metadata">

**Author:** [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Replies:** 3\
**Last updated:** [January 24, 2024, 1:28pm UTC](https://discourse.julialang.org/t/issue-while-using-nested-forwarddiff-dual/107923 "2024-01-24T13:28:14Z")

</div>

Hi! I’ve been working on some code that makes use of the dual number implementation in ForwardDiff.Dual. I end up using the dual numbers directly rather than through the functions provided by ForwardDiff as I’ve found i…

---

## [Add ForwardDiff rule to allow complex arguments\`](https://discourse.julialang.org/t/add-forwarddiff-rule-to-allow-complex-arguments/108821)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 9\
**Last updated:** [January 15, 2024, 9:18pm UTC](https://discourse.julialang.org/t/add-forwarddiff-rule-to-allow-complex-arguments/108821 "2024-01-15T21:18:45Z")

</div>

I’m having trouble getting the derivative of a function which uses a complex variable internally. The key function is Di(x,y,T) = real(expintx(complex(-(1+T^2),(x+y\*T)\*√(1+T^2)))) which Zygote is happy to deal with, but …

---

## [Using ForwardDiff and Symbolics, with arithmetic operations](https://discourse.julialang.org/t/using-forwarddiff-and-symbolics-with-arithmetic-operations/106530)

<div class="topic-metadata">

**Author:** [@polhager](https://discourse.julialang.org/u/polhager)\
**Replies:** 2\
**Last updated:** [January 2, 2024, 9:32am UTC](https://discourse.julialang.org/t/using-forwarddiff-and-symbolics-with-arithmetic-operations/106530 "2024-01-02T09:32:49Z")

</div>

I have a somewhat complicated function I’d like to find the analytical jacobian for. When using ForwardDiff and Symbolics and defining a function where both the input variables and certain parameters are symbolic, I get …

---

## [Issues with computing gradient with ForwardDiff.jl (Any fixes other than ND?)](https://discourse.julialang.org/t/issues-with-computing-gradient-with-forwarddiff-jl-any-fixes-other-than-nd/107989)

<div class="topic-metadata">

**Author:** [@ayushinav](https://discourse.julialang.org/u/ayushinav)\
**Replies:** 2\
**Last updated:** [December 24, 2023, 4:30am UTC](https://discourse.julialang.org/t/issues-with-computing-gradient-with-forwarddiff-jl-any-fixes-other-than-nd/107989 "2023-12-24T04:30:06Z")

</div>

When training a model using the boundary loss function, how do you all compute gradients? We can easily apply numerical differentiaion and get things up and running and I’ve seen a good example here. The Flux.gradient(.…

---

## [Incorrect Hessian when using \`exp\` function with complex input](https://discourse.julialang.org/t/incorrect-hessian-when-using-exp-function-with-complex-input/107739)

<div class="topic-metadata">

**Author:** [@rz.yu](https://discourse.julialang.org/u/rz.yu)\
**Replies:** 1\
**Last updated:** [December 17, 2023, 8:23pm UTC](https://discourse.julialang.org/t/incorrect-hessian-when-using-exp-function-with-complex-input/107739 "2023-12-17T20:23:32Z")

</div>

Incorrect Hessian by exp function · Issue #677 · JuliaDiff/ForwardDiff.jl (github.com) I was trying to calculate the Hessian of a simple function such as using ForwardDiff function busPQ(Ybus, Vθ) n = length(Vθ) …

---

## [Getting ForwardDiff.Dual to propagate through function](https://discourse.julialang.org/t/getting-forwarddiff-dual-to-propagate-through-function/107506)

<div class="topic-metadata">

**Author:** [@keynescoefen](https://discourse.julialang.org/u/keynescoefen)\
**Replies:** 5\
**Last updated:** [December 13, 2023, 8:01am UTC](https://discourse.julialang.org/t/getting-forwarddiff-dual-to-propagate-through-function/107506 "2023-12-13T08:01:43Z")

</div>

Hello! I would like to automatically differentiate a log-likelihood to obtain gradients and Hessians but have trouble propagating ForwardDiff.Dual types through my function. I have the same questions as here and tried t…

---

## [Gradient to jacobian in type stable way with ForwardDiff](https://discourse.julialang.org/t/gradient-to-jacobian-in-type-stable-way-with-forwarddiff/107015)

<div class="topic-metadata">

**Author:** [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Replies:** 0\
**Last updated:** [December 1, 2023, 8:01pm UTC](https://discourse.julialang.org/t/gradient-to-jacobian-in-type-stable-way-with-forwarddiff/107015 "2023-12-01T20:01:19Z")

</div>

I have a function f(x,y) where x and y are both vectors, and I would like to calculate the matrix of mixed partials. The following works but is not type stable using ForwardDiff f(x,y) = sum(x)\*sum(y) x0 = \[1.0, 2.0, 3.…

---

## [Gradient of neural network parameters used inside of SMC simulation](https://discourse.julialang.org/t/gradient-of-neural-network-parameters-used-inside-of-smc-simulation/105967)

<div class="topic-metadata">

**Author:** [@YSanchezAraujo](https://discourse.julialang.org/u/YSanchezAraujo)\
**Replies:** 4\
**Last updated:** [November 9, 2023, 6:58pm UTC](https://discourse.julialang.org/t/gradient-of-neural-network-parameters-used-inside-of-smc-simulation/105967 "2023-11-09T18:58:28Z")

</div>

I’m working on implementing variational sequential monte carlo as per this paper A simplified version of the set of functions I’m using are: using Optimisers, Flux, ForwardDiff, Distributions, ...; # samples pa…

---

## [Novel method for feature importance using ReverseMode + ForwardMode autodiff?](https://discourse.julialang.org/t/novel-method-for-feature-importance-using-reversemode-forwardmode-autodiff/105837)

<div class="topic-metadata">

**Author:** [@nielsls](https://discourse.julialang.org/u/nielsls)\
**Replies:** 4\
**Last updated:** [November 7, 2023, 8:04am UTC](https://discourse.julialang.org/t/novel-method-for-feature-importance-using-reversemode-forwardmode-autodiff/105837 "2023-11-07T08:04:33Z")

</div>

Using a combination of reverse- and forward-mode autodiff I have come across a highly efficient method for attributing the change in a differentiable scalar-valued function f: R^N-\>R^1 (e.g. a neural network) to the inpu…

---

## [Stackoverflow error with no stacktrace](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690)

<div class="topic-metadata">

**Author:** [@Larbino1](https://discourse.julialang.org/u/Larbino1)\
**Replies:** 3\
**Last updated:** [November 2, 2023, 1:21pm UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690 "2023-11-02T13:21:00Z")

</div>

I’m experienceing a strange bug which results in a stack overflow error with no stacktrace at all. I’m not sure how or why this happens, and I have found it impossible to diagnose. I haven’t been able to reprodruce the b…

---

## [Smoothed Spline Interpolation compatible with ForwardDiff?](https://discourse.julialang.org/t/smoothed-spline-interpolation-compatible-with-forwarddiff/104344)

<div class="topic-metadata">

**Author:** [@MHaensel](https://discourse.julialang.org/u/MHaensel)\
**Replies:** 6\
**Last updated:** [October 23, 2023, 5:22am UTC](https://discourse.julialang.org/t/smoothed-spline-interpolation-compatible-with-forwarddiff/104344 "2023-10-23T05:22:13Z")

</div>

Hi, I am wondering whether someone has insights on the following: I have a complicated function inside which I perform smoothed (1-D) Cubic Spline interpolation using an irregular grid. Right now I am using the Dierckx…

---

## [@constraint with ForwardDiff.gradient](https://discourse.julialang.org/t/constraint-with-forwarddiff-gradient/104949)

<div class="topic-metadata">

**Author:** [@justinberi](https://discourse.julialang.org/u/justinberi)\
**Replies:** 3\
**Last updated:** [October 16, 2023, 1:05pm UTC](https://discourse.julialang.org/t/constraint-with-forwarddiff-gradient/104949 "2023-10-16T13:05:56Z")

</div>

Hi All, Thanks in advance for any help and suggestions. I’m new to Julia (and JuMP) so go easy. Is there a way to use ForwardDiff.gradient within a nonlinear constraint in JuMP? An example is # Solve using JuMP inter…

---

## [Cannot ForwardDiff through linear least squares via QR](https://discourse.julialang.org/t/cannot-forwarddiff-through-linear-least-squares-via-qr/104257)

<div class="topic-metadata">

**Author:** [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Replies:** 6\
**Last updated:** [September 27, 2023, 6:26am UTC](https://discourse.julialang.org/t/cannot-forwarddiff-through-linear-least-squares-via-qr/104257 "2023-09-27T06:26:39Z")

</div>

Hey, I’d like to get derivatives for a linear least squares problem where the parameter appears in the right hand side: using LinearAlgebra using ForwardDiff A = rand(10, 3) b = rand(10) qr\_fact = qr(A) function f(p…

---

## [AutoForwardDiff() Error no method matching](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854)

<div class="topic-metadata">

**Author:** [@Francesco\_C](https://discourse.julialang.org/u/Francesco_C)\
**Replies:** 10\
**Last updated:** [September 14, 2023, 10:00pm UTC](https://discourse.julialang.org/t/autoforwarddiff-error-no-method-matching/103854 "2023-09-14T22:00:01Z")

</div>

Hi, I am trying to replicate the main examples for the Optimization package https://docs.sciml.ai/Optimization/stable/getting\_started/ However, when I try using the automatic differentiation Optimization.AutoForwardDif…

---

## [How to compute the last column of Hessian (over and over) with autodiff without computing entire Hessian?](https://discourse.julialang.org/t/how-to-compute-the-last-column-of-hessian-over-and-over-with-autodiff-without-computing-entire-hessian/103588)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 5\
**Last updated:** [September 7, 2023, 5:27am UTC](https://discourse.julialang.org/t/how-to-compute-the-last-column-of-hessian-over-and-over-with-autodiff-without-computing-entire-hessian/103588 "2023-09-07T05:27:41Z")

</div>

Hi community, I have an extended question from this post. I have a loss function f(y, X, β)::Number which requires data y and X. Matrix X changes often and I want to compute: The last column of the Hessian of f with r…

---

## [Setting up implicit solvers to beat the performance of explicit solvers](https://discourse.julialang.org/t/setting-up-implicit-solvers-to-beat-the-performance-of-explicit-solvers/102392)

<div class="topic-metadata">

**Author:** [@JordiBolibar](https://discourse.julialang.org/u/JordiBolibar)\
**Replies:** 10\
**Last updated:** [August 24, 2023, 4:16pm UTC](https://discourse.julialang.org/t/setting-up-implicit-solvers-to-beat-the-performance-of-explicit-solvers/102392 "2023-08-24T16:16:45Z")

</div>

We are trying to benchmark implicit solvers for an ice flow diffusivity PDE. So far we’ve stuck to explicit ones, but now we would like to cover all of them. Since many implicit solvers from DifferentialEquations.jl requ…

---

## [Directly modifying partials in ForwardDiff](https://discourse.julialang.org/t/directly-modifying-partials-in-forwarddiff/102755)

<div class="topic-metadata">

**Author:** [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Replies:** 14\
**Last updated:** [August 21, 2023, 8:19am UTC](https://discourse.julialang.org/t/directly-modifying-partials-in-forwarddiff/102755 "2023-08-21T08:19:09Z")

</div>

Hi all, I am currently trying to optimize a package I’ve written to model stellar evolution. Just in case I prefer to give some context to know if there might be a much better way to do what I’m trying to achieve. Stell…

---

## [Are there ways to preallocate memory via structs for JuMP autodiff?](https://discourse.julialang.org/t/are-there-ways-to-preallocate-memory-via-structs-for-jump-autodiff/102945)

<div class="topic-metadata">

**Author:** [@told](https://discourse.julialang.org/u/told)\
**Replies:** 2\
**Last updated:** [August 20, 2023, 8:58pm UTC](https://discourse.julialang.org/t/are-there-ways-to-preallocate-memory-via-structs-for-jump-autodiff/102945 "2023-08-20T20:58:20Z")

</div>

I’m very aware of the limitations of ForwardDiff.jl that code has to be written general enough to accept {T\<:Real}. The JuMP docs suggest to write target functions like function good\_f(x::T...) where {T\<:Real} y = …

---

## [Computing value and first & second derivatives of a scalar function with scalar input, using ForwardDiff](https://discourse.julialang.org/t/computing-value-and-first-second-derivatives-of-a-scalar-function-with-scalar-input-using-forwarddiff/102866)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 6\
**Last updated:** [August 16, 2023, 10:04pm UTC](https://discourse.julialang.org/t/computing-value-and-first-second-derivatives-of-a-scalar-function-with-scalar-input-using-forwarddiff/102866 "2023-08-16T22:04:33Z")

</div>

I cannot find, either in the documentation of ForwardDiff, or on the web more widely, any information on how to compute the second derivative of a scalar function with a scalar input. How can I do this? (Given a function…

---

## [Possibility to store outcome of \`ForwardDiff.jacobian\` already in sparse format](https://discourse.julialang.org/t/possibility-to-store-outcome-of-forwarddiff-jacobian-already-in-sparse-format/102635)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 2\
**Last updated:** [August 11, 2023, 6:19am UTC](https://discourse.julialang.org/t/possibility-to-store-outcome-of-forwarddiff-jacobian-already-in-sparse-format/102635 "2023-08-11T06:19:00Z")

</div>

I use ForwardDiff.jacobian in the following way: function \_jacobian\_ad\_forward(p, t0, u0\_ode, du\_ode, config) J = ForwardDiff.jacobian(du\_ode, u0\_ode, config) do du\_ode, u\_ode f!(du\_ode, u\_ode, p, t0) en…

---

## [Hard reset of Julia environment](https://discourse.julialang.org/t/hard-reset-of-julia-environment/102260)

<div class="topic-metadata">

**Author:** [@mesonepigreco](https://discourse.julialang.org/u/mesonepigreco)\
**Replies:** 1\
**Last updated:** [July 29, 2023, 11:50pm UTC](https://discourse.julialang.org/t/hard-reset-of-julia-environment/102260 "2023-07-29T23:50:00Z")

</div>

Hello, I need to reset a julia environment from all temporary files, like in a fresh installation after a mess I made that is causing many packages to fail precompiliation and loading. In particular, after I activate t…

---

## [ForwardDiff.jl with Symbolics.jl](https://discourse.julialang.org/t/forwarddiff-jl-with-symbolics-jl/98706)

<div class="topic-metadata">

**Author:** [@dchang10](https://discourse.julialang.org/u/dchang10)\
**Replies:** 3\
**Last updated:** [July 28, 2023, 2:43pm UTC](https://discourse.julialang.org/t/forwarddiff-jl-with-symbolics-jl/98706 "2023-07-28T14:43:28Z")

</div>

I’m trying to do mixed symbolic and numeric derivatives. I want to define a type that holds a function that I will use to differentiate on in the future, this function may be ill-defined, so I would like to be able to op…

---

## [Calculating Third (and Higher) Derivatives: ReverseDiff gives 0s while ForwardDiff works](https://discourse.julialang.org/t/calculating-third-and-higher-derivatives-reversediff-gives-0s-while-forwarddiff-works/101095)

<div class="topic-metadata">

**Author:** [@HappyQuokka](https://discourse.julialang.org/u/HappyQuokka)\
**Replies:** 1\
**Last updated:** [July 3, 2023, 2:14am UTC](https://discourse.julialang.org/t/calculating-third-and-higher-derivatives-reversediff-gives-0s-while-forwarddiff-works/101095 "2023-07-03T02:14:33Z")

</div>

I am trying to calculate the third derivative (tensor). ForwardDiff seems to work but is incredibly slow, also for lower orders. ReverseDiff, while fast for lower derivatives, doesn’t seem to work for third derivatives o…

---

## [How to calculate the Hessian vector product in a Flux model?](https://discourse.julialang.org/t/how-to-calculate-the-hessian-vector-product-in-a-flux-model/100215)

<div class="topic-metadata">

**Author:** [@taizoooo](https://discourse.julialang.org/u/taizoooo)\
**Replies:** 1\
**Last updated:** [June 13, 2023, 8:42pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-hessian-vector-product-in-a-flux-model/100215 "2023-06-13T20:42:26Z")

</div>

Hello. I implemented the Hessian vector product referring to the following link: Hessian Vector Products on GPU using ForwardDiff, Zygote, and Flux. The implementation works correctly on both CPU and GPU for a flux mod…

[Previous page](https://discourse.julialang.org/tag/forwarddiff/363.md?match_all_tags=true&page=1&tags%5B%5D=forwarddiff)

[Next page](https://discourse.julialang.org/tag/forwarddiff/363.md?match_all_tags=true&page=3&tags%5B%5D=forwarddiff)
