JuliaML / MLUtils.jl

Utilities and abstractions for Machine Learning tasks
MIT License
109 stars 22 forks source link

broken inferred tests for `stack` and `batch` #52

Closed CarloLucibello closed 1 year ago

CarloLucibello commented 2 years ago
julia> using MLUtils, Test

julia> x = [[1,2,3], [4,5,6]]
2-element Vector{Vector{Int64}}:
 [1, 2, 3]
 [4, 5, 6]

julia> @inferred batch(x)
ERROR: return type Matrix{Int64} does not match inferred return type Any
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] top-level scope
   @ REPL[4]:1

julia> @inferred stack(x; dims=1)
ERROR: return type Matrix{Int64} does not match inferred return type Any
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] top-level scope
   @ REPL[5]:1

The problem could be due to a brodcasted call to unsqueeze, on which stack relies:


julia> @inferred unsqueeze(x[1]; dims=1)
1×3 Matrix{Int64}:
 1  2  3

julia> f() = unsqueeze.(x; dims=1)
f (generic function with 1 method)

julia> @inferred f()
ERROR: return type Vector{Matrix{Int64}} does not match inferred return type Any
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] top-level scope
   @ REPL[13]:1
``
CarloLucibello commented 1 year ago

Fixed in #125

ulia> using MLUtils, Test

julia> x = [[1,2,3], [4,5,6]]
2-element Vector{Vector{Int64}}:
 [1, 2, 3]
 [4, 5, 6]

julia> @inferred batch(x)
3×2 Matrix{Int64}:
 1  4
 2  5
 3  6

julia> @inferred stack(x; dims=1)
2×3 Matrix{Int64}:
 1  2  3
 4  5  6