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

Function _check_same_outputs

tensorflow/python/ops/cond_v2.py:698–739  ·  view source on GitHub ↗

Raises an error if `graphs` have different outputs.

(op_type, graphs)

Source from the content-addressed store, hash-verified

696
697
698def _check_same_outputs(op_type, graphs):
699 """Raises an error if `graphs` have different outputs."""
700
701 def error(branch_idx, error_detail):
702 raise TypeError(
703 "{b0_name} and {bn_name} arguments to {op_name} must have the same "
704 "number, type, and overall structure of return values.\n"
705 "\n"
706 "{b0_name} output: {b0_out}\n"
707 "{bn_name} output: {bn_out}\n"
708 "\n"
709 "Error details:\n"
710 "{detail}".format(
711 b0_name="true_fn" if op_type == _COND else "branches[0]",
712 bn_name=("false_fn" if op_type == _COND else
713 "branches[{}]".format(branch_idx)),
714 op_name="tf.cond" if op_type == _COND else "tf.switch_case",
715 b0_out=graphs[0].structured_outputs,
716 bn_out=graphs[branch_idx].structured_outputs,
717 detail=error_detail))
718
719 for b in range(1, len(graphs)):
720 try:
721 nest.assert_same_structure(
722 graphs[0].structured_outputs,
723 graphs[b].structured_outputs,
724 expand_composites=True)
725 except (ValueError, TypeError) as e:
726 error(b, str(e))
727
728 op_type_str = "cond" if op_type == _COND else "case"
729 if len(graphs[0].outputs) != len(graphs[b].outputs):
730 raise ValueError("Lengths of branch outputs of {op_type} must match.\n"
731 "len(graphs[0].outputs): {len_0}\n"
732 "len(graphs[{b}].outputs): {len_b}\n".format(
733 op_type=op_type_str,
734 len_0=len(graphs[0].outputs),
735 b=b,
736 len_b=len(graphs[b].outputs)))
737 for b0_out, bn_out in zip(graphs[0].outputs, graphs[b].outputs):
738 if b0_out.dtype != bn_out.dtype:
739 error(b, "%s and %s have different types" % (b0_out, bn_out))
740
741
742def _get_output_shapes(*branch_graph_outputs):

Callers 4

_IfGradFunction · 0.85
_build_condFunction · 0.85
_CaseGradFunction · 0.85
_build_caseFunction · 0.85

Calls 3

rangeFunction · 0.70
errorFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected