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

pad_reflect broken #594

Closed
nikopj opened this issue Jun 24, 2024 · 3 comments · Fixed by #595
Closed

pad_reflect broken #594

nikopj opened this issue Jun 24, 2024 · 3 comments · Fixed by #595

Comments

@nikopj
Copy link
Contributor

nikopj commented Jun 24, 2024

seems the new release (v0.9.18) breaks padding.
before: v0.9.17

julia> using NNlib

julia> x = rand(1:9, 3,3,1,1)
3×3×1×1 Array{Int64, 4}:
[:, :, 1, 1] =
 7  3  2
 1  5  5
 7  7  6

julia> NNlib.pad_reflect(x, (1,0,1,0); dims=1:2)
4×4×1×1 Array{Int64, 4}:
[:, :, 1, 1] =
 5  1  5  5
 3  7  3  2
 5  1  5  5
 7  7  7  6

(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [872c559c] NNlib v0.9.17

after update: v0.9.18

(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [872c559c] NNlib v0.9.18

julia> NNlib.pad_reflect(x, (1,0,1,0); dims=1:2)
ERROR: DimensionMismatch: mismatch in dimension 2 (expected 3 got 1)
Stacktrace:
  [1] _cs
    @ ./abstractarray.jl:1785 [inlined]
  [2] _cshp
    @ ./abstractarray.jl:1771 [inlined]
  [3] _cshp
    @ ./abstractarray.jl:1782 [inlined]
  [4] _cat_size_shape
    @ ./abstractarray.jl:1761 [inlined]
  [5] _cat_size_shape(dims::Tuple{Bool}, shape::NTuple{4, Int64}, X::Array{Int64, 4}, tail::Vector{Int64})
    @ Base ./abstractarray.jl:1761
  [6] cat_size_shape(::Tuple{Bool}, ::Array{Int64, 4}, ::Array{Int64, 4}, ::Vararg{Any})
    @ Base ./abstractarray.jl:1759
  [7] _cat_t(::Int64, ::Type{Int64}, ::Array{Int64, 4}, ::Vararg{Any})
    @ Base ./abstractarray.jl:1800
  [8] _cat(::Int64, ::Array{Int64, 4}, ::Array{Int64, 4}, ::Vararg{AbstractArray{Int64}})
    @ Base ./abstractarray.jl:1995
  [9] cat
    @ ./abstractarray.jl:1993 [inlined]
 [10] pad_reflect(x::Array{Int64, 4}, pad::Tuple{Int64, Int64}; dims::Int64)
    @ NNlib ~/.julia/packages/NNlib/jLaeV/src/padding.jl:275
 [11] pad_reflect(x::Array{Int64, 4}, pad::NTuple{4, Int64}; dims::UnitRange{Int64})
    @ NNlib ~/.julia/packages/NNlib/jLaeV/src/padding.jl:263
 [12] top-level scope
    @ REPL[7]:1

It still works with even padding sizes (i.e. same padding on left and right).

julia> NNlib.pad_reflect(x, (1,1,1,1); dims=1:2)
5×5 Matrix{Int64}:
 5  1  5  5  5
 3  7  3  2  3
 5  1  5  5  5
 7  7  7  6  7
 5  1  5  5  5

perhaps you know the fix @pxl-th ?

The tests should probably be updated to catch this. Right now they only test same padding on left and right.

@pxl-th
Copy link
Member

pxl-th commented Jun 24, 2024

Ah, the problem is when one of the padding values is 0.
I'll push the fix later today, thanks for posting this!

@nikopj
Copy link
Contributor Author

nikopj commented Jul 10, 2024

@pxl-th any chance to fix this soon?

@pxl-th pxl-th mentioned this issue Jul 10, 2024
2 tasks
@pxl-th
Copy link
Member

pxl-th commented Jul 10, 2024

Sorry for the delay, should be fixed by #595

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

Successfully merging a pull request may close this issue.

2 participants