JuliaDiff / JuliaDiff/Diffractor.jl

Even very basic broadcasting breaks inferability

Open
#147 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
453
Forks
33
PR merge metrics
No merged PRs in 30d

Description

Even very simple broadcasting can't infer in Diffractor forward mode

Consider:

using Diffractor
using Diffractor: TaylorBundle, ZeroBundle, CompositeBundle
forward = Diffractor.∂☆{1}()
f(x) = 2 .* x
cb = CompositeBundle{1, Tuple{Float64, Float64}}((TaylorBundle{1}(1.0, (1.0,)), TaylorBundle{1}(1.0, (2.0,))))
@code_warntype forward(ZeroBundle{1}(f), cb)

The output is

julia> @code_warntype forward(ZeroBundle{1}(f), cb)
MethodInstance for (::Diffractor.∂☆{1})(::ZeroBundle{1, typeof(f)}, ::CompositeBundle{1, Tuple{Float64, Float64}, Tuple{Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}, Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}}})
  from (::Diffractor.∂☆{N})(args::Diffractor.AbstractTangentBundle{N}...) where N @ Diffractor ~/.julia/packages/Diffractor/a9mlv/src/stage1/forward.jl:148
Static Parameters
  N = 1
Arguments
  #self#::Core.Const(Diffractor.∂☆{1}())
  args::Tuple{ZeroBundle{1, typeof(f)}, CompositeBundle{1, Tuple{Float64, Float64}, Tuple{Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}, Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}}}}
Body::Any
1 ─ %1 = Core.apply_type(Diffractor.∂☆internal, $(Expr(:static_parameter, 1)))::Core.Const(Diffractor.∂☆internal{1})
│   %2 = (%1)()::Core.Const(Diffractor.∂☆internal{1}())
│   %3 = Core._apply_iterate(Base.iterate, %2, args)::Any
└──      return %3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with Julia's @code_warntype and start at stage1/forward.jl:148, where the displayed method dispatches through ∂☆internal. Trace the call for the provided ZeroBundle, CompositeBundle, and broadcasting function; done means the example no longer reports Body::Any and remains inferable.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.