Skip to content

Commit

Permalink
finish removing/renaming lowercase conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 9, 2015
1 parent 52709a1 commit 700abd2
Show file tree
Hide file tree
Showing 83 changed files with 666 additions and 651 deletions.
14 changes: 9 additions & 5 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ macro enum(T,syms...)
throw(ArgumentError("invalid type expression for enum $T"))
end
vals = Array((Symbol,Integer),0)
lo = typemax(Int)
hi = typemin(Int)
lo = hi = 0
i = -1
enumT = typeof(i)
hasexpr = false
Expand Down Expand Up @@ -65,9 +64,14 @@ macro enum(T,syms...)
end
push!(vals, (s,i))
I = typeof(i)
enumT = length(vals) == 1 ? I : promote_type(enumT,I)
lo = min(lo, i)
hi = max(hi, i)
if length(vals) == 1
enumT = I
lo = hi = i
else
enumT = promote_type(enumT,I)
lo = min(lo, i)
hi = max(hi, i)
end
end
if !hasexpr
n = length(vals)
Expand Down
14 changes: 7 additions & 7 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,9 @@ end

full(x::AbstractArray) = x

map{T}(::Type{T}, a::AbstractArray{T}) = a
map{T}(::Type{T}, a::AbstractArray) = convert(AbstractArray{T}, a)
map(::Type{Integer}, a::AbstractArray) = convert(AbstractArray{typeof(Integer(one(eltype(a))))}, a)
map(::Type{Signed}, a::AbstractArray) = convert(AbstractArray{typeof(Signed(one(eltype(a))))}, a)
map(::Type{Unsigned}, a::AbstractArray) = convert(AbstractArray{typeof(Unsigned(one(eltype(a))))}, a)
map(::Type{Integer}, a::Array) = map!(Integer, similar(a,typeof(Integer(one(eltype(a))))), a)
map(::Type{Signed}, a::Array) = map!(Signed, similar(a,typeof(Signed(one(eltype(a))))), a)
map(::Type{Unsigned}, a::Array) = map!(Unsigned, similar(a,typeof(Unsigned(one(eltype(a))))), a)

## range conversions ##

Expand Down Expand Up @@ -468,7 +466,7 @@ end
flipud(A::AbstractArray) = flipdim(A, 1)
fliplr(A::AbstractArray) = flipdim(A, 2)

circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [integer(shiftamt)])
circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [Integer(shiftamt)])
function circshift{T,N}(a::AbstractArray{T,N}, shiftamts)
I = ()
for i=1:N
Expand Down Expand Up @@ -1316,7 +1314,9 @@ function map_to!{T}(f, offs, dest::AbstractArray{T}, A::AbstractArray)
end

function map(f, A::AbstractArray)
if isempty(A); return similar(A); end
if isempty(A)
return isa(f,Type) ? similar(A,f) : similar(A)
end
first = f(A[1])
dest = similar(A, typeof(first))
dest[1] = first
Expand Down
2 changes: 1 addition & 1 deletion base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function length_checked_equal(args...)
n
end

map(f, a::Array{Any,1}) = Any[ f(a[i]) for i=1:length(a) ]
map(f::Function, a::Array{Any,1}) = Any[ f(a[i]) for i=1:length(a) ]

This comment has been minimized.

Copy link
@stevengj

stevengj Apr 28, 2015

Member

Should we allow a type here as well, so that you can map constructors efficiently?

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson Apr 28, 2015

Author Member

This definition is kind of a bug. It's only here because some code in inference expects map to behave this way. That code should be changed to request Any arrays, and then this definition can be removed.


macro thunk(ex); :(()->$(esc(ex))); end
macro L_str(s); s; end
Expand Down
4 changes: 2 additions & 2 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function gamma(n::Union(Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64))
n < 0 && throw(DomainError())
n == 0 && return Inf
n <= 2 && return 1.0
n > 20 && return gamma(float64(n))
@inbounds return float64(_fact_table64[n-1])
n > 20 && return gamma(Float64(n))
@inbounds return Float64(_fact_table64[n-1])
end

function factorial(n::Integer)
Expand Down
16 changes: 8 additions & 8 deletions base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ promote_rule{s}(::Type{MathConst{s}}, ::Type{Float32}) = Float32
promote_rule{s,t}(::Type{MathConst{s}}, ::Type{MathConst{t}}) = Float64
promote_rule{s,T<:Number}(::Type{MathConst{s}}, ::Type{T}) = promote_type(Float64,T)

