code: def construct_vol_data(volatility, total_covariance_fn, dim, dtype):
      """Constructs volatility data.
  
      This function resolves the supplied arguments in to the following ten cases:
      (vol -> volatility, total_covar -> total_covariance_fn)
      1. vol and total_covar are both None -> Return default values.
      2. total_covar is supplied and vol is None -> compute vol from total covar.
      3. total_covar is supplied and vol is a callable -> Return supplied values.
      4. total_covar is supplied and vol is a scalar constant.
      5. total_covar is supplied and vol is a vector constant.
      6. total_covar is supplied and vol is a matrix constant.
      7. total_covar is not supplied and vol is a callable -> Return None for total
        covariance function.
      8. total_covar is not supplied and vol is a scalar constant.
      9. total_covar is not supplied and vol is a vector constant.
      10. total_covar is not supplied and vol is a matrix.
  
      For cases 4, 5 and 6 we create an appropriate volatility fn. For cases 8
      through to 10 we do the same but also create an appropriate covariance
      function.
  
      Args:
        volatility: The volatility specification. None or a callable or a scalar,
          vector or matrix.
        total_covariance_fn: The total covariance function. Either None or a
          callable.
        dim: int. The dimension of the process.
        dtype: The default dtype to use.
  
      Returns:
        A tuple of two callables:
          volatility_fn: A function accepting a time argument and returning
            the volatility at that time.
          total_covariance_fn: A function accepting two time arguments and
            returning the total covariance between the two times.
      """
      # Case 1
      if volatility is None and total_covariance_fn is None:
          return _default_vol_data(dim, dtype)
  
      if total_covariance_fn is not None:
          # Case 2
          if volatility is None:
              vol_fn = _volatility_fn_from_total_covar_fn(
                  total_covariance_fn
              )
              return vol_fn, total_covariance_fn
          # Case 3
          if is_callable(volatility):
              return volatility, total_covariance_fn
          # Cases 4, 5, 6
          return _construct_vol_data_const_vol(
              volatility, total_covariance_fn, dim, dtype
          )
  
      # Case 7.
      if is_callable(volatility):
          # TODO(b/141091950): Add numerical integration.
          return volatility, None
  
      # Cases 8-10
      return _construct_vol_data_const_vol(volatility, None, dim, dtype)
  
file_path: tf-quant-finance/tf_quant_finance/models/legacy/brownian_motion_utils.py
imports: import tensorflow.compat.v2
  from tf_quant_finance.math import gradient
label_desc: Use image node_id 4 for calling a global function with example usage: construct_vol_data(volatility, total_covariance_fn, dim, dtype) and returns: _construct_vol_data_const_vol, _default_vol_data, _construct_vol_data_const_vol, volatility,  None, vol_fn,  total_covariance_fn, volatility,  total_covariance_fn