# Path: planet/tools/nested.py
# def zip_(*structures, **kwargs):
# def map_(function, *structures, **kwargs):
#   def impl(function, *structures):
# def flatten_(structure):
# def filter_(predicate, *structures, **kwargs):
#   def impl(predicate, *structures):


import tensorflow as tf
from planet.tools import nested
    num_chunks: Optionally specify the exact number of chunks to be extracted
        from the sequence. Requires input to be long enough.

  Returns:
    Nested dict of sequence tensors with chunk dimension.
  """
  with tf.device('/cpu:0'):
    if 'length' in sequence:
      length = sequence.pop('length')
    else:
      length = tf.shape(nested.flatten(sequence)[0])[0]
    if randomize:
      if num_chunks is None:
        num_chunks = tf.maximum(1, length // chunk_length - 1)
      else:
        num_chunks = num_chunks + 0 * length
      used_length = num_chunks * chunk_length
      max_offset = length - used_length
      offset = tf.random_uniform((), 0, max_offset + 1, dtype=tf.int32)
    else:
      if num_chunks is None:
        num_chunks = length // chunk_length
      else:
        num_chunks = num_chunks + 0 * length
      used_length = num_chunks * chunk_length
      max_offset = 0
      offset = 0
    clipped = nested.map(
        lambda tensor: tensor[offset: offset + used_length],
        sequence)

# Path: planet/tools/nested.py
# def zip_(*structures, **kwargs):
# def map_(function, *structures, **kwargs):
#   def impl(function, *structures):
# def flatten_(structure):
# def filter_(predicate, *structures, **kwargs):
#   def impl(predicate, *structures):


# Path: planet/tools/chunk_sequence.py
import tensorflow as tf
from planet.tools import nested

    num_chunks: Optionally specify the exact number of chunks to be extracted
        from the sequence. Requires input to be long enough.

  Returns:
    Nested dict of sequence tensors with chunk dimension.
  """
  with tf.device('/cpu:0'):
    if 'length' in sequence:
      length = sequence.pop('length')
    else:
      length = tf.shape(nested.flatten(sequence)[0])[0]
    if randomize:
      if num_chunks is None:
        num_chunks = tf.maximum(1, length // chunk_length - 1)
      else:
        num_chunks = num_chunks + 0 * length
      used_length = num_chunks * chunk_length
      max_offset = length - used_length
      offset = tf.random_uniform((), 0, max_offset + 1, dtype=tf.int32)
    else:
      if num_chunks is None:
        num_chunks = length // chunk_length
      else:
        num_chunks = num_chunks + 0 * length
      used_length = num_chunks * chunk_length
      max_offset = 0
      offset = 0
    clipped = nested.map(
        lambda tensor: tensor[offset: offset + used_length],
        sequence)

    chunks = nested.map(