convert(::Type{FloatingPoint}, x::MathConst) = float64(x)
convert(::Type{Float16}, x::MathConst) = float16(float32(x))
convert(::Type{FloatingPoint}, x::MathConst) = Float64(x)
convert(::Type{Float16}, x::MathConst) = Float16(Float32(x))
convert{T<:Real}(::Type{Complex{T}}, x::MathConst) = convert(Complex{T}, convert(T,x))
convert{T<:Integer}(::Type{Rational{T}}, x::MathConst) = convert(Rational{T}, float64(x))
convert{T<:Integer}(::Type{Rational{T}}, x::MathConst) = convert(Rational{T}, Float64(x))

stagedfunction call{T<:Union(Float32,Float64),s}(t::Type{T},c::MathConst{s},r::RoundingMode)
f = T(big(c()),r())
Expand Down Expand Up @@ -64,9 +64,9 @@ end

hash(x::MathConst, h::UInt) = 3*object_id(x) - h

-(x::MathConst) = -float64(x)
-(x::MathConst) = -Float64(x)
for op in Symbol[:+, :-, :*, :/, :^]
@eval $op(x::MathConst, y::MathConst) = $op(float64(x),float64(y))
@eval $op(x::MathConst, y::MathConst) = $op(Float64(x),Float64(y))
end

macro math_const(sym, val, def)
Expand All @@ -87,10 +87,10 @@ macro math_const(sym, val, def)
const $esym = MathConst{$qsym}()
$bigconvert
Base.convert(::Type{Float64}, ::MathConst{$qsym}) = $val
Base.convert(::Type{Float32}, ::MathConst{$qsym}) = $(float32(val))
Base.convert(::Type{Float32}, ::MathConst{$qsym}) = $(Float32(val))
@assert isa(big($esym), BigFloat)
@assert float64($esym) == float64(big($esym))
@assert float32($esym) == float32(big($esym))
@assert Float64($esym) == Float64(big($esym))
@assert Float32($esym) == Float32(big($esym))
end
end

Expand Down
4 changes: 2 additions & 2 deletions base/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Base.convert{R<:Real}(::Type{R},x::Date) = convert(R,value(x))
### External Conversions
const UNIXEPOCH = value(DateTime(1970)) #Rata Die milliseconds for 1970-01-01T00:00:00
function unix2datetime(x)
rata = UNIXEPOCH + Int64(1000*x)
rata = UNIXEPOCH + round(Int64,1000*x)
return DateTime(UTM(rata))
end
# Returns unix seconds since 1970-01-01T00:00:00
Expand All @@ -30,7 +30,7 @@ datetime2rata(dt::DateTime) = days(dt)
# Julian conversions
const JULIANEPOCH = value(DateTime(-4713,11,24,12))
function julian2datetime(f)
rata = JULIANEPOCH + Int64(86400000*f)
rata = JULIANEPOCH + round(Int64,86400000*f)
return DateTime(UTM(rata))
end
# Returns # of julian days since -4713-11-24T12:00:00
Expand Down
55 changes: 30 additions & 25 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,40 +295,45 @@ const base64 = base64encode
@deprecate filter!(r::Regex, d::Dict) filter!((k,v)->ismatch(r,k), d)

# 1470
@deprecate integer (s::AbstractString) parseint(Int,s)
@deprecate integer(s::AbstractString) parseint(Int,s)
@deprecate unsigned(s::AbstractString) parseint(UInt,s)
@deprecate int (s::AbstractString) parseint(Int,s)
@deprecate uint (s::AbstractString) parseint(UInt,s)
@deprecate int8 (s::AbstractString) parseint(Int8,s)
@deprecate uint8 (s::AbstractString) parseint(UInt8,s)
@deprecate int16 (s::AbstractString) parseint(Int16,s)
@deprecate uint16 (s::AbstractString) parseint(UInt16,s)
@deprecate int32 (s::AbstractString) parseint(Int32,s)
@deprecate uint32 (s::AbstractString) parseint(UInt32,s)
@deprecate int64 (s::AbstractString) parseint(Int64,s)
@deprecate uint64 (s::AbstractString) parseint(UInt64,s)
@deprecate int128 (s::AbstractString) parseint(Int128,s)
@deprecate uint128 (s::AbstractString) parseint(UInt128,s)
@deprecate float64(s::AbstractString) parsefloat(Float64, s)
@deprecate float32(s::AbstractString) parsefloat(Float32, s)

