JuliaImages / ImageDistances.jl

Distances between N-dimensional images
https://github.com/JuliaImages/Images.jl
Other
15 stars 8 forks source link

reducing memory allocation #22

Closed johnnychen94 closed 5 years ago

johnnychen94 commented 5 years ago

To achieve numerical accuracy, I explicitly promote FixedPoint types to floats, but this causes some significant memory allocations

intermediatetype(::Type{T}) where T<:Number = T
intermediatetype(::Type{T}) where T<:FixedPoint = FixedPointNumbers.floattype(T)
intermediatetype(::Type{T}) where T<:Bool = Float64

evaluate(dist::UnionMetrics, a::Gray2dImage{T1}, b::Gray2dImage{T2}) where  {T1<:FixedPoint, T2<:FixedPoint} =
    evaluate(dist, intermediatetype(T1).(a), intermediatetype(T2).(b))

Is there any way to make optimizations, or is this memory allocation inevitable?

timholy commented 5 years ago
using MappedArrays
aT = of_eltype(intermediatetype(eltype(a)), a)