Skip to content

Commit c822f5a

Browse files
committed
Support zeroarray for heterogeneous axes
Previously `ZeroArrayPromise` required homogeneous axes, this supports promotion prior to construction. The test requires BlockArrays 0.16.17 (specifically JuliaArrays/BlockArrays.jl#213) but it's not a dependency of the package, so let's just trust in the lack of conflicts.
1 parent 9e64fec commit c822f5a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Project.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ImageCore"
22
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
3-
version = "0.9.3"
3+
version = "0.9.4"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -29,7 +29,7 @@ julia = "1"
2929

3030
[extras]
3131
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
32-
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"
32+
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3333
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3434
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
3535
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
@@ -40,4 +40,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
4040
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4141

4242
[targets]
43-
test = ["Aqua", "ColorVectorSpace", "Documenter", "FFTW", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "Statistics", "Test"]
43+
test = ["Aqua", "BlockArrays", "Documenter", "FFTW", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "Statistics", "Test"]

src/stackedviews.jl

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct ZeroArray{T,N,R<:AbstractUnitRange} <: AbstractArray{T,N}
103103
end
104104

105105
ZeroArrayPromise{T}(inds::NTuple{N,R}) where {T,N,R<:AbstractUnitRange} = ZeroArray{T,N,R}(inds)
106+
ZeroArrayPromise{T}(inds::NTuple{N,AbstractUnitRange}) where {T,N} = ZeroArray{T}(promote(inds...)...)
106107
Base.eltype(::Type{ZeroArrayPromise{T}}) where {T} = T
107108

108109
Base.axes(A::ZeroArray) = A.inds

test/colorchannels.jl

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Colors, ImageCore, OffsetArrays, FixedPointNumbers, Test
22
using OffsetArrays: IdentityUnitRange
3+
using BlockArrays
34

45
# backward-compatibility to ColorTypes < v0.9 or Colors < v0.11
56
using ImageCore: XRGB, RGBX
@@ -409,6 +410,20 @@ end
409410
a = OffsetArray(rand(3, 3, 5), 0:2, -1:1, -2:2)
410411
@test_throws (VERSION >= v"1.6.0-DEV.1083" ? ArgumentError : DimensionMismatch) colorview(RGB, a)
411412
end
413+
414+
@testset "Custom/divergent axis types" begin
415+
img1 = rand(5, 4, 2)
416+
img2_2 = mortar(reshape([rand(5, 4, 1), rand(5, 4, 1)], 1, 1, 2))
417+
img2_all = mortar(reshape([rand(5, 4, 1), rand(5, 4, 1), rand(5, 4, 1)], 1, 1, 3))
418+
img2_odd = img2_all[:,:,1:2:end]
419+
for img2 in (img2_2, img2_odd)
420+
for imgrgb in (colorview(RGB, img1, img2, zeroarray),
421+
colorview(RGB, img2, img1, zeroarray))
422+
@test eltype(imgrgb) === RGB{Float64}
423+
@test size(imgrgb) == size(img1)
424+
end
425+
end
426+
end
412427
end
413428

414429
end

0 commit comments

Comments
 (0)