Attached is my 1st attempt at julia, it is a simple FIR filter, which I 
translated from my c++ version.

It is benchmarking about 10x slower than python wrapped c++ version.

Any suggestions?
module firmod

type FIR{in_t,coef_t}
    in::Vector{in_t}
    coef::Vector{coef_t}
    function FIR (coef::Vector{coef_t})
        new (zeros (in_t, size (coef)), copy (coef))
    end
end

  ## template<typename i_t>
  ## void shift (i_t i) {
  ##   std::copy_backward (in.begin(), in.end()-boost::size(i), in.end());
  ##   std::reverse_copy (i.begin(), i.end(), in.begin());
  ## }
function shift!{in_t,coef_t} (f::FIR{in_t,coef_t}, u::Vector{in_t})
    si = length(f.in)
    su = length(u)
    for i =si-su:-1:1
        f.in[i+su] = f.in[i]
    end
    f.in[1:su] = u[end:-1:1]
end

function compute1{in_t, coef_t} (f::FIR{in_t,coef_t})
    s = zero (promote_type (in_t, coef_t))
    size = length(f.coef)
    for i = 1:size
        s += f.in[i] * f.coef[i]
    end
    return s
end

function shift_compute1{in_t,coef_t} (f::FIR{in_t,coef_t}, u::Vector{in_t})
    shift! (f, u)
    return compute1 (f)
end

function compute{in_t,coef_t} (f::FIR{in_t,coef_t}, u::Vector{in_t})
    out = similar (u, promote_type (in_t,coef_t))
    size = length (u)
    for i = 1:size
        out[i] = shift_compute1 (f, u[i:i])
    end
    return out
end

c = float ([1:4])
g = FIR{Float64,Float64} (c)
h = FIR{Complex{Float64},Float64} (c)
j = float ([1:10])
k = compute (g, j)

function timeit()
    n = 10
    l = 1000000
    u = zeros(Float64, l)

    for i=1:n
        v = compute (g, u)
    end
end

end

Reply via email to