Comments (2)
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.
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)
- Alternative to Tullio for Chained Multiplication HOT 4
- @views macro causes module compilation failure HOT 3
- Reporting a bug when Tullio being included with LoopVectorization HOT 1
- [Question] How to change summation order? HOT 5
- Use package extensions HOT 1
- How finalizers `|>` work HOT 5
- Method error when broadcast and sum of matrices HOT 1
- GPU Kernel Compilation Failed with Interpolations HOT 2
- Upgrade to CUDA.CUDAKernels HOT 9
- Bug when using Tullio + LoopVectorization HOT 5
- Add Finch.jl backend HOT 4
- CUDA v4 support HOT 2
- Using threads, vs setting threads=false gives different result HOT 3
- Issue with vectorized functions on GPU HOT 3
- Error when specifying the range of an index with a UnitRange HOT 4
- Scalar indexing with CUDA HOT 10
- Please update dep of FillArrays to v1.
- Bad interaction with Enzyme? HOT 6
- Zygote with Tullio gives wrong gradients/pullbacks using CUDA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tullio.jl.