code: def _covar_from_vol(volatility, dim, dtype):
      rank = len(volatility.shape)
      if not rank:
          return volatility * volatility * tf.eye(dim, dtype=dtype)
      if rank == 1:
          return tf.linalg.tensor_diag(volatility * volatility)
      return tf.linalg.matmul(volatility, volatility, transpose_b=True)
  
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 10 for calling a global function with example usage: _covar_from_vol(volatility, dim, dtype) and returns: tf, unknown, tf