Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axes for conv of OffsetArrays seems off #504

Open
jishnub opened this issue Jul 21, 2023 · 1 comment
Open

axes for conv of OffsetArrays seems off #504

jishnub opened this issue Jul 21, 2023 · 1 comment

Comments

@jishnub
Copy link
Contributor

jishnub commented Jul 21, 2023

julia> a = 1:2
1:2

julia> conv(a, a)
3-element Vector{Int64}:
 1
 4
 4

julia> conv(OffsetArray(a), OffsetArray(a))
3-element OffsetArray(::Vector{Int64}, 2:4) with eltype Int64 with indices 2:4:
 1
 4
 4

julia> a == OffsetArray(a)
true

julia> conv(a, a) == conv(OffsetArray(a), OffsetArray(a))
false

I'm unsure what's the axis logic here, but it'll be good for this to be consistent.

@martinholters
Copy link
Member

Yeah, the issue is that convolution is naturally defined with zero-based indexing, i.e.

y[n] = sum(a[n-i] * b[i] for i in ...)

And that's what you get for OffsetArray. But as plain Arrays are one-based, this would always give a leading zero in the result, which would be highly undesirable. So whatever one does, it will always be inconsistent in some way.

Maybe we'd need a keyword argument zero_based or the like to opt into the behavior currently adopted automatically for OffsetArrays? Introducing it would be breaking if not done carefully, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants