Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master: (53 commits)
  edit embedding chapter
  formatting fixes
  Fix JuliaLang#5056
  more consitent/useful description of predicate in ie all()
  NEWS for JuliaLang#4042
  Add sparse matvec to perf benchmark (JuliaLang#4707)
  Use warn_once instead of warn (JuliaLang#5038)
  Use warn() instead of println in base/sprase/sparsematrix.jl
  allow scale(b,A) or scale(A,b) when b is a scalar as well as a vector, don't restrict scale unnecessarily to arrays of numbers (e.g. scaling arrays of arrays should work), and improve documentation for scale\!
  Added section about memory management
  added negative bitarray rolling
  More accurate linspace for types with greater precision than Float64
  add realmin realmax for BigFloat
  fix eps(realmax), add typemin and typemax for BigFloat
  fix JuliaLang#5025, ordering used by nextfloat/prevfloat
  roll back on errors during type definitions. fixes JuliaLang#5009
  improve method signature errors. fixes JuliaLang#5018
  update juliadoc
  add more asserts for casts
  Fix segfaulting on strstr() failure
  ...
  • Loading branch information
Michael Fox committed Dec 8, 2013
2 parents 54ddd9d + 05b0d5e commit 4e8db17
Show file tree
Hide file tree
Showing 45 changed files with 1,398 additions and 437 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Julia v0.3.0 Release Notes
New language features
---------------------

* Greatly enhanced performance for passing and returning tuples ([#4042]).

New library functions
---------------------

Expand Down
3 changes: 2 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ function linspace(start::Real, stop::Real, n::Integer)
return a
end
n -= 1
S = promote_type(T, Float64)
for i=0:n
a[i+1] = start*((n-i)/n) + stop*(i/n)
a[i+1] = start*(convert(S, (n-i))/n) + stop*(convert(S, i)/n)
end
a
end
Expand Down
2 changes: 2 additions & 0 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ function rol(B::BitVector, i::Integer)
n = length(B)
i %= n
i == 0 && return copy(B)
i < 0 && return ror(B, -i)
A = BitArray(n)
copy_chunks(A.chunks, 1, B.chunks, i+1, n-i)
copy_chunks(A.chunks, n-i+1, B.chunks, 1, i)
Expand All @@ -1730,6 +1731,7 @@ function ror(B::BitVector, i::Integer)
n = length(B)
i %= n
i == 0 && return copy(B)
i < 0 && return rol(B, -i)
A = BitArray(n)
copy_chunks(A.chunks, i+1, B.chunks, 1, n-i)
copy_chunks(A.chunks, 1, B.chunks, n-i+1, i)
Expand Down
46 changes: 39 additions & 7 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ isless (a::FloatingPoint, b::Integer) = (a<b) | isless(a,float(b))
<=(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)))

isnan(x::FloatingPoint) = (x != x)
isnan(x::Real) = isnan(float(x))
isnan(x::Integer) = false

isinf(x::FloatingPoint) = (abs(x) == Inf)
isinf(x::Real) = isinf(float(x))
isinf(x::Integer) = false

isfinite(x::FloatingPoint) = (x-x == 0)
isfinite(x::Real) = isfinite(float(x))
isfinite(x::Integer) = true

## floating point traits ##

const Inf16 = box(Float16,unbox(Uint16,0x7c00))
Expand All @@ -216,6 +231,29 @@ const NaN32 = box(Float32,unbox(Uint32,0x7fc00000))
const Inf = box(Float64,unbox(Uint64,0x7ff0000000000000))
const NaN = box(Float64,unbox(Uint64,0x7ff8000000000000))

## precision, as defined by the effective number of bits in the mantissa ##
precision(::Float16) = 11
precision(::Float32) = 24
precision(::Float64) = 53

function float_lex_order(f::Integer, delta::Integer)
# convert from signed magnitude to 2's complement and back
if f < 0
f = oftype(f, -(f & typemax(f)))
end
f = oftype(f, f + delta)
f < 0 ? oftype(f, -(f & typemax(f))) : f
end

nextfloat(x::Float16, i::Integer) =
reinterpret(Float16,float_lex_order(reinterpret(Int16,x), i))
nextfloat(x::Float32, i::Integer) =
reinterpret(Float32,float_lex_order(reinterpret(Int32,x), i))
nextfloat(x::Float64, i::Integer) =
reinterpret(Float64,float_lex_order(reinterpret(Int64,x), i))
nextfloat(x::FloatingPoint) = nextfloat(x,1)
prevfloat(x::FloatingPoint) = nextfloat(x,-1)

@eval begin
inf(::Type{Float16}) = $Inf16
nan(::Type{Float16}) = $NaN16
Expand Down Expand Up @@ -249,13 +287,7 @@ const NaN = box(Float64,unbox(Uint64,0x7ff8000000000000))
realmin() = realmin(Float64)
realmax() = realmax(Float64)

nextfloat(x::Float16, i::Integer) = box(Float16,add_int(reinterpret(Int16,x),unbox(Int16,int16(i))))
nextfloat(x::Float32, i::Integer) = box(Float32,add_int(unbox(Float32,x),unbox(Int32,int32(i))))
nextfloat(x::Float64, i::Integer) = box(Float64,add_int(unbox(Float64,x),unbox(Int64,int64(i))))
nextfloat(x::FloatingPoint) = nextfloat(x,1)
prevfloat(x::FloatingPoint) = nextfloat(x,-1)

eps(x::FloatingPoint) = isfinite(x) ? abs(nextfloat(x)-x) : nan(x)
eps(x::FloatingPoint) = isfinite(x) ? abs(x)-prevfloat(abs(x)) : nan(x)
eps(::Type{Float16}) = $(box(Float16,unbox(Uint16,0x1400)))
eps(::Type{Float32}) = $(box(Float32,unbox(Uint32,0x34000000)))
eps(::Type{Float64}) = $(box(Float64,unbox(Uint64,0x3cb0000000000000)))
Expand Down
20 changes: 0 additions & 20 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
## floating-point functions ##

abs(x::Float64) = box(Float64,abs_float(unbox(Float64,x)))
abs(x::Float32) = box(Float32,abs_float(unbox(Float32,x)))

isnan(x::FloatingPoint) = (x != x)
isnan(x::Real) = isnan(float(x))
isnan(x::Integer) = false

isinf(x::FloatingPoint) = (abs(x) == Inf)
isinf(x::Real) = isinf(float(x))
isinf(x::Integer) = false

isfinite(x::FloatingPoint) = (x-x == 0)
isfinite(x::Real) = isfinite(float(x))
isfinite(x::Integer) = true

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))
Expand All @@ -33,11 +18,6 @@ maxintfloat() = maxintfloat(Float64)

