Skip to content

Commit

Permalink
Merge pull request JuliaLang#17 from JuliaLang/master
Browse files Browse the repository at this point in the history
update to ea17459
  • Loading branch information
tkelman committed Mar 14, 2014
2 parents eef34f8 + ea17459 commit 7889544
Show file tree
Hide file tree
Showing 43 changed files with 735 additions and 222 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ New language features
the module is first loaded, and on process startup if a pre-compiled
version of the module is present ([#1268]).

* Multi-line comments ([#69], [#6128]): `#= .... =#`

* --bounds-check=yes|no compiler option

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

Expand Down
7 changes: 0 additions & 7 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,6 @@ imag{T<:Real}(x::AbstractArray{T}) = zero(x)

\(A::Number, B::AbstractArray) = B ./ A

./(x::Number,y::AbstractArray ) = throw(MethodError(./, (x,y)))
./(x::AbstractArray, y::Number) = throw(MethodError(./, (x,y)))

.^(x::Number,y::AbstractArray ) = throw(MethodError(.^, (x,y)))
.^(x::AbstractArray, y::Number) = throw(MethodError(.^, (x,y)))


## Indexing: getindex ##

getindex(t::AbstractArray, i::Real) = error("indexing not defined for ", typeof(t))
Expand Down
15 changes: 8 additions & 7 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ convert{T,n,S}(::Type{Array{T,n}}, x::Array{S,n}) = copy!(similar(x,T), x)

convert{T,S,N}(::Type{AbstractArray{T,N}}, B::StridedArray{S,N}) = copy!(similar(B,T), B)

function collect{C}(T::Type, itr::C)
if method_exists(length,(C,))
a = Array(T,length(itr))
function collect(T::Type, itr)
if applicable(length, itr)
# when length() isn't defined this branch might pollute the
# type of the other.
a = Array(T,length(itr)::Integer)
i = 0
for x in itr
a[i+=1] = x
Expand All @@ -276,9 +278,8 @@ function collect{C}(T::Type, itr::C)
end
return a
end
function collect{C}(itr::C)
method_exists(eltype,(C,)) ? collect(eltype(itr),itr) : [x for x in itr]
end

collect(itr) = collect(eltype(itr), itr)

## Indexing: getindex ##

Expand Down Expand Up @@ -786,7 +787,7 @@ for f in (:+, :-, :div, :mod, :&, :|, :$)
end
end
end
for f in (:.+, :.-, :.*, :./, :.%, :div, :mod, :rem, :&, :|, :$)
for f in (:.+, :.-, :.*, :./, :.\, :.%, :div, :mod, :rem, :&, :|, :$)
@eval begin
function ($f){T}(A::Number, B::StridedArray{T})
F = similar(B, promote_array_type(typeof(A),T))
Expand Down
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export
#checked_smul, checked_ssub, checked_uadd, checked_umul, checked_usub,
#nan_dom_err, copysign_float, ctlz_int, ctpop_int, cttz_int,
#div_float, eq_float, eq_int, eqfsi64, eqfui64, flipsign_int, select_value,
#fpext64, fpiseq, fpislt, fpsiround, fpuiround, fptosi, fptoui,
#sqrt_llvm, fpext64, fpiseq, fpislt, fpsiround, fpuiround, fptosi, fptoui,
#fptrunc32, le_float, lefsi64, lefui64, lesif64,
#leuif64, lshr_int, lt_float, ltfsi64, ltfui64, ltsif64, ltuif64, mul_float,
#mul_int, ne_float, ne_int, neg_float, neg_int, not_int, or_int, rem_float,
Expand Down
91 changes: 25 additions & 66 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Broadcast

using ..Cartesian
import Base.promote_eltype
import Base.@get!
import Base.num_bit_chunks, Base.@_msk_end, Base.getindex_unchecked
import Base.(.+), Base.(.-), Base.(.*), Base.(./), Base.(.\)
import Base.(.==), Base.(.<), Base.(.!=), Base.(.<=)
Expand Down Expand Up @@ -203,73 +204,31 @@ function gen_broadcast_function_tobitarray(genbody::Function, nd::Int, narrays::
end
end

let broadcast_cache = Dict()
global broadcast!
function broadcast!(f::Function, B, As::Union(Array,BitArray)...)
nd = ndims(B)
narrays = length(As)
key = (f, nd, narrays)
if !haskey(broadcast_cache, key)
func = gen_broadcast_function(gen_broadcast_body_iter, nd, narrays, f)
broadcast_cache[key] = func
else
func = broadcast_cache[key]
end
func(B, As...)
B
end
end # let broadcast_cache

let broadcast_cache = Dict()
global broadcast!
function broadcast!(f::Function, B::BitArray, As::Union(Array,BitArray)...)
nd = ndims(B)
narrays = length(As)
key = (f, nd, narrays)
if !haskey(broadcast_cache, key)
func = gen_broadcast_function_tobitarray(gen_broadcast_body_iter_tobitarray, nd, narrays, f)
broadcast_cache[key] = func
else
func = broadcast_cache[key]
end
func(B, As...)
B
end
end # let broadcast_cache

let broadcast_cache = Dict()
global broadcast!
function broadcast!(f::Function, B, As...)
nd = ndims(B)
narrays = length(As)
key = (f, nd, narrays)
if !haskey(broadcast_cache, key)
func = gen_broadcast_function(gen_broadcast_body_cartesian, nd, narrays, f)
broadcast_cache[key] = func
else
func = broadcast_cache[key]
end
func(B, As...)
B
end
end # let broadcast_cache

let broadcast_cache = Dict()
global broadcast!
function broadcast!(f::Function, B::BitArray, As...)
nd = ndims(B)
narrays = length(As)
key = (f, nd, narrays)
if !haskey(broadcast_cache, key)
func = gen_broadcast_function_tobitarray(gen_broadcast_body_cartesian_tobitarray, nd, narrays, f)
broadcast_cache[key] = func
else
func = broadcast_cache[key]
end
func(B, As...)
B
for (Bsig, Asig, gbf, gbb) in
((BitArray , Union(Array,BitArray) ,
:gen_broadcast_function_tobitarray, :gen_broadcast_body_iter_tobitarray ),
(Any , Union(Array,BitArray) ,
:gen_broadcast_function , :gen_broadcast_body_iter ),
(BitArray , Any ,
:gen_broadcast_function_tobitarray, :gen_broadcast_body_cartesian_tobitarray),
(Any , Any ,
:gen_broadcast_function , :gen_broadcast_body_cartesian ))

@eval let cache = Dict{Function,Dict{Int,Dict{Int,Function}}}()
global broadcast!
function broadcast!(f::Function, B::$Bsig, As::$Asig...)
nd = ndims(B)
narrays = length(As)

cache_f = @get! cache f Dict{Int,Dict{Int,Function}}()
cache_f_na = @get! cache_f narrays Dict{Int,Function}()
func = @get! cache_f_na nd $gbf($gbb, nd, narrays, f)

func(B, As...)
B
end
end # let broadcast_cache
end
end # let broadcast_cache


broadcast(f::Function, As...) = broadcast!(f, Array(promote_eltype(As...), broadcast_shape(As...)), As...)
Expand Down
7 changes: 5 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,17 @@ function load_juliarc()
try_include(abspath(homedir(),".juliarc.jl"))
end


function _start()
function early_init()
Sys.init_sysinfo()
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
start_gc_msgs_task()
end

function _start()
early_init()

try
any(a->(a=="--worker"), ARGS) || init_head_sched()
Expand Down
20 changes: 20 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,26 @@ function get!{K,V}(default::Function, h::Dict{K,V}, key0)
return v
end

# NOTE: this macro is specific to Dict, not Associative, and should
# therefore not be exported as-is: it's for internal use only.
macro get!(h, key0, default)
quote
K, V = eltype($(esc(h)))
key = convert(K, $(esc(key0)))
isequal(key, $(esc(key0))) || error($(esc(key0)), " is not a valid key for type ", K)
idx = ht_keyindex2($(esc(h)), key)
if idx < 0
idx = -idx
v = convert(V, $(esc(default)))
_setindex!($(esc(h)), v, key, idx)
else
@inbounds v = $(esc(h)).vals[idx]
end
v
end
end


function getindex{K,V}(h::Dict{K,V}, key)
index = ht_keyindex(h, key)
return (index<0) ? throw(KeyError(key)) : h.vals[index]::V
Expand Down
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ nextpow2(x::Integer) = oftype(x,x < 0 ? -nextpow2(unsigned(-x)) : nextpow2(unsig
prevpow2(x::Unsigned) = (one(x)>>(x==0)) << ((sizeof(x)<<3)-leading_zeros(x)-1)
prevpow2(x::Integer) = oftype(x,x < 0 ? -prevpow2(unsigned(-x)) : prevpow2(unsigned(x)))

ispow2(x::Integer) = ((x<=0) == (x&(x-1)))
ispow2(x::Integer) = count_ones(x)==1

# smallest a^n >= x, with integer n
function nextpow(a::Real, x::Real)
Expand Down
12 changes: 2 additions & 10 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,9 @@ function done(itr::EachLine, nada)
true
end
next(itr::EachLine, nada) = (readline(itr.stream), nothing)
eltype(itr::EachLine) = ByteString

function readlines(s, fx::Function...)
a = {}
for l in eachline(s)
for f in fx
l = f(l)
end
push!(a, l)
end
return a
end
readlines(s) = collect(eachline(s))


## IOStream
Expand Down
Loading

0 comments on commit 7889544

Please sign in to comment.