Skip to content

Commit f57b318

Browse files
committed
Preserve offset axes in @progress with comprehension
1 parent f39191e commit f57b318

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Media = "0.5"
1313
julia = "0.7, 1"
1414

1515
[extras]
16+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1617
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1718

1819
[targets]
19-
test = ["Test"]
20+
test = ["Test", "OffsetArrays"]

src/progress.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ end
9898

9999
function _progress(name, thresh, ex, target, result, loop, iter_vars, ranges, body)
100100
count_vars = [Symbol("i$k") for k=1:length(iter_vars)]
101-
iter_exprs = [:(($i,$(esc(v))) = enumerate($(esc(r))))
101+
iter_exprs = [:(($i,$(esc(v))) = pairs($(esc(r))))
102102
for (i,v,r) in zip(count_vars,iter_vars,ranges)]
103103
_id = "progress_$(gensym())"
104104
quote
@@ -107,10 +107,11 @@ function _progress(name, thresh, ex, target, result, loop, iter_vars, ranges, bo
107107
$target = try
108108
ranges = $(Expr(:vect,esc.(ranges)...))
109109
nranges = length(ranges)
110+
starts = firstindex.(ranges)
110111
lens = length.(ranges)
111112
n = prod(lens)
112113
strides = cumprod([1;lens[1:end-1]])
113-
_frac(i) = (sum((i-1)*s for (i,s) in zip(i,strides)) + 1) / n
114+
_frac(i) = (sum((i-j)*s for (i,j,s) in zip(i,starts,strides)) + 1) / n
114115
lastfrac = 0.0
115116

116117

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Juno
22
using Test
3+
using OffsetArrays
34

45
@test Juno.isactive() == false
56

@@ -64,4 +65,11 @@ let a = [], x
6465
@test x == nothing
6566
end
6667

68+
let off1 = -2, off2 = 21
69+
v1 = OffsetArray(1:3, off1)
70+
v2 = OffsetArray(-1:1, off2)
71+
x = @progress y = [i*j for i in v1, j in v2]
72+
@test x == y == OffsetArray([-1 0 1; -2 0 2; -3 0 3], off1, off2)
73+
end
74+
6775
@test Juno.notify("hi") == nothing

0 commit comments

Comments
 (0)