code: def reduce_mean(X, lengths, *, threads_per_block=128, num_blocks=128):
      _is_float_array(X)
  
      B = len(lengths)
      T = X.shape[0]
      O = X.shape[1]
  
      _check_lengths(lengths, T)
  
      out = _alloc((B, O), dtype=X.dtype, zeros=True)
  
      if X.dtype == "float32":
          reduce_sum_kernel_float(
              (num_blocks,),
              (threads_per_block,),
              (out, X, lengths, B, T, O),
          )
      else:
          reduce_sum_kernel_double(
              (num_blocks,),
              (threads_per_block,),
              (out, X, lengths, B, T, O),
          )
  
      # Avoid divide by zero
      out /= lengths.reshape((-1, 1)) + 1e-10
      return out
  
imports: import operator
  import re
  from collections import defaultdict
  from functools import reduce
  from pathlib import Path
  from typing import Callable, Optional, Tuple
  import numpy
  from ..compat import cupy, has_cupy_gpu
label_desc: Use image node_id 14 for calling a global function with example usage: reduce_mean(X, lengths) and returns: out