Allow columns with variable getindex return types#84
Allow columns with variable getindex return types#84colinxs wants to merge 2 commits intoJuliaArrays:masterfrom colinxs:feat/allow_views
Conversation
|
Added a @generated version of get_ith so that its return type can be inferred. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
Thanks for the PR! In general I'm hoping to reduce the number of generated functions. I used to have generated julia> x=nestedview(rand(2,3,10), 2);
julia> x[1] isa eltype(x)
falseShouldn't |
|
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! |
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,
getindexreturns a view of the underlying data, which has a variable (but stable) return type. StructArrays relies on a constant return type increateinstance. This leads to some odd behavior:This is because:
So in
createinstancea call toT(args), corresponding toNamedTuple{(:x,),Tuple{Array{Float64,2}}(s.x[1])is made, buttypeof(s.x[1])<:SubArrayso 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