Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Fix reducedim test for cartesianmap->CartesianRange
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Oct 7, 2015
1 parent 36413ab commit 05799ab
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions test/reducedim.jl
Expand Up @@ -79,24 +79,48 @@ function safe_mapslices{T}(f::Function, A::AbstractArray{T}, region, skipna)

first = true

Base.cartesianmap(itershape) do idxs...
if first
first = false
else
ia = [idxs...]
idx[otherdims] = ia
ridx[otherdims] = ia
try
R[ridx...] = f(reshape(A[idx...], Asliceshape); skipna=skipna)
catch e
if (isa(e, ErrorException) && e.msg == "Reducing over an empty array is not allowed.") ||
(isa(e, ArgumentError) && e.msg == "reducing over an empty collection is not allowed")

R[ridx...] = NA
else
println(typeof(e))
println(e.msg)
rethrow(e)
if VERSION < v"0.4.0-"
cartesianmap(itershape) do idxs...
if first
first = false
else
ia = [idxs...]
idx[otherdims] = ia
ridx[otherdims] = ia
try
R[ridx...] = f(reshape(A[idx...], Asliceshape); skipna=skipna)
catch e
if (isa(e, ErrorException) && e.msg == "Reducing over an empty array is not allowed.") ||
(isa(e, ArgumentError) && e.msg == "reducing over an empty collection is not allowed")

R[ridx...] = NA
else
println(typeof(e))
println(e.msg)
rethrow(e)
end
end
end
end
else
for idxs = CartesianRange(itershape)
if first
first = false
else
ia = [idxs.I...]
idx[otherdims] = ia
ridx[otherdims] = ia
try
R[ridx...] = f(reshape(A[idx...], Asliceshape); skipna=skipna)
catch e
if (isa(e, ErrorException) && e.msg == "Reducing over an empty array is not allowed.") || (isa(e, ArgumentError) && e.msg == "reducing over an empty collection is not allowed")

R[ridx...] = NA
else
println(typeof(e))
println(e.msg)
rethrow(e)
end
end
end
end
Expand Down

0 comments on commit 05799ab

Please sign in to comment.