Skip to content

Commit 1eb0a79

Browse files
authored
noop for singleton dimension (#8)
1 parent 711aee2 commit 1eb0a79

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/restrict.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ function __restrict_eltype(::Type{C}) where C
160160
end
161161

162162
function restrict!(out::AbstractArray{T,N}, A::AbstractArray, dim) where {T,N}
163-
if dim > N
163+
# a no-op for singleton dimension
164+
if size(A, dim) == 1 # this includes `dim > N` cases
164165
return copyto!(out, A)
165166
end
166167
indsout, indsA = axes(out), axes(A)

test/restrict.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
14.09375 32.875 18.78125;
5252
11.0390625 25.59375 14.5546875], dims=3) B
5353
end
54+
55+
@testset "singleton dimension" begin
56+
# https://github.com/JuliaImages/ImageTransformations.jl/issues/47
57+
@test restrict([1]) == [1.0]
58+
@test restrict([0 1 0]) == [0.25 0.25]
59+
@test restrict([0, 1, 0], 5) == [0, 1, 0]
60+
end
5461

5562
@testset "OffsetArray" begin
5663
A = rand(5, 4, 3)

0 commit comments

Comments
 (0)