-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: check/fix return types and tighten argument types #22
Conversation
I used The REPL outputs also look right, though I still wonder about julia> layout = AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5])
5-element AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}:
1.1
2.2
3.3
4.4
5.5
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Float64
julia> layout = AwkwardArray.ListOffsetArray([0, 3, 3, 5],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
)
3-element AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
Any[1.1, 2.2, 3.3]
0-element AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}
Any[4.4, 5.5]
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}
julia> layout = AwkwardArray.ListArray([0, 3, 3], [3, 3, 5],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
)
3-element AwkwardArray.ListArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
Any[1.1, 2.2, 3.3]
0-element AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}
Any[4.4, 5.5]
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}
julia> layout = AwkwardArray.RegularArray(
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5, 6.6]),
3,
)
2-element AwkwardArray.RegularArray{AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
Any[1.1, 2.2, 3.3]
Any[4.4, 5.5, 6.6]
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}
julia> layout = AwkwardArray.StringOffsetArray(
[0, 3, 8, 9, 11, 14, 18],
"heythere\$¢€💰",
)
6-element AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{UInt8, Vector{UInt8}, :char}, :string}:
"hey"
"there"
"\$"
"¢"
"€"
"💰"
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
String
julia> layout = AwkwardArray.StringArray(
[0, 3, 8, 9, 11, 14],
[3, 8, 9, 11, 14, 18],
"heythere\$¢€💰",
)
6-element AwkwardArray.ListArray{Vector{Int64}, AwkwardArray.PrimitiveArray{UInt8, Vector{UInt8}, :char}, :string}:
"hey"
"there"
"\$"
"¢"
"€"
"💰"
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
String
julia> layout = AwkwardArray.StringRegularArray(
"heyyou", 3
)
2-element AwkwardArray.RegularArray{AwkwardArray.PrimitiveArray{UInt8, Vector{UInt8}, :char}, :string}:
"hey"
"you"
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
String
julia> layout = AwkwardArray.RecordArray(
NamedTuple{(:a, :b)}((
AwkwardArray.PrimitiveArray([1, 2, 3]),
AwkwardArray.ListOffsetArray(
[0, 3, 3, 5],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
),
)),
)
3-element AwkwardArray.RecordArray{NamedTuple{(:a, :b), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}}, :default}:
AwkwardArray.Record{AwkwardArray.RecordArray{NamedTuple{(:a, :b), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}}, :default}}(Any[#= circular reference @-2 =#], 1)
AwkwardArray.Record{AwkwardArray.RecordArray{NamedTuple{(:a, :b), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}}, :default}}(Any[#= circular reference @-2 =#], 2)
AwkwardArray.Record{AwkwardArray.RecordArray{NamedTuple{(:a, :b), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}}, :default}}(Any[#= circular reference @-2 =#], 3)
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
AwkwardArray.Record{AwkwardArray.RecordArray{NamedTuple{(:a, :b), Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}}, :default}}
julia> layout = AwkwardArray.TupleArray(
(
AwkwardArray.PrimitiveArray([1, 2, 3]),
AwkwardArray.ListOffsetArray(
[0, 3, 3, 5],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
),
),
)
3-element AwkwardArray.TupleArray{Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}:
AwkwardArray.Tuple{AwkwardArray.TupleArray{Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}}(Any[#= circular reference @-2 =#], 1)
AwkwardArray.Tuple{AwkwardArray.TupleArray{Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}}(Any[#= circular reference @-2 =#], 2)
AwkwardArray.Tuple{AwkwardArray.TupleArray{Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}}(Any[#= circular reference @-2 =#], 3)
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
AwkwardArray.Tuple{AwkwardArray.TupleArray{Tuple{AwkwardArray.PrimitiveArray{Int64, Vector{Int64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}}
julia> layout = AwkwardArray.IndexedArray(
[4, 3, 3, 0],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
)
4-element AwkwardArray.IndexedArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
5.5
4.4
4.4
1.1
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Float64
julia> layout = AwkwardArray.IndexedOptionArray(
[4, 3, 3, -1, -1, 0],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
)
6-element AwkwardArray.IndexedOptionArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
5.5
4.4
4.4
missing
missing
1.1
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Union{Missing, Float64}
julia> layout = AwkwardArray.ByteMaskedArray(
[false, true, true, false, false],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
valid_when = false,
)
5-element AwkwardArray.ByteMaskedArray{Vector{Bool}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
1.1
missing
missing
4.4
5.5
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Union{Missing, Float64}
julia> layout = AwkwardArray.BitMaskedArray(
BitVector([false, true, true, false, false]),
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
valid_when = false,
)
5-element AwkwardArray.BitMaskedArray{AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
1.1
missing
missing
4.4
5.5
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Union{Missing, Float64}
julia> layout = AwkwardArray.UnmaskedArray(
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
)
5-element AwkwardArray.UnmaskedArray{AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}:
1.1
2.2
3.3
4.4
5.5
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Float64
julia> layout = AwkwardArray.UnionArray(
Vector{Int8}([0, 0, 0, 1]),
[0, 1, 2, 0],
(
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3]),
AwkwardArray.ListOffsetArray(
[0, 2],
AwkwardArray.PrimitiveArray([4.4, 5.5]),
),
),
)
4-element AwkwardArray.UnionArray{Vector{Int8}, Vector{Int64}, Tuple{AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, AwkwardArray.ListOffsetArray{Vector{Int64}, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}, :default}}, :default}:
1.1
2.2
3.3
Any[4.4, 5.5]
julia> Base.return_types(getindex, (typeof(layout), typeof(1)))
1-element Vector{Any}:
Union{Float64, AwkwardArray.PrimitiveArray{Float64, Vector{Float64}, :default}} |
There are some situations, like passing a With layout = AwkwardArray.RecordArray(
NamedTuple{(:a, :b)}((
AwkwardArray.PrimitiveArray([1, 2, 3]),
AwkwardArray.ListOffsetArray(
[0, 3, 3, 5],
AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]),
),
)),
) and @inferred layout[3][:a] I get
because of course. Same for the option-types of |
right, the only way for this to be inferrable @inferred layout[3][:a] is if |
@inferred layout[3] | ||
@inferred layout[1:3] | ||
@inferred layout[:a][3] | ||
@inferred layout[:b][3] | ||
@inferred layout[:b][3][1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With stronger typing, some of these can be inferred, but others can't:
@inferred layout[:a][3] # cool: these can be inferred!
@inferred layout[:b][3]
@inferred layout[:b][3][1]
@inferred layout[3][:a] # but these fail!
@inferred layout[3][:b]
@inferred layout[3][:b][1]
I thought maybe adding more types to the Record
struct (layout[3]
) and associated functions would do it, but apparently no, or not yet.
No description provided.