isinteger(x::FloatingPoint) = (trunc(x)==x)&isfinite(x)

## precision, as defined by the effective number of bits in the mantissa ##
precision(::Float16) = 11
precision(::Float32) = 24
precision(::Float64) = 53

num2hex(x::Float16) = hex(reinterpret(Uint16,x), 4)
num2hex(x::Float32) = hex(box(Uint32,unbox(Float32,x)),8)
num2hex(x::Float64) = hex(box(Uint64,unbox(Float64,x)),16)
Expand Down
2 changes: 1 addition & 1 deletion base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ function inlining_pass(e::Expr, sv, ast)
end

function add_variable(ast, name, typ)
vinf = {name,typ,2}
vinf = {name,typ,18}
locllist = ast.args[2][1]::Array{Any,1}
vinflist = ast.args[2][2]::Array{Any,1}
push!(locllist, name)
Expand Down
11 changes: 5 additions & 6 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ fd(s::IOStream) = int(ccall(:jl_ios_fd, Clong, (Ptr{Void},), s.ios))
close(s::IOStream) = ccall(:ios_close, Void, (Ptr{Void},), s.ios)
isopen(s::IOStream) = bool(ccall(:ios_isopen, Cint, (Ptr{Void},), s.ios))
flush(s::IOStream) = ccall(:ios_flush, Void, (Ptr{Void},), s.ios)
isreadonly(s::IOStream) = bool(ccall(:ios_get_readonly, Cint, (Ptr{Void},), s.ios))
iswritable(s::IOStream) = !isreadonly(s)
isreadable(s::IOStream) = true
iswritable(s::IOStream) = bool(ccall(:ios_get_writable, Cint, (Ptr{Void},), s.ios))
isreadable(s::IOStream) = bool(ccall(:ios_get_readable, Cint, (Ptr{Void},), s.ios))

