Open sethaxen opened 1 year ago
Yeah, it doesnt yet know the order or if the lookup is ordered at all.
You can (fully) specify the Categorical
lookup manually and it should be type stable.
Yes its fine if you specify Categorical
with the order
keyword:
using DimensionalData.LookupArrays
bar(x, y) = cat(x, y; dims=Dim{:foo}(Categorical([:c, :d]; order=ForwardOrdered())))
julia> @inferred bar(da, da)
3×2 DimArray{Float64,2} with dimensions:
Dim{:a},
Dim{:foo} Categorical{Symbol} Symbol[:c, :d] ForwardOrdered
:c :d
1.6825 1.6825
0.216932 0.216932
-0.66003 -0.66003
@rafaqz it seems on v0.25 even specifying the lookup does not cause cat
to be type-inferrable:
julia> using DimensionalData, Test
julia> using DimensionalData.LookupArrays
julia> bar(x, y) = cat(x, y; dims=Dim{:foo}(Categorical([:c, :d]; order=ForwardOrdered())))
bar (generic function with 1 method)
julia> da = DimArray(randn(3), Dim{:a})
3-element DimArray{Float64,1} with dimensions: Dim{:a}
1 -0.214735
2 0.395572
3 -0.388922
julia> @inferred bar(da, da)
ERROR: return type DimArray{Float64, 2, Tuple{Dim{:a, NoLookup{Base.OneTo{Int64}}}, Dim{:foo, Categorical{Symbol, Vector{Symbol}, ForwardOrdered, NoMetadata}}}, Tuple{}, Matrix{Float64}, DimensionalData.NoName, NoMetadata} does not match inferred return type Any
Making cat
type stable when allowing it to still work on runtime-validated incorrect dims is pretty hard.
Maybe we need to separate out method dispatch for this specific case so its not mixed into a method with multiple return types.
A PR would help, I've spent too much time working on cat
lately 😅
It seems that when using
cat
, Julia cannot infer the types of the resulting dimensions: