MCPcopy
hub / github.com/dask/dask / _match

Function _match

dask/rewrite.py:374–409  ·  view source on GitHub ↗

Structural matching of term S to discrimination net node N.

(S, N)

Source from the content-addressed store, hash-verified

372
373
374def _match(S, N):
375 """Structural matching of term S to discrimination net node N."""
376
377 stack = deque()
378 restore_state_flag = False
379 # matches are stored in a tuple, because all mutations result in a copy,
380 # preventing operations from changing matches stored on the stack.
381 matches = ()
382 while True:
383 if S.current is END:
384 yield N.patterns, matches
385 try:
386 # This try-except block is to catch hashing errors from un-hashable
387 # types. This allows for variables to be matched with un-hashable
388 # objects.
389 n = N.edges.get(S.current, None)
390 if n and not restore_state_flag:
391 stack.append((S.copy(), N, matches))
392 N = n
393 S.next()
394 continue
395 except TypeError:
396 pass
397 n = N.edges.get(VAR, None)
398 if n:
399 restore_state_flag = False
400 matches = matches + (S.term,)
401 S.skip()
402 N = n
403 continue
404 try:
405 # Backtrack here
406 S, N, matches = stack.pop()
407 restore_state_flag = True
408 except Exception:
409 return
410
411
412def _process_match(rule, syms):

Callers 1

iter_matchesMethod · 0.85

Calls 5

nextMethod · 0.80
skipMethod · 0.80
popMethod · 0.80
getMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…