function truncate(s::IOStream, n::Integer)
ccall(:ios_trunc, Int32, (Ptr{Void}, Uint), s.ios, n) == 0 ||
Expand Down Expand Up @@ -351,7 +350,7 @@ write(s::IOStream, b::Uint8) = int(ccall(:jl_putc, Int32, (Uint8, Ptr{Void}), b,

function write{T}(s::IOStream, a::Array{T})
if isbits(T)
if isreadonly(s)
if !iswritable(s)
error("attempt to write to a read-only IOStream")
end
int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint),
Expand All @@ -362,7 +361,7 @@ function write{T}(s::IOStream, a::Array{T})
end

function write(s::IOStream, p::Ptr, nb::Integer)
if isreadonly(s)
if !iswritable(s)
error("attempt to write to a read-only IOStream")
end
int(ccall(:ios_write, Uint, (Ptr{Void}, Ptr{Void}, Uint), s.ios, p, nb))
Expand Down Expand Up @@ -409,7 +408,7 @@ end
## text I/O ##

function write(s::IOStream, c::Char)
if isreadonly(s)
if !iswritable(s)
error("attempt to write to a read-only IOStream")
end
int(ccall(:ios_pututf8, Int32, (Ptr{Void}, Char), s.ios, c))
Expand Down
8 changes: 5 additions & 3 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
## linalg.jl: Some generic Linear Algebra definitions

scale{T<:Number}(X::AbstractArray{T}, s::Number) = scale!(copy(X), s)
scale(X::AbstractArray, s::Number) = scale!(copy(X), s)
scale(s::Number, X::AbstractArray) = scale!(copy(X), s)

function scale!{T<:Number}(X::AbstractArray{T}, s::Number)
function scale!(X::AbstractArray, s::Number)
for i in 1:length(X)
X[i] *= s
@inbounds X[i] *= s
end
X
end
scale!(s::Number, X::AbstractArray) = scale!(X, s)

cross(a::AbstractVector, b::AbstractVector) = [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[1]*b[3], a[1]*b[2]-a[2]*b[1]]

Expand Down
4 changes: 2 additions & 2 deletions base/linalg/hermitian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function copy!(A::Hermitian, B::Hermitian)
A
end
size(A::Hermitian, args...) = size(A.S, args...)
print_matrix(io::IO, A::Hermitian, rows::Integer, cols::Integer) = print_matrix(io, full(A), rows, cols)
full(A::Hermitian) = A.S
getindex(A::Hermitian, i::Integer, j::Integer) = (A.uplo == 'U') == (i < j) ? getindex(A.S, i, j) : conj(getindex(A.S, j, i))
full(A::Hermitian) = symmetrize_conj!(A.S, A.uplo)
ishermitian(A::Hermitian) = true
issym{T<:Real}(A::Hermitian{T}) = true
issym{T<:Complex}(A::Hermitian{T}) = all(imag(A.S) .== 0)
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function copy!(A::Symmetric, B::Symmetric)
A
end
size(A::Symmetric, args...) = size(A.S, args...)
print_matrix(io::IO, A::Symmetric, rows::Integer, cols::Integer) = print_matrix(io, full(A), rows, cols)
full(A::Symmetric) = A.S
getindex(A::Symmetric, i::Integer, j::Integer) = (A.uplo == 'U') == (i < j) ? getindex(A.S, i, j) : getindex(A.S, j, i)
full(A::Symmetric) = symmetrize!(A.S, A.uplo)
ishermitian{T<:Real}(A::Symmetric{T}) = true
ishermitian{T<:Complex}(A::Symmetric{T}) = all(imag(A.S) .== 0)
issym(A::Symmetric) = true
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function Triangular(A::Matrix)
end

size(A::Triangular, args...) = size(A.UL, args...)
full(A::Triangular) = (istril(A) ? tril : triu)(A.UL)
full(A::Triangular) = (istril(A) ? tril! : triu!)(A.UL)

print_matrix(io::IO, A::Triangular, rows::Integer, cols::Integer) = print_matrix(io, full(A), rows, cols)
getindex{T}(A::Triangular{T}, i::Integer, j::Integer) = i == j ? A.UL[i,j] : ((A.uplo == 'U') == (i < j) ? getindex(A.UL, i, j) : zero(T))

istril(A::Triangular) = A.uplo == 'L'
istriu(A::Triangular) = A.uplo == 'U'
Expand Down
7 changes: 5 additions & 2 deletions base/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,13 @@ function solve!{T<:BlasFloat}(x::AbstractArray{T}, xrng::Ranges{Int}, M::Tridiag
x[ix] = xlast
ix -= xstride
end
x
nothing
end

solve!(x::StridedVector, M::Tridiagonal, rhs::StridedVector) = solve!(x, 1:length(x), M, rhs, 1:length(rhs))
function solve!(x::StridedVector, M::Tridiagonal, rhs::StridedVector)
solve!(x, 1:length(x), M, rhs, 1:length(rhs))
x
end
solve{TM<:BlasFloat,TB<:BlasFloat}(M::Tridiagonal{TM}, B::StridedVecOrMat{TB}) = solve!(zeros(typeof(one(TM)/one(TB)), size(B)), M, B)
solve(M::Tridiagonal, B::StridedVecOrMat) = solve(float(M), float(B))
function solve!(X::StridedMatrix, M::Tridiagonal, B::StridedMatrix)
Expand Down
6 changes: 5 additions & 1 deletion base/linalg/woodbury.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ function solve!(x::AbstractArray, xrng::Ranges{Int}, W::Woodbury, rhs::AbstractA
x[indx] = W.tmpN1[i] - W.tmpN2[i]
indx += xinc
end
nothing
end

solve!(x::AbstractVector, W::Woodbury, rhs::AbstractVector) = solve!(x, 1:length(x), W, rhs, 1:length(rhs))
function solve!(x::AbstractVector, W::Woodbury, rhs::AbstractVector)
solve!(x, 1:length(x), W, rhs, 1:length(rhs))
x
end
solve(W::Woodbury, rhs::AbstractVector) = solve!(similar(rhs), W, rhs)
solve(W::Woodbury, B::StridedMatrix)=solve!(similar(B), W, B)
function solve!(X::StridedMatrix, W::Woodbury, B::StridedMatrix)
Expand Down
9 changes: 8 additions & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import
gamma, lgamma, digamma, erf, erfc, zeta, log1p, airyai, iceil, ifloor,
itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2,
serialize, deserialize, inf, nan, hash, cbrt
serialize, deserialize, inf, nan, hash, cbrt, typemax, typemin,
realmin, realmax

import Base.Math.lgamma_r

Expand Down Expand Up @@ -666,6 +667,9 @@ isfinite(x::BigFloat) = !isinf(x) && !isnan(x)
@eval inf(::Type{BigFloat}) = $(BigFloat(Inf))
@eval nan(::Type{BigFloat}) = $(BigFloat(NaN))

typemax(::Type{BigFloat}) = inf(BigFloat)
@eval typemin(::Type{BigFloat}) = $(BigFloat(-Inf))

function nextfloat(x::BigFloat)
z = BigFloat()
ccall((:mpfr_set, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{BigFloat}, Int32),
Expand All @@ -684,6 +688,9 @@ end

eps(::Type{BigFloat}) = nextfloat(BigFloat(1)) - BigFloat(1)

realmin(::Type{BigFloat}) = nextfloat(zero(BigFloat))
realmax(::Type{BigFloat}) = prevfloat(inf(BigFloat))

function with_bigfloat_precision(f::Function, precision::Integer)
old_precision = get_bigfloat_precision()
set_bigfloat_precision(precision)
Expand Down
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ done(mt::MethodTable, i::()) = true
uncompressed_ast(l::LambdaStaticData) =
isa(l.ast,Expr) ? l.ast : ccall(:jl_uncompress_ast, Any, (Any,Any), l, l.ast)

function _dump_function(f, t::ANY, native)
str = ccall(:jl_dump_function, Any, (Any,Any,Bool), f, t, native)::ByteString
function _dump_function(f, t::ANY, native, wrapper)
str = ccall(:jl_dump_function, Any, (Any,Any,Bool,Bool), f, t, native, wrapper)::ByteString
if str == ""
error("no method found for the specified argument types")
end
str
end

code_llvm (f::Callable, types::Tuple) = print(_dump_function(f, types, false))
code_native(f::Callable, types::Tuple) = print(_dump_function(f, types, true))
code_llvm (f::Callable, types::Tuple) = print(_dump_function(f, types, false, false))
code_native(f::Callable, types::Tuple) = print(_dump_function(f, types, true, false))

function functionlocs(f::Function, types=(Any...))
locs = Any[]
Expand Down
4 changes: 2 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function findn{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
J[count] = col
count += 1
else
println("warning: sparse matrix contains explicit stored zeros")
warn_once("sparse matrix contains explicit stored zeros")
end
end

Expand All @@ -313,7 +313,7 @@ function findnz{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
V[count] = S.nzval[k]
count += 1
else
println("warning: sparse matrix contains explicit stored zeros")
warn_once("sparse matrix contains explicit stored zeros")
end
end

Expand Down
Loading

0 comments on commit 4e8db17

Please sign in to comment.