Git Product home page Git Product logo

Comments (3)

dlfivefifty avatar dlfivefifty commented on June 25, 2024

That's mostly just me trying different things to get building operators to be faster. The big issue with @. is it makes nested broadcasting, which at some point breaks type inference. The manual . versions suffer the same problem, but not as bad.

It's likely that the BroadcastVector(...) version was a specific case where the nested broadcasting was too hard for type inference so by doing this we avoid nested broadcasting completely.

But this would have been a one-off experiment so has not been thoroughly investigated.

from multivariateorthogonalpolynomials.jl.

MikaelSlevinsky avatar MikaelSlevinsky commented on June 25, 2024

Does type assertion solve issues related to inference?

from multivariateorthogonalpolynomials.jl.

dlfivefifty avatar dlfivefifty commented on June 25, 2024

No. Here's a rough idea of the problem. Let's say we have a complicated nested BroadcastVector like

v = ((k .+ (c-1)) .* ( k .- n .- 1 ) ./ (2k .+ (b+c-1)))

When building operators the code basically lowers to

for K in Block.(1:N)
   copyto!(view(dest,K), view(v,K))
end

It's smart enough to recognise view(v,K) is itself equivalent to a BroadcastVector thus this becomes equivalent to:

k_K = view(k,K) # returns Base.OneTo(Int(K))
n_K = view(n,K) # returns Fill(Int(K),Int(K))
copyto!(view(dest,K), ((k_K .+ (c-1)) .* ( k_K .- n_K .- 1 ) ./ (2k_K .+ (b+c-1)))) # actually a nested Broadcasted 

When correctly type-inferred the last step then gets reduced to a tight loop, essentially as fast as if done manually. When type-inferrence fails, it doesn't know how to reduce the nested Broadcasted to a simple loop, and hence has to do dynamic dispatch looping over every entry of view(dest,K), so extremely slow.

from multivariateorthogonalpolynomials.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.