keras/src/layers/pooling/global_average_pooling1d.py/GlobalAveragePooling1D/call
class GlobalAveragePooling1D:    def call(self, inputs, mask=None):
        steps_axis = 1 if self.data_format == "channels_last" else 2
        if mask is not None:
            mask = backend.cast(mask, inputs[0].dtype)
            mask = ops.expand_dims(
                mask, 2 if self.data_format == "channels_last" else 1
            )
            inputs *= mask
            return ops.sum(
                inputs, axis=steps_axis, keepdims=self.keepdims
            ) / ops.sum(mask, axis=steps_axis, keepdims=self.keepdims)
        else:
            return ops.mean(inputs, axis=steps_axis, keepdims=self.keepdims)