code: def _reduce_monoid(
      operand,
      window_dimensions,
      window_strides,
      padding,
      base_dilation,
      window_dilation,
      computation_name,
      _in_avals: Sequence[core.ShapedArray],
      _out_aval: core.ShapedArray,
  ):
      dtype = operand.dtype
      # In presence of shape polymorphism, operand.shape may contain None. The
      # actual dimension polynomial shapes are in _in_avals.
      operand_shape = _in_avals[0].shape
  
      # TODO(marcvanzee): Put reduce_window arguments into dataclass, similar to
      # Gather, to simplify function calls.
      has_only_spatial_dims = _validate_reduce_window_inputs(
          operand_shape,
          computation_name,
          dtype,
          window_dimensions,
          window_strides,
          base_dilation,
          window_dilation,
      )
  
      operand, operand_shape, padding_type = _padding_reduce_window(
          operand,
          operand_shape,
          computation_name,
          window_dimensions,
          window_strides,
          padding,
      )
  
      (
          operand,
          window_dimensions,
          window_strides,
          dilations,
      ) = _reshape_reduce_window(
          operand,
          operand_shape,
          window_dimensions,
          window_strides,
          window_dilation,
          has_only_spatial_dims=has_only_spatial_dims,
      )
  
      def tf_pool(inputs, pooling_type):
          if any(
              not core.is_constant_shape(s)
              for s in (window_dimensions, window_strides, dilations)
          ):
              raise NotImplementedError(
                  f"TODO: use tf.nn.pool with dynamic shapes¨{window_dimensions=} "
                  f" {window_strides=} {dilations=}"
              )
          # tf.nn.pool() currently does not suport tf.int32 and so we cast back and
          # forth in order to be able to convert.
          if (
              inputs.dtype in [tf.int16, tf.int32]
          ) and computation_name == "add":
              original_dtype = inputs.dtype
              inputs = tf.cast(inputs, dtype=tf.float32)
          else:
              original_dtype = None
          result = tf.nn.pool(
              inputs,
              window_shape=window_dimensions,
              pooling_type=pooling_type,
              padding=padding_type,
              strides=window_strides,
              dilations=dilations,
          )
          if original_dtype:
              result = tf.cast(result, dtype=original_dtype)
  
          if has_only_spatial_dims:
              # If the input only had spatial dimensions we need to contract the batch
              # and channel dimensions before returning the output.
              result = tf.squeeze(result, [0, -1])
  
          jax2tf._assert_matching_abstract_shape(
              result, _out_aval.shape
          )
          return result
  
      negate = lambda x: tf.multiply(x, tf.constant(-1, dtype))
      if computation_name == "max":
          return tf_pool(operand, "MAX")
      elif computation_name == "min":
          return negate(tf_pool(negate(operand), "MAX"))
      elif computation_name == "add":
          # TODO(marcvanzee): This may give very large deviations on TPU when using
          # floats as inputs. Alternatively, we could implement this using a
          # convolution with an all-1's kernel.
          return tf.multiply(
              tf_pool(operand, "AVG"), math.prod(window_dimensions)
          )
  
imports: from __future__ import annotations
  import builtins
  from collections.abc import Sequence
  import dataclasses
  from functools import partial, wraps
  import math
  import string
  from typing import Any, Callable, Optional
  from jax._src import core
  from jax import lax
  from jax._src.lax import slicing
  from jax._src import dtypes
  from jax._src import util
  from jax.experimental.jax2tf import jax2tf
  import numpy
  import tensorflow
label_desc: Use image node_id 22 for calling a global function with example usage: _reduce_monoid(operand, window_dimensions, window_strides, padding, base_dilation, window_dilation, computation_name, _in_avals, _out_aval) and returns: result, tf_pool, negate, tf