Skip to content

Commit

Permalink
Merge pull request JuliaLang#3 from JuliaLang/master
Browse files Browse the repository at this point in the history
Rebase to a5b5d64
  • Loading branch information
tkelman committed Mar 2, 2014
2 parents 627c80b + a5b5d64 commit 5915346
Show file tree
Hide file tree
Showing 48 changed files with 429 additions and 370 deletions.
25 changes: 22 additions & 3 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ BUILD_LLDB = 0
#XC_HOST = i686-w64-mingw32
#XC_HOST = x86_64-w64-mingw32

# Figure out OS and architecture
BUILD_OS := $(shell uname)

ifeq ($(XC_HOST),)
CROSS_COMPILE=
HOSTCC = $(CC)
Expand All @@ -115,8 +118,13 @@ override OPENBLAS_DYNAMIC_ARCH = 1
override CROSS_COMPILE=$(XC_HOST)-
ifneq (,$(findstring mingw,$(XC_HOST)))
override OS := WINNT
ifneq (,$(findstring CYGWIN,$(BUILD_OS)))
export STD_LIB_PATH := $(shell $(CROSS_COMPILE)gcc -print-search-dirs | grep programs | sed -e "s/^programs: =//" -e "s!/lib/!/bin/!g")
export STD_LIB_PATH := $(STD_LIB_PATH):$(shell $(CROSS_COMPILE)gcc -print-search-dirs | grep libraries | sed -e "s/^libraries: =//" -e "s!/lib/!/bin/!g")
else
export STD_LIB_PATH := $(shell $(CROSS_COMPILE)gcc -print-search-dirs | grep programs | sed "s/^programs: =//" | xargs -d":" winepath -w | tr '\n' ';')
export STD_LIB_PATH := $(STD_LIB_PATH);$(shell $(CROSS_COMPILE)gcc -print-search-dirs | grep libraries | sed "s/^libraries: =//" | xargs -d":" winepath -w | tr '\n' ';')
endif
else
$(error "unknown XC_HOST variable set")
endif
Expand All @@ -125,7 +133,6 @@ endif
JLDOWNLOAD = $(JULIAHOME)/deps/jldownload

# Figure out OS and architecture
BUILD_OS := $(shell uname)
OS := $(BUILD_OS)

ifneq (,$(findstring MINGW,$(OS)))
Expand Down Expand Up @@ -367,7 +374,7 @@ LIBBLAS ?= -lblas
LIBBLASNAME ?= libblas
endif
else
LIBBLAS = -L$(build_libdir) -lopenblas
LIBBLAS = -L$(build_shlibdir) -lopenblas
LIBBLASNAME = libopenblas
endif

Expand All @@ -381,7 +388,7 @@ ifeq ($(USE_SYSTEM_LAPACK), 1)
LIBLAPACK = -llapack
LIBLAPACKNAME = liblapack
else
LIBLAPACK = -L$(build_libdir) -llapack $(LIBBLAS)
LIBLAPACK = -L$(build_shlibdir) -llapack $(LIBBLAS)
LIBLAPACKNAME = liblapack
endif
endif
Expand Down Expand Up @@ -572,6 +579,8 @@ endef

ifeq ($(BUILD_OS), WINNT)
spawn = $(1)
else ifneq (,$(findstring CYGWIN,$(BUILD_OS)))
spawn = $(1)
else
ifeq ($(OS), WINNT)
spawn = wine $(1)
Expand All @@ -580,9 +589,19 @@ spawn = $(1)
endif
endif

ifneq (,$(findstring CYGWIN,$(BUILD_OS)))
cygpath_w = `cygpath -w $(1)`
else
cygpath_w = $(1)
endif

exec = $(shell $(call spawn,$(1)))

ifneq (,$(findstring CYGWIN,$(BUILD_OS)))
wine_pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(2)))))
else
wine_pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(shell printf %s\n '$(2)' | xargs -d";" winepath -u | tr '\n' ' '))))
endif
pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(2)))))

JULIA_EXECUTABLE_debug = $(build_bindir)/julia-debug-$(DEFAULT_REPL)$(EXE)
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endif
$(build_private_libdir)/sys%ji: $(build_private_libdir)/sys%bc

$(build_private_libdir)/sys%o: $(build_private_libdir)/sys%bc
$(call spawn,$(LLVM_LLC)) -filetype=obj -relocation-model=pic -mattr=-bmi2,-avx2 -o $@ $<
$(call spawn,$(LLVM_LLC)) -filetype=obj -relocation-model=pic -mattr=-bmi2,-avx2 -o $(call cygpath_w,$@) $(call cygpath_w,$<)

.PRECIOUS: $(build_private_libdir)/sys%o

