Skip to content

Commit

Permalink
use Base.prod() when computing length(::CartesianIndices) (#524)
Browse files Browse the repository at this point in the history
* use Base.prod() to fix #523

* add tests for length(::CartesianIndices)
  • Loading branch information
rdeits authored and stevengj committed Mar 21, 2018
1 parent 294f171 commit 2bffc98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ end
size(iter::CartesianIndices) = map(dimlength, first(iter).I, last(iter).I)
dimlength(start, stop) = stop-start+1

length(iter::CartesianIndices) = prod(size(iter))
length(iter::CartesianIndices) = Base.prod(size(iter))

first(iter::CartesianIndices) = CartesianIndex(map(first, iter.indices))
last(iter::CartesianIndices) = CartesianIndex(map(last, iter.indices))
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1668,5 +1668,9 @@ end
@test Compat.reverse([1, 2, 3, 4]) == [4, 3, 2, 1]
@test Compat.reverse([1 2; 3 4], dims=1) == [3 4; 1 2]
@test Compat.reverse([1 2; 3 4], dims=2) == [2 1; 4 3]
# Issue #523
@test length(Compat.CartesianIndices((1:1,))) == 1
@test length(Compat.CartesianIndices((1:2,))) == 2
@test length(Compat.CartesianIndices((1:2, -1:1))) == 6

nothing

0 comments on commit 2bffc98

Please sign in to comment.