On Thursday, January 8, 2015 at 3:29:01 PM UTC-5, Joshua Adelman wrote:
>
> You're reading it correctly. I'm not sure exactly why numpy is performing 
> better for the larger matrices, but I suspect that numpy's accumulate 
> function that np.vander uses may be taking advantage of simd, sse or mkl 
> optimizations. I'd have to do a bit of digging though to confirm that. I 
> also haven't experimented with Julia's @inbounds or @simd operators, but 
> that might help. I also believe that some of the subarray stuff might be 
> better optimized in Julia 0.4 vs 0.3.4.
>

Josh, I think you can do better in Julia just by avoiding subarrays, 
powers, and cumprod entirely.  Here is a version that seems significantly 
faster than any of the ones in your notebook for large arrays:

function myvand{T}(p::Vector{T}, n::Int)
    # n: number of rows
    # p: a vector
    m = length(p)
    V = Array(T, m, n)
    for j = 1:m
        @inbounds V[j, 1] = 1
    end
    for i = 2:n
        for j = 1:m
            @inbounds V[j,i] = p[j] * V[j,i-1]
        end
    end
    return V
end


And I think you can do better still by more unrolling and rearrangement, 
even without using SIMD.

Reply via email to