Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundsError: attempt to access 1-element Vector{Float64} at index [1] #1593

Closed
mhauru opened this issue Jul 1, 2024 · 1 comment
Closed

Comments

@mhauru
Copy link

mhauru commented Jul 1, 2024

MWE:

module MWE

using SpecialFunctions: libopenspecfun
using Enzyme

function besseli(nu)
    kode = Int32(1)
    ai1, ai2 = Ref{Float64}(), Ref{Float64}()
    ae1, ae2 = Ref{Int32}(), Ref{Int32}()

    ccall((:zbesi_,libopenspecfun), Cvoid,
          (Ref{Float64}, Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32},
           Ref{Float64}, Ref{Float64}, Ref{Int32}, Ref{Int32}),
           1.0, 0.0, 1.0, kode, 1,
           ai1, ai2, ae1, ae2)

    if ae2[] == 0
        return complex(0.0, nu)
    else
        throw(AssertionError())
    end
end

f(x) = besseli(x[1])

Enzyme.gradient(Enzyme.Forward, f, [1.0])

end

Output:

ERROR: LoadError: BoundsError: attempt to access 1-element Vector{Float64} at index [1]
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] f
    @ ~/projects/Enzyme-mwes/callinst_metadata/false_boundserror.jl:24 [inlined]
  [3] f
    @ ~/projects/Enzyme-mwes/callinst_metadata/false_boundserror.jl:0 [inlined]
  [4] fwddiffejulia_f_1512_inner_1wrap
    @ ~/projects/Enzyme-mwes/callinst_metadata/false_boundserror.jl:0
  [5] macro expansion
    @ ~/.julia/packages/Enzyme/qd8AI/src/compiler.jl:6606 [inlined]
  [6] enzyme_call
    @ ~/.julia/packages/Enzyme/qd8AI/src/compiler.jl:6207 [inlined]
  [7] ForwardModeThunk
    @ ~/.julia/packages/Enzyme/qd8AI/src/compiler.jl:6087 [inlined]
  [8] autodiff(::EnzymeCore.ForwardMode{EnzymeCore.FFIABI}, f::EnzymeCore.Const{typeof(Main.MWE.f)}, ::Type{EnzymeCore.BatchDuplicatedNoNeed}, args::EnzymeCore.BatchDuplicated{Vector{Float64}, 1})
    @ Enzyme ~/.julia/packages/Enzyme/qd8AI/src/Enzyme.jl:417
  [9] autodiff
    @ ~/.julia/packages/Enzyme/qd8AI/src/Enzyme.jl:321 [inlined]
 [10] gradient(::EnzymeCore.ForwardMode{EnzymeCore.FFIABI}, f::Function, x::Vector{Float64}; shadow::Tuple{Vector{Float64}})
    @ Enzyme ~/.julia/packages/Enzyme/qd8AI/src/Enzyme.jl:1064
 [11] gradient(::EnzymeCore.ForwardMode{EnzymeCore.FFIABI}, f::Function, x::Vector{Float64})
    @ Enzyme ~/.julia/packages/Enzyme/qd8AI/src/Enzyme.jl:1060
 [12] top-level scope
    @ ~/projects/Enzyme-mwes/callinst_metadata/false_boundserror.jl:26
in expression starting at /Users/mhauru/projects/Enzyme-mwes/callinst_metadata/false_boundserror.jl:1
@mhauru
Copy link
Author

mhauru commented Jul 2, 2024

Fixed on main

@mhauru mhauru closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant