-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add support for converting between Stochastic FP numbers, and convenience methods for array conversions #56
Conversation
…venience functions for array conversions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I didn't see this PR before. Thanks for the contribution 😄 Yes, I appreciate the conversions between stochastic rounding formats!
src/conversions.jl
Outdated
Float16sr(x::Float32sr) = Float16sr(Float64(x)) | ||
|
||
# Conversion of arrays as long as they are some kind of floating point number | ||
function Float16sr(list::T where T<:AbstractArray{<:Union{BFloat16,AbstractFloat}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BFloat16
is already <:AbstractFloat
?
julia> BFloat16<:AbstractFloat
true
@@ -1,3 +1,4 @@ | |||
import BFloat16s.BFloat16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of adding this to individual files, we can add import BFloat16s: BFloat16
to src/StochasticRounding.jl
?
@@ -53,6 +54,10 @@ Base.Float64(x::Float32sr) = Float64(Float32(x)) | |||
Float32sr(x::Integer) = Float32sr(Float32(x)) | |||
(::Type{T})(x::Float32sr) where {T<:Integer} = T(Float32(x)) | |||
|
|||
# converting to and from BFloat16 | |||
Float32sr(x::BFloat16) = Float32sr(Float64(x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go via Float32
and not Float64
? That will just padd trailing zeros and reinterpret
src/conversions.jl
Outdated
|
||
# Conversions from other stochastic floating points to Float16sr | ||
Float16sr(x::BFloat16sr) = Float16sr(Float32(x)) | ||
Float16sr(x::Float32sr) = Float16sr(Float64(x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go via Float32
not Float64
I would like to convert between Stochastic Floating Points just as we can for Deterministic types, and have convenience functions to convert entire arrays at a time
Add the above functionality without breaking any existing features, and test the implementation
Added extra functions that convert between the stochastic types with deterministic types as a middle step
Generated large amounts of random floating point numbers, ensured that these numbers were exactly representable in BFloat16, Float16, Float32, and Float64 via "daisy chaining" these conversions, and then testing that conversions were done properly