JuliaSIMD / JuliaSIMD/LoopVectorization.jl
Inconsistent results w/ and w/o @turbo
- Dominant language
- Julia
- Stars
- 789
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Consider the following code
```julia
using LoopVectorization, OffsetArrays
function morph_dilate(A::AbstractArray{T,N}, kernel::AbstractArray{S,N}) where {T<:Integer,S<:Integer,N}
out = similar(A, tuple((first(axes(A, n)) + first(axes(kernel, n)):
last(axes(A, n)) + last(axes(kernel, n)) for n ∈ 1:N)...)...)
out .= zero(T)
Ks = CartesianIndices(kernel)
@turbo for I in CartesianIndices(A)
for K in Ks
out[I+K] |= A[I] & kernel[K]
end
end
out
end
```
[The function essentially performs a convolution with a given `kernel` of an input array `A`, using the integer *and* (`&`) and the *or* (`|`) instead of the product and sum in the convolution expression. It also *extends* the original input array *A*.]
When I use this function on a test input I obtain an unexpected result:
```julia
julia> morph_dilate([1 2 3; 4 5 6], OffsetArrays.centered([0 7 0; 7 7 7; 0 7 0]))
4×5 OffsetArray(::Matrix{Int64}, 0:3, 0:4) with eltype Int64 with indices 0:3×0:4:
0 1 0 3 0
1 5 3 7 3
4 5 6 7 6
0 4 0 6 0
```
Note that this result is wrong: the correct result, which can be obtained removing the `@turbo` macro in the definition above, is
```julia
julia> morph_dilate([1 2 3; 4 5 6], OffsetArrays.centered([0 7 0; 7 7 7; 0 7 0]))
4×5 OffsetArray(::Matrix{Int64}, 0:3, 0:4) with eltype Int64 with indices 0:3×0:4:
0 1 2 3 0
1 7 7 7 3
4 5 7 7 6
0 4 5 6 0
```
Am I using `@turbo` in an wrong way, or is that a bug?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.