@@ -187,6 +187,7 @@ function _macro(exone, extwo=nothing, exthree=nothing; call::CallInfo=CallInfo()
187187
188188 # Third pass to standardise & then glue, postwalk sees A[i] before A[i][j]
189189 right3 = MacroTools. postwalk (x -> standardglue (x, canon, store, call), right2)
190+ right3 = checkallseen (right3, canon, store, call)
190191
191192 if ! (:matmul in call. flags)
192193 # Then finally broadcasting if necc (or just permutedims etc. if not):
@@ -196,8 +197,6 @@ function _macro(exone, extwo=nothing, exthree=nothing; call::CallInfo=CallInfo()
196197 right4 = matmultarget (right3, canon, parsed, store, call)
197198 end
198199
199- checkallseen (canon, store, call) # this must be run before inplaceoutput()
200-
201200 # Return to LHS, build up what it requested:
202201 if :inplace in call. flags
203202 rightlist = inplaceoutput (right4, canon, parsed, store, call)
@@ -1344,6 +1343,25 @@ end
13441343# return sortperm(xi) == sortperm(yi)
13451344# end
13461345
1346+ """
1347+ checkallseen(rhs, ...)
1348+
1349+ Now not just a check, but also inserts trivial broadcasting, if needed,
1350+ over indices omitted from the rhs.
1351+ """
1352+ function checkallseen (ex, canon, store, call)
1353+ right = setdiff (store. seen, canon)
1354+ length (right) > 0 && throw (MacroError (" index $(right[1 ]) appears only on the right" , call))
1355+ left = setdiff (canon, unique! (store. seen))
1356+ # length(left) > 0 && throw(MacroError("index $(left[1]) appears only on the left", call))
1357+ if isempty (left)
1358+ ex
1359+ else
1360+ fake = map (i -> recursemacro (i, canon, store, call), left)
1361+ :( TensorCast. onlyfirst ($ ex, $ (fake... )) )
1362+ end
1363+ end
1364+
13471365"""
13481366 needview!([:, 3, A]) # true, need view(A, :,3,:)
13491367 needview!([:, :_, :]) # false, can use rview(A, :,1,:)
@@ -1467,14 +1485,6 @@ function checknorepeats(flat, call=nothing, msg=nothing)
14671485 end
14681486end
14691487
1470- function checkallseen (canon, store, call)
1471- left = setdiff (canon, unique! (store. seen))
1472- length (left) > 0 && throw (MacroError (" index $(left[1 ]) appears only on the left" , call))
1473- right = setdiff (store. seen, canon)
1474- length (right) > 0 && throw (MacroError (" index $(right[1 ]) appears only on the right" , call))
1475- end
1476-
1477- # this may never be necessary with checkallseen?
14781488function findcheck (i:: Symbol , flat:: Vector , call= nothing , msg= nothing )
14791489 msg == nothing && (msg = " in " * string (:( [$ (flat... )] )))
14801490 res = findfirst (isequal (i), flat)
@@ -1590,11 +1600,8 @@ function inplaceoutput(ex, canon, parsed, store::NamedTuple, call::CallInfo)
15901600 newleft = standardise (parsed. left, store, call)
15911601 @capture (newleft, zed_[ijk__]) || throw (MacroError (" failed to parse LHS correctly, $(parsed. left) -> $newleft " ))
15921602
1593- if ! (zed isa Symbol) # then standardise did something!
1603+ if newleft != parsed . left # then standardise did something!
15941604 push! (call. flags, :showfinal )
1595- Zsym = gensym (:reverse )
1596- push! (out, :( local $ Zsym = $ zed ) )
1597- zed = Zsym
15981605 end
15991606 end
16001607
@@ -1619,7 +1626,12 @@ function inplaceoutput(ex, canon, parsed, store::NamedTuple, call::CallInfo)
16191626 end
16201627
16211628 if :showfinal in call. flags
1622- push! (out, parsed. name)
1629+ A = parsed. name
1630+ if A isa Symbol || @capture (A, AA_. ff_)
1631+ else
1632+ A = Symbol (A," _val" ) # exact same symbol is used by standardise()
1633+ end
1634+ push! (out, A)
16231635 end
16241636
16251637 return out
0 commit comments