EnzymeAD / EnzymeAD/Enzyme

BLAS rule for nrm2 at [0.0] return NaN

Open
#2,419 3 comments 0 reactions 0 assignees View on GitHub
forward mode
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
1d 22h
Merged PRs (30d)
26

Description

https://github.com/EnzymeAD/Enzyme/blob/f513bdfc8c1fc09dea3f905c7ddcb9d9c91a45f7/enzyme/Enzyme/BlasDerivatives.td#L237-L243

compare with ChainRules

https://github.com/JuliaDiff/ChainRules.jl/blob/0923b1e7281b8d1418205a8798cc653c5cbd8552/src/rulesets/LinearAlgebra/blas.jl#L38-L47

And from Julia
```
using Enzyme
using LinearAlgebra

x = [5.0]
dx = [1.0]

autodiff(Forward, LinearAlgebra.BLAS.nrm2, Duplicated(x, dx)) # 0.447214
autodiff(Forward, LinearAlgebra.generic_norm2, Duplicated(x, dx)) # 1.0
```

Notably, the zero handling is also different.

```
dx = [1.0]
x = [0.0]

autodiff(Forward, LinearAlgebra.BLAS.nrm2, Duplicated(x, dx)) # NaN
autodiff(Forward, LinearAlgebra.generic_norm2, Duplicated(x, dx)) # 1.0 -- Same as ChainRules
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.