Mapslices() warntype?

mapslices just doesn’t behave very well, IMO, and you are much better off building the same thing from other pieces. These are fine:

@code_warntype map(prod, eachcol(mat))
@code_warntype map(prod, eachslice(mat, dims=2)) # same, with keyword

although of course you can write prod(mat, dims=1), but I guess it’s an example. If your function returns arrays, you want something like this:

f(x) = vcat(x, x .^ 2)
mapslices(f, mat, dims=1) == reduce(hcat, map(f, eachcol(mat))) # true
@code_warntype mapslices(f, mat, dims=1)          # Any
@code_warntype reduce(hcat, map(f, eachcol(mat))) # Array{Float64,2}
2 Likes