Skip to content

Commit

Permalink
Merge pull request #70 from JuliaParallel/anj/05
Browse files Browse the repository at this point in the history
Update to 0.5 changes. The factor function is now in the Primes.jl
  • Loading branch information
andreasnoack committed May 29, 2016
2 parents 1458fd7 + 0292b0c commit 0215b9d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.4
Compat 0.7.14
Primes
22 changes: 13 additions & 9 deletions src/DistributedArrays.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
VERSION >= v"0.4.0-dev+6521" && __precompile__(true)

# TODO
# - avoid temporary darrays being created by sum, mean, std, etc when called along specific dimensions

__precompile__(true)

module DistributedArrays

using Compat

if VERSION >= v"0.5.0-dev+4340"
using Primes
using Primes: factor
end

if VERSION < v"0.5.0-"
typealias Future RemoteRef
typealias Future RemoteRef
end

importall Base
Expand Down Expand Up @@ -675,7 +676,7 @@ function _mapreduce(f, opt, d::DArray)
end
reduce(opt, results)
end
Base.mapreduce(f, opt::Union{typeof(@functorize |), typeof(@functorize &)}, d::DArray) = _mapreduce(f, opt, d)
Base.mapreduce(f, opt::Union{typeof(@functorize(|)), typeof(@functorize(&))}, d::DArray) = _mapreduce(f, opt, d)
Base.mapreduce(f, opt::Function, d::DArray) = _mapreduce(f, opt, d)
Base.mapreduce(f, opt, d::DArray) = _mapreduce(f, opt, d)

Expand Down Expand Up @@ -760,6 +761,9 @@ Base.scale!(A::DArray, x::Number) = begin
return A
end

# TODO
# - avoid temporary darrays being created by sum, mean, std, etc when called along specific dimensions

# reduce like
for (fn, fr) in ((:sum, :+),
(:prod, :*),
Expand All @@ -783,7 +787,7 @@ for (fn, fr) in ((:any, :|),
(:all, :&),
(:count, :+))
@eval begin
(Base.$fn)(f::typeof(@functorize identity), d::DArray) = mapreduce(f, @functorize($fr), d)
(Base.$fn)(f::typeof(@functorize(identity)), d::DArray) = mapreduce(f, @functorize($fr), d)
(Base.$fn)(f::Base.Predicate, d::DArray) = mapreduce(f, @functorize($fr), d)
# (Base.$fn)(f::Base.Func{1}, d::DArray) = mapreduce(f, @functorize $fr, d)
(Base.$fn)(f::Callable, d::DArray) = mapreduce(f, @functorize($fr), d)
Expand Down Expand Up @@ -1037,7 +1041,7 @@ function dot(x::DVector, y::DVector)
@async push!(results, remotecall_fetch((x, y, i) -> dot(localpart(x), fetch(y, i)), x.pids[i], x, y, i))
end
end
return reduce(@functorize +, results)
return reduce(@functorize(+), results)
end

function norm(x::DVector, p::Real = 2)
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
FactCheck 0.2.3-
StatsBase
12 changes: 10 additions & 2 deletions test/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,20 @@ check_leaks()
# Commented out tests that need to be enabled in due course when DArray support is more complete
facts("test mapslices") do
a = drand((5,5), workers(), [1, min(nworkers(), 5)])
h = mapslices(v -> hist(v,0:0.1:1)[2], a, 1)
if VERSION < v"0.5.0-dev+4361"
h = mapslices(v -> hist(v,0:0.1:1)[2], a, 1)
else
h = mapslices(v -> fit(Histogram,v,0:0.1:1).weights, a, 1)
end
# H = mapslices(v -> hist(v,0:0.1:1)[2], a, 2)
# s = mapslices(sort, a, [1])
# S = mapslices(sort, a, [2])
for i = 1:5
@fact h[:,i] --> hist(a[:,i],0:0.1:1)[2]
if VERSION < v"0.5.0-dev+4361"
@fact h[:,i] --> hist(a[:,i],0:0.1:1)[2]
else
@fact h[:,i] --> fit(Histogram, a[:,i],0:0.1:1).weights
end
# @fact vec(H[i,:]) => hist(vec(a[i,:]),0:0.1:1)[2]
# @fact s[:,i] => sort(a[:,i])
# @fact vec(S[i,:]) => sort(vec(a[i,:]))
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# add at least 3 worker processes
if nworkers() < 3
n = max(3, min(8, CPU_CORES))
n = max(3, min(8, Sys.CPU_CORES))
addprocs(n; exeflags=`--check-bounds=yes`)
end
@assert nprocs() > 3
Expand All @@ -10,8 +10,9 @@ end
# https://github.com/JuliaLang/julia/issues/15766. Move back to top when bug is fixed.
using FactCheck
using DistributedArrays
using StatsBase # for fit(Histogram, ...)
@everywhere using StatsBase # because exported functions are not exported on workers with using

@everywhere blas_set_num_threads(1)
@everywhere srand(123 + myid())

include("darray.jl")
Expand Down

0 comments on commit 0215b9d

Please sign in to comment.