W3cubDocs

/TensorFlow Python

tf.contrib.framework.nest.assert_same_structure

tf.contrib.framework.nest.assert_same_structure(
    nest1,
    nest2,
    check_types=True
)

Defined in tensorflow/python/util/nest.py.

Asserts that two structures are nested in the same way.

Note that namedtuples with identical name and fields are always considered to have the same shallow structure (even with check_types=True). For intance, this code will print True:

def nt(a, b):
  return collections.namedtuple('foo', 'a b')(a, b)
print(assert_same_structure(nt(0, 1), nt(2, 3)))

Args:

  • nest1: an arbitrarily nested structure.
  • nest2: an arbitrarily nested structure.
  • check_types: if True (default) types of sequences are checked as well, including the keys of dictionaries. If set to False, for example a list and a tuple of objects will look the same if they have the same size. Note that namedtuples with identical name and fields are always considered to have the same shallow structure.

Raises:

  • ValueError: If the two structures do not have the same number of elements or if the two structures are not nested in the same way.
  • TypeError: If the two structures differ in the type of sequence in any of their substructures. Only possible if check_types is True.

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/framework/nest/assert_same_structure