for (f,t) in ((:char, Char), (:bool, Bool), (:integer, Integer), (:signed, Signed),
@deprecate int(s::AbstractString) parseint(Int,s)
@deprecate uint(s::AbstractString) parseint(UInt,s)
@deprecate int8(s::AbstractString) parseint(Int8,s)
@deprecate uint8(s::AbstractString) parseint(UInt8,s)
@deprecate int16(s::AbstractString) parseint(Int16,s)
@deprecate uint16(s::AbstractString) parseint(UInt16,s)
@deprecate int32(s::AbstractString) parseint(Int32,s)
@deprecate uint32(s::AbstractString) parseint(UInt32,s)
@deprecate int64(s::AbstractString) parseint(Int64,s)
@deprecate uint64(s::AbstractString) parseint(UInt64,s)
@deprecate int128(s::AbstractString) parseint(Int128,s)
@deprecate uint128(s::AbstractString) parseint(UInt128,s)
@deprecate float64(s::AbstractString) parsefloat(Float64,s)
@deprecate float32(s::AbstractString) parsefloat(Float32,s)

for (f,t) in ((:integer, Integer), (:signed, Signed),
(:unsigned, Unsigned), (:int, Int), (:int8, Int8), (:int16, Int16),
(:int32, Int32), (:int64, Int64), (:int128, Int128), (:uint, UInt),
(:uint8, UInt8), (:uint16, UInt16), (:uint32, UInt32), (:uint64, UInt64),
(:uint128, UInt128), (:float16, Float16), (:float32, Float32),
(:uint128, UInt128))
@eval begin
@deprecate $f(x::AbstractArray) round($t, x)
end
end

for (f,t) in ((:char, Char), (:bool, Bool), (:float16, Float16), (:float32, Float32),
(:float64, Float64), (:complex64, Complex64), (:complex128, Complex128))
@eval begin
@deprecate $f(x::AbstractArray) map($t, x)
end
end

const convert_funcs_and_types =
((:integer, Integer), (:signed, Signed), (:unsigned, Unsigned), (:int, Int),
(:int8, Int8), (:int16, Int16), (:int32, Int32), (:int64, Int64),
(:int128, Int128), (:uint, UInt), (:uint8, UInt8), (:uint16, UInt16),
(:uint32, UInt32), (:uint64, UInt64), (:uint128,UInt128), (:float16, Float16),
(:float32, Float32), (:float64, Float64))
((:integer, Integer), (:signed, Signed), (:unsigned, Unsigned), (:int, Int), (:int8, Int8),
(:int16, Int16), (:int32, Int32), (:int64, Int64), (:int128, Int128), (:uint, UInt),
(:uint8, UInt8), (:uint16, UInt16), (:uint32, UInt32), (:uint64, UInt64), (:uint128,UInt128),
(:float16, Float16), (:float32, Float32), (:float64, Float64))

for (f,t) in convert_funcs_and_types
@eval begin
Expand All @@ -337,9 +342,9 @@ for (f,t) in convert_funcs_and_types
end
end

for (fn,t) in ((:float16,:Float16),(:float32,:Float32),(:float64,:Float64))
for (f,t) in ((:float16,:Float16),(:float32,:Float32),(:float64,:Float64))
@eval begin
@deprecate $fn(r::FloatRange) map($t, r)
@deprecate $f(r::FloatRange) map($t, r)
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ end

fftwcopy{T<:fftwNumber}(X::StridedArray{T}) = copy(X)
fftwcopy{T<:Real}(X::StridedArray{T}) = float(X)
fftwcopy{T<:Complex}(X::StridedArray{T}) = complex128(X)
fftwcopy{T<:Complex}(X::StridedArray{T}) = map(Complex128,X)

for (f, fr2r, Y, Tx) in ((:dct, :r2r, :Y, :Number),
(:dct!, :r2r!, :X, :fftwNumber))
Expand Down
4 changes: 2 additions & 2 deletions base/fftw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ end
# (FIXME: is there a way to use the Julia promotion rules more cleverly here?)
complexfloat{T<:fftwComplex}(X::StridedArray{T}) = X
complexfloat{T<:fftwReal}(X::StridedArray{T}) = complex(X)
complexfloat{T<:Real}(X::StridedArray{T}) = complex128(X)
complexfloat{T<:Complex}(X::StridedArray{T}) = complex128(X)
complexfloat{T<:Real}(X::StridedArray{T}) = map(Complex128,X)
complexfloat{T<:Complex}(X::StridedArray{T}) = map(Complex128,X)

# In the Julia interface, a "plan" is just a function that executes
# an efficient FFT of fixed size/strides/alignment. For each FFT function
Expand Down
12 changes: 6 additions & 6 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ for Ti in (Int64,UInt64,Int128,UInt128)
end
end

==(x::Float32, y::Union(Int32,UInt32)) = float64(x)==float64(y)
==(x::Union(Int32,UInt32), y::Float32) = float64(x)==float64(y)
==(x::Float32, y::Union(Int32,UInt32)) = Float64(x)==Float64(y)
==(x::Union(Int32,UInt32), y::Float32) = Float64(x)==Float64(y)

<(x::Float32, y::Union(Int32,UInt32)) = float64(x)<float64(y)
<(x::Union(Int32,UInt32), y::Float32) = float64(x)<float64(y)
<(x::Float32, y::Union(Int32,UInt32)) = Float64(x)<Float64(y)
<(x::Union(Int32,UInt32), y::Float32) = Float64(x)<Float64(y)

<=(x::Float32, y::Union(Int32,UInt32)) = float64(x)<=float64(y)
<=(x::Union(Int32,UInt32), y::Float32) = float64(x)<=float64(y)
<=(x::Float32, y::Union(Int32,UInt32)) = Float64(x)<=Float64(y)
<=(x::Union(Int32,UInt32), y::Float32) = Float64(x)<=Float64(y)

abs(x::Float64) = box(Float64,abs_float(unbox(Float64,x)))
abs(x::Float32) = box(Float32,abs_float(unbox(Float32,x)))
Expand Down
44 changes: 22 additions & 22 deletions base/float16.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ function convert(::Type{Float16}, val::Float32)
end

convert(::Type{Bool}, x::Float16) = (x!=0)
convert(::Type{Int128}, x::Float16) = convert(Int128, float32(x))
convert(::Type{UInt128}, x::Float16) = convert(UInt128, float32(x))
convert(::Type{Int128}, x::Float16) = convert(Int128, Float32(x))
convert(::Type{UInt128}, x::Float16) = convert(UInt128, Float32(x))

convert{T<:Integer}(::Type{T}, x::Float16) = convert(T, float32(x))
convert{T<:Integer}(::Type{T}, x::Float16) = convert(T, Float32(x))

round{T<:Integer}(::Type{T}, x::Float16) = round(T, float32(x))
trunc{T<:Integer}(::Type{T}, x::Float16) = trunc(T, float32(x))
floor{T<:Integer}(::Type{T}, x::Float16) = floor(T, float32(x))
ceil {T<:Integer}(::Type{T}, x::Float16) = ceil(T, float32(x))
round{T<:Integer}(::Type{T}, x::Float16) = round(T, Float32(x))
trunc{T<:Integer}(::Type{T}, x::Float16) = trunc(T, Float32(x))
floor{T<:Integer}(::Type{T}, x::Float16) = floor(T, Float32(x))
ceil {T<:Integer}(::Type{T}, x::Float16) = ceil(T, Float32(x))

round(x::Float16) = Float16(round(float32(x)))
trunc(x::Float16) = Float16(trunc(float32(x)))
floor(x::Float16) = Float16(floor(float32(x)))
ceil(x::Float16) = Float16( ceil(float32(x)))
round(x::Float16) = Float16(round(Float32(x)))
trunc(x::Float16) = Float16(trunc(Float32(x)))
floor(x::Float16) = Float16(floor(Float32(x)))
ceil(x::Float16) = Float16( ceil(Float32(x)))

isnan(x::Float16) = reinterpret(UInt16,x)&0x7fff > 0x7c00
isinf(x::Float16) = reinterpret(UInt16,x)&0x7fff == 0x7c00
Expand All @@ -131,33 +131,33 @@ end
-(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) $ 0x8000)
abs(x::Float16) = reinterpret(Float16, reinterpret(UInt16,x) & 0x7fff)
for op in (:+,:-,:*,:/,:\,:^)
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(float32(a), float32(b)))
@eval ($op)(a::Float16, b::Float16) = Float16(($op)(Float32(a), Float32(b)))
end
function fma(a::Float16, b::Float16, c::Float16)
Float16(fma(float32(a), float32(b), float32(c)))
Float16(fma(Float32(a), Float32(b), Float32(c)))
end
function muladd(a::Float16, b::Float16, c::Float16)
Float16(muladd(float32(a), float32(b), float32(c)))
Float16(muladd(Float32(a), Float32(b), Float32(c)))
end
for op in (:<,:<=,:isless)
@eval ($op)(a::Float16, b::Float16) = ($op)(float32(a), float32(b))
@eval ($op)(a::Float16, b::Float16) = ($op)(Float32(a), Float32(b))
end
for func in (:sin,:cos,:tan,:asin,:acos,:atan,:sinh,:cosh,:tanh,:asinh,:acosh,
:atanh,:exp,:log,:log2,:log10,:sqrt,:lgamma,:log1p)
@eval begin
$func(a::Float16) = Float16($func(float32(a)))
$func(a::Complex32) = complex32($func(complex64(a)))
$func(a::Float16) = Float16($func(Float32(a)))
$func(a::Complex32) = Complex32($func(Complex64(a)))
end
end

