Perhaps just

f = (U,V) ->  flipdim(conv(flipdim(U, 1), V), 1)
if su < sv
    return f([u; zeros(eltype(u), sv - su)], v)
elseif sv < su
    return f(u, [v; zeros(eltype(v), su - sv)])
else
    return f(u, v)
end

?

Worth pointing out that this is not specific to SubArrays; any AbstractArray 
that isn't an Array will have the same problem.

But appending elements to a SubArray is not supported.

Best,
--Tim

On Saturday, July 16, 2016 7:41:10 AM CDT CrocoDuck O'Ducks wrote:
> Hey!
> 
> I started having a deeper look at the code. I tried this first fix:
> 
> function xcorr_fix(u, v)
> 
> su = size(u, 1)
> sv = size(v, 1)
> 
> if su < sv
>     # if u is a SubArray this will changes its type:
>     # u = [u; zeros(eltype(u),sv-su)]
>     # This avoids type instability, but forces array copy:
>     U = [u; zeros(eltype(u), sv - su)]
> elseif sv < su
>     # See above:
>     V = [v; zeros(eltype(v), su - sv)]
> else
>     U = collect(u)
>     V = collect(v)
> end
> 
>     flipdim(conv(flipdim(U, 1), V), 1)
> 
> end
> 
> This appears to be somewhat effective, but there are few problems:
> 
>    - It defeats the purpose of passing views to the function, as a copy of
>    the parent arrays is performed. Is that right?
>    - Passing SubArrays to conv() seems to produce type instability of p and
>    y variables.
> 
> Which makes me think that first conv() should be fixed (maybe adding a
> method for the Real signals case?). Second, I feel like views should be
> allowed to go all the way to fft() in order to have a performance boost by
> using them. Is there any way to append elements through SubArrays? I tried
> append!(), insert!() and push!() but none worked... Maybe I could overwrite
> to the input SubArrays new SubArrays of this kind?
> 
> 
> sub([u.parent; zeros(whatever_pad_length)], :, 1)
> 
> 
> I guess I will make more experiments to get comfortable with SubArrays. Any
> suggestion is welcome!


Reply via email to