def _try_tf_pool(op_name, operand, window_dimensions, window_strides, padding, base_dilation, window_dilation) -> TfVal:

    def error(msg):
        suffix = 'See source code for the precise conditions under which reduce_window can be converted without XLA.'
        return _xla_disabled_error('reduce_window', f'{msg} - {suffix}')
    dtype = operand.dtype
    if ((op_name == 'reduce_window_max') and (dtype in [tf.bool, tf.uint32, tf.uint64, tf.complex64, tf.complex128])):
        raise error(f'tf.nn.max_pool does not support operands of type {dtype}')
    if ((op_name == 'reduce_window_sum') and (operand.dtype not in [tf.float16, tf.float32, tf.float64])):
        raise error(f'tf.nn.avg_pool does not support operands of type {dtype}')
    has_batch_dim = (window_dimensions[0] == 1)
    has_channel_dim = (window_dimensions[(- 1)] == 1)
    nb_spatial_dimensions = ((len(operand.shape) - has_batch_dim) - has_channel_dim)
    if ((nb_spatial_dimensions < 1) or (nb_spatial_dimensions > 3)):
        raise error('TensorFlow can only handle pooling for arrays with 1, 2, or 3 spatial dimensions')
    if (list(base_dilation) != ([1] * len(operand.shape))):
        raise error('Unimplemented support for base dilation')
    if (list(window_dilation) != ([1] * len(operand.shape))):
        raise error('Unimplemented support for window dilation')
    if (list(padding) != ([(0, 0)] * len(operand.shape))):
        raise error('Unimplemented support for padding')
    tf_operand = operand
    tf_window_dimensions = list(window_dimensions)
    tf_window_strides = list(window_strides)
    if (not has_batch_dim):
        tf_operand = tf.expand_dims(tf_operand, 0)
        tf_window_dimensions = ([1] + tf_window_dimensions)
        tf_window_strides = ([1] + tf_window_strides)
    if (not has_channel_dim):
        tf_operand = tf.expand_dims(tf_operand, (- 1))
        tf_window_dimensions.append(1)
        tf_window_strides.append(1)
    tf_data_format = (('N' + 'DHW'[(- nb_spatial_dimensions):]) + 'C')
    tf_padding = 'VALID'
    if (op_name == 'reduce_window_max'):
        result = tf.nn.max_pool(tf_operand, tf_window_dimensions, tf_window_strides, tf_padding, tf_data_format)
    elif (op_name == 'reduce_window_sum'):
        avg = tf.nn.avg_pool(tf_operand, tf_window_dimensions, tf_window_strides, tf_padding, tf_data_format)
        result = (avg * np.prod(tf_window_dimensions))
    else:
        raise error(f'Unimplemented support for {op_name}')
    if (not has_batch_dim):
        result = tf.squeeze(result, 0)
    if (not has_channel_dim):
        result = tf.squeeze(result, (- 1))
    return result
def _try_tf_pool(op_name, operand, window_dimensions, window_strides, padding, base_dilation, window_dilation) -> TfVal:

    def error(msg):
        suffix = 'See source code for the precise conditions under which reduce_window can be converted without XLA.'
        return _xla_disabled_error('reduce_window', f'{msg} - {suffix}')
    dtype = operand.dtype
    if ((op_name == 'reduce_window_max') and (dtype in [tf.bool, tf.uint32, tf.uint64, tf.complex64, tf.complex128])):
        raise error(f'tf.nn.max_pool does not support operands of type {dtype}')
    if ((op_name == 'reduce_window_sum') and (operand.dtype not in [tf.float16, tf.float32, tf.float64])):
        raise error(f'tf.nn.avg_pool does not support operands of type {dtype}')
    has_batch_dim = (window_dimensions[0] == 1)
    has_channel_dim = (window_dimensions[(- 1)] == 1)
    nb_spatial_dimensions = ((len(operand.shape) - has_batch_dim) - has_channel_dim)
    if ((nb_spatial_dimensions < 1) or (nb_spatial_dimensions > 3)):
        raise error('TensorFlow can only handle pooling for arrays with 1, 2, or 3 spatial dimensions')
    if (list(base_dilation) != ([1] * len(operand.shape))):
        raise error('Unimplemented support for base dilation')
    if (list(window_dilation) != ([1] * len(operand.shape))):
        raise error('Unimplemented support for window dilation')
    if (list(padding) != ([(0, 0)] * len(operand.shape))):
        raise error('Unimplemented support for padding')
    tf_operand = operand
    tf_window_dimensions = list(window_dimensions)
    tf_window_strides = list(window_strides)
    if (not has_batch_dim):
        tf_operand = tf.expand_dims(tf_operand, 0)
        tf_window_dimensions = ([1] + tf_window_dimensions)
        tf_window_strides = ([1] + tf_window_strides)
    if (not has_channel_dim):
        tf_operand = tf.expand_dims(tf_operand, (- 1))
        tf_window_dimensions.append(1)
        tf_window_strides.append(1)
    tf_data_format = (('N' + 'DHW'[(- nb_spatial_dimensions):]) + 'C')
    tf_padding = 'VALID'
    if (op_name == 'reduce_window_max'):
        result = tf.nn.max_pool(tf_operand, tf_window_dimensions, tf_window_strides, tf_padding, tf_data_format)
    elif (op_name == 'reduce_window_sum'):
        avg = tf.nn.avg_pool(tf_operand, tf_window_dimensions, tf_window_strides, tf_padding, tf_data_format)
        result = (avg * np.prod(tf_window_dimensions))
    else:
        raise error(f'Unimplemented support for {op_name}')
    if (not has_batch_dim):
        result = tf.squeeze(result, 0)
    if (not has_channel_dim):
        result = tf.squeeze(result, (- 1))
    return result