for func in (:div,:fld,:cld,:rem,:mod,:atan2,:hypot)
@eval begin
$func(a::Float16,b::Float16) = Float16($func(float32(a),float32(a)))
$func(a::Float16,b::Float16) = Float16($func(Float32(a),Float32(a)))
end
end

ldexp(a::Float16, b::Integer) = Float16(ldexp(float32(a), b))
exponent(x::Float16) = exponent(float32(x))
^(x::Float16, y::Integer) = Float16(float32(x)^y)
ldexp(a::Float16, b::Integer) = Float16(ldexp(Float32(a), b))
exponent(x::Float16) = exponent(Float32(x))
^(x::Float16, y::Integer) = Float16(Float32(x)^y)

rationalize{T<:Integer}(::Type{T}, x::Float16; tol::Real=eps(x)) = rationalize(T, float32(x); tol=tol)
rationalize{T<:Integer}(::Type{T}, x::Float16; tol::Real=eps(x)) = rationalize(T, Float32(x); tol=tol)
12 changes: 6 additions & 6 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

copysign(x::Float64, y::Float64) = box(Float64,copysign_float(unbox(Float64,x),unbox(Float64,y)))
copysign(x::Float32, y::Float32) = box(Float32,copysign_float(unbox(Float32,x),unbox(Float32,y)))
copysign(x::Float32, y::Real) = copysign(x, float32(y))
copysign(x::Float64, y::Real) = copysign(x, float64(y))
copysign(x::Float32, y::Real) = copysign(x, Float32(y))
copysign(x::Float64, y::Real) = copysign(x, Float64(y))
@vectorize_2arg Real copysign

