Relevant source code from DataArrays.jl/src/datavector.jl

# TODO: should this be an AbstractDataVector, so it works with PDV's?
function Base.map(f::Function, dv::DataVector)
    n = length(dv)
    res = DataArray(Any, n) #<-- this Any is the cause.
    for i in 1:n
        res[i] = f(dv[i])
    end
    return res
end


the map function allocates the result as a DataArray(Any, n). If you know 
the output type of f is T, then you can use 

function map!(f::Function, res::DataArray, dv::DataVector)
    n = length(dv)
    for i in 1:n
        res[i] = f(dv[i])
    end
    return res
end

n = length(dv)
res = DataArray(T, n)
map!(f, res, dv)


Reply via email to