-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Deprecate vectorized float methods in favor of compact broadcast syntax #18495
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,12 @@ convert(::Type{AbstractFloat}, x::UInt32) = convert(Float64, x) | |
convert(::Type{AbstractFloat}, x::UInt64) = convert(Float64, x) # LOSSY | ||
convert(::Type{AbstractFloat}, x::UInt128) = convert(Float64, x) # LOSSY | ||
|
||
""" | ||
float(x) | ||
|
||
Convert a number or string to a `AbstractFloat` data type. For numeric data, the | ||
smallest suitable `AbstractFloat` type is used. Converts strings to `Float64`. | ||
""" | ||
float(x) = convert(AbstractFloat, x) | ||
|
||
# for constructing arrays | ||
|
@@ -532,16 +538,17 @@ significand_mask(::Type{Float32}) = 0x007f_ffff | |
|
||
## Array operations on floating point numbers ## | ||
|
||
float{T<:AbstractFloat}(A::AbstractArray{T}) = A | ||
|
||
function float{T}(A::AbstractArray{T}) | ||
if !isleaftype(T) | ||
error("`float` not defined on abstractly-typed arrays; please convert to a more specific type") | ||
end | ||
convert(AbstractArray{typeof(float(zero(T)))}, A) | ||
# float, broadcast over arrays | ||
broadcast{T<:AbstractFloat}(::typeof(float), A::AbstractArray{T}) = A | ||
broadcast(::typeof(float), r::UnitRange) = float(r.start):float(last(r)) | ||
broadcast(::typeof(float), r::StepRange) = float(r.start):float(r.step):float(last(r)) | ||
broadcast(::typeof(float), r::FloatRange) = FloatRange(float(r.start), float(r.step), r.len, float(r.divisor)) | ||
function broadcast(::typeof(float), r::LinSpace) | ||
float(r.len) == r.len || throw(ArgumentError(string(r, ": too long for ", float))) | ||
LinSpace(float(r.start), float(r.stop), float(r.len), float(r.divisor)) | ||
end | ||
|
||
for fn in (:float,:big) | ||
for fn in (:big,) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we also deprecate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely. |
||
@eval begin | ||
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r)) | ||
$fn(r::UnitRange) = $fn(r.start):$fn(last(r)) | ||
|
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.
Probably we should also have
broadcast{T<:AbstractFloat}(::typeof(float), A::AbstractArray{Complex{T}}) = A
in complex.jlThere 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.
Added. Thanks!