Skip to content

Commit

Permalink
noop for singleton dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Jun 2, 2021
1 parent 711aee2 commit 988a052
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/restrict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ function __restrict_eltype(::Type{C}) where C
end

function restrict!(out::AbstractArray{T,N}, A::AbstractArray, dim) where {T,N}
if dim > N
# a no-op for singleton dimension
if size(A, dim) == 1 # this includes `dim > N` cases
return copyto!(out, A)
end
indsout, indsA = axes(out), axes(A)
Expand Down
7 changes: 7 additions & 0 deletions test/restrict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
14.09375 32.875 18.78125;
11.0390625 25.59375 14.5546875], dims=3) B
end

@testset "singleton dimension" begin
# https://github.com/JuliaImages/ImageTransformations.jl/issues/47
@test restrict([1]) == [1.0]
@test restrict([0 1 0]) == [0.25 0.25]
@test restrict([0, 1, 0], 5) == [0, 1, 0]
end

@testset "OffsetArray" begin
A = rand(5, 4, 3)
Expand Down

0 comments on commit 988a052

Please sign in to comment.