Skip to content

Commit

Permalink
Merge pull request JuliaLang#10 from JuliaLang/master
Browse files Browse the repository at this point in the history
update to 5957a5f [ci skip]
  • Loading branch information
tkelman committed Mar 8, 2014
2 parents d8b79dc + 5957a5f commit 54ee245
Show file tree
Hide file tree
Showing 31 changed files with 548 additions and 452 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ New language features
Library improvements
--------------------

* `convert(Ptr{T1}, x::Array{T2})` is now deprecated unless `T1 == T2`
or `T1 == None` ([#6073]). (You can still explicitly `convert`
one pointer type into another if needed.)

* Well-behaved floating-point ranges ([#2333], [#5636]).
Introduced the `FloatRange` type for floating-point ranges with a step,
which will give intuitive/correct results for classically problematic
Expand Down
25 changes: 18 additions & 7 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,26 @@ end
# functions that should give an Int result for Bool arrays
for f in (:+, :-)
@eval begin
function ($f)(x::Bool, y::StridedArray{Bool})
reshape([ ($f)(x, y[i]) for i=1:length(y) ], size(y))
function ($f)(A::Bool, B::StridedArray{Bool})
F = Array(Int, size(B))
for i=1:length(B)
@inbounds F[i] = ($f)(A, B[i])
end
return F
end
function ($f)(x::StridedArray{Bool}, y::Bool)
reshape([ ($f)(x[i], y) for i=1:length(x) ], size(x))
function ($f)(A::StridedArray{Bool}, B::Bool)
F = Array(Int, size(A))
for i=1:length(A)
@inbounds F[i] = ($f)(A[i], B)
end
return F
end
function ($f)(x::StridedArray{Bool}, y::StridedArray{Bool})
shp = promote_shape(size(x),size(y))
reshape([ ($f)(x[i], y[i]) for i=1:length(x) ], shp)
function ($f)(A::StridedArray{Bool}, B::StridedArray{Bool})
F = Array(Int, promote_shape(size(A), size(B)))
for i=1:length(A)
@inbounds F[i] = ($f)(A[i], B[i])
end
return F
end
end
end
Expand Down
50 changes: 30 additions & 20 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ end
## Indexing: getindex ##

function getindex_unchecked(Bc::Vector{Uint64}, i::Int)
return (Bc[@_div64(int(i)-1)+1] & (uint64(1)<<@_mod64(int(i)-1))) != 0
return (Bc[@_div64(i-1)+1] & (uint64(1)<<@_mod64(i-1))) != 0
end

function getindex(B::BitArray, i::Int)
Expand Down Expand Up @@ -885,25 +885,35 @@ end
## Binary arithmetic operators ##

for f in (:+, :-)
@eval begin
function ($f)(A::BitArray, B::BitArray)
shp = promote_shape(size(A),size(B))
reshape(Int[ ($f)(A[i], B[i]) for i=1:length(A) ], shp)
end
function ($f)(B::BitArray, x::Bool)
reshape([ ($f)(B[i], x) for i = 1:length(B) ], size(B))
end
function ($f)(B::BitArray, x::Number)
pt = promote_array_type(typeof(x), Bool)
reshape((pt)[ ($f)(B[i], x) for i = 1:length(B) ], size(B))
end
function ($f)(x::Bool, B::BitArray)
reshape([ ($f)(x, B[i]) for i = 1:length(B) ], size(B))
end
function ($f)(x::Number, B::BitArray)
pt = promote_array_type(typeof(x), Bool)
reshape((pt)[ ($f)(x, B[i]) for i = 1:length(B) ], size(B))
end
@eval function ($f)(A::BitArray, B::BitArray)
r = Array(Int, promote_shape(size(A), size(B)))
ai = start(A)
bi = start(B)
ri = 1
while !done(A, ai)
a, ai = next(A, ai)
b, bi = next(B, bi)
@inbounds r[ri] = ($f)(a, b)
ri += 1
end
return r
end
end
for f in (:+, :-),
(arg1, arg2, T, fargs) in ((:(B::BitArray), :(x::Bool) , Int , :(b, x)),
(:(B::BitArray), :(x::Number) , :(promote_array_type(typeof(x), Bool)), :(b, x)),
(:(x::Bool) , :(B::BitArray), Int , :(x, b)),
(:(x::Number) , :(B::BitArray), :(promote_array_type(typeof(x), Bool)), :(x, b)))
@eval function ($f)($arg1, $arg2)
r = Array($T, size(B))
bi = start(B)
ri = 1
while !done(B, bi)
b, bi = next(B, bi)
@inbounds r[ri] = ($f)($fargs...)
ri += 1
end
return r
end
end

Expand Down
6 changes: 4 additions & 2 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ reim(z) = (real(z), imag(z))
isreal(x::Real) = true
isreal(z::Complex) = imag(z) == 0
isimag(z::Number) = real(z) == 0
isinteger(z::Complex) = isreal(z) && isinteger(real(z))
isfinite(z::Complex) = isfinite(real(z)) && isfinite(imag(z))
isinteger(z::Complex) = isreal(z) & isinteger(real(z))
isfinite(z::Complex) = isfinite(real(z)) & isfinite(imag(z))
isnan(z::Complex) = isnan(real(z)) | isnan(imag(z))
isinf(z::Complex) = isinf(real(z)) | isinf(imag(z))

complex(x::Real, y::Real) = Complex(x, y)
complex(x::Real) = Complex(x)
Expand Down
13 changes: 11 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ macro deprecate(old,new)
elseif isa(old,Expr) && old.head == :call
oldcall = sprint(io->show_unquoted(io,old))
newcall = sprint(io->show_unquoted(io,new))
oldname = Expr(:quote, old.args[1])
oldsym = if isa(old.args[1],Symbol)
old.args[1]
elseif isa(old.args[1],Expr) && old.args[1].head == :curly
old.args[1].args[1]
else
error("invalid usage of @deprecate")
end
oldname = Expr(:quote, oldsym)
Expr(:toplevel,
Expr(:export,esc(old.args[1])),
Expr(:export,esc(oldsym)),
:($(esc(old)) = begin
depwarn(string($oldcall," is deprecated, use ",$newcall," instead."),
$oldname)
Expand Down Expand Up @@ -402,6 +409,8 @@ Set{T<:Number}(xs::T...) = Set{T}(xs)

@deprecate normfro(A) vecnorm(A)

@deprecate convert{T}(p::Type{Ptr{T}}, a::Array) convert(p, pointer(a))

# 0.3 discontinued functions

function nnz(X)
Expand Down
48 changes: 15 additions & 33 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,25 +363,19 @@ function sum(arr::AbstractArray{BigInt})
return n
end

function factorial(bn::BigInt)
if bn<0
return BigInt(0)
else
n = uint(bn)
end
function factorial(x::BigInt)
x.size < 0 && return BigInt(0)
z = BigInt()
ccall((:__gmpz_fac_ui, :libgmp), Void,
(Ptr{BigInt}, Culong), &z, n)
ccall((:__gmpz_fac_ui, :libgmp), Void, (Ptr{BigInt}, Culong), &z, x)
return z
end

function binomial(n::BigInt, k::Uint)
z = BigInt()
ccall((:__gmpz_bin_ui, :libgmp), Void,
(Ptr{BigInt}, Ptr{BigInt}, Culong), &z, &n, k)
ccall((:__gmpz_bin_ui, :libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Culong), &z, &n, k)
return z
end
binomial(n::BigInt, k::Integer) = k<0 ? throw(DomainError()) : binomial(n, uint(k))
binomial(n::BigInt, k::Integer) = k < 0 ? throw(DomainError()) : binomial(n, uint(k))

==(x::BigInt, y::BigInt) = cmp(x,y) == 0
isequal(x::BigInt, y::BigInt) = cmp(x,y) == 0
Expand All @@ -390,39 +384,27 @@ isequal(x::BigInt, y::BigInt) = cmp(x,y) == 0
<(x::BigInt, y::BigInt) = cmp(x,y) < 0
>(x::BigInt, y::BigInt) = cmp(x,y) > 0

function string(x::BigInt)
lng = ndigits(x) + 2
z = Array(Uint8, lng)
lng = ccall((:__gmp_snprintf,:libgmp), Int32, (Ptr{Uint8}, Culong, Ptr{Uint8}, Ptr{BigInt}...), z, lng, "%Zd", &x)
return bytestring(z[1:lng])
end

function show(io::IO, x::BigInt)
print(io, string(x))
end
string(x::BigInt) = dec(x)
show(io::IO, x::BigInt) = print(io, string(x))

bin(n::BigInt) = base( 2, n)
oct(n::BigInt) = base( 8, n)
dec(n::BigInt) = base(10, n)
hex(n::BigInt) = base(16, n)

function base(b::Integer, n::BigInt)
if !(2 <= b <= 62)
error("invalid base: $b")
end
p = ccall((:__gmpz_get_str,:libgmp), Ptr{Uint8}, (Ptr{Uint8}, Cint, Ptr{BigInt}),
C_NULL, b, &n)
2 <= b <= 62 || error("invalid base: $b")
p = ccall((:__gmpz_get_str,:libgmp), Ptr{Uint8}, (Ptr{Uint8}, Cint, Ptr{BigInt}), C_NULL, b, &n)
len = int(ccall(:strlen, Csize_t, (Ptr{Uint8},), p))
ASCIIString(pointer_to_array(p,len,true))
end

function ndigits(x::BigInt, base::Integer=10)
function ndigits0z(x::BigInt, b::Integer=10)
# mpz_sizeinbase might return an answer 1 too big
n = int(ccall((:__gmpz_sizeinbase,:libgmp), Culong, (Ptr{BigInt}, Int32), &x, base))
abs(x) < big(base)^(n-1) ? n-1 : n
n = int(ccall((:__gmpz_sizeinbase,:libgmp), Culong, (Ptr{BigInt}, Int32), &x, b))
abs(x) < big(b)^(n-1) ? n-1 : n
end

ndigits0z(x::BigInt, base::Integer=10) = x == 0 ? 0 : ndigits(x)
ndigits(x::BigInt, b::Integer=10) = x.size == 0 ? 1 : ndigits0z(x,b)

isprime(x::BigInt, reps=25) = ccall((:__gmpz_probab_prime_p,:libgmp), Cint, (Ptr{BigInt}, Cint), &x, reps) > 0

Expand All @@ -431,7 +413,7 @@ widemul(x::Int128, y::Uint128) = BigInt(x)*BigInt(y)
widemul(x::Uint128, y::Int128) = BigInt(x)*BigInt(y)
widemul{T<:Integer}(x::T, y::T) = BigInt(x)*BigInt(y)

prevpow2(x::BigInt) = x < 0 ? -prevpow2(-x) : (x <= 2 ? x : one(BigInt) << (ndigits(x, 2)-1))
nextpow2(x::BigInt) = x < 0 ? -nextpow2(-x) : (x <= 2 ? x : one(BigInt) << ndigits(x-1, 2))
prevpow2(x::BigInt) = x.size < 0 ? -prevpow2(-x) : (x <= 2 ? x : one(BigInt) << (ndigits(x, 2)-1))
nextpow2(x::BigInt) = x.size < 0 ? -nextpow2(-x) : (x <= 2 ? x : one(BigInt) << ndigits(x-1, 2))

end # module
6 changes: 3 additions & 3 deletions base/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export @grisu_ccall, NEG, DIGITS, BUFLEN, LEN, POINT

import Base.show, Base.print, Base.showcompact

const NEG = Array(Bool,1)
const NEG = Array(Bool)
const DIGITS = Array(Uint8,309+17)
const BUFLEN = int32(length(DIGITS)+1)
const LEN = Array(Int32,1)
const POINT = Array(Int32,1)
const LEN = Array(Int32)
const POINT = Array(Int32)

macro grisu_ccall(value, mode, ndigits)
quote
Expand Down
43 changes: 31 additions & 12 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,39 +300,53 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars)
if isa(t,TypeVar) || isa(t,TypeConstructor)
return t
end
inexact = !cov && d > MAX_TYPE_DEPTH
if isa(t,Tuple)
t === () && return t
if d > MAX_TYPE_DEPTH
R = Tuple
if isvatuple(t)
R = Tuple
else
R = NTuple{length(t),Any}
end
else
R = map(x->limit_type_depth(x, d+1, cov, vars), t)
l0 = length(vars)
R = map(x->limit_type_depth(x, d+1, true, vars), t)
if !cov && (length(vars) > l0 || d == MAX_TYPE_DEPTH)
inexact = true
end
end
elseif isa(t,UnionType)
t === None && return t
if d > MAX_TYPE_DEPTH
R = Any
else
R = Union(limit_type_depth(t.types, d, cov, vars)...)
R = limit_type_depth(t.types, d, cov, vars)
if isa(R,TypeVar)
R = Union(R.ub...)
inexact = true
else
R = Union(R...)
end
end
elseif isa(t,DataType)
P = t.parameters
if P === ()
return t
end
P === () && return t
if d > MAX_TYPE_DEPTH
R = t.name.primary
else
Q = map(x->limit_type_depth(x, d+1, false, vars), P)
if !cov && any(p->contains_is(vars,p), Q)
R = TypeVar(:_,t.name.primary)
push!(vars, R)
return R
R = t.name.primary
inexact = true
else
R = t.name.primary{Q...}
end
end
else
return t
end
if !cov && d > MAX_TYPE_DEPTH
if inexact
R = TypeVar(:_,R)
push!(vars, R)
end
Expand Down Expand Up @@ -377,8 +391,13 @@ const getfield_tfunc = function (A, s0, name)
end
for i=1:length(s.names)
if is(s.names[i],fld)
return limit_type_depth(s.types[i], 0, true,
filter!(x->isa(x,TypeVar), {s.parameters...}))
R = s.types[i]
if s.parameters === ()
return R
else
return limit_type_depth(R, 0, true,
filter!(x->isa(x,TypeVar), {s.parameters...}))
end
end
end
return None
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
### These offsets should be reconfigured to be less error-prone in matches
const chm_com_offsets = Array(Int, length(ChmCommon.types))
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
Void, (Ptr{Uint8},), chm_com_offsets)
Void, (Ptr{Int},), chm_com_offsets)
const chm_final_ll_inds = (1:4) + chm_com_offsets[7]
const chm_prt_inds = (1:4) + chm_com_offsets[13]
const chm_ityp_inds = (1:4) + chm_com_offsets[18]
Expand Down
Loading

0 comments on commit 54ee245

Please sign in to comment.