Skip to content

Commit

Permalink
Add checks that reductions along dimensions are inferred
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jul 15, 2018
1 parent 0c1137c commit 38419ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1927,10 +1927,10 @@ function mapslices(f, A::AbstractArray; dims)
# TODO: maybe support removing dimensions
if !isa(r1, AbstractArray) || ndims(r1) == 0
# If the result of f on a single slice is a scalar then we add singleton
# dimensions. When adding adding the dimensions, we have to respect the
# dimensions. When adding the dimensions, we have to respect the
# index type of the input array (e.g. in the case of OffsetArrays)
tmp = similar(Aslice, typeof(r1), reduced_indices(Aslice, 1:ndims(Aslice)))
tmp[first(CartesianIndices(tmp))] = r1
tmp[firstindex(tmp)] = r1
r1 = tmp
end
nextra = max(0, length(dims)-ndims(r1))
Expand Down
16 changes: 8 additions & 8 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ safe_minabs(A::Array{T}, region) where {T} = safe_mapslices(minimum, abs.(A), re
fill!(r, -1.5)
@test minimum!(abs, r, Areduc, init=false) fill!(r2, -1.5)

@test sum(Areduc, dims=region) safe_sum(Areduc, region)
@test prod(Areduc, dims=region) safe_prod(Areduc, region)
@test maximum(Areduc, dims=region) safe_maximum(Areduc, region)
@test minimum(Areduc, dims=region) safe_minimum(Areduc, region)
@test sum(abs, Areduc, dims=region) safe_sumabs(Areduc, region)
@test sum(abs2, Areduc, dims=region) safe_sumabs2(Areduc, region)
@test maximum(abs, Areduc, dims=region) safe_maxabs(Areduc, region)
@test minimum(abs, Areduc, dims=region) safe_minabs(Areduc, region)
@test @inferred(sum(Areduc, dims=region)) safe_sum(Areduc, region)
@test @inferred(prod(Areduc, dims=region)) safe_prod(Areduc, region)
@test @inferred(maximum(Areduc, dims=region)) safe_maximum(Areduc, region)
@test @inferred(minimum(Areduc, dims=region)) safe_minimum(Areduc, region)
@test @inferred(sum(abs, Areduc, dims=region)) safe_sumabs(Areduc, region)
@test @inferred(sum(abs2, Areduc, dims=region)) safe_sumabs2(Areduc, region)
@test @inferred(maximum(abs, Areduc, dims=region)) safe_maxabs(Areduc, region)
@test @inferred(minimum(abs, Areduc, dims=region)) safe_minabs(Areduc, region)
end

# Test reduction along first dimension; this is special-cased for
Expand Down

0 comments on commit 38419ed

Please sign in to comment.