Closed JaredCrean2 closed 6 years ago
If you can use julia 0.4, consider trying slice
. slice
is also available in 0.3, but there it does not have the kind of performance you get from ArrayViews.
For slice
, the intended use case is to construct a slice object of a specified size, and use push! to copy values into it, right? This would be faster than ArrayViews for small arrays ( less than 3 or 4 elements I would guess, because of construction allocation), but not for large arrays.
Not sure I follow. slice
creates a view, just like ArrayViews.jl. It doesn't copy any data, nor is it growable.
I'm looking at slice.jl here: https://github.com/BioJulia/IntervalTrees.jl/blob/master/src/slice.jl . The inner constructor creates an array of a fixed size and the push! and setindex! methods populate it with values. I didn't mean to suggest the slice was growable. Were you referring to a different slice implementation?
Yes, the one in base: https://github.com/JuliaLang/julia/blob/master/base/subarray.jl
Ah, that explains it.
I built the latest version of Julia and slice
is significantly faster than it was with the version I built 16 days ago, but not quite on par with ArrayViews. The test code is here if you are curious: https://github.com/JaredCrean2/julia_tests/tree/master/array_speed2 . It does some computation over an array using a manually inlined double for loop, ArrayViews, and Slices.
Using Julia Version 0.4.0-dev+5149 (2015-06-01 18:58 UTC) Commit 317a4d1* (16 days old master)
592.426 milliseconds (14232 allocations: 586 KB)
double loop @time printed above
495.138 milliseconds (14422 allocations: 599 KB)
ArrayView @time printed above
15.753 seconds (300 M allocations: 8240 MB, 3.39% gc time)
slice @time printed above
Using Julia Version 0.4.0-dev+5439 (2015-06-18 13:48 UTC) Commit a23caa0* (0 days old master):
1.720 seconds (102 k allocations: 3600 KB)
double loop @time printed above
566.122 milliseconds (16237 allocations: 692 KB)
ArrayView @time printed above
4.137 seconds (240 M allocations: 8240 MB, 12.96% gc time)
slice @time printed above
It seems strange the double for loop is slower now that it was 16 days ago. Based on these results, it looks like ArrayViews is the way to go from a performance perspective.
Hmm, sounds like a possible regression. Might be worth filing as an issue.
Is this still a problem?
It is fixed.
I am using ArrayViews to loop over a big array and operate on little slices of it. It works extremely well and is very convenient, but I noticed that if I am extracting a row vector from a high dimensional array (N > 2), the result is a 2 dimensional array view. For example
gives a
1x2 ArrayViews.StridedView{Float64,2,0,Array{Float64,4}}:
I would have expected this to give a 1 dimensional strided view, rather than a 2 dimensional view. Is this the expected behavior?