code: def pool1d(x, window_length, name, mode="avg", stride=None):
      """1D pooling function that supports multiple different modes.
  
      Args:
        x: The [mb, time, channels] float tensor that we are going to pool over.
        window_length: The amount of samples we pool over.
        name: The name of the scope for the variables.
        mode: The type of pooling, either avg or max.
        stride: The stride length.
  
      Returns:
        pooled: The [mb, time // stride, channels] float tensor result of pooling.
      """
      if mode == "avg":
          pool_fn = tf.nn.avg_pool
      elif mode == "max":
          pool_fn = tf.nn.max_pool
  
      stride = stride or window_length
      batch_size, length, num_channels = x.get_shape().as_list()
      assert length % window_length == 0
      assert length % stride == 0
  
      window_shape = [1, 1, window_length, 1]
      strides = [1, 1, stride, 1]
      x_4d = tf.reshape(x, [batch_size, 1, length, num_channels])
      pooled = pool_fn(
          x_4d, window_shape, strides, padding="SAME", name=name
      )
      return tf.reshape(
          pooled, [batch_size, length // stride, num_channels]
      )
  
file_path: magenta/magenta/models/nsynth/wavenet/masked.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow.compat.v1
label_desc: Use image node_id 6 for calling a global function with example usage: pool1d(x, window_length, name, mode, stride) and returns: tf