tf.contrib.framework.nest.assert_shallow_structure
Stay organized with collections
Save and categorize content based on your preferences.
Asserts that shallow_tree
is a shallow structure of input_tree
.
tf.contrib.framework.nest.assert_shallow_structure(
shallow_tree, input_tree, check_types=True, expand_composites=False,
check_subtrees_length=True
)
That is, this function tests if the input_tree
structure can be created from
the shallow_tree
structure by replacing its leaf nodes with deeper
tree structures.
Examples:
The following code will raise an exception:
shallow_tree = {"a": "A", "b": "B"}
input_tree = {"a": 1, "c": 2}
assert_shallow_structure(shallow_tree, input_tree)
The following code will raise an exception:
shallow_tree = ["a", "b"]
input_tree = ["c", ["d", "e"], "f"]
assert_shallow_structure(shallow_tree, input_tree)
The following code will not raise an exception:
shallow_tree = ["a", "b"]
input_tree = ["c", ["d", "e"], "f"]
assert_shallow_structure(shallow_tree, input_tree,
check_subtrees_length=False)
Args |
shallow_tree
|
an arbitrarily nested structure.
|
input_tree
|
an arbitrarily nested structure.
|
check_types
|
if True (default) the sequence types of shallow_tree and
input_tree have to be the same. Note that even with check_types==True,
this function will consider two different namedtuple classes with the same
name and _fields attribute to be the same class.
|
expand_composites
|
If true, then composite tensors such as tf.SparseTensor
and tf.RaggedTensor are expanded into their component tensors.
|
check_subtrees_length
|
if True (default) the subtrees shallow_tree and
input_tree have to be the same length. If False sequences are treated
as key-value like mappings allowing them to be considered as valid
subtrees. Note that this may drop parts of the input_tree .
|
Raises |
TypeError
|
If shallow_tree is a sequence but input_tree is not.
|
TypeError
|
If the sequence types of shallow_tree are different from
input_tree . Only raised if check_types is True .
|
ValueError
|
If the sequence lengths of shallow_tree are different from
input_tree .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.framework.nest.assert_shallow_structure\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/util/nest.py#L651-L779) |\n\nAsserts that `shallow_tree` is a shallow structure of `input_tree`. \n\n tf.contrib.framework.nest.assert_shallow_structure(\n shallow_tree, input_tree, check_types=True, expand_composites=False,\n check_subtrees_length=True\n )\n\nThat is, this function tests if the `input_tree` structure can be created from\nthe `shallow_tree` structure by replacing its leaf nodes with deeper\ntree structures.\n\n#### Examples:\n\nThe following code will raise an exception: \n\n shallow_tree = {\"a\": \"A\", \"b\": \"B\"}\n input_tree = {\"a\": 1, \"c\": 2}\n assert_shallow_structure(shallow_tree, input_tree)\n\nThe following code will raise an exception: \n\n shallow_tree = [\"a\", \"b\"]\n input_tree = [\"c\", [\"d\", \"e\"], \"f\"]\n assert_shallow_structure(shallow_tree, input_tree)\n\nThe following code will not raise an exception: \n\n shallow_tree = [\"a\", \"b\"]\n input_tree = [\"c\", [\"d\", \"e\"], \"f\"]\n assert_shallow_structure(shallow_tree, input_tree,\n check_subtrees_length=False)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shallow_tree` | an arbitrarily nested structure. |\n| `input_tree` | an arbitrarily nested structure. |\n| `check_types` | if `True` (default) the sequence types of `shallow_tree` and `input_tree` have to be the same. Note that even with check_types==True, this function will consider two different namedtuple classes with the same name and _fields attribute to be the same class. |\n| `expand_composites` | If true, then composite tensors such as tf.SparseTensor and tf.RaggedTensor are expanded into their component tensors. |\n| `check_subtrees_length` | if `True` (default) the subtrees `shallow_tree` and `input_tree` have to be the same length. If `False` sequences are treated as key-value like mappings allowing them to be considered as valid subtrees. Note that this may drop parts of the `input_tree`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------------------------------------------------|\n| `TypeError` | If `shallow_tree` is a sequence but `input_tree` is not. |\n| `TypeError` | If the sequence types of `shallow_tree` are different from `input_tree`. Only raised if `check_types` is `True`. |\n| `ValueError` | If the sequence lengths of `shallow_tree` are different from `input_tree`. |\n\n\u003cbr /\u003e"]]