Skip to content

Commit 6044030

Browse files
authored
Merge pull request #105 from mcabbott/indexdiv2
Disallow `div` in indexing
2 parents 23fd3aa + 0c0914b commit 6044030

File tree

4 files changed

+9
-42
lines changed

4 files changed

+9
-42
lines changed

src/shifts.jl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,6 @@ issubset(addranges(1:10, 1:3) .- 1, 1:10)
6868
issubset(addranges(1:10, 1:3) .- 3, 1:10)
6969
=#
7070

71-
# # This is to get range of j in A[j÷2], from axes(A,1):
72-
73-
function mulrange(r::AbstractUnitRange, f::Integer)
74-
first(r)*f : last(r)*f
75-
end
76-
77-
function dotdiv(r::AbstractUnitRange, f::Integer)
78-
first(r)÷f : last(r)÷f
79-
end
80-
81-
#=
82-
mulrange(1:10, 2) .÷ 2 |> unique
83-
mulrange(0:10, 2) .÷ 2 |> unique
84-
mulrange(1:11, 2) .÷ 2 |> unique
85-
86-
mulrange(1:10, 3) .÷ 3 |> unique
87-
mulrange(-10:-1, 3) .÷ 3 |> unique
88-
mulrange(-11:-1, 3) .÷ 3 |> unique
89-
mulrange(-11:-2, 3) .÷ 3 |> unique
90-
mulrange(-12:-3, 3) .÷ 3 |> unique
91-
=#
92-
9371
# This is for A[I[j]] (where this range must be a subset of axes(A,1))
9472
# and for A[I[j]+k] (where it enters into the calculation of k's range).
9573

@@ -184,10 +162,8 @@ function range_expr_walk(r, ex::Expr, con=[])
184162
elseif op == :*
185163
is_const(a) && return range_expr_walk(:($divrange($r, $a)), b)
186164
is_const(b) && return range_expr_walk(:($divrange($r, $b)), a)
187-
elseif op == :÷
188-
is_const(b) && return range_expr_walk(:($mulrange($r, $b)), a)
189-
elseif op == :/
190-
throw("not sure what to do with $ex, perhaps you wanted ÷")
165+
elseif op in (:÷, :/)
166+
throw("division using ÷ or / in indexing is not supported")
191167
end
192168
elseif length(ex.args) > 3
193169
op, a, b, c = ex.args[1:4]
@@ -259,8 +235,6 @@ range_unwrap(ex::Expr) = begin
259235
elseif op == :-
260236
is_const(a) && return :($a .- $(range_unwrap(b)))
261237
is_const(b) && return :($(range_unwrap(a)) .- $b)
262-
elseif op == :÷
263-
is_const(b) && return :($dotdiv($(range_unwrap(a)), $b))
264238
end
265239
end
266240
throw("don't know how to handle $ex, sorry")

test/gradients.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,12 @@ end
226226
@printline
227227

228228
## scalar -- one with :=, one without
229-
sc1(x) = @tullio s = r22[b,β] * x[a,b,c] * r312[c,a,β] avx=false
229+
sc1(x) = @tullio s = r22[b,β] * x[a,b,c] * r312[c,a,β] avx=false verbose=true
230230
@test gradtest(sc1, (1,2,3)) # UndefVarError: ####op#798_0 not defined
231231

232-
sc2(x) = @tullio s := x[γ,c] * r3399[c,γ,i,i] avx=false
232+
@printline
233+
234+
sc2(x) = @tullio s := x[γ,c] * r3399[c,γ,i,i] avx=false verbose=true
233235
@test gradtest(sc2, (3,3))
234236

235237
end
@@ -354,7 +356,9 @@ if Tullio._GRAD[] != :Dual
354356
# relu(x) = max(x, zero(x))
355357
# lay2(x) = @tullio y[i,k] := mat[i,j] * x[j,k] |> relu
356358

357-
mx3(x) = @tullio (max) r[i] := x[i,j]^3 |> cbrt
359+
@printline
360+
361+
mx3(x) = @tullio (max) r[i] := x[i,j]^3 |> cbrt avx=false # sometimes gets stuck here?
358362
mx3(mat) # hmmm what is this?
359363
_gradient(summx3, mat)[1] # zero
360364

test/parsing.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,6 @@ using OffsetArrays
352352
@test axes(@tullio J[i,j] := A[-2j+i] + 0 * B[j]) == (9:12, 1:4)
353353
@test axes(@tullio J[i,j] := A[2i-2j] + 0 * B[j]) == (5:6, 1:4)
354354

355-
@test axes(@tullio I[i,j] := A[i+j÷2] + 0 * B[j]) == (1:8, 1:4)
356-
@test axes(@tullio I[i,j] := A[i+(j-1)÷2] + 0 * B[j]) == (1:9, 1:4)
357-
@test axes(@tullio I[i,j] := A[2i+(j-1)÷2] + 0 * B[j] avx=false) == (1:4, 1:4) # wtf?
358-
@test axes(@tullio I[i,j] := A[i+(j-1)÷3] + 0 * B[j]) == (1:9, 1:4)
359-
360355
@test_throws LoadError @eval @tullio I[i,j] := A[i+j] # under-specified
361356

362357
# in-place

test/utils.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ using Tullio: range_expr_walk, divrange, minusrange, subranges, addranges
5151
(i -> -1+2i, :(-1+2i)),
5252
(i -> 1-3i, :(1-3i)),
5353
(i -> 1-3(i+4), :(1-3(i+4))),
54-
# ÷
55-
(i -> i÷2, :(i÷2)),
56-
(i -> 1+i÷3, :(1+i÷3)),
57-
(i -> 1+(i-1)÷3, :(1+(i-1)÷3)),
5854
# triple...
5955
(i -> i+1+2, :(i+1+2)),
6056
(i -> 1+2+i, :(1+2+i)),
@@ -63,7 +59,6 @@ using Tullio: range_expr_walk, divrange, minusrange, subranges, addranges
6359
(i -> 1+2+3+4(-i), :(1+2+3+4(-i))),
6460
# evil
6561
(i -> (2i+1)*3+4, :((2i+1)*3+4)),
66-
(i -> 3-(-i)÷2, :(3-(-i)÷2)), # needs divrange_minus
6762
]
6863
rex, i = range_expr_walk(:($r .+ 0), ex)
6964
@test issubset(sort(f.(eval(rex))), r)
@@ -75,7 +70,6 @@ using Tullio: range_expr_walk, divrange, minusrange, subranges, addranges
7570
@test extrema(eval(rex)) == (first(r)-1-2, last(r)-1+5)
7671

7772
@test range_expr_walk(:($r .+ 0), :(i+j))[2] == (:i, :j) # weak test!
78-
@test range_expr_walk(:($r .+ 0), :(2i+(j-1)÷3))[2] == (:i, :j) # weak test!
7973

8074
# range adjusting functions
8175
@test minusrange(r) == divrange(r, -1)

0 commit comments

Comments
 (0)