flipsign(x::Float64, y::Float64) = box(Float64,xor_int(unbox(Float64,x),and_int(unbox(Float64,y),0x8000000000000000)))
flipsign(x::Float32, y::Float32) = box(Float32,xor_int(unbox(Float32,x),and_int(unbox(Float32,y),0x80000000)))
flipsign(x::Float32, y::Real) = flipsign(x, float32(y))
flipsign(x::Float64, y::Real) = flipsign(x, float64(y))
flipsign(x::Float32, y::Real) = flipsign(x, Float32(y))
flipsign(x::Float64, y::Real) = flipsign(x, Float64(y))
@vectorize_2arg Real flipsign

signbit(x::Float64) = signbit(reinterpret(Int64,x))
signbit(x::Float32) = signbit(reinterpret(Int32,x))
signbit(x::Float16) = signbit(reinterpret(Int16,x))

maxintfloat(::Type{Float64}) = 9007199254740992.
maxintfloat(::Type{Float32}) = float32(16777216.)
maxintfloat(::Type{Float16}) = float16(2048f0)
maxintfloat(::Type{Float32}) = Float32(16777216.)
maxintfloat(::Type{Float16}) = Float16(2048f0)
maxintfloat{T<:FloatingPoint}(x::T) = maxintfloat(T)
maxintfloat() = maxintfloat(Float64)

Expand Down
6 changes: 3 additions & 3 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function BigInt(x::Float64)
return z
end

BigInt(x::Union(Float16,Float32)) = BigInt(float64(x))
BigInt(x::Union(Float16,Float32)) = BigInt(Float64(x))

function BigInt(x::Integer)
if x < 0
Expand Down Expand Up @@ -197,8 +197,8 @@ function convert(::Type{Float64}, n::BigInt)
# TODO: this should round to nearest but instead rounds to zero
ccall((:__gmpz_get_d, :libgmp), Float64, (Ptr{BigInt},), &n)
end
convert(::Type{Float32}, n::BigInt) = float32(float64(n))
convert(::Type{Float16}, n::BigInt) = float16(float64(n))
convert(::Type{Float32}, n::BigInt) = Float32(Float64(n))
convert(::Type{Float16}, n::BigInt) = Float16(Float64(n))

rem(x::BigInt, ::Type{Bool}) = ((x&1)!=0)

Expand Down
2 changes: 1 addition & 1 deletion base/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function _show(io::IO, x::FloatingPoint, mode, n::Int, typed, nanstr, infstr)
write(io, typed ? infstr : "Inf")
return
end
typed && isa(x,Float16) && write(io, "float16(")
typed && isa(x,Float16) && write(io, "Float16(")
len,pt,neg,buffer = grisu(x,mode,n)
pdigits = pointer(buffer)
if mode == PRECISION
Expand Down
Loading

0 comments on commit 700abd2

Please sign in to comment.