Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 3, 2013
2 parents 0d39ee4 + 99295d2 commit 0753988
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
26 changes: 1 addition & 25 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1381,30 +1381,6 @@ end

## map over arrays ##

## along an axis
function amap(f::Function, A::AbstractArray, axis::Integer)
warn_once("amap is deprecated, use mapslices(f, A, dims) instead")
dimsA = size(A)
ndimsA = ndims(A)
axis_size = dimsA[axis]

if axis_size == 0
return f(A)
end

idx = ntuple(ndimsA, j -> j == axis ? 1 : 1:dimsA[j])
r = f(sub(A, idx))
R = Array(typeof(r), axis_size)
R[1] = r

for i = 2:axis_size
idx = ntuple(ndimsA, j -> j == axis ? i : 1:dimsA[j])
R[i] = f(sub(A, idx))
end

return R
end

## transform any set of dimensions
## dims specifies which dimensions will be transformed. for example
## dims==1:2 will call f on all slices A[:,:,...]
Expand Down Expand Up @@ -1440,7 +1416,7 @@ function mapslices(f::Function, A::AbstractArray, dims::AbstractVector)
if isempty(size(r1))
r1 = [r1]
end
Rsize[dims] = [size(r1)...]
Rsize[dims] = [size(r1)...; ones(Int,max(0,length(dims)-ndims(r1)))]
R = similar(r1, tuple(Rsize...))

ridx = cell(ndims(R))
Expand Down
24 changes: 24 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,27 @@ export assign

typealias ComplexPair Complex
export ComplexPair

## along an axis
function amap(f::Function, A::AbstractArray, axis::Integer)
warn_once("amap is deprecated, use mapslices(f, A, dims) instead")
dimsA = size(A)
ndimsA = ndims(A)
axis_size = dimsA[axis]

if axis_size == 0
return f(A)
end

idx = ntuple(ndimsA, j -> j == axis ? 1 : 1:dimsA[j])
r = f(sub(A, idx))
R = Array(typeof(r), axis_size)
R[1] = r

for i = 2:axis_size
idx = ntuple(ndimsA, j -> j == axis ? i : 1:dimsA[j])
R[i] = f(sub(A, idx))
end

return R
end
14 changes: 7 additions & 7 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1130,15 +1130,15 @@ function erfcinv(y::Float32)
else # Table 50 in Blair et al.
t = 1.0f0 / sqrt(-log(y))
return @horner(t, 0.15504_70003_116f0,
0.13827_19649_631f1,
0.69096_93488_87f0,
-0.11280_81391_617f1,
0.68054_42468_25f0,
-0.16444_15679_1f0) /
0.13827_19649_631f1,
0.69096_93488_87f0,
-0.11280_81391_617f1,
0.68054_42468_25f0,
-0.16444_15679_1f0) /
(t *
@horner(t, 0.15502_48498_22f0,
0.13852_28141_995f1,
0.1f1))
0.13852_28141_995f1,
0.1f1))
end
end

Expand Down
8 changes: 6 additions & 2 deletions base/pkg2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edit(f::Function, pkg, args...) = Dir.cd() do
error("unknown package $pkg")
end
r_ = f(r,pkg,args...)
r_ == r && return info("nothing to be done.")
r_ == r && return info("Nothing to be done.")
reqs_ = Reqs.parse(r_)
reqs_ != reqs && resolve(reqs_,avail)
Reqs.write("REQUIRE",r_)
Expand All @@ -44,6 +44,10 @@ update() = Dir.cd() do
Git.run(`pull -q`)
end
avail = Read.available()
for pkg in filter!(Read.isinstalled,[keys(avail)...])
Cache.prefetch(pkg, Read.url(pkg), [a.sha1 for (v,a)=avail[pkg]])
end
info("Computing changes...")
instd = Read.installed(avail)
fixed = Read.fixed(avail,instd)
for (pkg,ver) in fixed
Expand Down Expand Up @@ -85,7 +89,7 @@ resolve(
# compare what is installed with what should be
install, update, remove = Query.diff(have, want)
if isempty(install) && isempty(update) && isempty(remove)
return info("no packages to install, update or remove.")
return info("No packages to install, update or remove.")
end

# prefetch phase isolates network activity, nothing to roll back
Expand Down
3 changes: 2 additions & 1 deletion base/pkg2/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function prefetch{S<:String}(pkg::String, url::String, sha1s::Vector{S})
Git.run(`config remote.origin.url $url`, dir=cache)
end
if !all(sha1->Git.iscommit(sha1, dir=cache), sha1s)
Git.run(`remote update`, dir=cache, out=SpawnNullStream())
Git.success(`remote update`, dir=cache) ||
error("couldn't update $cache using `git remote update`")
end
filter(sha1->!Git.iscommit(sha1, dir=cache), sha1s)
end
Expand Down
2 changes: 1 addition & 1 deletion base/pkg2/dir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function cd(f::Function, d::String=path())
if haskey(ENV,"JULIA_PKGDIR")
error("Package directory $d doesn't exist; run Pkg.init() to create it.")
else
info("Auto-initializing default package repository $d.")
info("Initializing package repository $d.")
init()
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,14 @@ begin
@test s[:,i] == sort(a[:,i])
@test vec(S[i,:]) == sort(vec(a[i,:]))
end

# issue #3613
b = mapslices(sum, ones(2,3,4), [1,2])
@test size(b) === (1,1,4)
@test all(b.==6)
end


# single multidimensional index
let
a = rand(6,6)
Expand Down

0 comments on commit 0753988

Please sign in to comment.