JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Use with ForwardDiff
- Lingua principale
- Julia
- Stelle
- 789
- Fork
- 73
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I was trying to use this with ForwardDiff, but not an array of structs like #19, just using dual numbers within a loop and then extracting ordinary numbers. Something like this:
```julia
dA = ForwardDiff.Dual(0.0, (1.0, 0.0))
dB = ForwardDiff.Dual(0.0, (0.0, 1.0))
for i in axes(A,1)
tmp = (A[i] + dA) * log(B[i] + dB)
C[i] = ForwardDiff.partials(tmp, 1)
...
```
I got this to run with `@avx` on the loop, by filling in whatever methods were missing, such as:
```julia
function Base.:+(x::Dual{Z,T,D}, sv::SVec{N}) where {Z,T<:Number,D,N}
duals = ntuple(n -> +(x, sv[n]), N)
Dual(svec(val.(duals)), ntuple(d -> svec(partials.(duals, d)), D))
end
@inline val(d::Dual) = d.value
@inline svec(tup::NTuple{N,T}) where {N,T} = SVec{N,T}(tup...)
```
However the result is slower than without, and has many more allocations.
I wonder whether this is expected to work, and whether adding methods like this is right thing to do? I can tidy up an example if there isn't an obvious fatal flaw here.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.