Skip to content

Commit

Permalink
fix extrema(A,dim) when length(dim)>1
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarthur committed May 29, 2017
1 parent 1c5cfb0 commit d6ae8c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,7 @@ end
(@nref $N B i) = (AI, AI)
end
Bmax = sB
Istart = Int[sB[i] == 1 != sA[i] ? 2 : 1 for i = 1:ndims(A)]
@inbounds @nloops $N i d->(Istart[d]:size(A,d)) begin
@inbounds @nloops $N i A begin
AI = @nref $N A i
@nexprs $N d->(j_d = min(Bmax[d], i_{d}))
BJ = @nref $N B j
Expand Down
10 changes: 7 additions & 3 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
@test maximum(collect(Int16(1):Int16(100))) === Int16(100)
@test maximum(Int32[1,2]) === Int32(2)

@test extrema(reshape(1:24,2,3,4),1) == reshape([(1,2),(3,4),(5,6),(7,8),(9,10),(11,12),(13,14),(15,16),(17,18),(19,20),(21,22),(23,24)],1,3,4)
@test extrema(reshape(1:24,2,3,4),2) == reshape([(1,5),(2,6),(7,11),(8,12),(13,17),(14,18),(19,23),(20,24)],2,1,4)
@test extrema(reshape(1:24,2,3,4),3) == reshape([(1,19),(2,20),(3,21),(4,22),(5,23),(6,24)],2,3,1)
A = circshift( reshape(1:24,2,3,4), (0,1,1))
@test extrema(A,1) == reshape([(23,24),(19,20),(21,22),(5,6),(1,2),(3,4),(11,12),(7,8),(9,10),(17,18),(13,14),(15,16)],1,3,4)
@test extrema(A,2) == reshape([(19,23),(20,24),(1,5),(2,6),(7,11),(8,12),(13,17),(14,18)],2,1,4)
@test extrema(A,3) == reshape([(5,23),(6,24),(1,19),(2,20),(3,21),(4,22)],2,3,1)
@test extrema(A,(1,2)) == reshape([(19,24),(1,6),(7,12),(13,18)],1,1,4)
@test extrema(A,(1,3)) == reshape([(5,24),(1,20),(3,22)],1,3,1)
@test extrema(A,(2,3)) == reshape([(1,23),(2,24)],2,1,1)

# any & all

Expand Down

0 comments on commit d6ae8c9

Please sign in to comment.