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

Function _SetShapeInvariants

tensorflow/python/ops/control_flow_ops.py:530–559  ·  view source on GitHub ↗

Set the shapes of the tensors in `enter_vars` to `shapes`. Args: input_vars: A list of tensors that are inputs to `enter_vars`. enter_vars: A list of tensors whose shapes will be set. shapes: A (possibly nested) list of shapes. Raises: ValueError: If any tensor in `enter_vars`

(input_vars, enter_vars, shapes)

Source from the content-addressed store, hash-verified

528
529
530def _SetShapeInvariants(input_vars, enter_vars, shapes):
531 """Set the shapes of the tensors in `enter_vars` to `shapes`.
532
533 Args:
534 input_vars: A list of tensors that are inputs to `enter_vars`.
535 enter_vars: A list of tensors whose shapes will be set.
536 shapes: A (possibly nested) list of shapes.
537
538 Raises:
539 ValueError: If any tensor in `enter_vars` has a less specific shape
540 than its corresponding shape in `shapes`.
541 """
542 if shapes is None:
543 return
544 flat_shapes = nest.flatten(shapes)
545 if not all(isinstance(s, tensor_shape.TensorShape) for s in flat_shapes):
546 raise ValueError("`shapes` must be a (possibly nested) list of shapes.")
547 # Check that the shapes of the inputs are less than the shape invariants,
548 # and set the shapes of `enter_vars` to the shape invariants.
549 for inp, var, shape in zip(input_vars, enter_vars, flat_shapes):
550 if isinstance(var, ops.Tensor):
551 if not _ShapeLessThanOrEqual(inp.get_shape(), shape):
552 raise ValueError(
553 "The shape invariant specified for %s is not compatible with "
554 "the initial shape of the loop variable. It enters the loop "
555 "with shape %s, but the specified shape invariant is %s." %
556 (inp.name, inp.get_shape(), shape))
557 var.set_shape(shape)
558 else:
559 raise TypeError("Type %s not supported" % type(var))
560
561
562def _EnforceShapeInvariant(merge_var, next_var):

Callers 1

_BuildLoopMethod · 0.85

Calls 6

allFunction · 0.85
_ShapeLessThanOrEqualFunction · 0.85
typeFunction · 0.85
flattenMethod · 0.45
get_shapeMethod · 0.45
set_shapeMethod · 0.45

Tested by

no test coverage detected