Giter VIP home page Giter VIP logo

Comments (2)

mcabbott avatar mcabbott commented on June 20, 2024

Tullio doesn't really know how to make an array of arrays, nor even to write into them -- it thinks vs[i] is the name of the array, should really notice and have a better error:

julia> vs = [rand(3) for _ in 1:4];

julia> @tullio vs[i][j] = i+j;
ERROR: UndefVarError: `i` not defined

julia> @tullio w[i] := vs[i][j];  # reading is fine

julia> w  sum.(vs)
true

It is possible to make slices without ever talking about their inner indices, so that it doesn't have to think about them:

julia> r = rand(5, 1000);

julia> using StaticArrays

julia> @tullio out[i] := SVector{5, Float64}(r[:, i]);

julia> out[1]
5-element SVector{5, Float64} with indices SOneTo(5):
 0.7766767901258985
 0.7154993774154197
 0.37558253875140246
 0.9544276819410628
 0.841961127323515

julia> size(out)
(1000,)

julia> summary(@tullio _[i] := r[:, i])
"1000-element Vector{Vector{Float64}}"

julia> @btime @tullio out[i] := SVector{5, Float64}($r[:, i]);
  min 35.333 μs, mean 316.602 μs (1002 allocations, 132.86 KiB)

However, this is making r[:, 1]::Vector each time before making an SVector, so it won't be fast. Tullio does not have ambitions to be good at applying functions to slices, etc. It gets confused by things like @tullio _[i,j] := vcat(r[:,i],i)[j] and even if this did work, it would still be a loop over all i, j, thus applying the function N^2 times.

TensorCast is more interested in slices. And (with slightly obscure notation) has special paths for StaticArrays. This should just call reinterpret but appears to waste a few ns:

julia> using TensorCast

julia> @btime @cast out2[i] := $r{:5, i};
  min 24.515 ns, mean 184.877 ns (2 allocations, 80 bytes)

julia> @btime reinterpret(SVector{5, Float64}, $r)
  min 4.500 ns, mean 4.648 ns (0 allocations)

from tullio.jl.

shayandavoodii avatar shayandavoodii commented on June 20, 2024

Thank you so much for this comprehensive explanation! I figured out why I faced the problem. Nonetheless, wouldn't it be better if you merged these two packages?

from tullio.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.