Skip to content

Commit

Permalink
Change __getindex_dims to work better with inference (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Atol authored Aug 31, 2022
1 parent 145b0fa commit 03cc7d2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/FlexTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ function Base.view(t::FlexTable, inds::Union{AbstractArray, Colon}...)
return FlexTable{_getindex_dims(inds)}(map(col -> view(col, inds...), columns(t)))
end

@inline _getindex_dims(inds) = __getindex_dims(0, inds...)
@inline __getindex_dims(n::Int) = n
@inline __getindex_dims(n::Int, ::Int, inds...) = __getindex_dims(n, inds...)
@inline __getindex_dims(n::Int, ::AbstractArray{<:Any, m}, inds...) where {m} = __getindex_dims(n + m, inds...)
@inline __getindex_dims(n::Int, ::Colon, inds...) = __getindex_dims(n + 1, inds...)
@inline _getindex_dims(inds) = __getindex_dims(inds...)
@inline __getindex_dims() = 0
@inline __getindex_dims(::Int, inds...) = __getindex_dims(inds...)
@inline __getindex_dims(::AbstractArray{<:Any, m}, inds...) where {m} = __getindex_dims(inds...) + m
@inline __getindex_dims(::Colon, inds...) = __getindex_dims(inds...) + 1

# Deprecated for .= syntax (via Base.Broadcast.materialize!)
# It seems `Ref` might be the new cool here. Could also consider `AbstractArray{<:NamedTuple, 0}`?
Expand Down

0 comments on commit 03cc7d2

Please sign in to comment.