# Enzyme strange output for hessian

**URL:** <https://discourse.julialang.org/t/enzyme-strange-output-for-hessian/123899>\
**Category:** General Usage\
**Tags:** autodiff, enzyme\
**Created:** [December 16, 2024, 7:31pm UTC](https://discourse.julialang.org/t/enzyme-strange-output-for-hessian/123899 "2024-12-16T19:31:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![c\_sell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c_sell/32/38854_2.png) [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Post date:** [December 16, 2024, 7:31pm UTC](https://discourse.julialang.org/t/enzyme-strange-output-for-hessian/123899/1 "2024-12-16T19:31:25Z")

</div>

Hello, I get for the following small example the strage output:

freeing without malloc %53 = call noalias nonnull dereferenceable(32) dereferenceable\_or\_null(32) i8\* @malloc(i64 noundef 32) #20, !enzyme\_cache\_alloc !57  
freeing without malloc %\_malloccache107.i.i = call noalias nonnull dereferenceable(4) dereferenceable\_or\_null(4) i8\* @malloc(i64 noundef 4) #20, !enzyme\_cache\_alloc !59  
freeing without malloc %\_malloccache110.i.i = call noalias nonnull dereferenceable(4) dereferenceable\_or\_null(4) i8\* @malloc(i64 noundef 4) #20, !enzyme\_cache\_alloc !61

My julia version 1.11.2.

I hope you have any ideas, thank you!

My code:

```julia
using Enzyme

function foo1(uv)
    out = zeros(2)
    for i in eachindex(uv)
        out .+= uv[i]
    end
    out
end

function fun(uv::V,pars) where {V}
    s = zero(Float64)
    for _ in 1:4
        ∇u_x = foo1(uv)
        s += sum(∇u_x)
    end
    return s
end

function fun_grad(f::F,uv::V,
    uvb::V,pars) where {T<:Float64,V<:AbstractVector{T},F<:Function} 

    Enzyme.autodiff(Reverse,Const(f),Duplicated(uv,uvb),Const(pars))
    nothing
end

uv = rand(4); 
vx = ([1.0, 0.0, 0.0, 0.0],
        [0.0, 1.0, 0.0, 0.0],
        [0.0, 0.0, 1.0, 0.0],
        [0.0, 0.0, 0.0, 1.0])

fe = rand(4) 
Ke = ([0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0])

v = rand(10)

Enzyme.autodiff(Enzyme.Forward, fun_grad,
    Const(fun),
    BatchDuplicated(uv,vx),
    BatchDuplicated(fe,Ke),
    Const(v))

```
