From b35eaa7e1b7de6db2554a556273f5cdd414ddba3 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 21 Mar 2018 11:04:05 -0400 Subject: [PATCH 1/2] use Base.prod() to fix #523 --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index cb12d5512..f1835344f 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -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)) From 3de731bd9dad9aaca0d029299464619d01946c4c Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 21 Mar 2018 11:08:07 -0400 Subject: [PATCH 2/2] add tests for length(::CartesianIndices) --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 0245b5277..fe5e3c898 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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