Skip to content

Commit 0e1b57f

Browse files
authored
fix inferrence failure (#48)
1 parent 9fbda81 commit 0e1b57f

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ FixedPointNumbers = "0.6.1, 0.7, 0.8"
77
julia = "1"
88

99
[extras]
10-
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
10+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
1111
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
1212
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414

1515
[targets]
16-
test = ["OffsetArrays", "ColorTypes", "Test", "FixedPointNumbers"]
16+
test = ["OffsetArrays", "Colors", "Test", "FixedPointNumbers"]

src/MappedArrays.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ not set them).
5858
When multiple input arrays are supplied, `M[i] = f(A[i], B[i], C[i]...)`.
5959
"""
6060
function mappedarray(f, data::AbstractArray)
61-
T = Base._return_type(f, eltypes(data))
61+
infer_eltype() = Base._return_type(f, eltypes(data))
62+
T = infer_eltype()
6263
ReadonlyMappedArray{T,ndims(data),typeof(data),typeof(f)}(f, data)
6364
end
6465

@@ -67,7 +68,8 @@ function mappedarray(::Type{T}, data::AbstractArray) where T
6768
end
6869

6970
function mappedarray(f, data::AbstractArray...)
70-
T = Base._return_type(f, eltypes(data))
71+
infer_eltype() = Base._return_type(f, eltypes(data))
72+
T = infer_eltype()
7173
ReadonlyMultiMappedArray{T,ndims(first(data)),typeof(data),typeof(f)}(f, data)
7274
end
7375

@@ -86,20 +88,23 @@ the view and, correspondingly, the values in `A`.
8688
When multiple input arrays are supplied, `M[i] = f(A[i], B[i], C[i]...)`.
8789
"""
8890
function mappedarray(f, finv, data::AbstractArray)
89-
T = Base._return_type(f, eltypes(data))
91+
infer_eltype() = Base._return_type(f, eltypes(data))
92+
T = infer_eltype()
9093
MappedArray{T,ndims(data),typeof(data),typeof(f),typeof(finv)}(f, finv, data)
9194
end
9295

9396
function mappedarray(f, finv, data::AbstractArray...)
94-
T = Base._return_type(f, eltypes(data))
97+
infer_eltype() = Base._return_type(f, eltypes(data))
98+
T = infer_eltype()
9599
MultiMappedArray{T,ndims(first(data)),typeof(data),typeof(f),typeof(finv)}(f, finv, data)
96100
end
97101

98102
function mappedarray(::Type{T}, finv, data::AbstractArray...) where T
99103
MultiMappedArray{T,ndims(first(data)),typeof(data),Type{T},typeof(finv)}(T, finv, data)
100104
end
101105
function mappedarray(f, ::Type{Finv}, data::AbstractArray...) where Finv
102-
T = Base._return_type(f, eltypes(data))
106+
infer_eltype() = Base._return_type(f, eltypes(data))
107+
T = infer_eltype()
103108
MultiMappedArray{T,ndims(first(data)),typeof(data),typeof(f),Type{Finv}}(f, Finv, data)
104109
end
105110

@@ -113,7 +118,7 @@ end
113118
114119
creates a view of `A` that lazily-converts the element type to `T`.
115120
"""
116-
of_eltype(::Type{T}, data::AbstractArray{S}) where {S,T} = mappedarray(x->convert(T,x), y->convert(S,y), data)
121+
of_eltype(::Type{T}, data::AbstractArray{S}) where {S,T} = mappedarray(x->convert(T,x)::T, y->convert(S,y)::S, data)
117122
of_eltype(::Type{T}, data::AbstractArray{T}) where {T} = data
118123
of_eltype(::T, data::AbstractArray{S}) where {S,T} = of_eltype(T, data)
119124

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Test
33

44
@test isempty(detect_ambiguities(MappedArrays, Base, Core))
55

6-
using FixedPointNumbers, OffsetArrays, ColorTypes
6+
using FixedPointNumbers, OffsetArrays, Colors
77

88
@testset "ReadonlyMappedArray" begin
99
a = [1,4,9,16]
@@ -213,4 +213,9 @@ end
213213
@test eltype(mappedarray(_maybe_int, Float64, [1, -1])) == Int64
214214
@test eltype(mappedarray(Float64, _maybe_int, [1.0, 1, -1, -1.0])) == Float64
215215
@test eltype(mappedarray(Float64, _maybe_int, [1, -1])) == Float64
216+
217+
X = rand(Lab{Float32}, 4, 4)
218+
@test eltype(of_eltype(RGB{Float32}, X)) == RGB{Float32}
219+
X = Any[1, 2, 3]
220+
@test eltype(of_eltype(Int, X)) == Int
216221
end

0 commit comments

Comments
 (0)