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

Allow columns with variable getindex return types #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Allow columns with variable getindex return types #84

wants to merge 2 commits into from

Conversation

colinxs
Copy link

@colinxs colinxs commented Jun 27, 2019

There's an interesting new package floating about that has been quite useful: https://github.com/oschulz/ArraysOfArrays.jl. The gist is that it allows viewing an M+N dimensional array as an M-dimensional array of N-dimensional arrays. To achieve this, getindex returns a view of the underlying data, which has a variable (but stable) return type. StructArrays relies on a constant return type in createinstance. This leads to some odd behavior:

julia> s=StructArray(x=nestedview(rand(2,3,10), 2));
julia> s[1].x .= 2;
julia> s[1].x
2×3 Array{Float64,2}:
 0.979757  0.282793  0.948475
 0.850188  0.611789  0.959696

This is because:

julia> eltype(s.x)
Array{Float64,2}

So in createinstance a call to T(args), corresponding to NamedTuple{(:x,),Tuple{Array{Float64,2}}(s.x[1]) is made, but typeof(s.x[1])<:SubArray so a copy of the data is made.

This PR fixes the above issue but introduces a new one: now the inferred return type for getindex(::StructArray, ...) is Any.

-Colin

@colinxs
Copy link
Author

colinxs commented Jun 27, 2019

Added a @generated version of get_ith so that its return type can be inferred.

@codecov-io
Copy link

codecov-io commented Jun 27, 2019

Codecov Report

Merging #84 into master will decrease coverage by 0.19%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #84     +/-   ##
=========================================
- Coverage   91.08%   90.88%   -0.2%     
=========================================
  Files           9        9             
  Lines         370      373      +3     
=========================================
+ Hits          337      339      +2     
- Misses         33       34      +1
Impacted Files Coverage Δ
src/structarray.jl 86.86% <100%> (+0.27%) ⬆️
src/interface.jl 71.42% <50%> (-11.91%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d22a69e...862af3a. Read the comment docs.

@piever
Copy link
Collaborator

piever commented Jul 1, 2019

Thanks for the PR! In general I'm hoping to reduce the number of generated functions. I used to have generated getindex but it turns out it was not needed. Here I think the problem is a bug with ArrayOfArrays.jl:

julia> x=nestedview(rand(2,3,10), 2);

julia> x[1] isa eltype(x)
false

Shouldn't ArrayOfSimilarArrays have the correct eltype instead?

@colinxs
Copy link
Author

colinxs commented Jul 17, 2019

Sorry for the delay, been a bit busy!

I entirely see you point. I brought the issue up in ArraysOfArrays here. Would you mind leaving this issue open until a fix (either here or there) is implemented?

Thanks!
Colin

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

Successfully merging this pull request may close these issues.

3 participants