Expand All @@ -79,12 +79,12 @@ $(build_private_libdir)/sys%$(SHLIB_EXT): $(build_private_libdir)/sys%o

$(build_private_libdir)/sys0.bc:
@$(QUIET_JULIA) cd base && \
$(call spawn,$(JULIA_EXECUTABLE)) --build $(build_private_libdir)/sys0 sysimg.jl
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)/sys0) sysimg.jl

$(build_private_libdir)/sys.bc: VERSION base/*.jl base/pkg/*.jl base/linalg/*.jl base/sparse/*.jl $(build_datarootdir)/julia/helpdb.jl $(build_datarootdir)/man/man1/julia.1 $(build_private_libdir)/sys0.$(SHLIB_EXT)
@$(QUIET_JULIA) cd base && \
$(call spawn,$(JULIA_EXECUTABLE)) --build $(build_private_libdir)/sys \
-J$(build_private_libdir)/$$([ -e $(build_private_libdir)/sys.ji ] && echo sys.ji || echo sys0.ji) -f sysimg.jl \
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)/sys) \
-J$(call cygpath_w,$(build_private_libdir))/$$([ -e $(build_private_libdir)/sys.ji ] && echo sys.ji || echo sys0.ji) -f sysimg.jl \
|| (echo "*** This error is usually fixed by running 'make clean'. If the error persists, try 'make cleanall'. ***" && false)

run-julia-debug run-julia-release: run-julia-%:
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ New language features
* Unicode identifiers are normalized (NFC) so that different encodings
of equivalent strings are treated as the same identifier ([#5462]).

* If a module contains a function `__init__()`, it will be called when
the module is first loaded, and on process startup if a pre-compiled
version of the module is present ([#1268]).

Library improvements
--------------------

Expand Down Expand Up @@ -282,6 +286,7 @@ Deprecated or removed
[#4996]: https://github.com/JuliaLang/julia/issues/4996
[#2333]: https://github.com/JuliaLang/julia/issues/2333
[#5636]: https://github.com/JuliaLang/julia/issues/5636
[#1268]: https://github.com/JuliaLang/julia/issues/1268

Julia v0.2.0 Release Notes
==========================
Expand Down
57 changes: 28 additions & 29 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function repl_callback(ast::ANY, show_value)
put!(repl_channel, (ast, show_value))
end

_eval_done = Condition()
_repl_start = Condition()

function run_repl()
global const repl_channel = RemoteRef()
Expand All @@ -152,34 +152,51 @@ function run_repl()

# install Ctrl-C interrupt handler (InterruptException)
ccall(:jl_install_sigint_handler, Void, ())
buf = Uint8[0]
@async begin
while !eof(STDIN)
read(STDIN, buf)
ccall(:jl_read_buffer,Void,(Ptr{Void},Cssize_t),buf,1)
if _repl_enough_stdin
wait(_eval_done)
buf = Array(Uint8)
global _repl_enough_stdin = true
input = @async begin
try
while true
if _repl_enough_stdin
wait(_repl_start)
end
try
if eof(STDIN) # if TTY, can throw InterruptException, must be in try/catch block
return
end
read(STDIN, buf)
ccall(:jl_read_buffer,Void,(Ptr{Void},Cssize_t),buf,length(buf))
catch ex
if isa(ex,InterruptException)
println(STDOUT, "^C")
ccall(:jl_reset_input,Void,())
repl_callback(nothing, 0)
else
rethrow(ex)
end
end
end
finally
put!(repl_channel,(nothing,-1))
end
put!(repl_channel,(nothing,-1))
end

while true
while !istaskdone(input)
if have_color
prompt_string = "\01\033[1m\033[32m\02julia> \01\033[0m"*input_color()*"\02"
else
prompt_string = "julia> "
end
ccall(:repl_callback_enable, Void, (Ptr{Uint8},), prompt_string)
global _repl_enough_stdin = false
notify(_repl_start)
start_reading(STDIN)
(ast, show_value) = take!(repl_channel)
if show_value == -1
# exit flag
break
end
eval_user_input(ast, show_value!=0)
notify(_eval_done)
end

if have_color
Expand Down Expand Up @@ -336,11 +353,6 @@ function init_head_sched()
register_worker(LPROC)
end

function init_profiler()
# Use a max size of 1M profile samples, and fire timer every 1ms
Profile.init(1_000_000, 0.001)
end

function load_juliarc()
# If the user built us with a specific Base.SYSCONFDIR, check that location first for a juliarc.jl file
# If it is not found, then continue on to the relative path based on JULIA_HOME
Expand All @@ -354,25 +366,12 @@ end


function _start()
# set up standard streams
reinit_stdio()
fdwatcher_reinit()
# Initialize RNG
Random.librandom_init()
Sys.init()
global const CPU_CORES = Sys.CPU_CORES
if CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
# Prevent openblas from stating to many threads, unless/until specifically requested
ENV["OPENBLAS_NUM_THREADS"] = 8
end
# Check that BLAS is correctly built
check_blas()
LinAlg.init()
GMP.gmp_init()
init_profiler()
start_gc_msgs_task()

#atexit(()->flush(STDOUT))
try
any(a->(a=="--worker"), ARGS) || init_head_sched()
init_load_path()
Expand Down
14 changes: 8 additions & 6 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
_gmp_clear_func = C_NULL
_mpfr_clear_func = C_NULL

function gmp_init()
function __init__()
global _gmp_clear_func = cglobal((:__gmpz_clear, :libgmp))
global _mpfr_clear_func = cglobal((:mpfr_clear, :libmpfr))
ccall((:__gmp_set_memory_functions, :libgmp), Void,
Expand Down Expand Up @@ -262,21 +262,23 @@ for (fJ, fC) in ((:-, :neg), (:~, :com))
end
end

function <<(x::BigInt, c::Uint)
function <<(x::BigInt, c::Int32)
c < 0 && throw(DomainError())
c == 0 && return x
z = BigInt()
ccall((:__gmpz_mul_2exp, :libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Culong), &z, &x, c)
return z
end

function >>>(x::BigInt, c::Uint)
function >>(x::BigInt, c::Int32)
c < 0 && throw(DomainError())
c == 0 && return x
z = BigInt()
ccall((:__gmpz_fdiv_q_2exp, :libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Culong), &z, &x, c)
return z
end

<<(x::BigInt, c::Int32) = c < 0 ? throw(DomainError()) : x << uint(c)
>>>(x::BigInt, c::Int32) = c < 0 ? throw(DomainError()) : x >>> uint(c)
>>(x::BigInt, c::Int32) = x >>> c
>>>(x::BigInt, c::Int32) = x >> c

trailing_zeros(x::BigInt) = int(ccall((:__gmpz_scan1, :libgmp), Culong, (Ptr{BigInt}, Culong), &x, 0))
trailing_ones(x::BigInt) = int(ccall((:__gmpz_scan0, :libgmp), Culong, (Ptr{BigInt}, Culong), &x, 0))
Expand Down
6 changes: 2 additions & 4 deletions base/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ show(io::IO, x::Float16) = _show(io, x, PRECISION, 5, true)
print(io::IO, x::Float32) = _show(io, x, SHORTEST_SINGLE, 0, false)
print(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)

showcompact(io::IO, x::Float64) =
(Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST, 0, false)
showcompact(io::IO, x::Float32) =
(Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST_SINGLE, 0, false)
showcompact(io::IO, x::Float64) = _show(io, x, PRECISION, 6, false)
showcompact(io::IO, x::Float32) = _show(io, x, PRECISION, 6, false)
showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)

# normal:
Expand Down
4 changes: 2 additions & 2 deletions base/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export
axpy!,
bkfact,
bkfact!,
check_blas,
chol,
cholfact,
cholfact!,
Expand Down Expand Up @@ -214,7 +213,8 @@ include("linalg/cholmod.jl")
include("linalg/arpack.jl")
include("linalg/arnoldi.jl")

function init()
function __init__()
Base.check_blas()
if Base.blas_vendor() == :mkl
ccall((:MKL_Set_Interface_Layer, Base.libblas_name), Void, (Cint,), USE_BLAS64 ? 1 : 0)
end
Expand Down
10 changes: 6 additions & 4 deletions base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,16 @@ end
A_ldiv_B!(A::QR, B::StridedVector) = A_ldiv_B!(A, reshape(B, length(B), 1))[:]
A_ldiv_B!(A::QRPivoted, B::StridedVector) = A_ldiv_B!(QR(A.factors,A.τ),B)[invperm(A.jpvt)]
A_ldiv_B!(A::QRPivoted, B::StridedMatrix) = A_ldiv_B!(QR(A.factors,A.τ),B)[invperm(A.jpvt),:]
function \{TA,TB}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),B::StridedVector{TB})
S = promote_type(TA,TB)
function \{TA,Tb}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),b::StridedVector{Tb})
S = promote_type(TA,Tb)
m,n = size(A)
n > m ? A_ldiv_B!(convert(typeof(A).name.primary{S},A),[B,zeros(S,n-m)]) : A_ldiv_B!(convert(typeof(A).name.primary{S},A), S == TB ? copy(B) : convert(Vector{S}, B))
m == length(b) || throw(DimensionMismatch("left hand side has $(m) rows, but right hand side has length $(length(b))"))
n > m ? A_ldiv_B!(convert(typeof(A).name.primary{S},A),[b,zeros(S,n-m)]) : A_ldiv_B!(convert(typeof(A).name.primary{S},A), S == Tb ? copy(b) : convert(Vector{S}, b))
end
function \{TA,TB}(A::Union(QR{TA},QRCompactWY{TA},QRPivoted{TA}),B::StridedMatrix{TB})
S = promote_type(TA,TB)
m,n = size(A)
m == size(B,1) || throw(DimensionMismatch("left hand side has $(m) rows, but right hand side has $(size(B,1)) rows"))
n > m ? A_ldiv_B!(convert(typeof(A).name.primary{S},A),[B;zeros(S,n-m,size(B,2))]) : A_ldiv_B!(convert(typeof(A).name.primary{S},A), S == TB ? copy(B) : convert(Matrix{S}, B))
end

Expand Down Expand Up @@ -820,7 +822,7 @@ svdfact{TA,TB}(A::StridedMatrix{TA}, B::StridedMatrix{TB}) = (S = promote_type(F

function svd(A::AbstractMatrix, B::AbstractMatrix)
F = svdfact(A, B)
F[:U], F[:V], F[:Q]*F[:R0]', F[:D1], F[:D2]
F[:U], F[:V], F[:Q], F[:D1], F[:D2], F[:R0]
end

function getindex{T}(obj::GeneralizedSVD{T}, d::Symbol)
Expand Down
3 changes: 2 additions & 1 deletion base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ function gemv{T<:BlasFloat}(y::StridedVector{T}, tA::Char, A::StridedMatrix{T},
(mA, nA) = size(A)
end

nA==length(x) || mA==length(y) || throw(DimensionMismatch("*"))
nA==length(x) || throw(DimensionMismatch(""))
mA==length(y) || throw(DimensionMismatch(""))
mA == 0 && return zeros(T, 0)
nA == 0 && return zeros(T, mA)
return BLAS.gemv!(tA, one(T), A, x, zero(T), y)
Expand Down
14 changes: 6 additions & 8 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,13 @@ function besselj(nu::Float64, z::Complex128)
end
end

function besselj(nu::Integer, x::FloatingPoint)
nu > typemax(Int32) && throw(DomainError())
return oftype(x, ccall((:jn, libm), Float64, (Cint, Float64), nu, x))
end
besselj(nu::Integer, x::FloatingPoint) = typemin(Int32) <= nu <= typemax(Int32) ?
oftype(x, ccall((:jn, libm), Float64, (Cint, Float64), nu, x)) :
besselj(float64(nu), x)

function besselj(nu::Integer, x::Float32)
nu > typemax(Int32) && throw(DomainError())
return ccall((:jnf, libm), Float32, (Cint, Float32), nu, x)
end
besselj(nu::Integer, x::Float32) = typemin(Int32) <= nu <= typemax(Int32) ?
ccall((:jnf, libm), Float32, (Cint, Float32), nu, x) :
besselj(float64(nu), x)

besselk(nu::Float64, z::Complex128) = _besselk(abs(nu), z)

Expand Down
10 changes: 6 additions & 4 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ function *(x::BigFloat, c::Culong)
return z
end
*(c::Culong, x::BigFloat) = x * c
*(c::Unsigned, x::BigFloat) = x * convert(Culong, c)
*(x::BigFloat, c::Unsigned) = x * convert(Culong, c)
if Culong === Uint64
*(c::Uint32, x::BigFloat) = x * convert(Culong, c)
*(x::BigFloat, c::Uint32) = x * convert(Culong, c)
end

# Signed multiplication
function *(x::BigFloat, c::Clong)
Expand All @@ -243,7 +245,8 @@ function *(x::BigFloat, c::Clong)
return z
end
*(c::Clong, x::BigFloat) = x * c
*(x::BigFloat, c::Signed) = x * convert(Clong, c)
*(x::BigFloat, c::Union(Int8,Uint8,Int16,Uint16,Int32)) = x * convert(Clong, c)
*(c::Union(Int8,Uint8,Int16,Uint16,Int32), x::BigFloat) = x * convert(Clong, c)

# Float64 multiplication
function *(x::BigFloat, c::Float64)
Expand All @@ -256,7 +259,6 @@ end
*(x::BigFloat, c::Float32) = x * convert(Float64, c)

# BigInt multiplication
*(c::Signed, x::BigFloat) = x * convert(Clong, c)
function *(x::BigFloat, c::BigInt)
z = BigFloat()
ccall((:mpfr_mul_z, :libmpfr), Int32, (Ptr{BigFloat}, Ptr{BigFloat}, Ptr{BigInt}, Int32), &z, &x, &c, ROUNDING_MODE[end])
Expand Down
Loading

0 comments on commit 5915346

Please sign in to comment.