One typo in my code:

> FIR{S, T}(in::Vector{S}, coef::Vector{T}) = FIR{S, T}(zeros(S, size(in)), 
> coef)

should be

> FIR{S, T}(in::Vector{S}, coef::Vector{T}) = FIR{S, T}(in, coef)

 — John

On Jul 30, 2014, at 8:11 AM, John Myles White <[email protected]> wrote:

> Hi Neal,
> 
> I think rewriting your code to follow a little bit more conventional Julia 
> style will help you to see where you’ve gone wrong:
> 
> type FIR{S, T}
>   in::Vector{S}
>   coef::Vector{T}
>   function FIR(in::Vector{S}, coef::Vector{T})
>        new(zeros(S, size(in)), coef)
>   end
> end
> 
> FIR{S, T}(in::Vector{S}, coef::Vector{T}) = FIR{S, T}(zeros(S, size(in)), 
> coef)
> 
> w = zeros(Float64, 10)
> f = FIR(w,w)
> 
> Note that you must include the outer constructor definition or you will not 
> have access to the custom inner constructor that you’ve defined. This is one 
> of the unusual properties of how parametric types work.
> 
> Also worth noting that, because of ambiguities, Julia may one day need to 
> prohibit function invocation with spaces between function names and 
> parentheses. So it’s better to write FIR(a, b) than to write FIR (a, b).
> 
> — John
> 
> On Jul 30, 2014, at 8:00 AM, Neal Becker <[email protected]> wrote:
> 
>> As a learning exercise, I am trying to code a simple FIR filter.
>> As a start, it has 2 fields and a constructor:
>> 
>> type FIR{in_t, coef_t}
>>   in::Vector{in_t}
>>   coef::Vector{coef_t}
>>   FIR (in_::Vector{in_t}, coef_::Vector{coef_t}) = (x=new(); x.in = 
>> zeros(in_t, size (in_)); x.coef = coef_;)
>> end
>> 
>> w = zeros (Float64, 10)
>> f = FIR{Float64,Float64}(w,w)
>> 
>> This code executes, but seems very confused:
>> julia> typeof(f)
>> Array{Float64,1}
>> 
>> Huh?  I expected "f" to be of type FIR{Float64,Float64}.  Clearly I'm doing 
>> something very wrong.
>> 
> 

Reply via email to