Closed gabrevaya closed 1 year ago
Adding a method which takes a Val
dims arg would work, but someone would have to do it.
Thanks! Would this be OK?
unstack(xs; dims::Val{D}) where D = [copy(selectdim(xs, D, i)) for i in 1:size(xs, D)]
If it infers for you and passes the existing tests (with Val instead of Int dims), then drop a PR :)
I don't understand why when I add the new method
unstack(xs; dims::Int) = [copy(selectdim(xs, dims, i)) for i in 1:size(xs, dims)]
unstack(xs; dims::Val{D}) where {D} = [copy(selectdim(xs, D, i)) for i in 1:size(xs, D)]
when I run the tests, the previous method with dims::Int is not found:
Test threw exception
Expression: stack(unstack(stacked_array, dims = 1), dims = 1) == stacked_array
MethodError: no method matching var"#unstack#102"(::Int64, ::typeof(unstack), ::Matrix{Int64})
Closest candidates are:
var"#unstack#102"(::Val{D}, ::typeof(unstack), ::Any) where D at ~/Documents/issues/MLUtils.jl/src/utils.jl:80
It's like the new method would be overwriting the other one. But that doesn't make sense because they should be considered as two different methods, with different signatures. For example, the following works well:
julia> f(x::Int) = "int"
julia> f(x::Val{d}) where d = "val"
julia> f(2)
"int"
julia> f(Val(2))
"val"
Do you know what is the problem in the case of unstack
?
I've just realized that it's due to the keyword argument. I guess I'll have to make that method with dims not being a keyword argument.
I'll make the PR now :)
Bellow you can find a MWE. Is there any workaround?