Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent floattype result to float #127

Open
johnnychen94 opened this issue Aug 9, 2019 · 3 comments
Open

Inconsistent floattype result to float #127

johnnychen94 opened this issue Aug 9, 2019 · 3 comments
Milestone

Comments

@johnnychen94
Copy link
Collaborator

johnnychen94 commented Aug 9, 2019

FixedPointNumbers.floattype seems inconsistent to Base.float

julia> float(Int8)
Float64

julia> floattype(Int8)
Float32

Should we update accordingly?

@timholy
Copy link
Member

timholy commented Aug 12, 2019

Good observation and question. Wth this package it's designed to convert to the smallest type that can store it exactly. For Int8 technically that's Float16, but Float16 has bad compute performance so we use either Float32 or Float64.

Base consistency is important, but so too is the goal of ensuring that images don't blow up to something much bigger than necessary. The right choice seems either (1) to change this package or (2) submit a PR to Base, tagged for Julia 2.0, that changes float(Int8) to Float32. I'm unsure about which of these to pick.

@timholy timholy added this to the 1.0 milestone Nov 22, 2019
@timholy timholy mentioned this issue Nov 22, 2019
@johnnychen94
Copy link
Collaborator Author

I imagine we could break floattype down to float and accumulatortype

float(Int) = Float64
floattype(Int) = float(Int)
floattype(:+, Int) = accumulatortype(:+, Int)

But I'm not sure how broadly floattype(:+, Int) can be used externally.

@johnnychen94
Copy link
Collaborator Author

johnnychen94 commented Jun 28, 2022

The fact that floattype(Int) == BigFloat seems troublesome when adopting LoopVectorization in JuliaImages.
Sometimes, the output array is pre-allocated via similar(img, floattype(eltype(img)). With floattype(Int) == BigFloat, this is either extremely inefficient or just segfaults (because LoopVectorization doesn't understand it well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants