Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Row Vector Dimension #29

Closed
JaredCrean2 opened this issue Jun 17, 2015 · 9 comments
Closed

Row Vector Dimension #29

JaredCrean2 opened this issue Jun 17, 2015 · 9 comments

Comments

@JaredCrean2
Copy link
Contributor

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

big_array = randn(2,2, 3, 4)
view1 = view(big_array, 1, :, 1, 1)

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?

@timholy
Copy link
Member

timholy commented Jun 17, 2015

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.

@JaredCrean2
Copy link
Contributor Author

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.

@timholy
Copy link
Member

timholy commented Jun 18, 2015

Not sure I follow. slice creates a view, just like ArrayViews.jl. It doesn't copy any data, nor is it growable.

@JaredCrean2
Copy link
Contributor Author

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?

@timholy
Copy link
Member

timholy commented Jun 18, 2015

@JaredCrean2
Copy link
Contributor Author

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.

@timholy
Copy link
Member

timholy commented Jun 20, 2015

Hmm, sounds like a possible regression. Might be worth filing as an issue.

@andreasnoack
Copy link
Member

Is this still a problem?

@JaredCrean2
Copy link
Contributor Author

It is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants