MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _EnforceShapeInvariant

Function _EnforceShapeInvariant

tensorflow/python/ops/control_flow_ops.py:562–588  ·  view source on GitHub ↗

Check if the shapes of the loops variables are invariants. Args: merge_var: The list of tensors representing the initial values of the loop variables. next_var: The list of tensors representing the values of the loop variables after one loop iteration. Raises: ValueErro

(merge_var, next_var)

Source from the content-addressed store, hash-verified

560
561
562def _EnforceShapeInvariant(merge_var, next_var):
563 """Check if the shapes of the loops variables are invariants.
564
565 Args:
566 merge_var: The list of tensors representing the initial values of the loop
567 variables.
568 next_var: The list of tensors representing the values of the loop variables
569 after one loop iteration.
570
571 Raises:
572 ValueError: If any tensor in `merge_var` has a more specific shape than
573 its correspnding tensor in `next_var`.
574 """
575 if isinstance(merge_var, ops.Tensor):
576 m_shape = merge_var.get_shape()
577 n_shape = next_var.get_shape()
578 if not _ShapeLessThanOrEqual(n_shape, m_shape):
579 enter = merge_var.op.inputs[0].op
580 assert util.IsLoopEnter(enter)
581 input_t = enter.inputs[0]
582 raise ValueError(
583 "Input tensor '%s' enters the loop with shape %s, but has shape %s "
584 "after one iteration. To allow the shape to vary across iterations, "
585 "use the `shape_invariants` argument of tf.while_loop to specify a "
586 "less-specific shape." % (input_t.name, input_t.shape, n_shape))
587 else:
588 raise TypeError("Type %s not supported" % type(merge_var))
589
590
591def _AddNextAndBackEdge(m, v, enforce_shape_invariant=True):

Callers 1

_AddNextAndBackEdgeFunction · 0.85

Calls 3

_ShapeLessThanOrEqualFunction · 0.85
typeFunction · 0.85
get_shapeMethod · 0.45

Tested by

no test coverage detected